blob: b45f3b41929ab8549901ad3791d13e8c4efdae50 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010034import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070035import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000036import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080037import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080038import android.os.RemoteException;
39import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070040import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040041import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040042import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010043import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070044import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080045import android.util.Log;
46
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070047import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040048import com.android.org.conscrypt.TrustedCertificateStore;
49
Jessica Hummel91da58d2014-04-10 17:39:43 +010050import org.xmlpull.v1.XmlPullParserException;
51
Maggie Benthallda51e682013-08-08 22:35:44 -040052import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080053import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070054import java.net.InetSocketAddress;
55import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010056import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010057import java.security.PrivateKey;
58import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040059import java.security.cert.CertificateException;
60import java.security.cert.CertificateFactory;
61import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010062import java.security.spec.PKCS8EncodedKeySpec;
63import java.security.spec.InvalidKeySpecException;
64import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070065import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070066import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080067import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080068
69/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000070 * Public interface for managing policies enforced on a device. Most clients of this class must be
71 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000072 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000073 * a device administrator may be registered as either a profile or device owner. A given method is
74 * accessible to all device administrators unless the documentation for that method specifies that
75 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080076 *
77 * <div class="special reference">
78 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000079 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080080 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070081 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080083 */
84public class DevicePolicyManager {
85 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080086
87 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080088 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070089
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070090 private DevicePolicyManager(Context context) {
91 this(context, IDevicePolicyManager.Stub.asInterface(
92 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Dianne Hackbornd6847842010-01-12 18:14:19 -080093 }
94
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080095 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070096 @VisibleForTesting
97 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
98 mContext = context;
99 mService = service;
100 }
101
102 /** @hide */
103 public static DevicePolicyManager create(Context context) {
104 DevicePolicyManager me = new DevicePolicyManager(context);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800105 return me.mService != null ? me : null;
106 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700107
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700108 /** @hide test will override it. */
109 @VisibleForTesting
110 protected int myUserId() {
111 return UserHandle.myUserId();
112 }
113
Dianne Hackbornd6847842010-01-12 18:14:19 -0800114 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000115 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100117 * <p>A managed profile allows data separation for example for the usage of a
118 * device as a personal and corporate device. The user which provisioning is started from and
119 * the managed profile share a launcher.
120 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800121 * <p>This intent will typically be sent by a mobile device management application (MDM).
122 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
123 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100124 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000125 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
126 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700127 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000128 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
129 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000131 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
132 * in the provisioning intent. The
133 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
134 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
135 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100136 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100137 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
138 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100139 *
140 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
141 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
142 * the provisioning flow was successful, although this doesn't guarantee the full flow will
143 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
144 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000145 */
146 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
147 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100148 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000149
150 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100151 * Activity action: Starts the provisioning flow which sets up a managed device.
152 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
153 *
154 * <p> During device owner provisioning a device admin app is set as the owner of the device.
155 * A device owner has full control over the device. The device owner can not be modified by the
156 * user.
157 *
158 * <p> A typical use case would be a device that is owned by a company, but used by either an
159 * employee or client.
160 *
161 * <p> An intent with this action can be sent only on an unprovisioned device.
162 * It is possible to check if the device is provisioned or not by looking at
163 * {@link android.provider.Settings.Global#DEVICE_PROVISIONED}
164 *
165 * The intent contains the following extras:
166 * <ul>
167 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
168 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
169 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100170 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100171 * </ul>
172 *
173 * <p> When device owner provisioning has completed, an intent of the type
174 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
175 * device owner.
176 *
177 * <p> If provisioning fails, the device is factory reset.
178 *
Alan Treadway4582f812015-07-28 11:49:35 +0100179 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
180 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
181 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
182 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100183 */
184 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
185 public static final String ACTION_PROVISION_MANAGED_DEVICE
186 = "android.app.action.PROVISION_MANAGED_DEVICE";
187
188 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100189 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100190 * allows a mobile device management application or NFC programmer application which starts
191 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100192 * <p>
193 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
194 * sends the intent to pass data to itself on the newly created profile.
195 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
196 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100197 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
198 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
199 * message should contain a stringified {@link java.util.Properties} instance, whose string
200 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
201 * management application after provisioning.
202 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100203 * <p>
204 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700205 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
206 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100207 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100208 */
209 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100210 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100211
212 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100213 * A String extra holding the package name of the mobile device management application that
214 * will be set as the profile owner or device owner.
215 *
216 * <p>If an application starts provisioning directly via an intent with action
217 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
218 * application that started provisioning. The package will be set as profile owner in that case.
219 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000220 * <p>This package is set as device owner when device owner provisioning is started by an NFC
221 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000222 *
223 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700224 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000225
226 * @see DeviceAdminReceiver
227 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100228 * supported, but only if there is only one device admin receiver in the package that requires
229 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000230 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000231 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000232 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100233 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000234
235 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000236 * A ComponentName extra indicating the device admin receiver of the mobile device management
237 * application that will be set as the profile owner or device owner and active admin.
238 *
239 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100240 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
241 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
242 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000243 *
244 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100245 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
246 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400247 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000248 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000249 *
250 * @see DeviceAdminReceiver
251 */
252 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
253 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
254
255 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000256 * An {@link android.accounts.Account} extra holding the account to migrate during managed
257 * profile provisioning. If the account supplied is present in the primary user, it will be
258 * copied, along with its credentials to the managed profile and removed from the primary user.
259 *
260 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
261 */
262
263 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
264 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
265
266 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100267 * A String extra that, holds the email address of the account which a managed profile is
268 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
269 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100270 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100271 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
272 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100273 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
274 * contains this extra, it is forwarded in the
275 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
276 * device management application that was set as the profile owner during provisioning.
277 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100278 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100279 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
280 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100281
282 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000283 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700284 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000285 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100286 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
287 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000288 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000289 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
290 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000291
292 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100293 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
294 * will be set to.
295 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000296 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
297 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100298 */
299 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100300 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100301
302 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100303 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
304 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100305 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000306 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
307 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100308 */
309 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100310 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100311
312 /**
313 * A String extra holding the {@link java.util.Locale} that the device will be set to.
314 * Format: xx_yy, where xx is the language code, and yy the country code.
315 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000316 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
317 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100318 */
319 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100320 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100321
322 /**
323 * A String extra holding the ssid of the wifi network that should be used during nfc device
324 * owner provisioning for downloading the mobile device management application.
325 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000326 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
327 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100328 */
329 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100330 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100331
332 /**
333 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
334 * is hidden or not.
335 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000336 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
337 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100338 */
339 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100340 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100341
342 /**
343 * A String extra indicating the security type of the wifi network in
344 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
345 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000346 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
347 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100348 */
349 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100350 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100351
352 /**
353 * A String extra holding the password of the wifi network in
354 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
355 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000356 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
357 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100358 */
359 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100360 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100361
362 /**
363 * A String extra holding the proxy host for the wifi network in
364 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
365 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000366 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
367 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100368 */
369 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100370 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100371
372 /**
373 * An int extra holding the proxy port for the wifi network in
374 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
375 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000376 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
377 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100378 */
379 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100380 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100381
382 /**
383 * A String extra holding the proxy bypass for the wifi network in
384 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
385 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000386 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
387 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100388 */
389 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100390 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100391
392 /**
393 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
394 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
395 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000396 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
397 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100398 */
399 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100400 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100401
402 /**
403 * A String extra holding a url that specifies the download location of the device admin
404 * package. When not provided it is assumed that the device admin package is already installed.
405 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000406 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
407 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100408 */
409 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100410 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100411
412 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400413 * An int extra holding a minimum required version code for the device admin package. If the
414 * device admin is already installed on the device, it will only be re-downloaded from
415 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
416 * installed package is less than this version code.
417 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400418 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400419 * provisioning via an NFC bump.
420 */
421 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
422 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
423
424 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100425 * A String extra holding a http cookie header which should be used in the http request to the
426 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
427 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000428 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
429 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100430 */
431 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100432 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100433
434 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100435 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
436 * the file at download location specified in
437 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100438 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100439 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100440 * present. The provided checksum should match the checksum of the file at the download
441 * location. If the checksum doesn't match an error will be shown to the user and the user will
442 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100443 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000444 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
445 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100446 *
447 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
448 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700449 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100450 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100451 */
452 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100453 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100454
455 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100456 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100457 * android package archive at the download location specified in {@link
458 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
459 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100460 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100461 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
462 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
463 *
464 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100465 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100466 * the download location. If the checksum does not match an error will be shown to the user and
467 * the user will be asked to factory reset the device.
468 *
469 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
470 * provisioning via an NFC bump.
471 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100472 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
473 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100474
475 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000476 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
477 * has completed successfully.
478 *
479 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700480 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000481 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800482 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000483 * corresponds to the account requested to be migrated at provisioning time, if any.
484 */
485 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
486 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
487 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
488
489 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400490 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500491 * provisioning.
492 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400493 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100494 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500495 */
496 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
497 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
498
499 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400500 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100501 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400502 * <p>During device owner provisioning a device admin app is set as the owner of the device.
503 * A device owner has full control over the device. The device owner can not be modified by the
504 * user and the only way of resetting the device is if the device owner app calls a factory
505 * reset.
506 *
507 * <p> A typical use case would be a device that is owned by a company, but used by either an
508 * employee or client.
509 *
510 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100511 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000512 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100513 * contains the following properties:
514 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400515 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
516 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100517 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400518 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100519 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
520 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
521 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
522 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
523 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
524 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
525 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
526 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
527 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
528 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100529 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
530 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
531 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100532 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000533 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700534 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400535 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
536 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
537 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400538 */
539 public static final String MIME_TYPE_PROVISIONING_NFC
540 = "application/com.android.managedprovisioning";
541
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100542 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800543 * Activity action: ask the user to add a new device administrator to the system.
544 * The desired policy is the ComponentName of the policy in the
545 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
546 * bring the user through adding the device administrator to the system (or
547 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700548 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800549 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
550 * field to provide the user with additional explanation (in addition
551 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800552 *
553 * <p>If your administrator is already active, this will ordinarily return immediately (without
554 * user intervention). However, if your administrator has been updated and is requesting
555 * additional uses-policy flags, the user will be presented with the new list. New policies
556 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800557 */
558 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
559 public static final String ACTION_ADD_DEVICE_ADMIN
560 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700561
Dianne Hackbornd6847842010-01-12 18:14:19 -0800562 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700563 * @hide
564 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700565 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700566 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700567 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
568 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700569 * to remotely control restrictions on the user.
570 *
571 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
572 * result of whether or not the user approved the action. If approved, the result will
573 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
574 * as a profile owner.
575 *
576 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
577 * field to provide the user with additional explanation (in addition
578 * to your component's description) about what is being added.
579 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700580 * <p>If there is already a profile owner active or the caller is not a system app, the
581 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700582 */
583 @SystemApi
584 public static final String ACTION_SET_PROFILE_OWNER
585 = "android.app.action.SET_PROFILE_OWNER";
586
587 /**
588 * @hide
589 * Name of the profile owner admin that controls the user.
590 */
591 @SystemApi
592 public static final String EXTRA_PROFILE_OWNER_NAME
593 = "android.app.extra.PROFILE_OWNER_NAME";
594
595 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100596 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700597 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700598 *
Jim Miller284b62e2010-06-08 14:27:42 -0700599 * @hide
600 */
601 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
602 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
603
604 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100605 * Broadcast action: sent when the device owner is set or changed.
606 *
607 * This broadcast is sent only to the primary user.
608 * @see #ACTION_PROVISION_MANAGED_DEVICE
609 */
610 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
611 public static final String ACTION_DEVICE_OWNER_CHANGED
612 = "android.app.action.DEVICE_OWNER_CHANGED";
613
614 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800615 * The ComponentName of the administrator component.
616 *
617 * @see #ACTION_ADD_DEVICE_ADMIN
618 */
619 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700620
Dianne Hackbornd6847842010-01-12 18:14:19 -0800621 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800622 * An optional CharSequence providing additional explanation for why the
623 * admin is being added.
624 *
625 * @see #ACTION_ADD_DEVICE_ADMIN
626 */
627 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700628
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800629 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700630 * Activity action: have the user enter a new password. This activity should
631 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
632 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
633 * enter a new password that meets the current requirements. You can use
634 * {@link #isActivePasswordSufficient()} to determine whether you need to
635 * have the user select a new password in order to meet the current
636 * constraints. Upon being resumed from this activity, you can check the new
637 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800638 */
639 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
640 public static final String ACTION_SET_NEW_PASSWORD
641 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700642
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000643 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000644 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
645 * the parent profile to access intents sent from the managed profile.
646 * That is, when an app in the managed profile calls
647 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
648 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000649 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100650 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000651
652 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000653 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
654 * the managed profile to access intents sent from the parent profile.
655 * That is, when an app in the parent profile calls
656 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
657 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000658 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100659 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700660
Dianne Hackbornd6847842010-01-12 18:14:19 -0800661 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100662 * Broadcast action: notify that a new local system update policy has been set by the device
663 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000664 */
665 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100666 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
667 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000668
Amith Yamasanid49489b2015-04-28 14:00:26 -0700669 /**
670 * Permission policy to prompt user for new permission requests for runtime permissions.
671 * Already granted or denied permissions are not affected by this.
672 */
673 public static final int PERMISSION_POLICY_PROMPT = 0;
674
675 /**
676 * Permission policy to always grant new permission requests for runtime permissions.
677 * Already granted or denied permissions are not affected by this.
678 */
679 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
680
681 /**
682 * Permission policy to always deny new permission requests for runtime permissions.
683 * Already granted or denied permissions are not affected by this.
684 */
685 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
686
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700687 /**
688 * Runtime permission state: The user can manage the permission
689 * through the UI.
690 */
691 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
692
693 /**
694 * Runtime permission state: The permission is granted to the app
695 * and the user cannot manage the permission through the UI.
696 */
697 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
698
699 /**
700 * Runtime permission state: The permission is denied to the app
701 * and the user cannot manage the permission through the UI.
702 */
703 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000704
705 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800706 * Return true if the given administrator component is currently
707 * active (enabled) in the system.
708 */
Robin Lee25e26452015-06-02 09:56:29 -0700709 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700710 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100711 }
712
713 /**
714 * @see #isAdminActive(ComponentName)
715 * @hide
716 */
Robin Lee25e26452015-06-02 09:56:29 -0700717 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800718 if (mService != null) {
719 try {
Robin Lee25e26452015-06-02 09:56:29 -0700720 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800721 } catch (RemoteException e) {
722 Log.w(TAG, "Failed talking with device policy service", e);
723 }
724 }
725 return false;
726 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800727 /**
728 * Return true if the given administrator component is currently being removed
729 * for the user.
730 * @hide
731 */
Robin Lee25e26452015-06-02 09:56:29 -0700732 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800733 if (mService != null) {
734 try {
Robin Lee25e26452015-06-02 09:56:29 -0700735 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800736 } catch (RemoteException e) {
737 Log.w(TAG, "Failed talking with device policy service", e);
738 }
739 }
740 return false;
741 }
742
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700743
Dianne Hackbornd6847842010-01-12 18:14:19 -0800744 /**
Robin Lee25e26452015-06-02 09:56:29 -0700745 * Return a list of all currently active device administrators' component
746 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800747 * returned.
748 */
749 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700750 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100751 }
752
753 /**
754 * @see #getActiveAdmins()
755 * @hide
756 */
757 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800758 if (mService != null) {
759 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100760 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800761 } catch (RemoteException e) {
762 Log.w(TAG, "Failed talking with device policy service", e);
763 }
764 }
765 return null;
766 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700767
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800768 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700769 * Used by package administration code to determine if a package can be stopped
770 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800771 * @hide
772 */
773 public boolean packageHasActiveAdmins(String packageName) {
774 if (mService != null) {
775 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700776 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800777 } catch (RemoteException e) {
778 Log.w(TAG, "Failed talking with device policy service", e);
779 }
780 }
781 return false;
782 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700783
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800784 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800785 * Remove a current administration component. This can only be called
786 * by the application that owns the administration component; if you
787 * try to remove someone else's component, a security exception will be
788 * thrown.
789 */
Robin Lee25e26452015-06-02 09:56:29 -0700790 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800791 if (mService != null) {
792 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700793 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800794 } catch (RemoteException e) {
795 Log.w(TAG, "Failed talking with device policy service", e);
796 }
797 }
798 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700799
Dianne Hackbornd6847842010-01-12 18:14:19 -0800800 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800801 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700802 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800803 * but requires additional policies after an upgrade.
804 *
805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
806 * an active administrator, or an exception will be thrown.
807 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
808 */
Robin Lee25e26452015-06-02 09:56:29 -0700809 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800810 if (mService != null) {
811 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700812 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800813 } catch (RemoteException e) {
814 Log.w(TAG, "Failed talking with device policy service", e);
815 }
816 }
817 return false;
818 }
819
820 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800821 * Constant for {@link #setPasswordQuality}: the policy has no requirements
822 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800823 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800824 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800825 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700826
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700828 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
829 * recognition technology. This implies technologies that can recognize the identity of
830 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
831 * Note that quality constants are ordered so that higher values are more restrictive.
832 */
833 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
834
835 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800836 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100837 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800838 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800839 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800840 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700841
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800842 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800843 * Constant for {@link #setPasswordQuality}: the user must have entered a
844 * password containing at least numeric characters. Note that quality
845 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800846 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800847 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700848
Dianne Hackbornd6847842010-01-12 18:14:19 -0800849 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800850 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800851 * password containing at least numeric characters with no repeating (4444)
852 * or ordered (1234, 4321, 2468) sequences. Note that quality
853 * constants are ordered so that higher values are more restrictive.
854 */
855 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
856
857 /**
858 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700859 * password containing at least alphabetic (or other symbol) characters.
860 * Note that quality constants are ordered so that higher values are more
861 * restrictive.
862 */
863 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700864
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700865 /**
866 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800867 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700868 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800869 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800870 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700871 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700872
Dianne Hackbornd6847842010-01-12 18:14:19 -0800873 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700874 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700875 * password containing at least a letter, a numerical digit and a special
876 * symbol, by default. With this password quality, passwords can be
877 * restricted to contain various sets of characters, like at least an
878 * uppercase letter, etc. These are specified using various methods,
879 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
880 * that quality constants are ordered so that higher values are more
881 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700882 */
883 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
884
885 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800886 * Called by an application that is administering the device to set the
887 * password restrictions it is imposing. After setting this, the user
888 * will not be able to enter a new password that is not at least as
889 * restrictive as what has been set. Note that the current password
890 * will remain until the user has set a new one, so the change does not
891 * take place immediately. To prompt the user for a new password, use
892 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700893 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800894 * <p>Quality constants are ordered so that higher values are more restrictive;
895 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800896 * the user's preference, and any other considerations) is the one that
897 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700898 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800899 * <p>The calling device admin must have requested
900 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
901 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700902 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800904 * @param quality The new desired quality. One of
905 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800906 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
907 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
908 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800909 */
Robin Lee25e26452015-06-02 09:56:29 -0700910 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800911 if (mService != null) {
912 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800913 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800914 } catch (RemoteException e) {
915 Log.w(TAG, "Failed talking with device policy service", e);
916 }
917 }
918 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700919
Dianne Hackbornd6847842010-01-12 18:14:19 -0800920 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100921 * Retrieve the current minimum password quality for all admins of this user
922 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -0700923 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -0800924 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800925 */
Robin Lee25e26452015-06-02 09:56:29 -0700926 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700927 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700928 }
929
930 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -0700931 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800932 if (mService != null) {
933 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700934 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800935 } catch (RemoteException e) {
936 Log.w(TAG, "Failed talking with device policy service", e);
937 }
938 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800939 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800940 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700941
Dianne Hackbornd6847842010-01-12 18:14:19 -0800942 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800943 * Called by an application that is administering the device to set the
944 * minimum allowed password length. After setting this, the user
945 * will not be able to enter a new password that is not at least as
946 * restrictive as what has been set. Note that the current password
947 * will remain until the user has set a new one, so the change does not
948 * take place immediately. To prompt the user for a new password, use
949 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
950 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800951 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
952 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
953 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700954 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800955 * <p>The calling device admin must have requested
956 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
957 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700958 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800959 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800960 * @param length The new desired minimum password length. A value of 0
961 * means there is no restriction.
962 */
Robin Lee25e26452015-06-02 09:56:29 -0700963 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800964 if (mService != null) {
965 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800966 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800967 } catch (RemoteException e) {
968 Log.w(TAG, "Failed talking with device policy service", e);
969 }
970 }
971 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700972
Dianne Hackbornd6847842010-01-12 18:14:19 -0800973 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100974 * Retrieve the current minimum password length for all admins of this
975 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -0700976 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -0800977 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800978 */
Robin Lee25e26452015-06-02 09:56:29 -0700979 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700980 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700981 }
982
983 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -0700984 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800985 if (mService != null) {
986 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700987 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800988 } catch (RemoteException e) {
989 Log.w(TAG, "Failed talking with device policy service", e);
990 }
991 }
992 return 0;
993 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700994
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700995 /**
996 * Called by an application that is administering the device to set the
997 * minimum number of upper case letters required in the password. After
998 * setting this, the user will not be able to enter a new password that is
999 * not at least as restrictive as what has been set. Note that the current
1000 * password will remain until the user has set a new one, so the change does
1001 * not take place immediately. To prompt the user for a new password, use
1002 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1003 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001004 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1005 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001006 * <p>
1007 * The calling device admin must have requested
1008 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1009 * this method; if it has not, a security exception will be thrown.
1010 *
1011 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1012 * with.
1013 * @param length The new desired minimum number of upper case letters
1014 * required in the password. A value of 0 means there is no
1015 * restriction.
1016 */
Robin Lee25e26452015-06-02 09:56:29 -07001017 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001018 if (mService != null) {
1019 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001020 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001021 } catch (RemoteException e) {
1022 Log.w(TAG, "Failed talking with device policy service", e);
1023 }
1024 }
1025 }
1026
1027 /**
1028 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001029 * password for all admins of this user and its profiles or a particular one.
1030 * This is the same value as set by
1031 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001032 * and only applies when the password quality is
1033 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001034 *
Robin Lee25e26452015-06-02 09:56:29 -07001035 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001036 * aggregate all admins.
1037 * @return The minimum number of upper case letters required in the
1038 * password.
1039 */
Robin Lee25e26452015-06-02 09:56:29 -07001040 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001041 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001042 }
1043
1044 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001045 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001046 if (mService != null) {
1047 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001048 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001049 } catch (RemoteException e) {
1050 Log.w(TAG, "Failed talking with device policy service", e);
1051 }
1052 }
1053 return 0;
1054 }
1055
1056 /**
1057 * Called by an application that is administering the device to set the
1058 * minimum number of lower case letters required in the password. After
1059 * setting this, the user will not be able to enter a new password that is
1060 * not at least as restrictive as what has been set. Note that the current
1061 * password will remain until the user has set a new one, so the change does
1062 * not take place immediately. To prompt the user for a new password, use
1063 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1064 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001065 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1066 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001067 * <p>
1068 * The calling device admin must have requested
1069 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1070 * this method; if it has not, a security exception will be thrown.
1071 *
1072 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1073 * with.
1074 * @param length The new desired minimum number of lower case letters
1075 * required in the password. A value of 0 means there is no
1076 * restriction.
1077 */
Robin Lee25e26452015-06-02 09:56:29 -07001078 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001079 if (mService != null) {
1080 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001081 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001082 } catch (RemoteException e) {
1083 Log.w(TAG, "Failed talking with device policy service", e);
1084 }
1085 }
1086 }
1087
1088 /**
1089 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001090 * password for all admins of this user and its profiles or a particular one.
1091 * This is the same value as set by
1092 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001093 * and only applies when the password quality is
1094 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001095 *
Robin Lee25e26452015-06-02 09:56:29 -07001096 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001097 * aggregate all admins.
1098 * @return The minimum number of lower case letters required in the
1099 * password.
1100 */
Robin Lee25e26452015-06-02 09:56:29 -07001101 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001102 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001103 }
1104
1105 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001106 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001107 if (mService != null) {
1108 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001109 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001110 } catch (RemoteException e) {
1111 Log.w(TAG, "Failed talking with device policy service", e);
1112 }
1113 }
1114 return 0;
1115 }
1116
1117 /**
1118 * Called by an application that is administering the device to set the
1119 * minimum number of letters required in the password. After setting this,
1120 * the user will not be able to enter a new password that is not at least as
1121 * restrictive as what has been set. Note that the current password will
1122 * remain until the user has set a new one, so the change does not take
1123 * place immediately. To prompt the user for a new password, use
1124 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1125 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001126 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1127 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001128 * <p>
1129 * The calling device admin must have requested
1130 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1131 * this method; if it has not, a security exception will be thrown.
1132 *
1133 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1134 * with.
1135 * @param length The new desired minimum number of letters required in the
1136 * password. A value of 0 means there is no restriction.
1137 */
Robin Lee25e26452015-06-02 09:56:29 -07001138 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001139 if (mService != null) {
1140 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001141 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001142 } catch (RemoteException e) {
1143 Log.w(TAG, "Failed talking with device policy service", e);
1144 }
1145 }
1146 }
1147
1148 /**
1149 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001150 * admins or a particular one. This is the same value as
1151 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1152 * and only applies when the password quality is
1153 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001154 *
Robin Lee25e26452015-06-02 09:56:29 -07001155 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001156 * aggregate all admins.
1157 * @return The minimum number of letters required in the password.
1158 */
Robin Lee25e26452015-06-02 09:56:29 -07001159 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001160 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001161 }
1162
1163 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001164 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001165 if (mService != null) {
1166 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001167 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001168 } catch (RemoteException e) {
1169 Log.w(TAG, "Failed talking with device policy service", e);
1170 }
1171 }
1172 return 0;
1173 }
1174
1175 /**
1176 * Called by an application that is administering the device to set the
1177 * minimum number of numerical digits required in the password. After
1178 * setting this, the user will not be able to enter a new password that is
1179 * not at least as restrictive as what has been set. Note that the current
1180 * password will remain until the user has set a new one, so the change does
1181 * not take place immediately. To prompt the user for a new password, use
1182 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1183 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001184 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1185 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001186 * <p>
1187 * The calling device admin must have requested
1188 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1189 * this method; if it has not, a security exception will be thrown.
1190 *
1191 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1192 * with.
1193 * @param length The new desired minimum number of numerical digits required
1194 * in the password. A value of 0 means there is no restriction.
1195 */
Robin Lee25e26452015-06-02 09:56:29 -07001196 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001197 if (mService != null) {
1198 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001199 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001200 } catch (RemoteException e) {
1201 Log.w(TAG, "Failed talking with device policy service", e);
1202 }
1203 }
1204 }
1205
1206 /**
1207 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001208 * for all admins of this user and its profiles or a particular one.
1209 * This is the same value as set by
1210 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001211 * and only applies when the password quality is
1212 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001213 *
Robin Lee25e26452015-06-02 09:56:29 -07001214 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001215 * aggregate all admins.
1216 * @return The minimum number of numerical digits required in the password.
1217 */
Robin Lee25e26452015-06-02 09:56:29 -07001218 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001219 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001220 }
1221
1222 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001223 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001224 if (mService != null) {
1225 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001226 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001227 } catch (RemoteException e) {
1228 Log.w(TAG, "Failed talking with device policy service", e);
1229 }
1230 }
1231 return 0;
1232 }
1233
1234 /**
1235 * Called by an application that is administering the device to set the
1236 * minimum number of symbols required in the password. After setting this,
1237 * the user will not be able to enter a new password that is not at least as
1238 * restrictive as what has been set. Note that the current password will
1239 * remain until the user has set a new one, so the change does not take
1240 * place immediately. To prompt the user for a new password, use
1241 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1242 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001243 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1244 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001245 * <p>
1246 * The calling device admin must have requested
1247 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1248 * this method; if it has not, a security exception will be thrown.
1249 *
1250 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1251 * with.
1252 * @param length The new desired minimum number of symbols required in the
1253 * password. A value of 0 means there is no restriction.
1254 */
Robin Lee25e26452015-06-02 09:56:29 -07001255 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001256 if (mService != null) {
1257 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001258 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001259 } catch (RemoteException e) {
1260 Log.w(TAG, "Failed talking with device policy service", e);
1261 }
1262 }
1263 }
1264
1265 /**
1266 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001267 * admins or a particular one. This is the same value as
1268 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1269 * and only applies when the password quality is
1270 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001271 *
Robin Lee25e26452015-06-02 09:56:29 -07001272 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001273 * aggregate all admins.
1274 * @return The minimum number of symbols required in the password.
1275 */
Robin Lee25e26452015-06-02 09:56:29 -07001276 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001277 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001278 }
1279
1280 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001281 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001282 if (mService != null) {
1283 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001284 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001285 } catch (RemoteException e) {
1286 Log.w(TAG, "Failed talking with device policy service", e);
1287 }
1288 }
1289 return 0;
1290 }
1291
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001292 /**
1293 * Called by an application that is administering the device to set the
1294 * minimum number of non-letter characters (numerical digits or symbols)
1295 * required in the password. After setting this, the user will not be able
1296 * to enter a new password that is not at least as restrictive as what has
1297 * been set. Note that the current password will remain until the user has
1298 * set a new one, so the change does not take place immediately. To prompt
1299 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1300 * setting this value. This constraint is only imposed if the administrator
1301 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1302 * {@link #setPasswordQuality}. The default value is 0.
1303 * <p>
1304 * The calling device admin must have requested
1305 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1306 * this method; if it has not, a security exception will be thrown.
1307 *
1308 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1309 * with.
1310 * @param length The new desired minimum number of letters required in the
1311 * password. A value of 0 means there is no restriction.
1312 */
Robin Lee25e26452015-06-02 09:56:29 -07001313 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001314 if (mService != null) {
1315 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001316 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001317 } catch (RemoteException e) {
1318 Log.w(TAG, "Failed talking with device policy service", e);
1319 }
1320 }
1321 }
1322
1323 /**
1324 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001325 * password for all admins of this user and its profiles or a particular one.
1326 * This is the same value as set by
1327 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001328 * and only applies when the password quality is
1329 * {@link #PASSWORD_QUALITY_COMPLEX}.
1330 *
Robin Lee25e26452015-06-02 09:56:29 -07001331 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001332 * aggregate all admins.
1333 * @return The minimum number of letters required in the password.
1334 */
Robin Lee25e26452015-06-02 09:56:29 -07001335 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001336 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001337 }
1338
1339 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001340 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001341 if (mService != null) {
1342 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001343 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001344 } catch (RemoteException e) {
1345 Log.w(TAG, "Failed talking with device policy service", e);
1346 }
1347 }
1348 return 0;
1349 }
1350
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001351 /**
1352 * Called by an application that is administering the device to set the length
1353 * of the password history. After setting this, the user will not be able to
1354 * enter a new password that is the same as any password in the history. Note
1355 * that the current password will remain until the user has set a new one, so
1356 * the change does not take place immediately. To prompt the user for a new
1357 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1358 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001359 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1360 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1361 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001362 *
1363 * <p>
1364 * The calling device admin must have requested
1365 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1366 * method; if it has not, a security exception will be thrown.
1367 *
1368 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1369 * with.
1370 * @param length The new desired length of password history. A value of 0
1371 * means there is no restriction.
1372 */
Robin Lee25e26452015-06-02 09:56:29 -07001373 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001374 if (mService != null) {
1375 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001376 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001377 } catch (RemoteException e) {
1378 Log.w(TAG, "Failed talking with device policy service", e);
1379 }
1380 }
1381 }
1382
1383 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001384 * Called by a device admin to set the password expiration timeout. Calling this method
1385 * will restart the countdown for password expiration for the given admin, as will changing
1386 * the device password (for all admins).
1387 *
1388 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1389 * For example, to have the password expire 5 days from now, timeout would be
1390 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1391 *
1392 * <p>To disable password expiration, a value of 0 may be used for timeout.
1393 *
Jim Millera4e28d12010-11-08 16:15:47 -08001394 * <p>The calling device admin must have requested
1395 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1396 * method; if it has not, a security exception will be thrown.
1397 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001398 * <p> Note that setting the password will automatically reset the expiration time for all
1399 * active admins. Active admins do not need to explicitly call this method in that case.
1400 *
Jim Millera4e28d12010-11-08 16:15:47 -08001401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1402 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1403 * means there is no restriction (unlimited).
1404 */
Robin Lee25e26452015-06-02 09:56:29 -07001405 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001406 if (mService != null) {
1407 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001408 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001409 } catch (RemoteException e) {
1410 Log.w(TAG, "Failed talking with device policy service", e);
1411 }
1412 }
1413 }
1414
1415 /**
Jim Miller6b857682011-02-16 16:27:41 -08001416 * Get the password expiration timeout for the given admin. The expiration timeout is the
1417 * recurring expiration timeout provided in the call to
1418 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001419 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001420 *
Robin Lee25e26452015-06-02 09:56:29 -07001421 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001422 * @return The timeout for the given admin or the minimum of all timeouts
1423 */
Robin Lee25e26452015-06-02 09:56:29 -07001424 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001425 if (mService != null) {
1426 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001427 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001428 } catch (RemoteException e) {
1429 Log.w(TAG, "Failed talking with device policy service", e);
1430 }
1431 }
1432 return 0;
1433 }
1434
1435 /**
1436 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001437 * all admins of this user and its profiles if admin is null. If the password is
1438 * expired, this will return the time since the password expired as a negative number.
1439 * If admin is null, then a composite of all expiration timeouts is returned
1440 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001441 *
Robin Lee25e26452015-06-02 09:56:29 -07001442 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001443 * @return The password expiration time, in ms.
1444 */
Robin Lee25e26452015-06-02 09:56:29 -07001445 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001446 if (mService != null) {
1447 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001448 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001449 } catch (RemoteException e) {
1450 Log.w(TAG, "Failed talking with device policy service", e);
1451 }
1452 }
1453 return 0;
1454 }
1455
1456 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001457 * Retrieve the current password history length for all admins of this
1458 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001459 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001460 * all admins.
1461 * @return The length of the password history
1462 */
Robin Lee25e26452015-06-02 09:56:29 -07001463 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001464 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001465 }
1466
1467 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001468 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001469 if (mService != null) {
1470 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001471 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001472 } catch (RemoteException e) {
1473 Log.w(TAG, "Failed talking with device policy service", e);
1474 }
1475 }
1476 return 0;
1477 }
1478
Dianne Hackbornd6847842010-01-12 18:14:19 -08001479 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001480 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001481 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001482 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001483 * @return Returns the maximum length that the user can enter.
1484 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001485 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001486 // Kind-of arbitrary.
1487 return 16;
1488 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001489
Dianne Hackborn254cb442010-01-27 19:23:59 -08001490 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001491 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001492 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001493 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001494 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001495 * <p>The calling device admin must have requested
1496 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1497 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001498 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001499 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001500 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001501 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001502 if (mService != null) {
1503 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001504 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001505 } catch (RemoteException e) {
1506 Log.w(TAG, "Failed talking with device policy service", e);
1507 }
1508 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001509 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001510 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001511
Dianne Hackbornd6847842010-01-12 18:14:19 -08001512 /**
1513 * Retrieve the number of times the user has failed at entering a
1514 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001515 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001516 * <p>The calling device admin must have requested
1517 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1518 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001519 */
1520 public int getCurrentFailedPasswordAttempts() {
1521 if (mService != null) {
1522 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001523 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001524 } catch (RemoteException e) {
1525 Log.w(TAG, "Failed talking with device policy service", e);
1526 }
1527 }
1528 return -1;
1529 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001530
1531 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001532 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001533 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001534 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001535 * @hide
1536 */
1537 public boolean getDoNotAskCredentialsOnBoot() {
1538 if (mService != null) {
1539 try {
1540 return mService.getDoNotAskCredentialsOnBoot();
1541 } catch (RemoteException e) {
1542 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1543 }
1544 }
1545 return false;
1546 }
1547
1548 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001549 * Setting this to a value greater than zero enables a built-in policy
1550 * that will perform a device wipe after too many incorrect
1551 * device-unlock passwords have been entered. This built-in policy combines
1552 * watching for failed passwords and wiping the device, and requires
1553 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001554 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001555 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001556 * <p>To implement any other policy (e.g. wiping data for a particular
1557 * application only, erasing or revoking credentials, or reporting the
1558 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001559 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001560 * instead. Do not use this API, because if the maximum count is reached,
1561 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001562 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001564 * @param num The number of failed password attempts at which point the
1565 * device will wipe its data.
1566 */
Robin Lee25e26452015-06-02 09:56:29 -07001567 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001568 if (mService != null) {
1569 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001570 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001571 } catch (RemoteException e) {
1572 Log.w(TAG, "Failed talking with device policy service", e);
1573 }
1574 }
1575 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001576
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001577 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001578 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001579 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001580 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001581 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001582 * all admins.
1583 */
Robin Lee25e26452015-06-02 09:56:29 -07001584 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001585 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001586 }
1587
1588 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001589 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001590 if (mService != null) {
1591 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001592 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001593 } catch (RemoteException e) {
1594 Log.w(TAG, "Failed talking with device policy service", e);
1595 }
1596 }
1597 return 0;
1598 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001599
Dianne Hackborn254cb442010-01-27 19:23:59 -08001600 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001601 * Returns the profile with the smallest maximum failed passwords for wipe,
1602 * for the given user. So for primary user, it might return the primary or
1603 * a managed profile. For a secondary user, it would be the same as the
1604 * user passed in.
1605 * @hide Used only by Keyguard
1606 */
1607 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1608 if (mService != null) {
1609 try {
1610 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1611 } catch (RemoteException e) {
1612 Log.w(TAG, "Failed talking with device policy service", e);
1613 }
1614 }
1615 return UserHandle.USER_NULL;
1616 }
1617
1618 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001619 * Flag for {@link #resetPassword}: don't allow other admins to change
1620 * the password again until the user has entered it.
1621 */
1622 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001623
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001624 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001625 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1626 * If the flag is set, the device can be booted without asking for user password.
1627 * The absence of this flag does not change the current boot requirements. This flag
1628 * can be set by the device owner only. If the app is not the device owner, the flag
1629 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1630 * device to factory defaults.
1631 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001632 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001633
1634 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001635 * Force a new device unlock password (the password needed to access the
1636 * entire device, not for individual accounts) on the user. This takes
1637 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001638 * The given password must be sufficient for the
1639 * current password quality and length constraints as returned by
1640 * {@link #getPasswordQuality(ComponentName)} and
1641 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1642 * these constraints, then it will be rejected and false returned. Note
1643 * that the password may be a stronger quality (containing alphanumeric
1644 * characters when the requested quality is only numeric), in which case
1645 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001646 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001647 * <p>Calling with a null or empty password will clear any existing PIN,
1648 * pattern or password if the current password constraints allow it.
1649 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001650 * <p>The calling device admin must have requested
1651 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1652 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001653 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001654 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001655 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001656 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001657 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001658 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001659 * @return Returns true if the password was applied, or false if it is
1660 * not acceptable for the current constraints.
1661 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001662 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001663 if (mService != null) {
1664 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001665 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001666 } catch (RemoteException e) {
1667 Log.w(TAG, "Failed talking with device policy service", e);
1668 }
1669 }
1670 return false;
1671 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001672
Dianne Hackbornd6847842010-01-12 18:14:19 -08001673 /**
1674 * Called by an application that is administering the device to set the
1675 * maximum time for user activity until the device will lock. This limits
1676 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001677 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001678 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001679 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001680 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001681 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001682 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001683 * @param timeMs The new desired maximum time to lock in milliseconds.
1684 * A value of 0 means there is no restriction.
1685 */
Robin Lee25e26452015-06-02 09:56:29 -07001686 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001687 if (mService != null) {
1688 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001689 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001690 } catch (RemoteException e) {
1691 Log.w(TAG, "Failed talking with device policy service", e);
1692 }
1693 }
1694 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001695
Dianne Hackbornd6847842010-01-12 18:14:19 -08001696 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001697 * Retrieve the current maximum time to unlock for all admins of this user
1698 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001699 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001700 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001701 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001702 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001703 */
Robin Lee25e26452015-06-02 09:56:29 -07001704 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001705 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001706 }
1707
1708 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001709 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001710 if (mService != null) {
1711 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001712 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001713 } catch (RemoteException e) {
1714 Log.w(TAG, "Failed talking with device policy service", e);
1715 }
1716 }
1717 return 0;
1718 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001719
Dianne Hackbornd6847842010-01-12 18:14:19 -08001720 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001721 * Make the device lock immediately, as if the lock screen timeout has
1722 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001723 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001724 * <p>The calling device admin must have requested
1725 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1726 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001727 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001728 public void lockNow() {
1729 if (mService != null) {
1730 try {
1731 mService.lockNow();
1732 } catch (RemoteException e) {
1733 Log.w(TAG, "Failed talking with device policy service", e);
1734 }
1735 }
1736 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001737
Dianne Hackbornd6847842010-01-12 18:14:19 -08001738 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001739 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001740 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001741 */
1742 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1743
1744 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001745 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1746 * data.
1747 *
Paul Crowley2934b262014-12-02 11:21:13 +00001748 * <p>This flag may only be set by device owner admins; if it is set by
1749 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001750 */
1751 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1752
1753 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001754 * Ask the user data be wiped. Wiping the primary user will cause the
1755 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001756 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001757 * <p>The calling device admin must have requested
1758 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1759 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001760 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001761 * @param flags Bit mask of additional options: currently supported flags
1762 * are {@link #WIPE_EXTERNAL_STORAGE} and
1763 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001764 */
1765 public void wipeData(int flags) {
1766 if (mService != null) {
1767 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001768 mService.wipeData(flags, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001769 } catch (RemoteException e) {
1770 Log.w(TAG, "Failed talking with device policy service", e);
1771 }
1772 }
1773 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001774
Dianne Hackbornd6847842010-01-12 18:14:19 -08001775 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001776 * Called by an application that is administering the device to set the
1777 * global proxy and exclusion list.
1778 * <p>
1779 * The calling device admin must have requested
1780 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1781 * this method; if it has not, a security exception will be thrown.
1782 * Only the first device admin can set the proxy. If a second admin attempts
1783 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001784 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001785 * be returned.
1786 * The method can be called repeatedly by the device admin alrady setting the
1787 * proxy to update the proxy and exclusion list.
1788 *
Robin Lee25e26452015-06-02 09:56:29 -07001789 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001790 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1791 * Pass Proxy.NO_PROXY to reset the proxy.
1792 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001793 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1794 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001795 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001796 */
Robin Lee25e26452015-06-02 09:56:29 -07001797 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001798 List<String> exclusionList ) {
1799 if (proxySpec == null) {
1800 throw new NullPointerException();
1801 }
1802 if (mService != null) {
1803 try {
1804 String hostSpec;
1805 String exclSpec;
1806 if (proxySpec.equals(Proxy.NO_PROXY)) {
1807 hostSpec = null;
1808 exclSpec = null;
1809 } else {
1810 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1811 throw new IllegalArgumentException();
1812 }
1813 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1814 String hostName = sa.getHostName();
1815 int port = sa.getPort();
1816 StringBuilder hostBuilder = new StringBuilder();
1817 hostSpec = hostBuilder.append(hostName)
1818 .append(":").append(Integer.toString(port)).toString();
1819 if (exclusionList == null) {
1820 exclSpec = "";
1821 } else {
1822 StringBuilder listBuilder = new StringBuilder();
1823 boolean firstDomain = true;
1824 for (String exclDomain : exclusionList) {
1825 if (!firstDomain) {
1826 listBuilder = listBuilder.append(",");
1827 } else {
1828 firstDomain = false;
1829 }
1830 listBuilder = listBuilder.append(exclDomain.trim());
1831 }
1832 exclSpec = listBuilder.toString();
1833 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001834 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1835 != android.net.Proxy.PROXY_VALID)
1836 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001837 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001838 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001839 } catch (RemoteException e) {
1840 Log.w(TAG, "Failed talking with device policy service", e);
1841 }
1842 }
1843 return null;
1844 }
1845
1846 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001847 * Set a network-independent global HTTP proxy. This is not normally what you want
1848 * for typical HTTP proxies - they are generally network dependent. However if you're
1849 * doing something unusual like general internal filtering this may be useful. On
1850 * a private network where the proxy is not accessible, you may break HTTP using this.
1851 *
1852 * <p>This method requires the caller to be the device owner.
1853 *
1854 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1855 * @see ProxyInfo
1856 *
1857 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1858 * with.
1859 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1860 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1861 */
Robin Lee25e26452015-06-02 09:56:29 -07001862 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1863 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001864 if (mService != null) {
1865 try {
1866 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1867 } catch (RemoteException e) {
1868 Log.w(TAG, "Failed talking with device policy service", e);
1869 }
1870 }
1871 }
1872
1873 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001874 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001875 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1876 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001877 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001878 */
1879 public ComponentName getGlobalProxyAdmin() {
1880 if (mService != null) {
1881 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001882 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001883 } catch (RemoteException e) {
1884 Log.w(TAG, "Failed talking with device policy service", e);
1885 }
1886 }
1887 return null;
1888 }
1889
1890 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001891 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001892 * indicating that encryption is not supported.
1893 */
1894 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1895
1896 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001897 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001898 * indicating that encryption is supported, but is not currently active.
1899 */
1900 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1901
1902 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001903 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001904 * indicating that encryption is not currently active, but is currently
1905 * being activated. This is only reported by devices that support
1906 * encryption of data and only when the storage is currently
1907 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1908 * to become encrypted will never return this value.
1909 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001910 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001911
1912 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001913 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001914 * indicating that encryption is active.
1915 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001916 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001917
1918 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001919 * Result code for {@link #getStorageEncryptionStatus}:
1920 * indicating that encryption is active, but an encryption key has not
1921 * been set by the user.
1922 */
1923 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1924
1925 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001926 * Activity action: begin the process of encrypting data on the device. This activity should
1927 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1928 * After resuming from this activity, use {@link #getStorageEncryption}
1929 * to check encryption status. However, on some devices this activity may never return, as
1930 * it may trigger a reboot and in some cases a complete data wipe of the device.
1931 */
1932 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1933 public static final String ACTION_START_ENCRYPTION
1934 = "android.app.action.START_ENCRYPTION";
1935
1936 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001937 * Widgets are enabled in keyguard
1938 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001939 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001940
1941 /**
Jim Miller50e62182014-04-23 17:25:00 -07001942 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001943 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001944 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1945
1946 /**
1947 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1948 */
1949 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1950
1951 /**
Jim Miller50e62182014-04-23 17:25:00 -07001952 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1953 */
1954 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1955
1956 /**
1957 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1958 */
1959 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1960
1961 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001962 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001963 * (e.g. PIN/Pattern/Password).
1964 */
1965 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1966
1967 /**
Jim Miller06e34502014-07-17 14:46:05 -07001968 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1969 */
1970 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1971
1972 /**
Jim Miller35207742012-11-02 15:33:20 -07001973 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001974 */
1975 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001976
1977 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001978 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001979 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001980 *
1981 * <p>When multiple device administrators attempt to control device
1982 * encryption, the most secure, supported setting will always be
1983 * used. If any device administrator requests device encryption,
1984 * it will be enabled; Conversely, if a device administrator
1985 * attempts to disable device encryption while another
1986 * device administrator has enabled it, the call to disable will
1987 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1988 *
1989 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001990 * written to other storage areas may or may not be encrypted, and this policy does not require
1991 * or control the encryption of any other storage areas.
1992 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1993 * {@code true}, then the directory returned by
1994 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1995 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001996 *
1997 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1998 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1999 * the encryption key may not be fully secured. For maximum security, the administrator should
2000 * also require (and check for) a pattern, PIN, or password.
2001 *
2002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2003 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002004 * @return the new request status (for all active admins) - will be one of
2005 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2006 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2007 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002008 */
Robin Lee25e26452015-06-02 09:56:29 -07002009 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002010 if (mService != null) {
2011 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002012 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002013 } catch (RemoteException e) {
2014 Log.w(TAG, "Failed talking with device policy service", e);
2015 }
2016 }
2017 return ENCRYPTION_STATUS_UNSUPPORTED;
2018 }
2019
2020 /**
2021 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002022 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002023 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2025 * this will return the requested encryption setting as an aggregate of all active
2026 * administrators.
2027 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002028 */
Robin Lee25e26452015-06-02 09:56:29 -07002029 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002030 if (mService != null) {
2031 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002032 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002033 } catch (RemoteException e) {
2034 Log.w(TAG, "Failed talking with device policy service", e);
2035 }
2036 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002037 return false;
2038 }
2039
2040 /**
2041 * Called by an application that is administering the device to
2042 * determine the current encryption status of the device.
2043 *
2044 * Depending on the returned status code, the caller may proceed in different
2045 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2046 * storage system does not support encryption. If the
2047 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2048 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002049 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2050 * storage system has enabled encryption but no password is set so further action
2051 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002052 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2053 *
Robin Lee7e678712014-07-24 16:41:31 +01002054 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002055 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002056 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2057 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002058 */
2059 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002060 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002061 }
2062
2063 /** @hide per-user version */
2064 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002065 if (mService != null) {
2066 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002067 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002068 } catch (RemoteException e) {
2069 Log.w(TAG, "Failed talking with device policy service", e);
2070 }
2071 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002072 return ENCRYPTION_STATUS_UNSUPPORTED;
2073 }
2074
2075 /**
Robin Lee7e678712014-07-24 16:41:31 +01002076 * Installs the given certificate as a user CA.
2077 *
Robin Lee25e26452015-06-02 09:56:29 -07002078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2079 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002080 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002081 *
2082 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002083 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002084 */
Robin Lee25e26452015-06-02 09:56:29 -07002085 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002086 if (mService != null) {
2087 try {
Robin Lee7e678712014-07-24 16:41:31 +01002088 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002089 } catch (RemoteException e) {
2090 Log.w(TAG, "Failed talking with device policy service", e);
2091 }
2092 }
2093 return false;
2094 }
2095
2096 /**
Robin Lee7e678712014-07-24 16:41:31 +01002097 * Uninstalls the given certificate from trusted user CAs, if present.
2098 *
Robin Lee25e26452015-06-02 09:56:29 -07002099 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2100 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002101 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002102 */
Robin Lee25e26452015-06-02 09:56:29 -07002103 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002104 if (mService != null) {
2105 try {
Robin Lee306fe082014-06-19 14:04:24 +00002106 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002107 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002108 } catch (CertificateException e) {
2109 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002110 } catch (RemoteException e) {
2111 Log.w(TAG, "Failed talking with device policy service", e);
2112 }
2113 }
2114 }
2115
2116 /**
Robin Lee7e678712014-07-24 16:41:31 +01002117 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2118 * If a user has installed any certificates by other means than device policy these will be
2119 * included too.
2120 *
Robin Lee25e26452015-06-02 09:56:29 -07002121 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2122 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002123 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002124 */
Robin Lee25e26452015-06-02 09:56:29 -07002125 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002126 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002127 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002128 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002129 mService.enforceCanManageCaCerts(admin);
2130 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2131 for (String alias : certStore.userAliases()) {
2132 try {
2133 certs.add(certStore.getCertificate(alias).getEncoded());
2134 } catch (CertificateException ce) {
2135 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2136 }
2137 }
2138 } catch (RemoteException re) {
2139 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002140 }
2141 }
2142 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002143 }
2144
2145 /**
Robin Lee7e678712014-07-24 16:41:31 +01002146 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2147 * means other than device policy will also be removed, except for system CA certificates.
2148 *
Robin Lee25e26452015-06-02 09:56:29 -07002149 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2150 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002151 */
Robin Lee25e26452015-06-02 09:56:29 -07002152 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002153 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002154 try {
2155 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2156 .toArray(new String[0]));
2157 } catch (RemoteException re) {
2158 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002159 }
2160 }
2161 }
2162
2163 /**
2164 * Returns whether this certificate is installed as a trusted CA.
2165 *
Robin Lee25e26452015-06-02 09:56:29 -07002166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2167 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002168 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002169 */
Robin Lee25e26452015-06-02 09:56:29 -07002170 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002171 if (mService != null) {
2172 try {
2173 mService.enforceCanManageCaCerts(admin);
2174 return getCaCertAlias(certBuffer) != null;
2175 } catch (RemoteException re) {
2176 Log.w(TAG, "Failed talking with device policy service", re);
2177 } catch (CertificateException ce) {
2178 Log.w(TAG, "Could not parse certificate", ce);
2179 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002180 }
2181 return false;
2182 }
2183
2184 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002185 * Called by a device or profile owner to install a certificate and private key pair. The
2186 * keypair will be visible to all apps within the profile.
2187 *
Robin Lee25e26452015-06-02 09:56:29 -07002188 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2189 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002190 * @param privKey The private key to install.
2191 * @param cert The certificate to install.
2192 * @param alias The private key alias under which to install the certificate. If a certificate
2193 * with that alias already exists, it will be overwritten.
2194 * @return {@code true} if the keys were installed, {@code false} otherwise.
2195 */
Robin Lee25e26452015-06-02 09:56:29 -07002196 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002197 String alias) {
2198 try {
2199 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002200 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2201 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002202 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002203 } catch (RemoteException e) {
2204 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002205 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2206 Log.w(TAG, "Failed to obtain private key material", e);
2207 } catch (CertificateException | IOException e) {
2208 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002209 }
2210 return false;
2211 }
2212
2213 /**
Robin Lee25e26452015-06-02 09:56:29 -07002214 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002215 * doesn't exist.
2216 */
2217 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2218 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2219 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2220 new ByteArrayInputStream(certBuffer));
2221 return new TrustedCertificateStore().getCertificateAlias(cert);
2222 }
2223
2224 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002225 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002226 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002227 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002228 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002229 * <p>
2230 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2231 * it is later cleared by calling this method with a null value or uninstallling the certificate
2232 * installer.
2233 *
Robin Lee25e26452015-06-02 09:56:29 -07002234 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002235 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002236 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002237 */
Robin Lee25e26452015-06-02 09:56:29 -07002238 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2239 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002240 if (mService != null) {
2241 try {
Robin Lee25e26452015-06-02 09:56:29 -07002242 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002243 } catch (RemoteException e) {
2244 Log.w(TAG, "Failed talking with device policy service", e);
2245 }
2246 }
2247 }
2248
2249 /**
2250 * Called by a profile owner or device owner to retrieve the certificate installer for the
2251 * current user. null if none is set.
2252 *
Robin Lee25e26452015-06-02 09:56:29 -07002253 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2254 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002255 * if none is set.
2256 */
Robin Lee25e26452015-06-02 09:56:29 -07002257 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002258 if (mService != null) {
2259 try {
Robin Lee25e26452015-06-02 09:56:29 -07002260 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002261 } catch (RemoteException e) {
2262 Log.w(TAG, "Failed talking with device policy service", e);
2263 }
2264 }
2265 return null;
2266 }
2267
2268 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002269 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002270 * on the device, for this user. After setting this, no applications running as this user
2271 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002272 *
2273 * <p>The calling device admin must have requested
2274 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2275 * this method; if it has not, a security exception will be thrown.
2276 *
2277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2278 * @param disabled Whether or not the camera should be disabled.
2279 */
Robin Lee25e26452015-06-02 09:56:29 -07002280 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002281 if (mService != null) {
2282 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002283 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002284 } catch (RemoteException e) {
2285 Log.w(TAG, "Failed talking with device policy service", e);
2286 }
2287 }
2288 }
2289
2290 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002291 * Determine whether or not the device's cameras have been disabled for this user,
2292 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002293 * @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 -07002294 * have disabled the camera
2295 */
Robin Lee25e26452015-06-02 09:56:29 -07002296 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002297 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002298 }
2299
2300 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002301 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002302 if (mService != null) {
2303 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002304 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002305 } catch (RemoteException e) {
2306 Log.w(TAG, "Failed talking with device policy service", e);
2307 }
2308 }
2309 return false;
2310 }
2311
2312 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002313 * Determine whether or not creating a guest user has been disabled for the device
2314 *
2315 * @hide
2316 */
2317 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2318 // Currently guest users can always be created if multi-user is enabled
2319 // TODO introduce a policy for guest user creation
2320 return false;
2321 }
2322
2323 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002324 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2325 * screen capture also prevents the content from being shown on display devices that do not have
2326 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2327 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002328 *
2329 * <p>The calling device admin must be a device or profile owner. If it is not, a
2330 * security exception will be thrown.
2331 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002332 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002333 * blocks assist requests for all activities of the relevant user.
2334 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002335 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002336 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002337 */
Robin Lee25e26452015-06-02 09:56:29 -07002338 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002339 if (mService != null) {
2340 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002341 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002342 } catch (RemoteException e) {
2343 Log.w(TAG, "Failed talking with device policy service", e);
2344 }
2345 }
2346 }
2347
2348 /**
2349 * Determine whether or not screen capture has been disabled by the current
2350 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002351 * @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 +01002352 * have disabled screen capture.
2353 */
Robin Lee25e26452015-06-02 09:56:29 -07002354 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002355 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002356 }
2357
2358 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002359 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002360 if (mService != null) {
2361 try {
2362 return mService.getScreenCaptureDisabled(admin, userHandle);
2363 } catch (RemoteException e) {
2364 Log.w(TAG, "Failed talking with device policy service", e);
2365 }
2366 }
2367 return false;
2368 }
2369
2370 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002371 * Called by a device owner to set whether auto time is required. If auto time is
2372 * required the user cannot set the date and time, but has to use network date and time.
2373 *
2374 * <p>Note: if auto time is required the user can still manually set the time zone.
2375 *
2376 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2377 * be thrown.
2378 *
2379 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2380 * @param required Whether auto time is set required or not.
2381 */
Robin Lee25e26452015-06-02 09:56:29 -07002382 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002383 if (mService != null) {
2384 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002385 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002386 } catch (RemoteException e) {
2387 Log.w(TAG, "Failed talking with device policy service", e);
2388 }
2389 }
2390 }
2391
2392 /**
2393 * @return true if auto time is required.
2394 */
2395 public boolean getAutoTimeRequired() {
2396 if (mService != null) {
2397 try {
2398 return mService.getAutoTimeRequired();
2399 } catch (RemoteException e) {
2400 Log.w(TAG, "Failed talking with device policy service", e);
2401 }
2402 }
2403 return false;
2404 }
2405
2406 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002407 * Called by an application that is administering the device to disable keyguard customizations,
2408 * such as widgets. After setting this, keyguard features will be disabled according to the
2409 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002410 *
2411 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002412 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002413 * this method; if it has not, a security exception will be thrown.
2414 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002415 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002416 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002417 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002418 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002419 * <ul>
2420 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2421 * these will affect the profile's parent user.
2422 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2423 * generated by applications in the managed profile.
2424 * </ul>
2425 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2426 * can check which features have been disabled by calling
2427 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002428 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002430 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2431 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002432 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002433 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2434 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002435 */
Robin Lee25e26452015-06-02 09:56:29 -07002436 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002437 if (mService != null) {
2438 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002439 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002440 } catch (RemoteException e) {
2441 Log.w(TAG, "Failed talking with device policy service", e);
2442 }
2443 }
2444 }
2445
2446 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002447 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002448 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002449 * @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 -07002450 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002451 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2452 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002453 */
Robin Lee25e26452015-06-02 09:56:29 -07002454 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002455 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002456 }
2457
2458 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002459 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002460 if (mService != null) {
2461 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002462 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002463 } catch (RemoteException e) {
2464 Log.w(TAG, "Failed talking with device policy service", e);
2465 }
2466 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002467 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002468 }
2469
2470 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002471 * @hide
2472 */
Robin Lee25e26452015-06-02 09:56:29 -07002473 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2474 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002475 if (mService != null) {
2476 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002477 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002478 } catch (RemoteException e) {
2479 Log.w(TAG, "Failed talking with device policy service", e);
2480 }
2481 }
2482 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002483
Dianne Hackbornd6847842010-01-12 18:14:19 -08002484 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002485 * @hide
2486 */
Robin Lee25e26452015-06-02 09:56:29 -07002487 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002488 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002489 }
2490
2491 /**
Robin Lee25e26452015-06-02 09:56:29 -07002492 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002493 * @hide
2494 */
Robin Lee25e26452015-06-02 09:56:29 -07002495 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002496 ActivityInfo ai;
2497 try {
2498 ai = mContext.getPackageManager().getReceiverInfo(cn,
2499 PackageManager.GET_META_DATA);
2500 } catch (PackageManager.NameNotFoundException e) {
2501 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2502 return null;
2503 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002504
Dianne Hackbornd6847842010-01-12 18:14:19 -08002505 ResolveInfo ri = new ResolveInfo();
2506 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002507
Dianne Hackbornd6847842010-01-12 18:14:19 -08002508 try {
2509 return new DeviceAdminInfo(mContext, ri);
2510 } catch (XmlPullParserException e) {
2511 Log.w(TAG, "Unable to parse device policy " + cn, e);
2512 return null;
2513 } catch (IOException e) {
2514 Log.w(TAG, "Unable to parse device policy " + cn, e);
2515 return null;
2516 }
2517 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002518
Dianne Hackbornd6847842010-01-12 18:14:19 -08002519 /**
2520 * @hide
2521 */
Robin Lee25e26452015-06-02 09:56:29 -07002522 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002523 if (mService != null) {
2524 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002525 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002526 } catch (RemoteException e) {
2527 Log.w(TAG, "Failed talking with device policy service", e);
2528 }
2529 }
2530 }
2531
2532 /**
2533 * @hide
2534 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002535 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002536 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002537 if (mService != null) {
2538 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002539 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002540 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002541 } catch (RemoteException e) {
2542 Log.w(TAG, "Failed talking with device policy service", e);
2543 }
2544 }
2545 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002546
Dianne Hackbornd6847842010-01-12 18:14:19 -08002547 /**
2548 * @hide
2549 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002550 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002551 if (mService != null) {
2552 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002553 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002554 } catch (RemoteException e) {
2555 Log.w(TAG, "Failed talking with device policy service", e);
2556 }
2557 }
2558 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002559
Dianne Hackbornd6847842010-01-12 18:14:19 -08002560 /**
2561 * @hide
2562 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002563 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002564 if (mService != null) {
2565 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002566 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002567 } catch (RemoteException e) {
2568 Log.w(TAG, "Failed talking with device policy service", e);
2569 }
2570 }
2571 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002572
2573 /**
2574 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002575 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002576 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2577 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002578 * @return whether the package was successfully registered as the device owner.
2579 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002580 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002581 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002582 public boolean setDeviceOwner(ComponentName who) {
2583 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002584 }
2585
2586 /**
2587 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002588 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002589 public boolean setDeviceOwner(ComponentName who, int userId) {
2590 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002591 }
2592
2593 /**
2594 * @hide
2595 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002596 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2597 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002598 }
2599
2600 /**
2601 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002602 * Sets the given package as the device owner. The package must already be installed. There
2603 * must not already be a device owner.
2604 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2605 * this method.
2606 * Calling this after the setup phase of the primary user has completed is allowed only if
2607 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002608 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002609 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002610 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002611 * @return whether the package was successfully registered as the device owner.
2612 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002613 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002614 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002615 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002616 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002617 if (mService != null) {
2618 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002619 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002620 } catch (RemoteException re) {
2621 Log.w(TAG, "Failed to set device owner");
2622 }
2623 }
2624 return false;
2625 }
2626
2627 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002628 * Used to determine if a particular package has been registered as a Device Owner app.
2629 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002630 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002631 * package is currently registered as the device owner app, pass in the package name from
2632 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002633 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002634 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2635 * the setup process.
2636 * @param packageName the package name of the app, to compare with the registered device owner
2637 * app, if any.
Makoto Onukia52562c2015-10-01 16:12:31 -07002638 * @return whether or not the package is registered as the device owner app. Note this method
2639 * does *not* check weather the device owner is actually running on the current user.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002640 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002641 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002642 if (mService != null) {
2643 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002644 return mService.isDeviceOwnerPackage(packageName);
2645 } catch (RemoteException e) {
2646 Log.w(TAG, "Failed talking with device policy service", e);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002647 }
2648 }
2649 return false;
2650 }
2651
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002652 /**
2653 * @hide
2654 * Redirect to isDeviceOwnerApp.
2655 */
2656 public boolean isDeviceOwner(String packageName) {
2657 return isDeviceOwnerApp(packageName);
2658 }
2659
Jason Monkb0dced82014-06-06 14:36:20 -04002660 /**
Makoto Onukia52562c2015-10-01 16:12:31 -07002661 * Check whether a given component is registered as a device owner.
2662 * Note this method does *not* check weather the device owner is actually running on the current
2663 * user.
2664 *
2665 * @hide
2666 */
2667 public boolean isDeviceOwner(ComponentName who) {
2668 return (who != null) && who.equals(getDeviceOwner());
2669 }
2670
2671 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002672 * Clears the current device owner. The caller must be the device owner.
2673 *
2674 * This function should be used cautiously as once it is called it cannot
2675 * be undone. The device owner can only be set as a part of device setup
2676 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002677 *
2678 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002679 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002680 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002681 if (mService != null) {
2682 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002683 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002684 } catch (RemoteException re) {
2685 Log.w(TAG, "Failed to clear device owner");
2686 }
2687 }
2688 }
2689
Makoto Onukia52562c2015-10-01 16:12:31 -07002690 /**
2691 * Returns the device owner package name. Note this method will still return the device owner
2692 * package name even if it's running on a different user.
2693 *
2694 * @hide
2695 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002696 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002697 public String getDeviceOwner() {
Makoto Onukia52562c2015-10-01 16:12:31 -07002698 final ComponentName componentName = getDeviceOwnerComponent();
2699 return componentName == null ? null : componentName.getPackageName();
2700 }
2701
2702 /**
2703 * Returns the device owner name. Note this method will still return the device owner
2704 * name even if it's running on a different user.
2705 *
2706 * @hide
2707 */
2708 public String getDeviceOwnerName() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002709 if (mService != null) {
2710 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002711 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002712 } catch (RemoteException re) {
2713 Log.w(TAG, "Failed to get device owner");
2714 }
2715 }
2716 return null;
2717 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002718
Makoto Onukia52562c2015-10-01 16:12:31 -07002719 /**
2720 * Returns the device owner component name. Note this method will still return the device owner
2721 * component name even if it's running on a different user.
2722 *
2723 * @hide
2724 */
2725 public ComponentName getDeviceOwnerComponent() {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002726 if (mService != null) {
2727 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002728 return mService.getDeviceOwner();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002729 } catch (RemoteException re) {
2730 Log.w(TAG, "Failed to get device owner");
2731 }
2732 }
2733 return null;
2734 }
Adam Connors776c5552014-01-09 10:42:56 +00002735
2736 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002737 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002738 * @deprecated Do not use
2739 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002740 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002741 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002742 @SystemApi
2743 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002744 return null;
2745 }
2746
2747 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002748 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002749 * @deprecated Do not use
2750 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002751 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002752 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002753 @SystemApi
2754 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002755 return null;
2756 }
2757
Julia Reynolds20118f12015-02-11 12:34:08 -05002758 /**
Adam Connors776c5552014-01-09 10:42:56 +00002759 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002760 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302761 * Sets the given component as an active admin and registers the package as the profile
2762 * owner for this user. The package must already be installed and there shouldn't be
2763 * an existing profile owner registered for this user. Also, this method must be called
2764 * before the user setup has been completed.
2765 * <p>
2766 * This method can only be called by system apps that hold MANAGE_USERS permission and
2767 * MANAGE_DEVICE_ADMINS permission.
2768 * @param admin The component to register as an active admin and profile owner.
2769 * @param ownerName The user-visible name of the entity that is managing this user.
2770 * @return whether the admin was successfully registered as the profile owner.
2771 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2772 * the user has already been set up.
2773 */
Justin Morey80440cc2014-07-24 09:16:35 -05002774 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002775 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302776 throws IllegalArgumentException {
2777 if (mService != null) {
2778 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002779 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302780 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002781 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302782 } catch (RemoteException re) {
2783 Log.w(TAG, "Failed to set profile owner " + re);
2784 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2785 }
2786 }
2787 return false;
2788 }
2789
2790 /**
2791 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002792 * Clears the active profile owner and removes all user restrictions. The caller must
2793 * be from the same package as the active profile owner for this user, otherwise a
2794 * SecurityException will be thrown.
2795 *
2796 * @param admin The component to remove as the profile owner.
2797 * @return
2798 */
2799 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002800 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002801 if (mService != null) {
2802 try {
2803 mService.clearProfileOwner(admin);
2804 } catch (RemoteException re) {
2805 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2806 }
2807 }
2808 }
2809
2810 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002811 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002812 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002813 */
2814 public boolean hasUserSetupCompleted() {
2815 if (mService != null) {
2816 try {
2817 return mService.hasUserSetupCompleted();
2818 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002819 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002820 }
2821 }
2822 return true;
2823 }
2824
2825 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002826 * @hide
2827 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002828 * already be installed. There must not already be a profile owner for this user.
2829 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2830 * this method.
2831 * Calling this after the setup phase of the specified user has completed is allowed only if:
2832 * - the caller is SYSTEM_UID.
2833 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002834 * @param admin the component name to be registered as profile owner.
2835 * @param ownerName the human readable name of the organisation associated with this DPM.
2836 * @param userHandle the userId to set the profile owner for.
2837 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002838 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2839 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002840 */
Robin Lee25e26452015-06-02 09:56:29 -07002841 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002842 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002843 if (admin == null) {
2844 throw new NullPointerException("admin cannot be null");
2845 }
Adam Connors776c5552014-01-09 10:42:56 +00002846 if (mService != null) {
2847 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002848 if (ownerName == null) {
2849 ownerName = "";
2850 }
2851 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002852 } catch (RemoteException re) {
2853 Log.w(TAG, "Failed to set profile owner", re);
2854 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2855 }
2856 }
2857 return false;
2858 }
2859
2860 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002861 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2862 * be used. Only the profile owner can call this.
2863 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002864 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002865 *
2866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2867 */
Robin Lee25e26452015-06-02 09:56:29 -07002868 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002869 if (mService != null) {
2870 try {
2871 mService.setProfileEnabled(admin);
2872 } catch (RemoteException e) {
2873 Log.w(TAG, "Failed talking with device policy service", e);
2874 }
2875 }
2876 }
2877
2878 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002879 * Sets the name of the profile. In the device owner case it sets the name of the user
2880 * 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 +01002881 * never called by the profile or device owner, the name will be set to default values.
2882 *
2883 * @see #isProfileOwnerApp
2884 * @see #isDeviceOwnerApp
2885 *
Robin Lee25e26452015-06-02 09:56:29 -07002886 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01002887 * @param profileName The name of the profile.
2888 */
Robin Lee25e26452015-06-02 09:56:29 -07002889 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01002890 if (mService != null) {
2891 try {
Robin Lee25e26452015-06-02 09:56:29 -07002892 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07002893 } catch (RemoteException e) {
2894 Log.w(TAG, "Failed talking with device policy service", e);
2895 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002896 }
2897 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002898
2899 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002900 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002901 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002902 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002903 *
2904 * @param packageName The package name of the app to compare with the registered profile owner.
2905 * @return Whether or not the package is registered as the profile owner.
2906 */
2907 public boolean isProfileOwnerApp(String packageName) {
2908 if (mService != null) {
2909 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002910 ComponentName profileOwner = mService.getProfileOwner(
2911 Process.myUserHandle().getIdentifier());
2912 return profileOwner != null
2913 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002914 } catch (RemoteException re) {
2915 Log.w(TAG, "Failed to check profile owner");
2916 }
2917 }
2918 return false;
2919 }
2920
2921 /**
2922 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002923 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00002924 * owner has been set for that user.
2925 * @throws IllegalArgumentException if the userId is invalid.
2926 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002927 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002928 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002929 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2930 }
2931
2932 /**
2933 * @see #getProfileOwner()
2934 * @hide
2935 */
2936 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002937 if (mService != null) {
2938 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002939 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002940 } catch (RemoteException re) {
2941 Log.w(TAG, "Failed to get profile owner");
2942 throw new IllegalArgumentException(
2943 "Requested profile owner for invalid userId", re);
2944 }
2945 }
2946 return null;
2947 }
2948
2949 /**
2950 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002951 * @return the human readable name of the organisation associated with this DPM or {@code null}
2952 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00002953 * @throws IllegalArgumentException if the userId is invalid.
2954 */
2955 public String getProfileOwnerName() throws IllegalArgumentException {
2956 if (mService != null) {
2957 try {
2958 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2959 } catch (RemoteException re) {
2960 Log.w(TAG, "Failed to get profile owner");
2961 throw new IllegalArgumentException(
2962 "Requested profile owner for invalid userId", re);
2963 }
2964 }
2965 return null;
2966 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002967
2968 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002969 * @hide
2970 * @param user The user for whom to fetch the profile owner name, if any.
2971 * @return the human readable name of the organisation associated with this profile owner or
2972 * null if one is not set.
2973 * @throws IllegalArgumentException if the userId is invalid.
2974 */
2975 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002976 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002977 if (mService != null) {
2978 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002979 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002980 } catch (RemoteException re) {
2981 Log.w(TAG, "Failed to get profile owner");
2982 throw new IllegalArgumentException(
2983 "Requested profile owner for invalid userId", re);
2984 }
2985 }
2986 return null;
2987 }
2988
2989 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002990 * Called by a profile owner or device owner to add a default intent handler activity for
2991 * intents that match a certain intent filter. This activity will remain the default intent
2992 * handler even if the set of potential event handlers for the intent filter changes and if
2993 * the intent preferences are reset.
2994 *
2995 * <p>The default disambiguation mechanism takes over if the activity is not installed
2996 * (anymore). When the activity is (re)installed, it is automatically reset as default
2997 * intent handler for the filter.
2998 *
2999 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3000 * security exception will be thrown.
3001 *
3002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3003 * @param filter The IntentFilter for which a default handler is added.
3004 * @param activity The Activity that is added as default intent handler.
3005 */
Robin Lee25e26452015-06-02 09:56:29 -07003006 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3007 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003008 if (mService != null) {
3009 try {
3010 mService.addPersistentPreferredActivity(admin, filter, activity);
3011 } catch (RemoteException e) {
3012 Log.w(TAG, "Failed talking with device policy service", e);
3013 }
3014 }
3015 }
3016
3017 /**
3018 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003019 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003020 *
3021 * <p>The calling device admin must be a profile owner. If it is not, a security
3022 * exception will be thrown.
3023 *
3024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3025 * @param packageName The name of the package for which preferences are removed.
3026 */
Robin Lee25e26452015-06-02 09:56:29 -07003027 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003028 String packageName) {
3029 if (mService != null) {
3030 try {
3031 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3032 } catch (RemoteException e) {
3033 Log.w(TAG, "Failed talking with device policy service", e);
3034 }
3035 }
3036 }
Robin Lee66e5d962014-04-09 16:44:21 +01003037
3038 /**
3039 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003040 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003041 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003042 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3043 * <ul>
3044 * <li>{@code boolean}
3045 * <li>{@code int}
3046 * <li>{@code String} or {@code String[]}
3047 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3048 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003049 *
3050 * <p>The application restrictions are only made visible to the target application and the
3051 * profile or device owner.
3052 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003053 * <p>If the restrictions are not available yet, but may be applied in the near future,
3054 * the admin can notify the target application of that by adding
3055 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3056 *
Robin Lee66e5d962014-04-09 16:44:21 +01003057 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3058 * exception will be thrown.
3059 *
3060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3061 * @param packageName The name of the package to update restricted settings for.
3062 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3063 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003064 *
3065 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003066 */
Robin Lee25e26452015-06-02 09:56:29 -07003067 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003068 Bundle settings) {
3069 if (mService != null) {
3070 try {
3071 mService.setApplicationRestrictions(admin, packageName, settings);
3072 } catch (RemoteException e) {
3073 Log.w(TAG, "Failed talking with device policy service", e);
3074 }
3075 }
3076 }
3077
3078 /**
Jim Millere303bf42014-08-26 17:12:29 -07003079 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3080 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3081 * trust agents but those enabled by this function call. If flag
3082 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003083 *
3084 * <p>The calling device admin must have requested
3085 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003086 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003087 *
3088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003089 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003090 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003091 * will be strictly disabled according to the state of the
3092 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3093 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3094 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3095 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003096 */
Robin Lee25e26452015-06-02 09:56:29 -07003097 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3098 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003099 if (mService != null) {
3100 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003101 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003102 } catch (RemoteException e) {
3103 Log.w(TAG, "Failed talking with device policy service", e);
3104 }
3105 }
3106 }
3107
3108 /**
Jim Millere303bf42014-08-26 17:12:29 -07003109 * Gets configuration for the given trust agent based on aggregating all calls to
3110 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3111 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003112 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3114 * this function returns a list of configurations for all admins that declare
3115 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3116 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3117 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3118 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003119 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003120 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003121 */
Robin Lee25e26452015-06-02 09:56:29 -07003122 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3123 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003124 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003125 }
3126
3127 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003128 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3129 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003130 if (mService != null) {
3131 try {
Jim Millere303bf42014-08-26 17:12:29 -07003132 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003133 } catch (RemoteException e) {
3134 Log.w(TAG, "Failed talking with device policy service", e);
3135 }
3136 }
Jim Millere303bf42014-08-26 17:12:29 -07003137 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003138 }
3139
3140 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003141 * Called by a profile owner of a managed profile to set whether caller-Id information from
3142 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003143 *
3144 * <p>The calling device admin must be a profile owner. If it is not, a
3145 * security exception will be thrown.
3146 *
Robin Lee25e26452015-06-02 09:56:29 -07003147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003148 * @param disabled If true caller-Id information in the managed profile is not displayed.
3149 */
Robin Lee25e26452015-06-02 09:56:29 -07003150 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003151 if (mService != null) {
3152 try {
Robin Lee25e26452015-06-02 09:56:29 -07003153 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003154 } catch (RemoteException e) {
3155 Log.w(TAG, "Failed talking with device policy service", e);
3156 }
3157 }
3158 }
3159
3160 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003161 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3162 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003163 *
3164 * <p>The calling device admin must be a profile owner. If it is not, a
3165 * security exception will be thrown.
3166 *
Robin Lee25e26452015-06-02 09:56:29 -07003167 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003168 */
Robin Lee25e26452015-06-02 09:56:29 -07003169 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003170 if (mService != null) {
3171 try {
Robin Lee25e26452015-06-02 09:56:29 -07003172 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003173 } catch (RemoteException e) {
3174 Log.w(TAG, "Failed talking with device policy service", e);
3175 }
3176 }
3177 return false;
3178 }
3179
3180 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003181 * Determine whether or not caller-Id information has been disabled.
3182 *
3183 * @param userHandle The user for whom to check the caller-id permission
3184 * @hide
3185 */
3186 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3187 if (mService != null) {
3188 try {
3189 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3190 } catch (RemoteException e) {
3191 Log.w(TAG, "Failed talking with device policy service", e);
3192 }
3193 }
3194 return false;
3195 }
3196
3197 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003198 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3199 * @hide
3200 */
3201 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3202 Intent originalIntent) {
3203 if (mService != null) {
3204 try {
3205 mService.startManagedQuickContact(
3206 actualLookupKey, actualContactId, originalIntent);
3207 } catch (RemoteException e) {
3208 Log.w(TAG, "Failed talking with device policy service", e);
3209 }
3210 }
3211 }
3212
3213 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003214 * Called by a profile owner of a managed profile to set whether bluetooth
3215 * devices can access enterprise contacts.
3216 * <p>
3217 * The calling device admin must be a profile owner. If it is not, a
3218 * security exception will be thrown.
3219 * <p>
3220 * This API works on managed profile only.
3221 *
Robin Lee25e26452015-06-02 09:56:29 -07003222 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003223 * with.
3224 * @param disabled If true, bluetooth devices cannot access enterprise
3225 * contacts.
3226 */
Robin Lee25e26452015-06-02 09:56:29 -07003227 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003228 if (mService != null) {
3229 try {
Robin Lee25e26452015-06-02 09:56:29 -07003230 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003231 } catch (RemoteException e) {
3232 Log.w(TAG, "Failed talking with device policy service", e);
3233 }
3234 }
3235 }
3236
3237 /**
3238 * Called by a profile owner of a managed profile to determine whether or
3239 * not Bluetooth devices cannot access enterprise contacts.
3240 * <p>
3241 * The calling device admin must be a profile owner. If it is not, a
3242 * security exception will be thrown.
3243 * <p>
3244 * This API works on managed profile only.
3245 *
Robin Lee25e26452015-06-02 09:56:29 -07003246 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003247 * with.
3248 */
Robin Lee25e26452015-06-02 09:56:29 -07003249 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003250 if (mService != null) {
3251 try {
Robin Lee25e26452015-06-02 09:56:29 -07003252 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003253 } catch (RemoteException e) {
3254 Log.w(TAG, "Failed talking with device policy service", e);
3255 }
3256 }
3257 return true;
3258 }
3259
3260 /**
3261 * Determine whether or not Bluetooth devices cannot access contacts.
3262 * <p>
3263 * This API works on managed profile UserHandle only.
3264 *
3265 * @param userHandle The user for whom to check the caller-id permission
3266 * @hide
3267 */
3268 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3269 if (mService != null) {
3270 try {
3271 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3272 .getIdentifier());
3273 } catch (RemoteException e) {
3274 Log.w(TAG, "Failed talking with device policy service", e);
3275 }
3276 }
3277 return true;
3278 }
3279
3280 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003281 * Called by the profile owner of a managed profile so that some intents sent in the managed
3282 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003283 * Only activity intents are supported.
3284 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003286 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3287 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003288 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3289 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003290 */
Robin Lee25e26452015-06-02 09:56:29 -07003291 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003292 if (mService != null) {
3293 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003294 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003295 } catch (RemoteException e) {
3296 Log.w(TAG, "Failed talking with device policy service", e);
3297 }
3298 }
3299 }
3300
3301 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003302 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3303 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003304 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3306 */
Robin Lee25e26452015-06-02 09:56:29 -07003307 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003308 if (mService != null) {
3309 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003310 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003311 } catch (RemoteException e) {
3312 Log.w(TAG, "Failed talking with device policy service", e);
3313 }
3314 }
3315 }
3316
3317 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003318 * Called by a profile or device owner to set the permitted accessibility services. When
3319 * set by a device owner or profile owner the restriction applies to all profiles of the
3320 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003321 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003322 * By default the user can use any accessiblity service. When zero or more packages have
3323 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003324 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003325 *
3326 * <p> Calling with a null value for the list disables the restriction so that all services
3327 * can be used, calling with an empty list only allows the builtin system's services.
3328 *
3329 * <p> System accesibility services are always available to the user the list can't modify
3330 * this.
3331 *
3332 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3333 * @param packageNames List of accessibility service package names.
3334 *
3335 * @return true if setting the restriction succeeded. It fail if there is
3336 * one or more non-system accessibility services enabled, that are not in the list.
3337 */
Robin Lee25e26452015-06-02 09:56:29 -07003338 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003339 List<String> packageNames) {
3340 if (mService != null) {
3341 try {
3342 return mService.setPermittedAccessibilityServices(admin, packageNames);
3343 } catch (RemoteException e) {
3344 Log.w(TAG, "Failed talking with device policy service", e);
3345 }
3346 }
3347 return false;
3348 }
3349
3350 /**
3351 * Returns the list of permitted accessibility services set by this device or profile owner.
3352 *
3353 * <p>An empty list means no accessibility services except system services are allowed.
3354 * Null means all accessibility services are allowed.
3355 *
3356 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3357 * @return List of accessiblity service package names.
3358 */
Robin Lee25e26452015-06-02 09:56:29 -07003359 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003360 if (mService != null) {
3361 try {
3362 return mService.getPermittedAccessibilityServices(admin);
3363 } catch (RemoteException e) {
3364 Log.w(TAG, "Failed talking with device policy service", e);
3365 }
3366 }
3367 return null;
3368 }
3369
3370 /**
3371 * Returns the list of accessibility services permitted by the device or profiles
3372 * owners of this user.
3373 *
3374 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3375 * it will contain the intersection of the permitted lists for any device or profile
3376 * owners that apply to this user. It will also include any system accessibility services.
3377 *
3378 * @param userId which user to check for.
3379 * @return List of accessiblity service package names.
3380 * @hide
3381 */
3382 @SystemApi
3383 public List<String> getPermittedAccessibilityServices(int userId) {
3384 if (mService != null) {
3385 try {
3386 return mService.getPermittedAccessibilityServicesForUser(userId);
3387 } catch (RemoteException e) {
3388 Log.w(TAG, "Failed talking with device policy service", e);
3389 }
3390 }
3391 return null;
3392 }
3393
3394 /**
3395 * Called by a profile or device owner to set the permitted input methods services. When
3396 * set by a device owner or profile owner the restriction applies to all profiles of the
3397 * user the device owner or profile owner is an admin for.
3398 *
3399 * By default the user can use any input method. When zero or more packages have
3400 * been added, input method that are not in the list and not part of the system
3401 * can not be enabled by the user.
3402 *
3403 * This method will fail if it is called for a admin that is not for the foreground user
3404 * or a profile of the foreground user.
3405 *
3406 * <p> Calling with a null value for the list disables the restriction so that all input methods
3407 * can be used, calling with an empty list disables all but the system's own input methods.
3408 *
3409 * <p> System input methods are always available to the user this method can't modify this.
3410 *
3411 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3412 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003413 * @return true if setting the restriction succeeded. It will fail if there are
3414 * one or more non-system input methods currently enabled that are not in
3415 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003416 */
Robin Lee25e26452015-06-02 09:56:29 -07003417 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003418 if (mService != null) {
3419 try {
3420 return mService.setPermittedInputMethods(admin, packageNames);
3421 } catch (RemoteException e) {
3422 Log.w(TAG, "Failed talking with device policy service", e);
3423 }
3424 }
3425 return false;
3426 }
3427
3428
3429 /**
3430 * Returns the list of permitted input methods set by this device or profile owner.
3431 *
3432 * <p>An empty list means no input methods except system input methods are allowed.
3433 * Null means all input methods are allowed.
3434 *
3435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3436 * @return List of input method package names.
3437 */
Robin Lee25e26452015-06-02 09:56:29 -07003438 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003439 if (mService != null) {
3440 try {
3441 return mService.getPermittedInputMethods(admin);
3442 } catch (RemoteException e) {
3443 Log.w(TAG, "Failed talking with device policy service", e);
3444 }
3445 }
3446 return null;
3447 }
3448
3449 /**
3450 * Returns the list of input methods permitted by the device or profiles
3451 * owners of the current user.
3452 *
3453 * <p>Null means all input methods are allowed, if a non-null list is returned
3454 * it will contain the intersection of the permitted lists for any device or profile
3455 * owners that apply to this user. It will also include any system input methods.
3456 *
3457 * @return List of input method package names.
3458 * @hide
3459 */
3460 @SystemApi
3461 public List<String> getPermittedInputMethodsForCurrentUser() {
3462 if (mService != null) {
3463 try {
3464 return mService.getPermittedInputMethodsForCurrentUser();
3465 } catch (RemoteException e) {
3466 Log.w(TAG, "Failed talking with device policy service", e);
3467 }
3468 }
3469 return null;
3470 }
3471
3472 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003473 * Called by a device owner to create a user with the specified name. The UserHandle returned
3474 * by this method should not be persisted as user handles are recycled as users are removed and
3475 * created. If you need to persist an identifier for this user, use
3476 * {@link UserManager#getSerialNumberForUser}.
3477 *
3478 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3479 * @param name the user's name
3480 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003481 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3482 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003483 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003484 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003485 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003486 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003487 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003488 try {
3489 return mService.createUser(admin, name);
3490 } catch (RemoteException re) {
3491 Log.w(TAG, "Could not create a user", re);
3492 }
3493 return null;
3494 }
3495
3496 /**
Jason Monk03978a42014-06-10 15:05:30 -04003497 * Called by a device owner to create a user with the specified name. The UserHandle returned
3498 * by this method should not be persisted as user handles are recycled as users are removed and
3499 * created. If you need to persist an identifier for this user, use
3500 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3501 * immediately.
3502 *
3503 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3504 * as registered as an active admin on the new user. The profile owner package will be
3505 * installed on the new user if it already is installed on the device.
3506 *
3507 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3508 * profileOwnerComponent when onEnable is called.
3509 *
3510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3511 * @param name the user's name
3512 * @param ownerName the human readable name of the organisation associated with this DPM.
3513 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3514 * the user.
3515 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3516 * on the new user.
3517 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003518 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3519 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003520 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003521 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003522 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003523 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003524 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3525 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003526 try {
3527 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3528 adminExtras);
3529 } catch (RemoteException re) {
3530 Log.w(TAG, "Could not create a user", re);
3531 }
3532 return null;
3533 }
3534
3535 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003536 * Called by a device owner to remove a user and all associated data. The primary user can
3537 * not be removed.
3538 *
3539 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3540 * @param userHandle the user to remove.
3541 * @return {@code true} if the user was removed, {@code false} otherwise.
3542 */
Robin Lee25e26452015-06-02 09:56:29 -07003543 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003544 try {
3545 return mService.removeUser(admin, userHandle);
3546 } catch (RemoteException re) {
3547 Log.w(TAG, "Could not remove user ", re);
3548 return false;
3549 }
3550 }
3551
3552 /**
Jason Monk582d9112014-07-09 19:57:08 -04003553 * Called by a device owner to switch the specified user to the foreground.
3554 *
3555 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3556 * @param userHandle the user to switch to; null will switch to primary.
3557 * @return {@code true} if the switch was successful, {@code false} otherwise.
3558 *
3559 * @see Intent#ACTION_USER_FOREGROUND
3560 */
Robin Lee25e26452015-06-02 09:56:29 -07003561 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003562 try {
3563 return mService.switchUser(admin, userHandle);
3564 } catch (RemoteException re) {
3565 Log.w(TAG, "Could not switch user ", re);
3566 return false;
3567 }
3568 }
3569
3570 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003571 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003572 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003573 *
3574 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3575 * exception will be thrown.
3576 *
3577 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3578 * @param packageName The name of the package to fetch restricted settings of.
3579 * @return {@link Bundle} of settings corresponding to what was set last time
3580 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3581 * if no restrictions have been set.
3582 */
Robin Lee25e26452015-06-02 09:56:29 -07003583 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003584 if (mService != null) {
3585 try {
3586 return mService.getApplicationRestrictions(admin, packageName);
3587 } catch (RemoteException e) {
3588 Log.w(TAG, "Failed talking with device policy service", e);
3589 }
3590 }
3591 return null;
3592 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003593
3594 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003595 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003596 * <p>
3597 * The calling device admin must be a profile or device owner; if it is not,
3598 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003599 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003600 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3601 * with.
3602 * @param key The key of the restriction. See the constants in
3603 * {@link android.os.UserManager} for the list of keys.
3604 */
Robin Lee25e26452015-06-02 09:56:29 -07003605 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003606 if (mService != null) {
3607 try {
3608 mService.setUserRestriction(admin, key, true);
3609 } catch (RemoteException e) {
3610 Log.w(TAG, "Failed talking with device policy service", e);
3611 }
3612 }
3613 }
3614
3615 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003616 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003617 * <p>
3618 * The calling device admin must be a profile or device owner; if it is not,
3619 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003620 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003621 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3622 * with.
3623 * @param key The key of the restriction. See the constants in
3624 * {@link android.os.UserManager} for the list of keys.
3625 */
Robin Lee25e26452015-06-02 09:56:29 -07003626 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003627 if (mService != null) {
3628 try {
3629 mService.setUserRestriction(admin, key, false);
3630 } catch (RemoteException e) {
3631 Log.w(TAG, "Failed talking with device policy service", e);
3632 }
3633 }
3634 }
Adam Connors010cfd42014-04-16 12:48:13 +01003635
3636 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003637 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003638 * is unavailable for use, but the data and actual package file remain.
3639 *
3640 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003641 * @param packageName The name of the package to hide or unhide.
3642 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3643 * unhidden.
3644 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003645 */
Robin Lee25e26452015-06-02 09:56:29 -07003646 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003647 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003648 if (mService != null) {
3649 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003650 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003651 } catch (RemoteException e) {
3652 Log.w(TAG, "Failed talking with device policy service", e);
3653 }
3654 }
3655 return false;
3656 }
3657
3658 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003659 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003660 *
3661 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003662 * @param packageName The name of the package to retrieve the hidden status of.
3663 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003664 */
Robin Lee25e26452015-06-02 09:56:29 -07003665 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003666 if (mService != null) {
3667 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003668 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003669 } catch (RemoteException e) {
3670 Log.w(TAG, "Failed talking with device policy service", e);
3671 }
3672 }
3673 return false;
3674 }
3675
3676 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003677 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003678 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003679 *
3680 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3681 * @param packageName The package to be re-enabled in the current profile.
3682 */
Robin Lee25e26452015-06-02 09:56:29 -07003683 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003684 if (mService != null) {
3685 try {
3686 mService.enableSystemApp(admin, packageName);
3687 } catch (RemoteException e) {
3688 Log.w(TAG, "Failed to install package: " + packageName);
3689 }
3690 }
3691 }
3692
3693 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003694 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003695 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003696 *
3697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3698 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3699 * intent will be re-enabled in the current profile.
3700 * @return int The number of activities that matched the intent and were installed.
3701 */
Robin Lee25e26452015-06-02 09:56:29 -07003702 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003703 if (mService != null) {
3704 try {
3705 return mService.enableSystemAppWithIntent(admin, intent);
3706 } catch (RemoteException e) {
3707 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3708 }
3709 }
3710 return 0;
3711 }
3712
3713 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003714 * Called by a device owner or profile owner to disable account management for a specific type
3715 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003716 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003717 * <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 +01003718 * security exception will be thrown.
3719 *
3720 * <p>When account management is disabled for an account type, adding or removing an account
3721 * of that type will not be possible.
3722 *
3723 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3724 * @param accountType For which account management is disabled or enabled.
3725 * @param disabled The boolean indicating that account management will be disabled (true) or
3726 * enabled (false).
3727 */
Robin Lee25e26452015-06-02 09:56:29 -07003728 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003729 boolean disabled) {
3730 if (mService != null) {
3731 try {
3732 mService.setAccountManagementDisabled(admin, accountType, disabled);
3733 } catch (RemoteException e) {
3734 Log.w(TAG, "Failed talking with device policy service", e);
3735 }
3736 }
3737 }
3738
3739 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003740 * Gets the array of accounts for which account management is disabled by the profile owner.
3741 *
3742 * <p> Account management can be disabled/enabled by calling
3743 * {@link #setAccountManagementDisabled}.
3744 *
3745 * @return a list of account types for which account management has been disabled.
3746 *
3747 * @see #setAccountManagementDisabled
3748 */
3749 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003750 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003751 }
3752
3753 /**
3754 * @see #getAccountTypesWithManagementDisabled()
3755 * @hide
3756 */
3757 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003758 if (mService != null) {
3759 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003760 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003761 } catch (RemoteException e) {
3762 Log.w(TAG, "Failed talking with device policy service", e);
3763 }
3764 }
3765
3766 return null;
3767 }
justinzhang511e0d82014-03-24 16:09:24 -04003768
3769 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003770 * Sets which packages may enter lock task mode.
3771 *
3772 * <p>Any packages that shares uid with an allowed package will also be allowed
3773 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003774 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003775 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003776 * package list results in locked tasks belonging to those packages to be finished.
3777 *
Jason Monkc5185f22014-06-24 11:12:42 -04003778 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003779 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003780 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003781 *
3782 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003783 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3784 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003785 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003786 */
Robin Lee25e26452015-06-02 09:56:29 -07003787 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003788 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003789 if (mService != null) {
3790 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003791 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003792 } catch (RemoteException e) {
3793 Log.w(TAG, "Failed talking with device policy service", e);
3794 }
3795 }
3796 }
3797
3798 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003799 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003800 *
3801 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003802 * @hide
3803 */
Robin Lee25e26452015-06-02 09:56:29 -07003804 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003805 if (mService != null) {
3806 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003807 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003808 } catch (RemoteException e) {
3809 Log.w(TAG, "Failed talking with device policy service", e);
3810 }
3811 }
3812 return null;
3813 }
3814
3815 /**
3816 * This function lets the caller know whether the given component is allowed to start the
3817 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003818 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003819 */
Jason Monkd7b86212014-06-16 13:15:38 -04003820 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003821 if (mService != null) {
3822 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003823 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003824 } catch (RemoteException e) {
3825 Log.w(TAG, "Failed talking with device policy service", e);
3826 }
3827 }
3828 return false;
3829 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003830
3831 /**
3832 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3833 * 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 -04003834 * <p>The settings that can be updated with this method are:
3835 * <ul>
3836 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3837 * <li>{@link Settings.Global#AUTO_TIME}</li>
3838 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003839 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003840 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003841 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003842 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003843 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003844 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01003845 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003846 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01003847 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003848 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003849 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003850 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003851 * <ul>
3852 * <li>{@link Settings.Global#BLUETOOTH_ON}.
3853 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
3854 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
3855 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3856 * <li>{@link Settings.Global#MODE_RINGER}.
3857 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
3858 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3859 * <li>{@link Settings.Global#WIFI_ON}.
3860 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
3861 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003862 *
3863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3864 * @param setting The name of the setting to update.
3865 * @param value The value to update the setting to.
3866 */
Robin Lee25e26452015-06-02 09:56:29 -07003867 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003868 if (mService != null) {
3869 try {
3870 mService.setGlobalSetting(admin, setting, value);
3871 } catch (RemoteException e) {
3872 Log.w(TAG, "Failed talking with device policy service", e);
3873 }
3874 }
3875 }
3876
3877 /**
3878 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3879 * that the value of the setting is in the correct form for the setting type should be performed
3880 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003881 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003882 * <ul>
3883 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003884 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003885 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3886 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003887 * <p>A device owner can additionally update the following settings:
3888 * <ul>
3889 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3890 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3892 * @param setting The name of the setting to update.
3893 * @param value The value to update the setting to.
3894 */
Robin Lee25e26452015-06-02 09:56:29 -07003895 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003896 if (mService != null) {
3897 try {
3898 mService.setSecureSetting(admin, setting, value);
3899 } catch (RemoteException e) {
3900 Log.w(TAG, "Failed talking with device policy service", e);
3901 }
3902 }
3903 }
3904
Amith Yamasanif20d6402014-05-24 15:34:37 -07003905 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003906 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003907 * making permission requests of a local or remote administrator of the user.
3908 * <p/>
3909 * Only a profile owner can designate the restrictions provider.
3910 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003911 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003912 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003913 * it removes the restrictions provider previously assigned.
3914 */
Robin Lee25e26452015-06-02 09:56:29 -07003915 public void setRestrictionsProvider(@NonNull ComponentName admin,
3916 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003917 if (mService != null) {
3918 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003919 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003920 } catch (RemoteException re) {
3921 Log.w(TAG, "Failed to set permission provider on device policy service");
3922 }
3923 }
3924 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003925
3926 /**
3927 * Called by profile or device owners to set the master volume mute on or off.
3928 *
3929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3930 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3931 */
Robin Lee25e26452015-06-02 09:56:29 -07003932 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003933 if (mService != null) {
3934 try {
3935 mService.setMasterVolumeMuted(admin, on);
3936 } catch (RemoteException re) {
3937 Log.w(TAG, "Failed to setMasterMute on device policy service");
3938 }
3939 }
3940 }
3941
3942 /**
3943 * Called by profile or device owners to check whether the master volume mute is on or off.
3944 *
3945 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3946 * @return {@code true} if master volume is muted, {@code false} if it's not.
3947 */
Robin Lee25e26452015-06-02 09:56:29 -07003948 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003949 if (mService != null) {
3950 try {
3951 return mService.isMasterVolumeMuted(admin);
3952 } catch (RemoteException re) {
3953 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3954 }
3955 }
3956 return false;
3957 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003958
3959 /**
3960 * Called by profile or device owners to change whether a user can uninstall
3961 * a package.
3962 *
3963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3964 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003965 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003966 */
Robin Lee25e26452015-06-02 09:56:29 -07003967 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003968 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003969 if (mService != null) {
3970 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003971 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003972 } catch (RemoteException re) {
3973 Log.w(TAG, "Failed to call block uninstall on device policy service");
3974 }
3975 }
3976 }
3977
3978 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003979 * Check whether the current user has been blocked by device policy from uninstalling a package.
3980 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00003981 * <p>
3982 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07003983 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00003984 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07003985 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01003986 *
Robin Lee25e26452015-06-02 09:56:29 -07003987 * @param admin The name of the admin component whose blocking policy will be checked, or
3988 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003989 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003990 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003991 */
Robin Lee25e26452015-06-02 09:56:29 -07003992 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003993 if (mService != null) {
3994 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003995 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003996 } catch (RemoteException re) {
3997 Log.w(TAG, "Failed to call block uninstall on device policy service");
3998 }
3999 }
4000 return false;
4001 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004002
4003 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004004 * Called by the profile owner of a managed profile to enable widget providers from a
4005 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004006 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004007 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004008 * a package may have zero or more provider components, where each component
4009 * provides a different widget type.
4010 * <p>
4011 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004012 *
4013 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4014 * @param packageName The package from which widget providers are white-listed.
4015 * @return Whether the package was added.
4016 *
4017 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4018 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4019 */
Robin Lee25e26452015-06-02 09:56:29 -07004020 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004021 if (mService != null) {
4022 try {
4023 return mService.addCrossProfileWidgetProvider(admin, packageName);
4024 } catch (RemoteException re) {
4025 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4026 }
4027 }
4028 return false;
4029 }
4030
4031 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004032 * Called by the profile owner of a managed profile to disable widget providers from a given
4033 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004034 * package should have been added via {@link #addCrossProfileWidgetProvider(
4035 * android.content.ComponentName, String)}.
4036 * <p>
4037 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004038 *
4039 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4040 * @param packageName The package from which widget providers are no longer
4041 * white-listed.
4042 * @return Whether the package was removed.
4043 *
4044 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4045 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4046 */
Robin Lee25e26452015-06-02 09:56:29 -07004047 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004048 if (mService != null) {
4049 try {
4050 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4051 } catch (RemoteException re) {
4052 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4053 }
4054 }
4055 return false;
4056 }
4057
4058 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004059 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004060 * available in the parent profile.
4061 *
4062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4063 * @return The white-listed package list.
4064 *
4065 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4066 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4067 */
Robin Lee25e26452015-06-02 09:56:29 -07004068 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004069 if (mService != null) {
4070 try {
4071 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4072 if (providers != null) {
4073 return providers;
4074 }
4075 } catch (RemoteException re) {
4076 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4077 }
4078 }
4079 return Collections.emptyList();
4080 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004081
4082 /**
4083 * Called by profile or device owners to set the current user's photo.
4084 *
4085 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4086 * @param icon the bitmap to set as the photo.
4087 */
Robin Lee25e26452015-06-02 09:56:29 -07004088 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004089 try {
4090 mService.setUserIcon(admin, icon);
4091 } catch (RemoteException re) {
4092 Log.w(TAG, "Could not set the user icon ", re);
4093 }
4094 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004095
4096 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004097 * Called by device owners to set a local system update policy. When a new policy is set,
4098 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004099 *
Robin Lee25e26452015-06-02 09:56:29 -07004100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4101 * components in the device owner package can set system update policies and the
4102 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004103 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004104 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004105 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004106 */
Robin Lee25e26452015-06-02 09:56:29 -07004107 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004108 if (mService != null) {
4109 try {
Robin Lee25e26452015-06-02 09:56:29 -07004110 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004111 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004112 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004113 }
4114 }
4115 }
4116
4117 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004118 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004119 *
Robin Lee25e26452015-06-02 09:56:29 -07004120 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004121 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004122 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004123 if (mService != null) {
4124 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004125 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004126 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004127 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004128 }
4129 }
4130 return null;
4131 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004132
4133 /**
4134 * Called by a device owner to disable the keyguard altogether.
4135 *
4136 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4137 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4138 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4139 * being disabled.
4140 *
4141 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004142 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004143 *
4144 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004145 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004146 */
Robin Lee25e26452015-06-02 09:56:29 -07004147 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004148 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004149 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004150 } catch (RemoteException re) {
4151 Log.w(TAG, "Failed talking with device policy service", re);
4152 return false;
4153 }
4154 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004155
4156 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004157 * Called by device owner to disable the status bar. Disabling the status bar blocks
4158 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004159 * a single use device.
4160 *
4161 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004162 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4163 *
4164 * @return {@code false} if attempting to disable the status bar failed.
4165 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004166 */
Robin Lee25e26452015-06-02 09:56:29 -07004167 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004168 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004169 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004170 } catch (RemoteException re) {
4171 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004172 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004173 }
4174 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004175
4176 /**
4177 * Callable by the system update service to notify device owners about pending updates.
4178 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4179 * permission.
4180 *
4181 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4182 * when the current pending update was first available. -1 if no update is available.
4183 * @hide
4184 */
4185 @SystemApi
4186 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4187 if (mService != null) {
4188 try {
4189 mService.notifyPendingSystemUpdate(updateReceivedTime);
4190 } catch (RemoteException re) {
4191 Log.w(TAG, "Could not notify device owner about pending system update", re);
4192 }
4193 }
4194 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004195
4196 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004197 * Called by profile or device owners to set the default response for future runtime permission
4198 * requests by applications. The policy can allow for normal operation which prompts the
4199 * user to grant a permission, or can allow automatic granting or denying of runtime
4200 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004201 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4202 * the permission grant state via {@link #setPermissionGrantState}.
4203 *
4204 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004205 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004206 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004207 * @param admin Which profile or device owner this request is associated with.
4208 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4209 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004210 *
4211 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004212 */
Robin Lee25e26452015-06-02 09:56:29 -07004213 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004214 try {
4215 mService.setPermissionPolicy(admin, policy);
4216 } catch (RemoteException re) {
4217 Log.w(TAG, "Failed talking with device policy service", re);
4218 }
4219 }
4220
4221 /**
4222 * Returns the current runtime permission policy set by the device or profile owner. The
4223 * default is {@link #PERMISSION_POLICY_PROMPT}.
4224 * @param admin Which profile or device owner this request is associated with.
4225 * @return the current policy for future permission requests.
4226 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004227 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004228 try {
4229 return mService.getPermissionPolicy(admin);
4230 } catch (RemoteException re) {
4231 return PERMISSION_POLICY_PROMPT;
4232 }
4233 }
4234
4235 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004236 * Sets the grant state of a runtime permission for a specific application. The state
4237 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4238 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4239 * is denied and the user cannot manage it through the UI, and {@link
4240 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4241 * user cannot manage it through the UI. This might affect all permissions in a
4242 * group that the runtime permission belongs to. This method can only be called
4243 * by a profile or device owner.
4244 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004245 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4246 * revoke the permission. It retains the previous grant, if any.
4247 *
4248 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004249 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004250 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004251 * @param admin Which profile or device owner this request is associated with.
4252 * @param packageName The application to grant or revoke a permission to.
4253 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004254 * @param grantState The permission grant state which is one of {@link
4255 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4256 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4257 * @return whether the permission was successfully granted or revoked.
4258 *
4259 * @see #PERMISSION_GRANT_STATE_DENIED
4260 * @see #PERMISSION_GRANT_STATE_DEFAULT
4261 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004262 */
Robin Lee25e26452015-06-02 09:56:29 -07004263 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004264 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004265 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004266 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004267 } catch (RemoteException re) {
4268 Log.w(TAG, "Failed talking with device policy service", re);
4269 return false;
4270 }
4271 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004272
4273 /**
4274 * Returns the current grant state of a runtime permission for a specific application.
4275 *
4276 * @param admin Which profile or device owner this request is associated with.
4277 * @param packageName The application to check the grant state for.
4278 * @param permission The permission to check for.
4279 * @return the current grant state specified by device policy. If the profile or device owner
4280 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4281 * This does not indicate whether or not the permission is currently granted for the package.
4282 *
4283 * <p/>If a grant state was set by the profile or device owner, then the return value will
4284 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4285 * which indicates if the permission is currently denied or granted.
4286 *
4287 * @see #setPermissionGrantState(ComponentName, String, String, int)
4288 * @see PackageManager#checkPermission(String, String)
4289 */
Robin Lee25e26452015-06-02 09:56:29 -07004290 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004291 String permission) {
4292 try {
4293 return mService.getPermissionGrantState(admin, packageName, permission);
4294 } catch (RemoteException re) {
4295 Log.w(TAG, "Failed talking with device policy service", re);
4296 return PERMISSION_GRANT_STATE_DEFAULT;
4297 }
4298 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004299}