blob: 5c22ed579dc42af07ab585e14c77b5d49a587ba4 [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;
Ricky Wai494b95d2015-11-20 16:07:15 +000043import android.provider.ContactsContract.Directory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010044import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070045import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import android.util.Log;
47
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070048import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040049import com.android.org.conscrypt.TrustedCertificateStore;
50
Jessica Hummel91da58d2014-04-10 17:39:43 +010051import org.xmlpull.v1.XmlPullParserException;
52
Maggie Benthallda51e682013-08-08 22:35:44 -040053import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070055import java.net.InetSocketAddress;
56import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010057import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010058import java.security.PrivateKey;
59import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040060import java.security.cert.CertificateException;
61import java.security.cert.CertificateFactory;
62import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010063import java.security.spec.PKCS8EncodedKeySpec;
64import java.security.spec.InvalidKeySpecException;
65import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070066import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070067import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080068import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080069
70/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000071 * Public interface for managing policies enforced on a device. Most clients of this class must be
72 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000073 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000074 * a device administrator may be registered as either a profile or device owner. A given method is
75 * accessible to all device administrators unless the documentation for that method specifies that
76 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080077 *
78 * <div class="special reference">
79 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000080 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080081 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070082 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080083 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080084 */
85public class DevicePolicyManager {
86 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080087
88 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080089 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070090
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070091 private DevicePolicyManager(Context context) {
92 this(context, IDevicePolicyManager.Stub.asInterface(
93 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Dianne Hackbornd6847842010-01-12 18:14:19 -080094 }
95
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080096 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070097 @VisibleForTesting
98 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
99 mContext = context;
100 mService = service;
101 }
102
103 /** @hide */
104 public static DevicePolicyManager create(Context context) {
105 DevicePolicyManager me = new DevicePolicyManager(context);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800106 return me.mService != null ? me : null;
107 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700108
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700109 /** @hide test will override it. */
110 @VisibleForTesting
111 protected int myUserId() {
112 return UserHandle.myUserId();
113 }
114
Dianne Hackbornd6847842010-01-12 18:14:19 -0800115 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000117 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100118 * <p>A managed profile allows data separation for example for the usage of a
119 * device as a personal and corporate device. The user which provisioning is started from and
120 * the managed profile share a launcher.
121 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800122 * <p>This intent will typically be sent by a mobile device management application (MDM).
123 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
124 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100125 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000126 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
127 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700128 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000129 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
130 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000131 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000132 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
133 * in the provisioning intent. The
134 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
135 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
136 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100137 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100138 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
139 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100140 *
141 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
142 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
143 * the provisioning flow was successful, although this doesn't guarantee the full flow will
144 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
145 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000146 */
147 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
148 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100149 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000150
151 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100152 * Activity action: Starts the provisioning flow which sets up a managed device.
153 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
154 *
155 * <p> During device owner provisioning a device admin app is set as the owner of the device.
156 * A device owner has full control over the device. The device owner can not be modified by the
157 * user.
158 *
159 * <p> A typical use case would be a device that is owned by a company, but used by either an
160 * employee or client.
161 *
162 * <p> An intent with this action can be sent only on an unprovisioned device.
163 * It is possible to check if the device is provisioned or not by looking at
164 * {@link android.provider.Settings.Global#DEVICE_PROVISIONED}
165 *
166 * The intent contains the following extras:
167 * <ul>
168 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
169 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
170 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100171 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100172 * </ul>
173 *
174 * <p> When device owner provisioning has completed, an intent of the type
175 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
176 * device owner.
177 *
178 * <p> If provisioning fails, the device is factory reset.
179 *
Alan Treadway4582f812015-07-28 11:49:35 +0100180 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
181 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
182 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
183 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100184 */
185 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
186 public static final String ACTION_PROVISION_MANAGED_DEVICE
187 = "android.app.action.PROVISION_MANAGED_DEVICE";
188
189 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100190 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100191 * allows a mobile device management application or NFC programmer application which starts
192 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100193 * <p>
194 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
195 * sends the intent to pass data to itself on the newly created profile.
196 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
197 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100198 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
199 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
200 * message should contain a stringified {@link java.util.Properties} instance, whose string
201 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
202 * management application after provisioning.
203 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100204 * <p>
205 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700206 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
207 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100208 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100209 */
210 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100211 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100212
213 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100214 * A String extra holding the package name of the mobile device management application that
215 * will be set as the profile owner or device owner.
216 *
217 * <p>If an application starts provisioning directly via an intent with action
218 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
219 * application that started provisioning. The package will be set as profile owner in that case.
220 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000221 * <p>This package is set as device owner when device owner provisioning is started by an NFC
222 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000223 *
224 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700225 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000226
227 * @see DeviceAdminReceiver
228 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100229 * supported, but only if there is only one device admin receiver in the package that requires
230 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000231 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000232 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000233 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100234 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000235
236 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000237 * A ComponentName extra indicating the device admin receiver of the mobile device management
238 * application that will be set as the profile owner or device owner and active admin.
239 *
240 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100241 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
242 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
243 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000244 *
245 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100246 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
247 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400248 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000249 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000250 *
251 * @see DeviceAdminReceiver
252 */
253 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
254 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
255
256 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000257 * An {@link android.accounts.Account} extra holding the account to migrate during managed
258 * profile provisioning. If the account supplied is present in the primary user, it will be
259 * copied, along with its credentials to the managed profile and removed from the primary user.
260 *
261 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
262 */
263
264 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
265 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
266
267 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100268 * A String extra that, holds the email address of the account which a managed profile is
269 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
270 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100271 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100272 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
273 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100274 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
275 * contains this extra, it is forwarded in the
276 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
277 * device management application that was set as the profile owner during provisioning.
278 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100279 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100280 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
281 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100282
283 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000284 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700285 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000286 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100287 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
288 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000289 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000290 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
291 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000292
293 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100294 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
295 * will be set to.
296 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000297 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
298 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100299 */
300 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100301 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100302
303 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100304 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
305 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100306 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000307 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
308 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100309 */
310 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100311 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100312
313 /**
314 * A String extra holding the {@link java.util.Locale} that the device will be set to.
315 * Format: xx_yy, where xx is the language code, and yy the country code.
316 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000317 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
318 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319 */
320 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100321 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100322
323 /**
324 * A String extra holding the ssid of the wifi network that should be used during nfc device
325 * owner provisioning for downloading the mobile device management application.
326 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000327 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
328 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329 */
330 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100331 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100332
333 /**
334 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
335 * is hidden or not.
336 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000337 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
338 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100339 */
340 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100341 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100342
343 /**
344 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100345 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
346 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100347 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000348 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
349 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100350 */
351 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100352 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100353
354 /**
355 * A String extra holding the password of the wifi network in
356 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
357 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000358 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
359 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100360 */
361 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100362 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100363
364 /**
365 * A String extra holding the proxy host for the wifi network in
366 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
367 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000368 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
369 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100370 */
371 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100372 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373
374 /**
375 * An int extra holding the proxy port for the wifi network in
376 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
377 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000378 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
379 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100380 */
381 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100382 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100383
384 /**
385 * A String extra holding the proxy bypass for the wifi network in
386 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
387 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000388 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
389 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100390 */
391 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100392 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100393
394 /**
395 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
396 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
397 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000398 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
399 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100400 */
401 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100402 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100403
404 /**
405 * A String extra holding a url that specifies the download location of the device admin
406 * package. When not provided it is assumed that the device admin package is already installed.
407 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000408 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
409 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100410 */
411 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100412 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100413
414 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400415 * An int extra holding a minimum required version code for the device admin package. If the
416 * device admin is already installed on the device, it will only be re-downloaded from
417 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
418 * installed package is less than this version code.
419 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400420 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400421 * provisioning via an NFC bump.
422 */
423 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
424 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
425
426 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100427 * A String extra holding a http cookie header which should be used in the http request to the
428 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
429 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000430 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
431 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100432 */
433 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100434 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100435
436 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100437 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
438 * the file at download location specified in
439 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100440 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100441 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100442 * present. The provided checksum should match the checksum of the file at the download
443 * location. If the checksum doesn't match an error will be shown to the user and the user will
444 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100445 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000446 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
447 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100448 *
449 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
450 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700451 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100452 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100453 */
454 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100455 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100456
457 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100458 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100459 * android package archive at the download location specified in {@link
460 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
461 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100462 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100463 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
464 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
465 *
466 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100467 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100468 * the download location. If the checksum does not match an error will be shown to the user and
469 * the user will be asked to factory reset the device.
470 *
471 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
472 * provisioning via an NFC bump.
473 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100474 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
475 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100476
477 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000478 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
479 * has completed successfully.
480 *
481 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700482 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000483 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800484 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000485 * corresponds to the account requested to be migrated at provisioning time, if any.
486 */
487 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
488 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
489 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
490
491 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400492 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500493 * provisioning.
494 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400495 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100496 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500497 */
498 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
499 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
500
501 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400502 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100503 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400504 * <p>During device owner provisioning a device admin app is set as the owner of the device.
505 * A device owner has full control over the device. The device owner can not be modified by the
506 * user and the only way of resetting the device is if the device owner app calls a factory
507 * reset.
508 *
509 * <p> A typical use case would be a device that is owned by a company, but used by either an
510 * employee or client.
511 *
512 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100513 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000514 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100515 * contains the following properties:
516 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400517 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
518 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100519 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400520 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100521 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
522 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
523 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
524 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
525 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
526 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
527 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
528 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
529 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
530 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100531 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
532 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
533 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100534 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000535 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700536 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400537 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
538 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
539 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400540 */
541 public static final String MIME_TYPE_PROVISIONING_NFC
542 = "application/com.android.managedprovisioning";
543
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100544 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800545 * Activity action: ask the user to add a new device administrator to the system.
546 * The desired policy is the ComponentName of the policy in the
547 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
548 * bring the user through adding the device administrator to the system (or
549 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700550 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800551 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
552 * field to provide the user with additional explanation (in addition
553 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800554 *
555 * <p>If your administrator is already active, this will ordinarily return immediately (without
556 * user intervention). However, if your administrator has been updated and is requesting
557 * additional uses-policy flags, the user will be presented with the new list. New policies
558 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800559 */
560 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
561 public static final String ACTION_ADD_DEVICE_ADMIN
562 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700563
Dianne Hackbornd6847842010-01-12 18:14:19 -0800564 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700565 * @hide
566 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700567 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700568 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700569 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
570 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700571 * to remotely control restrictions on the user.
572 *
573 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
574 * result of whether or not the user approved the action. If approved, the result will
575 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
576 * as a profile owner.
577 *
578 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
579 * field to provide the user with additional explanation (in addition
580 * to your component's description) about what is being added.
581 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700582 * <p>If there is already a profile owner active or the caller is not a system app, the
583 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700584 */
585 @SystemApi
586 public static final String ACTION_SET_PROFILE_OWNER
587 = "android.app.action.SET_PROFILE_OWNER";
588
589 /**
590 * @hide
591 * Name of the profile owner admin that controls the user.
592 */
593 @SystemApi
594 public static final String EXTRA_PROFILE_OWNER_NAME
595 = "android.app.extra.PROFILE_OWNER_NAME";
596
597 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100598 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700599 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700600 *
Jim Miller284b62e2010-06-08 14:27:42 -0700601 * @hide
602 */
603 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
604 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
605
606 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100607 * Broadcast action: sent when the device owner is set or changed.
608 *
609 * This broadcast is sent only to the primary user.
610 * @see #ACTION_PROVISION_MANAGED_DEVICE
611 */
612 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
613 public static final String ACTION_DEVICE_OWNER_CHANGED
614 = "android.app.action.DEVICE_OWNER_CHANGED";
615
616 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800617 * The ComponentName of the administrator component.
618 *
619 * @see #ACTION_ADD_DEVICE_ADMIN
620 */
621 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700622
Dianne Hackbornd6847842010-01-12 18:14:19 -0800623 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800624 * An optional CharSequence providing additional explanation for why the
625 * admin is being added.
626 *
627 * @see #ACTION_ADD_DEVICE_ADMIN
628 */
629 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700630
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800631 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700632 * Activity action: have the user enter a new password. This activity should
633 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
634 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
635 * enter a new password that meets the current requirements. You can use
636 * {@link #isActivePasswordSufficient()} to determine whether you need to
637 * have the user select a new password in order to meet the current
638 * constraints. Upon being resumed from this activity, you can check the new
639 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800640 */
641 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
642 public static final String ACTION_SET_NEW_PASSWORD
643 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700644
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000645 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000646 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
647 * the parent profile to access intents sent from the managed profile.
648 * That is, when an app in the managed profile calls
649 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
650 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000651 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100652 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000653
654 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000655 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
656 * the managed profile to access intents sent from the parent profile.
657 * That is, when an app in the parent profile calls
658 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
659 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000660 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100661 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700662
Dianne Hackbornd6847842010-01-12 18:14:19 -0800663 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100664 * Broadcast action: notify that a new local system update policy has been set by the device
665 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000666 */
667 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100668 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
669 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000670
Amith Yamasanid49489b2015-04-28 14:00:26 -0700671 /**
672 * Permission policy to prompt user for new permission requests for runtime permissions.
673 * Already granted or denied permissions are not affected by this.
674 */
675 public static final int PERMISSION_POLICY_PROMPT = 0;
676
677 /**
678 * Permission policy to always grant new permission requests for runtime permissions.
679 * Already granted or denied permissions are not affected by this.
680 */
681 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
682
683 /**
684 * Permission policy to always deny new permission requests for runtime permissions.
685 * Already granted or denied permissions are not affected by this.
686 */
687 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
688
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700689 /**
690 * Runtime permission state: The user can manage the permission
691 * through the UI.
692 */
693 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
694
695 /**
696 * Runtime permission state: The permission is granted to the app
697 * and the user cannot manage the permission through the UI.
698 */
699 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
700
701 /**
702 * Runtime permission state: The permission is denied to the app
703 * and the user cannot manage the permission through the UI.
704 */
705 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000706
707 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800708 * Return true if the given administrator component is currently
709 * active (enabled) in the system.
710 */
Robin Lee25e26452015-06-02 09:56:29 -0700711 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700712 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100713 }
714
715 /**
716 * @see #isAdminActive(ComponentName)
717 * @hide
718 */
Robin Lee25e26452015-06-02 09:56:29 -0700719 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800720 if (mService != null) {
721 try {
Robin Lee25e26452015-06-02 09:56:29 -0700722 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800723 } catch (RemoteException e) {
724 Log.w(TAG, "Failed talking with device policy service", e);
725 }
726 }
727 return false;
728 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800729 /**
730 * Return true if the given administrator component is currently being removed
731 * for the user.
732 * @hide
733 */
Robin Lee25e26452015-06-02 09:56:29 -0700734 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800735 if (mService != null) {
736 try {
Robin Lee25e26452015-06-02 09:56:29 -0700737 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800738 } catch (RemoteException e) {
739 Log.w(TAG, "Failed talking with device policy service", e);
740 }
741 }
742 return false;
743 }
744
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700745
Dianne Hackbornd6847842010-01-12 18:14:19 -0800746 /**
Robin Lee25e26452015-06-02 09:56:29 -0700747 * Return a list of all currently active device administrators' component
748 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800749 * returned.
750 */
751 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700752 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100753 }
754
755 /**
756 * @see #getActiveAdmins()
757 * @hide
758 */
759 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800760 if (mService != null) {
761 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100762 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800763 } catch (RemoteException e) {
764 Log.w(TAG, "Failed talking with device policy service", e);
765 }
766 }
767 return null;
768 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700769
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800770 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700771 * Used by package administration code to determine if a package can be stopped
772 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800773 * @hide
774 */
775 public boolean packageHasActiveAdmins(String packageName) {
776 if (mService != null) {
777 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700778 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800779 } catch (RemoteException e) {
780 Log.w(TAG, "Failed talking with device policy service", e);
781 }
782 }
783 return false;
784 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700785
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800786 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800787 * Remove a current administration component. This can only be called
788 * by the application that owns the administration component; if you
789 * try to remove someone else's component, a security exception will be
790 * thrown.
791 */
Robin Lee25e26452015-06-02 09:56:29 -0700792 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800793 if (mService != null) {
794 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700795 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800796 } catch (RemoteException e) {
797 Log.w(TAG, "Failed talking with device policy service", e);
798 }
799 }
800 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700801
Dianne Hackbornd6847842010-01-12 18:14:19 -0800802 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800803 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700804 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800805 * but requires additional policies after an upgrade.
806 *
807 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
808 * an active administrator, or an exception will be thrown.
809 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
810 */
Robin Lee25e26452015-06-02 09:56:29 -0700811 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800812 if (mService != null) {
813 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700814 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800815 } catch (RemoteException e) {
816 Log.w(TAG, "Failed talking with device policy service", e);
817 }
818 }
819 return false;
820 }
821
822 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800823 * Constant for {@link #setPasswordQuality}: the policy has no requirements
824 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800825 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800826 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800827 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700828
Dianne Hackbornd6847842010-01-12 18:14:19 -0800829 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700830 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
831 * recognition technology. This implies technologies that can recognize the identity of
832 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
833 * Note that quality constants are ordered so that higher values are more restrictive.
834 */
835 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
836
837 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800838 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100839 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800840 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800841 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800842 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700843
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800844 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800845 * Constant for {@link #setPasswordQuality}: the user must have entered a
846 * password containing at least numeric characters. Note that quality
847 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800848 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800849 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700850
Dianne Hackbornd6847842010-01-12 18:14:19 -0800851 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800852 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800853 * password containing at least numeric characters with no repeating (4444)
854 * or ordered (1234, 4321, 2468) sequences. Note that quality
855 * constants are ordered so that higher values are more restrictive.
856 */
857 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
858
859 /**
860 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700861 * password containing at least alphabetic (or other symbol) characters.
862 * Note that quality constants are ordered so that higher values are more
863 * restrictive.
864 */
865 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700866
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700867 /**
868 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800869 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700870 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800871 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800872 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700873 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700874
Dianne Hackbornd6847842010-01-12 18:14:19 -0800875 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700876 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700877 * password containing at least a letter, a numerical digit and a special
878 * symbol, by default. With this password quality, passwords can be
879 * restricted to contain various sets of characters, like at least an
880 * uppercase letter, etc. These are specified using various methods,
881 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
882 * that quality constants are ordered so that higher values are more
883 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700884 */
885 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
886
887 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800888 * Called by an application that is administering the device to set the
889 * password restrictions it is imposing. After setting this, the user
890 * will not be able to enter a new password that is not at least as
891 * restrictive as what has been set. Note that the current password
892 * will remain until the user has set a new one, so the change does not
893 * take place immediately. To prompt the user for a new password, use
894 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700895 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800896 * <p>Quality constants are ordered so that higher values are more restrictive;
897 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800898 * the user's preference, and any other considerations) is the one that
899 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700900 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800901 * <p>The calling device admin must have requested
902 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
903 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700904 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800906 * @param quality The new desired quality. One of
907 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800908 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
909 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
910 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800911 */
Robin Lee25e26452015-06-02 09:56:29 -0700912 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800913 if (mService != null) {
914 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800915 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800916 } catch (RemoteException e) {
917 Log.w(TAG, "Failed talking with device policy service", e);
918 }
919 }
920 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700921
Dianne Hackbornd6847842010-01-12 18:14:19 -0800922 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100923 * Retrieve the current minimum password quality for all admins of this user
924 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -0700925 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -0800926 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800927 */
Robin Lee25e26452015-06-02 09:56:29 -0700928 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700929 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700930 }
931
932 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -0700933 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800934 if (mService != null) {
935 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700936 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800937 } catch (RemoteException e) {
938 Log.w(TAG, "Failed talking with device policy service", e);
939 }
940 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800941 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800942 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700943
Dianne Hackbornd6847842010-01-12 18:14:19 -0800944 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800945 * Called by an application that is administering the device to set the
946 * minimum allowed password length. After setting this, the user
947 * will not be able to enter a new password that is not at least as
948 * restrictive as what has been set. Note that the current password
949 * will remain until the user has set a new one, so the change does not
950 * take place immediately. To prompt the user for a new password, use
951 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
952 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800953 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
954 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
955 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700956 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800957 * <p>The calling device admin must have requested
958 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
959 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700960 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800961 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800962 * @param length The new desired minimum password length. A value of 0
963 * means there is no restriction.
964 */
Robin Lee25e26452015-06-02 09:56:29 -0700965 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800966 if (mService != null) {
967 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800968 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800969 } catch (RemoteException e) {
970 Log.w(TAG, "Failed talking with device policy service", e);
971 }
972 }
973 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700974
Dianne Hackbornd6847842010-01-12 18:14:19 -0800975 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100976 * Retrieve the current minimum password length for all admins of this
977 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -0700978 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -0800979 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800980 */
Robin Lee25e26452015-06-02 09:56:29 -0700981 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700982 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700983 }
984
985 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -0700986 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800987 if (mService != null) {
988 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700989 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800990 } catch (RemoteException e) {
991 Log.w(TAG, "Failed talking with device policy service", e);
992 }
993 }
994 return 0;
995 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700996
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700997 /**
998 * Called by an application that is administering the device to set the
999 * minimum number of upper case letters required in the password. After
1000 * setting this, the user will not be able to enter a new password that is
1001 * not at least as restrictive as what has been set. Note that the current
1002 * password will remain until the user has set a new one, so the change does
1003 * not take place immediately. To prompt the user for a new password, use
1004 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1005 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001006 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1007 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001008 * <p>
1009 * The calling device admin must have requested
1010 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1011 * this method; if it has not, a security exception will be thrown.
1012 *
1013 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1014 * with.
1015 * @param length The new desired minimum number of upper case letters
1016 * required in the password. A value of 0 means there is no
1017 * restriction.
1018 */
Robin Lee25e26452015-06-02 09:56:29 -07001019 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001020 if (mService != null) {
1021 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001022 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001023 } catch (RemoteException e) {
1024 Log.w(TAG, "Failed talking with device policy service", e);
1025 }
1026 }
1027 }
1028
1029 /**
1030 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001031 * password for all admins of this user and its profiles or a particular one.
1032 * This is the same value as set by
1033 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001034 * and only applies when the password quality is
1035 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001036 *
Robin Lee25e26452015-06-02 09:56:29 -07001037 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001038 * aggregate all admins.
1039 * @return The minimum number of upper case letters required in the
1040 * password.
1041 */
Robin Lee25e26452015-06-02 09:56:29 -07001042 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001043 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001044 }
1045
1046 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001047 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001048 if (mService != null) {
1049 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001050 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001051 } catch (RemoteException e) {
1052 Log.w(TAG, "Failed talking with device policy service", e);
1053 }
1054 }
1055 return 0;
1056 }
1057
1058 /**
1059 * Called by an application that is administering the device to set the
1060 * minimum number of lower case letters required in the password. After
1061 * setting this, the user will not be able to enter a new password that is
1062 * not at least as restrictive as what has been set. Note that the current
1063 * password will remain until the user has set a new one, so the change does
1064 * not take place immediately. To prompt the user for a new password, use
1065 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1066 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001067 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1068 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001069 * <p>
1070 * The calling device admin must have requested
1071 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1072 * this method; if it has not, a security exception will be thrown.
1073 *
1074 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1075 * with.
1076 * @param length The new desired minimum number of lower case letters
1077 * required in the password. A value of 0 means there is no
1078 * restriction.
1079 */
Robin Lee25e26452015-06-02 09:56:29 -07001080 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001081 if (mService != null) {
1082 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001083 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001084 } catch (RemoteException e) {
1085 Log.w(TAG, "Failed talking with device policy service", e);
1086 }
1087 }
1088 }
1089
1090 /**
1091 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001092 * password for all admins of this user and its profiles or a particular one.
1093 * This is the same value as set by
1094 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001095 * and only applies when the password quality is
1096 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001097 *
Robin Lee25e26452015-06-02 09:56:29 -07001098 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001099 * aggregate all admins.
1100 * @return The minimum number of lower case letters required in the
1101 * password.
1102 */
Robin Lee25e26452015-06-02 09:56:29 -07001103 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001104 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001105 }
1106
1107 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001108 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001109 if (mService != null) {
1110 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001111 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001112 } catch (RemoteException e) {
1113 Log.w(TAG, "Failed talking with device policy service", e);
1114 }
1115 }
1116 return 0;
1117 }
1118
1119 /**
1120 * Called by an application that is administering the device to set the
1121 * minimum number of letters required in the password. After setting this,
1122 * the user will not be able to enter a new password that is not at least as
1123 * restrictive as what has been set. Note that the current password will
1124 * remain until the user has set a new one, so the change does not take
1125 * place immediately. To prompt the user for a new password, use
1126 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1127 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001128 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1129 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001130 * <p>
1131 * The calling device admin must have requested
1132 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1133 * this method; if it has not, a security exception will be thrown.
1134 *
1135 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1136 * with.
1137 * @param length The new desired minimum number of letters required in the
1138 * password. A value of 0 means there is no restriction.
1139 */
Robin Lee25e26452015-06-02 09:56:29 -07001140 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001141 if (mService != null) {
1142 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001143 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001144 } catch (RemoteException e) {
1145 Log.w(TAG, "Failed talking with device policy service", e);
1146 }
1147 }
1148 }
1149
1150 /**
1151 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001152 * admins or a particular one. This is the same value as
1153 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1154 * and only applies when the password quality is
1155 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001156 *
Robin Lee25e26452015-06-02 09:56:29 -07001157 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001158 * aggregate all admins.
1159 * @return The minimum number of letters required in the password.
1160 */
Robin Lee25e26452015-06-02 09:56:29 -07001161 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001162 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001163 }
1164
1165 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001166 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001167 if (mService != null) {
1168 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001169 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001170 } catch (RemoteException e) {
1171 Log.w(TAG, "Failed talking with device policy service", e);
1172 }
1173 }
1174 return 0;
1175 }
1176
1177 /**
1178 * Called by an application that is administering the device to set the
1179 * minimum number of numerical digits required in the password. After
1180 * setting this, the user will not be able to enter a new password that is
1181 * not at least as restrictive as what has been set. Note that the current
1182 * password will remain until the user has set a new one, so the change does
1183 * not take place immediately. To prompt the user for a new password, use
1184 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1185 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001186 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1187 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 * <p>
1189 * The calling device admin must have requested
1190 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1191 * this method; if it has not, a security exception will be thrown.
1192 *
1193 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1194 * with.
1195 * @param length The new desired minimum number of numerical digits required
1196 * in the password. A value of 0 means there is no restriction.
1197 */
Robin Lee25e26452015-06-02 09:56:29 -07001198 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001199 if (mService != null) {
1200 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001201 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001202 } catch (RemoteException e) {
1203 Log.w(TAG, "Failed talking with device policy service", e);
1204 }
1205 }
1206 }
1207
1208 /**
1209 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001210 * for all admins of this user and its profiles or a particular one.
1211 * This is the same value as set by
1212 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001213 * and only applies when the password quality is
1214 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001215 *
Robin Lee25e26452015-06-02 09:56:29 -07001216 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001217 * aggregate all admins.
1218 * @return The minimum number of numerical digits required in the password.
1219 */
Robin Lee25e26452015-06-02 09:56:29 -07001220 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001221 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001222 }
1223
1224 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001225 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001226 if (mService != null) {
1227 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001228 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001229 } catch (RemoteException e) {
1230 Log.w(TAG, "Failed talking with device policy service", e);
1231 }
1232 }
1233 return 0;
1234 }
1235
1236 /**
1237 * Called by an application that is administering the device to set the
1238 * minimum number of symbols required in the password. After setting this,
1239 * the user will not be able to enter a new password that is not at least as
1240 * restrictive as what has been set. Note that the current password will
1241 * remain until the user has set a new one, so the change does not take
1242 * place immediately. To prompt the user for a new password, use
1243 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1244 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001245 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1246 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001247 * <p>
1248 * The calling device admin must have requested
1249 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1250 * this method; if it has not, a security exception will be thrown.
1251 *
1252 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1253 * with.
1254 * @param length The new desired minimum number of symbols required in the
1255 * password. A value of 0 means there is no restriction.
1256 */
Robin Lee25e26452015-06-02 09:56:29 -07001257 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001258 if (mService != null) {
1259 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001260 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001261 } catch (RemoteException e) {
1262 Log.w(TAG, "Failed talking with device policy service", e);
1263 }
1264 }
1265 }
1266
1267 /**
1268 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001269 * admins or a particular one. This is the same value as
1270 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1271 * and only applies when the password quality is
1272 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001273 *
Robin Lee25e26452015-06-02 09:56:29 -07001274 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001275 * aggregate all admins.
1276 * @return The minimum number of symbols required in the password.
1277 */
Robin Lee25e26452015-06-02 09:56:29 -07001278 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001279 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001280 }
1281
1282 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001283 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001284 if (mService != null) {
1285 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001286 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001287 } catch (RemoteException e) {
1288 Log.w(TAG, "Failed talking with device policy service", e);
1289 }
1290 }
1291 return 0;
1292 }
1293
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001294 /**
1295 * Called by an application that is administering the device to set the
1296 * minimum number of non-letter characters (numerical digits or symbols)
1297 * required in the password. After setting this, the user will not be able
1298 * to enter a new password that is not at least as restrictive as what has
1299 * been set. Note that the current password will remain until the user has
1300 * set a new one, so the change does not take place immediately. To prompt
1301 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1302 * setting this value. This constraint is only imposed if the administrator
1303 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1304 * {@link #setPasswordQuality}. The default value is 0.
1305 * <p>
1306 * The calling device admin must have requested
1307 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1308 * this method; if it has not, a security exception will be thrown.
1309 *
1310 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1311 * with.
1312 * @param length The new desired minimum number of letters required in the
1313 * password. A value of 0 means there is no restriction.
1314 */
Robin Lee25e26452015-06-02 09:56:29 -07001315 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001316 if (mService != null) {
1317 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001318 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001319 } catch (RemoteException e) {
1320 Log.w(TAG, "Failed talking with device policy service", e);
1321 }
1322 }
1323 }
1324
1325 /**
1326 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001327 * password for all admins of this user and its profiles or a particular one.
1328 * This is the same value as set by
1329 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001330 * and only applies when the password quality is
1331 * {@link #PASSWORD_QUALITY_COMPLEX}.
1332 *
Robin Lee25e26452015-06-02 09:56:29 -07001333 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001334 * aggregate all admins.
1335 * @return The minimum number of letters required in the password.
1336 */
Robin Lee25e26452015-06-02 09:56:29 -07001337 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001338 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001339 }
1340
1341 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001342 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001343 if (mService != null) {
1344 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001345 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001346 } catch (RemoteException e) {
1347 Log.w(TAG, "Failed talking with device policy service", e);
1348 }
1349 }
1350 return 0;
1351 }
1352
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001353 /**
1354 * Called by an application that is administering the device to set the length
1355 * of the password history. After setting this, the user will not be able to
1356 * enter a new password that is the same as any password in the history. Note
1357 * that the current password will remain until the user has set a new one, so
1358 * the change does not take place immediately. To prompt the user for a new
1359 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1360 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001361 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1362 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1363 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001364 *
1365 * <p>
1366 * The calling device admin must have requested
1367 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1368 * method; if it has not, a security exception will be thrown.
1369 *
1370 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1371 * with.
1372 * @param length The new desired length of password history. A value of 0
1373 * means there is no restriction.
1374 */
Robin Lee25e26452015-06-02 09:56:29 -07001375 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001376 if (mService != null) {
1377 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001378 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001379 } catch (RemoteException e) {
1380 Log.w(TAG, "Failed talking with device policy service", e);
1381 }
1382 }
1383 }
1384
1385 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001386 * Called by a device admin to set the password expiration timeout. Calling this method
1387 * will restart the countdown for password expiration for the given admin, as will changing
1388 * the device password (for all admins).
1389 *
1390 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1391 * For example, to have the password expire 5 days from now, timeout would be
1392 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1393 *
1394 * <p>To disable password expiration, a value of 0 may be used for timeout.
1395 *
Jim Millera4e28d12010-11-08 16:15:47 -08001396 * <p>The calling device admin must have requested
1397 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1398 * method; if it has not, a security exception will be thrown.
1399 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001400 * <p> Note that setting the password will automatically reset the expiration time for all
1401 * active admins. Active admins do not need to explicitly call this method in that case.
1402 *
Jim Millera4e28d12010-11-08 16:15:47 -08001403 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1404 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1405 * means there is no restriction (unlimited).
1406 */
Robin Lee25e26452015-06-02 09:56:29 -07001407 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001408 if (mService != null) {
1409 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001410 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001411 } catch (RemoteException e) {
1412 Log.w(TAG, "Failed talking with device policy service", e);
1413 }
1414 }
1415 }
1416
1417 /**
Jim Miller6b857682011-02-16 16:27:41 -08001418 * Get the password expiration timeout for the given admin. The expiration timeout is the
1419 * recurring expiration timeout provided in the call to
1420 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001421 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001422 *
Robin Lee25e26452015-06-02 09:56:29 -07001423 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001424 * @return The timeout for the given admin or the minimum of all timeouts
1425 */
Robin Lee25e26452015-06-02 09:56:29 -07001426 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001427 if (mService != null) {
1428 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001429 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001430 } catch (RemoteException e) {
1431 Log.w(TAG, "Failed talking with device policy service", e);
1432 }
1433 }
1434 return 0;
1435 }
1436
1437 /**
1438 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001439 * all admins of this user and its profiles if admin is null. If the password is
1440 * expired, this will return the time since the password expired as a negative number.
1441 * If admin is null, then a composite of all expiration timeouts is returned
1442 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001443 *
Robin Lee25e26452015-06-02 09:56:29 -07001444 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001445 * @return The password expiration time, in ms.
1446 */
Robin Lee25e26452015-06-02 09:56:29 -07001447 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001448 if (mService != null) {
1449 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001450 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001451 } catch (RemoteException e) {
1452 Log.w(TAG, "Failed talking with device policy service", e);
1453 }
1454 }
1455 return 0;
1456 }
1457
1458 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001459 * Retrieve the current password history length for all admins of this
1460 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001461 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001462 * all admins.
1463 * @return The length of the password history
1464 */
Robin Lee25e26452015-06-02 09:56:29 -07001465 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001466 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001467 }
1468
1469 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001470 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001471 if (mService != null) {
1472 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001473 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001474 } catch (RemoteException e) {
1475 Log.w(TAG, "Failed talking with device policy service", e);
1476 }
1477 }
1478 return 0;
1479 }
1480
Dianne Hackbornd6847842010-01-12 18:14:19 -08001481 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001482 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001483 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001484 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001485 * @return Returns the maximum length that the user can enter.
1486 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001487 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001488 // Kind-of arbitrary.
1489 return 16;
1490 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001491
Dianne Hackborn254cb442010-01-27 19:23:59 -08001492 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001493 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001494 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001495 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001496 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001497 * <p>The calling device admin must have requested
1498 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1499 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001500 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001501 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001502 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001503 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001504 if (mService != null) {
1505 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001506 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001507 } catch (RemoteException e) {
1508 Log.w(TAG, "Failed talking with device policy service", e);
1509 }
1510 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001511 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001512 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001513
Dianne Hackbornd6847842010-01-12 18:14:19 -08001514 /**
1515 * Retrieve the number of times the user has failed at entering a
1516 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001517 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001518 * <p>The calling device admin must have requested
1519 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1520 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001521 */
1522 public int getCurrentFailedPasswordAttempts() {
1523 if (mService != null) {
1524 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001525 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001526 } catch (RemoteException e) {
1527 Log.w(TAG, "Failed talking with device policy service", e);
1528 }
1529 }
1530 return -1;
1531 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001532
1533 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001534 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001535 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001536 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001537 * @hide
1538 */
1539 public boolean getDoNotAskCredentialsOnBoot() {
1540 if (mService != null) {
1541 try {
1542 return mService.getDoNotAskCredentialsOnBoot();
1543 } catch (RemoteException e) {
1544 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1545 }
1546 }
1547 return false;
1548 }
1549
1550 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001551 * Setting this to a value greater than zero enables a built-in policy
1552 * that will perform a device wipe after too many incorrect
1553 * device-unlock passwords have been entered. This built-in policy combines
1554 * watching for failed passwords and wiping the device, and requires
1555 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001556 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001557 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001558 * <p>To implement any other policy (e.g. wiping data for a particular
1559 * application only, erasing or revoking credentials, or reporting the
1560 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001561 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001562 * instead. Do not use this API, because if the maximum count is reached,
1563 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001564 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001566 * @param num The number of failed password attempts at which point the
1567 * device will wipe its data.
1568 */
Robin Lee25e26452015-06-02 09:56:29 -07001569 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001570 if (mService != null) {
1571 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001572 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001573 } catch (RemoteException e) {
1574 Log.w(TAG, "Failed talking with device policy service", e);
1575 }
1576 }
1577 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001578
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001579 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001580 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001581 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001582 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001583 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001584 * all admins.
1585 */
Robin Lee25e26452015-06-02 09:56:29 -07001586 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001587 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001588 }
1589
1590 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001591 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001592 if (mService != null) {
1593 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001594 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001595 } catch (RemoteException e) {
1596 Log.w(TAG, "Failed talking with device policy service", e);
1597 }
1598 }
1599 return 0;
1600 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001601
Dianne Hackborn254cb442010-01-27 19:23:59 -08001602 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001603 * Returns the profile with the smallest maximum failed passwords for wipe,
1604 * for the given user. So for primary user, it might return the primary or
1605 * a managed profile. For a secondary user, it would be the same as the
1606 * user passed in.
1607 * @hide Used only by Keyguard
1608 */
1609 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1610 if (mService != null) {
1611 try {
1612 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1613 } catch (RemoteException e) {
1614 Log.w(TAG, "Failed talking with device policy service", e);
1615 }
1616 }
1617 return UserHandle.USER_NULL;
1618 }
1619
1620 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001621 * Flag for {@link #resetPassword}: don't allow other admins to change
1622 * the password again until the user has entered it.
1623 */
1624 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001625
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001626 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001627 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1628 * If the flag is set, the device can be booted without asking for user password.
1629 * The absence of this flag does not change the current boot requirements. This flag
1630 * can be set by the device owner only. If the app is not the device owner, the flag
1631 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1632 * device to factory defaults.
1633 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001634 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001635
1636 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001637 * Force a new device unlock password (the password needed to access the
1638 * entire device, not for individual accounts) on the user. This takes
1639 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001640 * The given password must be sufficient for the
1641 * current password quality and length constraints as returned by
1642 * {@link #getPasswordQuality(ComponentName)} and
1643 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1644 * these constraints, then it will be rejected and false returned. Note
1645 * that the password may be a stronger quality (containing alphanumeric
1646 * characters when the requested quality is only numeric), in which case
1647 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001648 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001649 * <p>Calling with a null or empty password will clear any existing PIN,
1650 * pattern or password if the current password constraints allow it.
1651 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001652 * <p>The calling device admin must have requested
1653 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1654 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001655 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001656 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001657 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001658 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001659 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001660 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001661 * @return Returns true if the password was applied, or false if it is
1662 * not acceptable for the current constraints.
1663 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001664 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001665 if (mService != null) {
1666 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001667 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001668 } catch (RemoteException e) {
1669 Log.w(TAG, "Failed talking with device policy service", e);
1670 }
1671 }
1672 return false;
1673 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001674
Dianne Hackbornd6847842010-01-12 18:14:19 -08001675 /**
1676 * Called by an application that is administering the device to set the
1677 * maximum time for user activity until the device will lock. This limits
1678 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001679 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001680 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001681 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001682 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001683 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001685 * @param timeMs The new desired maximum time to lock in milliseconds.
1686 * A value of 0 means there is no restriction.
1687 */
Robin Lee25e26452015-06-02 09:56:29 -07001688 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001689 if (mService != null) {
1690 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001691 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001692 } catch (RemoteException e) {
1693 Log.w(TAG, "Failed talking with device policy service", e);
1694 }
1695 }
1696 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001697
Dianne Hackbornd6847842010-01-12 18:14:19 -08001698 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001699 * Retrieve the current maximum time to unlock for all admins of this user
1700 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001701 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001702 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001703 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001704 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001705 */
Robin Lee25e26452015-06-02 09:56:29 -07001706 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001707 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001708 }
1709
1710 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001711 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001712 if (mService != null) {
1713 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001714 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001715 } catch (RemoteException e) {
1716 Log.w(TAG, "Failed talking with device policy service", e);
1717 }
1718 }
1719 return 0;
1720 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001721
Dianne Hackbornd6847842010-01-12 18:14:19 -08001722 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001723 * Make the device lock immediately, as if the lock screen timeout has
1724 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001725 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001726 * <p>The calling device admin must have requested
1727 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1728 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001729 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001730 public void lockNow() {
1731 if (mService != null) {
1732 try {
1733 mService.lockNow();
1734 } catch (RemoteException e) {
1735 Log.w(TAG, "Failed talking with device policy service", e);
1736 }
1737 }
1738 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001739
Dianne Hackbornd6847842010-01-12 18:14:19 -08001740 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001741 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001742 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001743 */
1744 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1745
1746 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001747 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1748 * data.
1749 *
Paul Crowley2934b262014-12-02 11:21:13 +00001750 * <p>This flag may only be set by device owner admins; if it is set by
1751 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001752 */
1753 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1754
1755 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001756 * Ask the user data be wiped. Wiping the primary user will cause the
1757 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001758 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001759 * <p>The calling device admin must have requested
1760 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1761 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001762 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001763 * @param flags Bit mask of additional options: currently supported flags
1764 * are {@link #WIPE_EXTERNAL_STORAGE} and
1765 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001766 */
1767 public void wipeData(int flags) {
1768 if (mService != null) {
1769 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001770 mService.wipeData(flags, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001771 } catch (RemoteException e) {
1772 Log.w(TAG, "Failed talking with device policy service", e);
1773 }
1774 }
1775 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001776
Dianne Hackbornd6847842010-01-12 18:14:19 -08001777 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001778 * Called by an application that is administering the device to set the
1779 * global proxy and exclusion list.
1780 * <p>
1781 * The calling device admin must have requested
1782 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1783 * this method; if it has not, a security exception will be thrown.
1784 * Only the first device admin can set the proxy. If a second admin attempts
1785 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001786 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001787 * be returned.
1788 * The method can be called repeatedly by the device admin alrady setting the
1789 * proxy to update the proxy and exclusion list.
1790 *
Robin Lee25e26452015-06-02 09:56:29 -07001791 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001792 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1793 * Pass Proxy.NO_PROXY to reset the proxy.
1794 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001795 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1796 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001797 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001798 */
Robin Lee25e26452015-06-02 09:56:29 -07001799 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001800 List<String> exclusionList ) {
1801 if (proxySpec == null) {
1802 throw new NullPointerException();
1803 }
1804 if (mService != null) {
1805 try {
1806 String hostSpec;
1807 String exclSpec;
1808 if (proxySpec.equals(Proxy.NO_PROXY)) {
1809 hostSpec = null;
1810 exclSpec = null;
1811 } else {
1812 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1813 throw new IllegalArgumentException();
1814 }
1815 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1816 String hostName = sa.getHostName();
1817 int port = sa.getPort();
1818 StringBuilder hostBuilder = new StringBuilder();
1819 hostSpec = hostBuilder.append(hostName)
1820 .append(":").append(Integer.toString(port)).toString();
1821 if (exclusionList == null) {
1822 exclSpec = "";
1823 } else {
1824 StringBuilder listBuilder = new StringBuilder();
1825 boolean firstDomain = true;
1826 for (String exclDomain : exclusionList) {
1827 if (!firstDomain) {
1828 listBuilder = listBuilder.append(",");
1829 } else {
1830 firstDomain = false;
1831 }
1832 listBuilder = listBuilder.append(exclDomain.trim());
1833 }
1834 exclSpec = listBuilder.toString();
1835 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001836 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1837 != android.net.Proxy.PROXY_VALID)
1838 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001839 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001840 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001841 } catch (RemoteException e) {
1842 Log.w(TAG, "Failed talking with device policy service", e);
1843 }
1844 }
1845 return null;
1846 }
1847
1848 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001849 * Set a network-independent global HTTP proxy. This is not normally what you want
1850 * for typical HTTP proxies - they are generally network dependent. However if you're
1851 * doing something unusual like general internal filtering this may be useful. On
1852 * a private network where the proxy is not accessible, you may break HTTP using this.
1853 *
1854 * <p>This method requires the caller to be the device owner.
1855 *
1856 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1857 * @see ProxyInfo
1858 *
1859 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1860 * with.
1861 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1862 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1863 */
Robin Lee25e26452015-06-02 09:56:29 -07001864 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1865 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001866 if (mService != null) {
1867 try {
1868 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1869 } catch (RemoteException e) {
1870 Log.w(TAG, "Failed talking with device policy service", e);
1871 }
1872 }
1873 }
1874
1875 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001876 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001877 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1878 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001879 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001880 */
1881 public ComponentName getGlobalProxyAdmin() {
1882 if (mService != null) {
1883 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001884 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001885 } catch (RemoteException e) {
1886 Log.w(TAG, "Failed talking with device policy service", e);
1887 }
1888 }
1889 return null;
1890 }
1891
1892 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001893 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001894 * indicating that encryption is not supported.
1895 */
1896 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1897
1898 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001899 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001900 * indicating that encryption is supported, but is not currently active.
1901 */
1902 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1903
1904 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001905 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001906 * indicating that encryption is not currently active, but is currently
1907 * being activated. This is only reported by devices that support
1908 * encryption of data and only when the storage is currently
1909 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1910 * to become encrypted will never return this value.
1911 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001912 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001913
1914 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001915 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001916 * indicating that encryption is active.
1917 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001918 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001919
1920 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001921 * Result code for {@link #getStorageEncryptionStatus}:
1922 * indicating that encryption is active, but an encryption key has not
1923 * been set by the user.
1924 */
1925 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1926
1927 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001928 * Activity action: begin the process of encrypting data on the device. This activity should
1929 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1930 * After resuming from this activity, use {@link #getStorageEncryption}
1931 * to check encryption status. However, on some devices this activity may never return, as
1932 * it may trigger a reboot and in some cases a complete data wipe of the device.
1933 */
1934 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1935 public static final String ACTION_START_ENCRYPTION
1936 = "android.app.action.START_ENCRYPTION";
1937
1938 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001939 * Widgets are enabled in keyguard
1940 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001941 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001942
1943 /**
Jim Miller50e62182014-04-23 17:25:00 -07001944 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001945 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001946 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1947
1948 /**
1949 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1950 */
1951 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1952
1953 /**
Jim Miller50e62182014-04-23 17:25:00 -07001954 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1955 */
1956 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1957
1958 /**
1959 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1960 */
1961 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1962
1963 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001964 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001965 * (e.g. PIN/Pattern/Password).
1966 */
1967 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1968
1969 /**
Jim Miller06e34502014-07-17 14:46:05 -07001970 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1971 */
1972 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1973
1974 /**
Jim Miller35207742012-11-02 15:33:20 -07001975 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001976 */
1977 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001978
1979 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001980 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001981 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001982 *
1983 * <p>When multiple device administrators attempt to control device
1984 * encryption, the most secure, supported setting will always be
1985 * used. If any device administrator requests device encryption,
1986 * it will be enabled; Conversely, if a device administrator
1987 * attempts to disable device encryption while another
1988 * device administrator has enabled it, the call to disable will
1989 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1990 *
1991 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001992 * written to other storage areas may or may not be encrypted, and this policy does not require
1993 * or control the encryption of any other storage areas.
1994 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1995 * {@code true}, then the directory returned by
1996 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1997 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001998 *
1999 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2000 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2001 * the encryption key may not be fully secured. For maximum security, the administrator should
2002 * also require (and check for) a pattern, PIN, or password.
2003 *
2004 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2005 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002006 * @return the new request status (for all active admins) - will be one of
2007 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2008 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2009 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002010 */
Robin Lee25e26452015-06-02 09:56:29 -07002011 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002012 if (mService != null) {
2013 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002014 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002015 } catch (RemoteException e) {
2016 Log.w(TAG, "Failed talking with device policy service", e);
2017 }
2018 }
2019 return ENCRYPTION_STATUS_UNSUPPORTED;
2020 }
2021
2022 /**
2023 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002024 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002025 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002026 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2027 * this will return the requested encryption setting as an aggregate of all active
2028 * administrators.
2029 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002030 */
Robin Lee25e26452015-06-02 09:56:29 -07002031 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002032 if (mService != null) {
2033 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002034 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002035 } catch (RemoteException e) {
2036 Log.w(TAG, "Failed talking with device policy service", e);
2037 }
2038 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002039 return false;
2040 }
2041
2042 /**
2043 * Called by an application that is administering the device to
2044 * determine the current encryption status of the device.
2045 *
2046 * Depending on the returned status code, the caller may proceed in different
2047 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2048 * storage system does not support encryption. If the
2049 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2050 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002051 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2052 * storage system has enabled encryption but no password is set so further action
2053 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002054 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2055 *
Robin Lee7e678712014-07-24 16:41:31 +01002056 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002057 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002058 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2059 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002060 */
2061 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002062 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002063 }
2064
2065 /** @hide per-user version */
2066 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002067 if (mService != null) {
2068 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002069 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002070 } catch (RemoteException e) {
2071 Log.w(TAG, "Failed talking with device policy service", e);
2072 }
2073 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002074 return ENCRYPTION_STATUS_UNSUPPORTED;
2075 }
2076
2077 /**
Robin Lee7e678712014-07-24 16:41:31 +01002078 * Installs the given certificate as a user CA.
2079 *
Robin Lee25e26452015-06-02 09:56:29 -07002080 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2081 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002082 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002083 *
2084 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002085 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002086 */
Robin Lee25e26452015-06-02 09:56:29 -07002087 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002088 if (mService != null) {
2089 try {
Robin Lee7e678712014-07-24 16:41:31 +01002090 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002091 } catch (RemoteException e) {
2092 Log.w(TAG, "Failed talking with device policy service", e);
2093 }
2094 }
2095 return false;
2096 }
2097
2098 /**
Robin Lee7e678712014-07-24 16:41:31 +01002099 * Uninstalls the given certificate from trusted user CAs, if present.
2100 *
Robin Lee25e26452015-06-02 09:56:29 -07002101 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2102 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002103 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002104 */
Robin Lee25e26452015-06-02 09:56:29 -07002105 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002106 if (mService != null) {
2107 try {
Robin Lee306fe082014-06-19 14:04:24 +00002108 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002109 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002110 } catch (CertificateException e) {
2111 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002112 } catch (RemoteException e) {
2113 Log.w(TAG, "Failed talking with device policy service", e);
2114 }
2115 }
2116 }
2117
2118 /**
Robin Lee7e678712014-07-24 16:41:31 +01002119 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2120 * If a user has installed any certificates by other means than device policy these will be
2121 * included too.
2122 *
Robin Lee25e26452015-06-02 09:56:29 -07002123 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2124 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002125 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002126 */
Robin Lee25e26452015-06-02 09:56:29 -07002127 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002128 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002129 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002130 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002131 mService.enforceCanManageCaCerts(admin);
2132 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2133 for (String alias : certStore.userAliases()) {
2134 try {
2135 certs.add(certStore.getCertificate(alias).getEncoded());
2136 } catch (CertificateException ce) {
2137 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2138 }
2139 }
2140 } catch (RemoteException re) {
2141 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002142 }
2143 }
2144 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002145 }
2146
2147 /**
Robin Lee7e678712014-07-24 16:41:31 +01002148 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2149 * means other than device policy will also be removed, except for system CA certificates.
2150 *
Robin Lee25e26452015-06-02 09:56:29 -07002151 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2152 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002153 */
Robin Lee25e26452015-06-02 09:56:29 -07002154 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002155 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002156 try {
2157 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2158 .toArray(new String[0]));
2159 } catch (RemoteException re) {
2160 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002161 }
2162 }
2163 }
2164
2165 /**
2166 * Returns whether this certificate is installed as a trusted CA.
2167 *
Robin Lee25e26452015-06-02 09:56:29 -07002168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2169 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002170 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002171 */
Robin Lee25e26452015-06-02 09:56:29 -07002172 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002173 if (mService != null) {
2174 try {
2175 mService.enforceCanManageCaCerts(admin);
2176 return getCaCertAlias(certBuffer) != null;
2177 } catch (RemoteException re) {
2178 Log.w(TAG, "Failed talking with device policy service", re);
2179 } catch (CertificateException ce) {
2180 Log.w(TAG, "Could not parse certificate", ce);
2181 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002182 }
2183 return false;
2184 }
2185
2186 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002187 * Called by a device or profile owner to install a certificate and private key pair. The
2188 * keypair will be visible to all apps within the profile.
2189 *
Robin Lee25e26452015-06-02 09:56:29 -07002190 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2191 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002192 * @param privKey The private key to install.
2193 * @param cert The certificate to install.
2194 * @param alias The private key alias under which to install the certificate. If a certificate
2195 * with that alias already exists, it will be overwritten.
2196 * @return {@code true} if the keys were installed, {@code false} otherwise.
2197 */
Robin Lee25e26452015-06-02 09:56:29 -07002198 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002199 String alias) {
2200 try {
2201 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002202 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2203 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002204 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002205 } catch (RemoteException e) {
2206 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002207 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2208 Log.w(TAG, "Failed to obtain private key material", e);
2209 } catch (CertificateException | IOException e) {
2210 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002211 }
2212 return false;
2213 }
2214
2215 /**
Robin Lee25e26452015-06-02 09:56:29 -07002216 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002217 * doesn't exist.
2218 */
2219 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2220 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2221 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2222 new ByteArrayInputStream(certBuffer));
2223 return new TrustedCertificateStore().getCertificateAlias(cert);
2224 }
2225
2226 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002227 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002228 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002229 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002230 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002231 * <p>
2232 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2233 * it is later cleared by calling this method with a null value or uninstallling the certificate
2234 * installer.
2235 *
Robin Lee25e26452015-06-02 09:56:29 -07002236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002237 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002238 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002239 */
Robin Lee25e26452015-06-02 09:56:29 -07002240 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2241 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002242 if (mService != null) {
2243 try {
Robin Lee25e26452015-06-02 09:56:29 -07002244 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002245 } catch (RemoteException e) {
2246 Log.w(TAG, "Failed talking with device policy service", e);
2247 }
2248 }
2249 }
2250
2251 /**
2252 * Called by a profile owner or device owner to retrieve the certificate installer for the
2253 * current user. null if none is set.
2254 *
Robin Lee25e26452015-06-02 09:56:29 -07002255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2256 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002257 * if none is set.
2258 */
Robin Lee25e26452015-06-02 09:56:29 -07002259 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002260 if (mService != null) {
2261 try {
Robin Lee25e26452015-06-02 09:56:29 -07002262 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002263 } catch (RemoteException e) {
2264 Log.w(TAG, "Failed talking with device policy service", e);
2265 }
2266 }
2267 return null;
2268 }
2269
2270 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002271 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002272 * on the device, for this user. After setting this, no applications running as this user
2273 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002274 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002275 * <p>If the caller is device owner, then the restriction will be applied to all users.
2276 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002277 * <p>The calling device admin must have requested
2278 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2279 * this method; if it has not, a security exception will be thrown.
2280 *
2281 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2282 * @param disabled Whether or not the camera should be disabled.
2283 */
Robin Lee25e26452015-06-02 09:56:29 -07002284 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002285 if (mService != null) {
2286 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002287 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002288 } catch (RemoteException e) {
2289 Log.w(TAG, "Failed talking with device policy service", e);
2290 }
2291 }
2292 }
2293
2294 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002295 * Determine whether or not the device's cameras have been disabled for this user,
2296 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002297 * @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 -07002298 * have disabled the camera
2299 */
Robin Lee25e26452015-06-02 09:56:29 -07002300 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002301 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002302 }
2303
2304 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002305 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002306 if (mService != null) {
2307 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002308 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002309 } catch (RemoteException e) {
2310 Log.w(TAG, "Failed talking with device policy service", e);
2311 }
2312 }
2313 return false;
2314 }
2315
2316 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002317 * Determine whether or not creating a guest user has been disabled for the device
2318 *
2319 * @hide
2320 */
2321 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2322 // Currently guest users can always be created if multi-user is enabled
2323 // TODO introduce a policy for guest user creation
2324 return false;
2325 }
2326
2327 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002328 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2329 * screen capture also prevents the content from being shown on display devices that do not have
2330 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2331 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002332 *
2333 * <p>The calling device admin must be a device or profile owner. If it is not, a
2334 * security exception will be thrown.
2335 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002336 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002337 * blocks assist requests for all activities of the relevant user.
2338 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002340 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002341 */
Robin Lee25e26452015-06-02 09:56:29 -07002342 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002343 if (mService != null) {
2344 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002345 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002346 } catch (RemoteException e) {
2347 Log.w(TAG, "Failed talking with device policy service", e);
2348 }
2349 }
2350 }
2351
2352 /**
2353 * Determine whether or not screen capture has been disabled by the current
2354 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002355 * @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 +01002356 * have disabled screen capture.
2357 */
Robin Lee25e26452015-06-02 09:56:29 -07002358 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002359 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002360 }
2361
2362 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002363 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002364 if (mService != null) {
2365 try {
2366 return mService.getScreenCaptureDisabled(admin, userHandle);
2367 } catch (RemoteException e) {
2368 Log.w(TAG, "Failed talking with device policy service", e);
2369 }
2370 }
2371 return false;
2372 }
2373
2374 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002375 * Called by a device owner to set whether auto time is required. If auto time is
2376 * required the user cannot set the date and time, but has to use network date and time.
2377 *
2378 * <p>Note: if auto time is required the user can still manually set the time zone.
2379 *
2380 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2381 * be thrown.
2382 *
2383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2384 * @param required Whether auto time is set required or not.
2385 */
Robin Lee25e26452015-06-02 09:56:29 -07002386 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002387 if (mService != null) {
2388 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002389 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002390 } catch (RemoteException e) {
2391 Log.w(TAG, "Failed talking with device policy service", e);
2392 }
2393 }
2394 }
2395
2396 /**
2397 * @return true if auto time is required.
2398 */
2399 public boolean getAutoTimeRequired() {
2400 if (mService != null) {
2401 try {
2402 return mService.getAutoTimeRequired();
2403 } catch (RemoteException e) {
2404 Log.w(TAG, "Failed talking with device policy service", e);
2405 }
2406 }
2407 return false;
2408 }
2409
2410 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002411 * Called by an application that is administering the device to disable keyguard customizations,
2412 * such as widgets. After setting this, keyguard features will be disabled according to the
2413 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002414 *
2415 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002416 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002417 * this method; if it has not, a security exception will be thrown.
2418 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002419 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002420 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002421 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002422 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002423 * <ul>
2424 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2425 * these will affect the profile's parent user.
2426 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2427 * generated by applications in the managed profile.
2428 * </ul>
2429 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2430 * can check which features have been disabled by calling
2431 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002432 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002433 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002434 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2435 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002436 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002437 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2438 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002439 */
Robin Lee25e26452015-06-02 09:56:29 -07002440 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002441 if (mService != null) {
2442 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002443 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002444 } catch (RemoteException e) {
2445 Log.w(TAG, "Failed talking with device policy service", e);
2446 }
2447 }
2448 }
2449
2450 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002451 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002452 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002453 * @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 -07002454 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002455 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2456 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002457 */
Robin Lee25e26452015-06-02 09:56:29 -07002458 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002459 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002460 }
2461
2462 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002463 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002464 if (mService != null) {
2465 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002466 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002467 } catch (RemoteException e) {
2468 Log.w(TAG, "Failed talking with device policy service", e);
2469 }
2470 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002471 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002472 }
2473
2474 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002475 * @hide
2476 */
Robin Lee25e26452015-06-02 09:56:29 -07002477 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2478 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002479 if (mService != null) {
2480 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002481 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002482 } catch (RemoteException e) {
2483 Log.w(TAG, "Failed talking with device policy service", e);
2484 }
2485 }
2486 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002487
Dianne Hackbornd6847842010-01-12 18:14:19 -08002488 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002489 * @hide
2490 */
Robin Lee25e26452015-06-02 09:56:29 -07002491 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002492 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002493 }
2494
2495 /**
Robin Lee25e26452015-06-02 09:56:29 -07002496 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002497 * @hide
2498 */
Robin Lee25e26452015-06-02 09:56:29 -07002499 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002500 ActivityInfo ai;
2501 try {
2502 ai = mContext.getPackageManager().getReceiverInfo(cn,
2503 PackageManager.GET_META_DATA);
2504 } catch (PackageManager.NameNotFoundException e) {
2505 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2506 return null;
2507 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002508
Dianne Hackbornd6847842010-01-12 18:14:19 -08002509 ResolveInfo ri = new ResolveInfo();
2510 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002511
Dianne Hackbornd6847842010-01-12 18:14:19 -08002512 try {
2513 return new DeviceAdminInfo(mContext, ri);
2514 } catch (XmlPullParserException e) {
2515 Log.w(TAG, "Unable to parse device policy " + cn, e);
2516 return null;
2517 } catch (IOException e) {
2518 Log.w(TAG, "Unable to parse device policy " + cn, e);
2519 return null;
2520 }
2521 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002522
Dianne Hackbornd6847842010-01-12 18:14:19 -08002523 /**
2524 * @hide
2525 */
Robin Lee25e26452015-06-02 09:56:29 -07002526 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002527 if (mService != null) {
2528 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002529 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002530 } catch (RemoteException e) {
2531 Log.w(TAG, "Failed talking with device policy service", e);
2532 }
2533 }
2534 }
2535
2536 /**
2537 * @hide
2538 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002539 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002540 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002541 if (mService != null) {
2542 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002543 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002544 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002545 } catch (RemoteException e) {
2546 Log.w(TAG, "Failed talking with device policy service", e);
2547 }
2548 }
2549 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002550
Dianne Hackbornd6847842010-01-12 18:14:19 -08002551 /**
2552 * @hide
2553 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002554 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002555 if (mService != null) {
2556 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002557 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002558 } catch (RemoteException e) {
2559 Log.w(TAG, "Failed talking with device policy service", e);
2560 }
2561 }
2562 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002563
Dianne Hackbornd6847842010-01-12 18:14:19 -08002564 /**
2565 * @hide
2566 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002567 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002568 if (mService != null) {
2569 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002570 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002571 } catch (RemoteException e) {
2572 Log.w(TAG, "Failed talking with device policy service", e);
2573 }
2574 }
2575 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002576
2577 /**
2578 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002579 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002580 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2581 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002582 * @return whether the package was successfully registered as the device owner.
2583 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002584 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002585 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002586 public boolean setDeviceOwner(ComponentName who) {
2587 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002588 }
2589
2590 /**
2591 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002592 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002593 public boolean setDeviceOwner(ComponentName who, int userId) {
2594 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002595 }
2596
2597 /**
2598 * @hide
2599 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002600 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2601 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002602 }
2603
2604 /**
2605 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002606 * Sets the given package as the device owner. The package must already be installed. There
2607 * must not already be a device owner.
2608 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2609 * this method.
2610 * Calling this after the setup phase of the primary user has completed is allowed only if
2611 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002612 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002613 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002614 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002615 * @return whether the package was successfully registered as the device owner.
2616 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002617 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002618 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002619 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002620 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002621 if (mService != null) {
2622 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002623 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002624 } catch (RemoteException re) {
2625 Log.w(TAG, "Failed to set device owner");
2626 }
2627 }
2628 return false;
2629 }
2630
2631 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002632 * Used to determine if a particular package has been registered as a Device Owner app.
2633 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002634 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002635 * package is currently registered as the device owner app, pass in the package name from
2636 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002637 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002638 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2639 * the setup process.
2640 * @param packageName the package name of the app, to compare with the registered device owner
2641 * app, if any.
Makoto Onukia52562c2015-10-01 16:12:31 -07002642 * @return whether or not the package is registered as the device owner app. Note this method
2643 * does *not* check weather the device owner is actually running on the current user.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002644 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002645 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002646 if (mService != null) {
2647 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002648 return mService.isDeviceOwnerPackage(packageName);
2649 } catch (RemoteException e) {
2650 Log.w(TAG, "Failed talking with device policy service", e);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002651 }
2652 }
2653 return false;
2654 }
2655
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002656 /**
2657 * @hide
2658 * Redirect to isDeviceOwnerApp.
2659 */
2660 public boolean isDeviceOwner(String packageName) {
2661 return isDeviceOwnerApp(packageName);
2662 }
2663
Jason Monkb0dced82014-06-06 14:36:20 -04002664 /**
Makoto Onukia52562c2015-10-01 16:12:31 -07002665 * Check whether a given component is registered as a device owner.
2666 * Note this method does *not* check weather the device owner is actually running on the current
2667 * user.
2668 *
2669 * @hide
2670 */
2671 public boolean isDeviceOwner(ComponentName who) {
2672 return (who != null) && who.equals(getDeviceOwner());
2673 }
2674
2675 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002676 * Clears the current device owner. The caller must be the device owner.
2677 *
2678 * This function should be used cautiously as once it is called it cannot
2679 * be undone. The device owner can only be set as a part of device setup
2680 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002681 *
2682 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002683 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002684 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002685 if (mService != null) {
2686 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002687 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002688 } catch (RemoteException re) {
2689 Log.w(TAG, "Failed to clear device owner");
2690 }
2691 }
2692 }
2693
Makoto Onukia52562c2015-10-01 16:12:31 -07002694 /**
2695 * Returns the device owner package name. Note this method will still return the device owner
2696 * package name even if it's running on a different user.
2697 *
2698 * @hide
2699 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002700 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002701 public String getDeviceOwner() {
Makoto Onukia52562c2015-10-01 16:12:31 -07002702 final ComponentName componentName = getDeviceOwnerComponent();
2703 return componentName == null ? null : componentName.getPackageName();
2704 }
2705
2706 /**
2707 * Returns the device owner name. Note this method will still return the device owner
2708 * name even if it's running on a different user.
2709 *
2710 * @hide
2711 */
2712 public String getDeviceOwnerName() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002713 if (mService != null) {
2714 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002715 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002716 } catch (RemoteException re) {
2717 Log.w(TAG, "Failed to get device owner");
2718 }
2719 }
2720 return null;
2721 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002722
Makoto Onukia52562c2015-10-01 16:12:31 -07002723 /**
2724 * Returns the device owner component name. Note this method will still return the device owner
2725 * component name even if it's running on a different user.
2726 *
2727 * @hide
2728 */
2729 public ComponentName getDeviceOwnerComponent() {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002730 if (mService != null) {
2731 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002732 return mService.getDeviceOwner();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002733 } catch (RemoteException re) {
2734 Log.w(TAG, "Failed to get device owner");
2735 }
2736 }
2737 return null;
2738 }
Adam Connors776c5552014-01-09 10:42:56 +00002739
2740 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002741 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002742 * @deprecated Do not use
2743 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002744 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002745 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002746 @SystemApi
2747 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002748 return null;
2749 }
2750
2751 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002752 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002753 * @deprecated Do not use
2754 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002755 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002756 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002757 @SystemApi
2758 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002759 return null;
2760 }
2761
Julia Reynolds20118f12015-02-11 12:34:08 -05002762 /**
Adam Connors776c5552014-01-09 10:42:56 +00002763 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002764 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302765 * Sets the given component as an active admin and registers the package as the profile
2766 * owner for this user. The package must already be installed and there shouldn't be
2767 * an existing profile owner registered for this user. Also, this method must be called
2768 * before the user setup has been completed.
2769 * <p>
2770 * This method can only be called by system apps that hold MANAGE_USERS permission and
2771 * MANAGE_DEVICE_ADMINS permission.
2772 * @param admin The component to register as an active admin and profile owner.
2773 * @param ownerName The user-visible name of the entity that is managing this user.
2774 * @return whether the admin was successfully registered as the profile owner.
2775 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2776 * the user has already been set up.
2777 */
Justin Morey80440cc2014-07-24 09:16:35 -05002778 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002779 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302780 throws IllegalArgumentException {
2781 if (mService != null) {
2782 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002783 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302784 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002785 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302786 } catch (RemoteException re) {
2787 Log.w(TAG, "Failed to set profile owner " + re);
2788 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2789 }
2790 }
2791 return false;
2792 }
2793
2794 /**
2795 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002796 * Clears the active profile owner and removes all user restrictions. The caller must
2797 * be from the same package as the active profile owner for this user, otherwise a
2798 * SecurityException will be thrown.
2799 *
2800 * @param admin The component to remove as the profile owner.
2801 * @return
2802 */
2803 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002804 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002805 if (mService != null) {
2806 try {
2807 mService.clearProfileOwner(admin);
2808 } catch (RemoteException re) {
2809 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2810 }
2811 }
2812 }
2813
2814 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002815 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002816 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002817 */
2818 public boolean hasUserSetupCompleted() {
2819 if (mService != null) {
2820 try {
2821 return mService.hasUserSetupCompleted();
2822 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002823 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002824 }
2825 }
2826 return true;
2827 }
2828
2829 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002830 * @hide
2831 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002832 * already be installed. There must not already be a profile owner for this user.
2833 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2834 * this method.
2835 * Calling this after the setup phase of the specified user has completed is allowed only if:
2836 * - the caller is SYSTEM_UID.
2837 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002838 * @param admin the component name to be registered as profile owner.
2839 * @param ownerName the human readable name of the organisation associated with this DPM.
2840 * @param userHandle the userId to set the profile owner for.
2841 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002842 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2843 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002844 */
Robin Lee25e26452015-06-02 09:56:29 -07002845 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002846 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002847 if (admin == null) {
2848 throw new NullPointerException("admin cannot be null");
2849 }
Adam Connors776c5552014-01-09 10:42:56 +00002850 if (mService != null) {
2851 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002852 if (ownerName == null) {
2853 ownerName = "";
2854 }
2855 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002856 } catch (RemoteException re) {
2857 Log.w(TAG, "Failed to set profile owner", re);
2858 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2859 }
2860 }
2861 return false;
2862 }
2863
2864 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002865 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2866 * be used. Only the profile owner can call this.
2867 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002868 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002869 *
2870 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2871 */
Robin Lee25e26452015-06-02 09:56:29 -07002872 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002873 if (mService != null) {
2874 try {
2875 mService.setProfileEnabled(admin);
2876 } catch (RemoteException e) {
2877 Log.w(TAG, "Failed talking with device policy service", e);
2878 }
2879 }
2880 }
2881
2882 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002883 * Sets the name of the profile. In the device owner case it sets the name of the user
2884 * 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 +01002885 * never called by the profile or device owner, the name will be set to default values.
2886 *
2887 * @see #isProfileOwnerApp
2888 * @see #isDeviceOwnerApp
2889 *
Robin Lee25e26452015-06-02 09:56:29 -07002890 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01002891 * @param profileName The name of the profile.
2892 */
Robin Lee25e26452015-06-02 09:56:29 -07002893 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01002894 if (mService != null) {
2895 try {
Robin Lee25e26452015-06-02 09:56:29 -07002896 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07002897 } catch (RemoteException e) {
2898 Log.w(TAG, "Failed talking with device policy service", e);
2899 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002900 }
2901 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002902
2903 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002904 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002905 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002906 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002907 *
2908 * @param packageName The package name of the app to compare with the registered profile owner.
2909 * @return Whether or not the package is registered as the profile owner.
2910 */
2911 public boolean isProfileOwnerApp(String packageName) {
2912 if (mService != null) {
2913 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002914 ComponentName profileOwner = mService.getProfileOwner(
2915 Process.myUserHandle().getIdentifier());
2916 return profileOwner != null
2917 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002918 } catch (RemoteException re) {
2919 Log.w(TAG, "Failed to check profile owner");
2920 }
2921 }
2922 return false;
2923 }
2924
2925 /**
2926 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002927 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00002928 * owner has been set for that user.
2929 * @throws IllegalArgumentException if the userId is invalid.
2930 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002931 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002932 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002933 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2934 }
2935
2936 /**
2937 * @see #getProfileOwner()
2938 * @hide
2939 */
2940 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002941 if (mService != null) {
2942 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002943 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002944 } catch (RemoteException re) {
2945 Log.w(TAG, "Failed to get profile owner");
2946 throw new IllegalArgumentException(
2947 "Requested profile owner for invalid userId", re);
2948 }
2949 }
2950 return null;
2951 }
2952
2953 /**
2954 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002955 * @return the human readable name of the organisation associated with this DPM or {@code null}
2956 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00002957 * @throws IllegalArgumentException if the userId is invalid.
2958 */
2959 public String getProfileOwnerName() throws IllegalArgumentException {
2960 if (mService != null) {
2961 try {
2962 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2963 } catch (RemoteException re) {
2964 Log.w(TAG, "Failed to get profile owner");
2965 throw new IllegalArgumentException(
2966 "Requested profile owner for invalid userId", re);
2967 }
2968 }
2969 return null;
2970 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002971
2972 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002973 * @hide
2974 * @param user The user for whom to fetch the profile owner name, if any.
2975 * @return the human readable name of the organisation associated with this profile owner or
2976 * null if one is not set.
2977 * @throws IllegalArgumentException if the userId is invalid.
2978 */
2979 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002980 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002981 if (mService != null) {
2982 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002983 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002984 } catch (RemoteException re) {
2985 Log.w(TAG, "Failed to get profile owner");
2986 throw new IllegalArgumentException(
2987 "Requested profile owner for invalid userId", re);
2988 }
2989 }
2990 return null;
2991 }
2992
2993 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002994 * Called by a profile owner or device owner to add a default intent handler activity for
2995 * intents that match a certain intent filter. This activity will remain the default intent
2996 * handler even if the set of potential event handlers for the intent filter changes and if
2997 * the intent preferences are reset.
2998 *
2999 * <p>The default disambiguation mechanism takes over if the activity is not installed
3000 * (anymore). When the activity is (re)installed, it is automatically reset as default
3001 * intent handler for the filter.
3002 *
3003 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3004 * security exception will be thrown.
3005 *
3006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3007 * @param filter The IntentFilter for which a default handler is added.
3008 * @param activity The Activity that is added as default intent handler.
3009 */
Robin Lee25e26452015-06-02 09:56:29 -07003010 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3011 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003012 if (mService != null) {
3013 try {
3014 mService.addPersistentPreferredActivity(admin, filter, activity);
3015 } catch (RemoteException e) {
3016 Log.w(TAG, "Failed talking with device policy service", e);
3017 }
3018 }
3019 }
3020
3021 /**
3022 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003023 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003024 *
3025 * <p>The calling device admin must be a profile owner. If it is not, a security
3026 * exception will be thrown.
3027 *
3028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3029 * @param packageName The name of the package for which preferences are removed.
3030 */
Robin Lee25e26452015-06-02 09:56:29 -07003031 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003032 String packageName) {
3033 if (mService != null) {
3034 try {
3035 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3036 } catch (RemoteException e) {
3037 Log.w(TAG, "Failed talking with device policy service", e);
3038 }
3039 }
3040 }
Robin Lee66e5d962014-04-09 16:44:21 +01003041
3042 /**
3043 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003044 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003045 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003046 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3047 * <ul>
3048 * <li>{@code boolean}
3049 * <li>{@code int}
3050 * <li>{@code String} or {@code String[]}
3051 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3052 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003053 *
3054 * <p>The application restrictions are only made visible to the target application and the
3055 * profile or device owner.
3056 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003057 * <p>If the restrictions are not available yet, but may be applied in the near future,
3058 * the admin can notify the target application of that by adding
3059 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3060 *
Robin Lee66e5d962014-04-09 16:44:21 +01003061 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3062 * exception will be thrown.
3063 *
3064 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3065 * @param packageName The name of the package to update restricted settings for.
3066 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3067 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003068 *
3069 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003070 */
Robin Lee25e26452015-06-02 09:56:29 -07003071 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003072 Bundle settings) {
3073 if (mService != null) {
3074 try {
3075 mService.setApplicationRestrictions(admin, packageName, settings);
3076 } catch (RemoteException e) {
3077 Log.w(TAG, "Failed talking with device policy service", e);
3078 }
3079 }
3080 }
3081
3082 /**
Jim Millere303bf42014-08-26 17:12:29 -07003083 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3084 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3085 * trust agents but those enabled by this function call. If flag
3086 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003087 *
3088 * <p>The calling device admin must have requested
3089 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003090 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003091 *
3092 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003093 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003094 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003095 * will be strictly disabled according to the state of the
3096 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3097 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3098 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3099 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003100 */
Robin Lee25e26452015-06-02 09:56:29 -07003101 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3102 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003103 if (mService != null) {
3104 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003105 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003106 } catch (RemoteException e) {
3107 Log.w(TAG, "Failed talking with device policy service", e);
3108 }
3109 }
3110 }
3111
3112 /**
Jim Millere303bf42014-08-26 17:12:29 -07003113 * Gets configuration for the given trust agent based on aggregating all calls to
3114 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3115 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003116 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003117 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3118 * this function returns a list of configurations for all admins that declare
3119 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3120 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3121 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3122 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003123 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003124 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003125 */
Robin Lee25e26452015-06-02 09:56:29 -07003126 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3127 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003128 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003129 }
3130
3131 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003132 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3133 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003134 if (mService != null) {
3135 try {
Jim Millere303bf42014-08-26 17:12:29 -07003136 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003137 } catch (RemoteException e) {
3138 Log.w(TAG, "Failed talking with device policy service", e);
3139 }
3140 }
Jim Millere303bf42014-08-26 17:12:29 -07003141 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003142 }
3143
3144 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003145 * Called by a profile owner of a managed profile to set whether caller-Id information from
3146 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003147 *
3148 * <p>The calling device admin must be a profile owner. If it is not, a
3149 * security exception will be thrown.
3150 *
Robin Lee25e26452015-06-02 09:56:29 -07003151 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003152 * @param disabled If true caller-Id information in the managed profile is not displayed.
3153 */
Robin Lee25e26452015-06-02 09:56:29 -07003154 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003155 if (mService != null) {
3156 try {
Robin Lee25e26452015-06-02 09:56:29 -07003157 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003158 } catch (RemoteException e) {
3159 Log.w(TAG, "Failed talking with device policy service", e);
3160 }
3161 }
3162 }
3163
3164 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003165 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3166 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003167 *
3168 * <p>The calling device admin must be a profile owner. If it is not, a
3169 * security exception will be thrown.
3170 *
Robin Lee25e26452015-06-02 09:56:29 -07003171 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003172 */
Robin Lee25e26452015-06-02 09:56:29 -07003173 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003174 if (mService != null) {
3175 try {
Robin Lee25e26452015-06-02 09:56:29 -07003176 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003177 } catch (RemoteException e) {
3178 Log.w(TAG, "Failed talking with device policy service", e);
3179 }
3180 }
3181 return false;
3182 }
3183
3184 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003185 * Determine whether or not caller-Id information has been disabled.
3186 *
3187 * @param userHandle The user for whom to check the caller-id permission
3188 * @hide
3189 */
3190 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3191 if (mService != null) {
3192 try {
3193 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3194 } catch (RemoteException e) {
3195 Log.w(TAG, "Failed talking with device policy service", e);
3196 }
3197 }
3198 return false;
3199 }
3200
3201 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003202 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3203 * @hide
3204 */
3205 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Ricky Wai494b95d2015-11-20 16:07:15 +00003206 long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003207 if (mService != null) {
3208 try {
3209 mService.startManagedQuickContact(
Ricky Wai494b95d2015-11-20 16:07:15 +00003210 actualLookupKey, actualContactId, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003211 } catch (RemoteException e) {
3212 Log.w(TAG, "Failed talking with device policy service", e);
3213 }
3214 }
3215 }
3216
3217 /**
Ricky Wai494b95d2015-11-20 16:07:15 +00003218 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3219 * @hide
3220 */
3221 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3222 Intent originalIntent) {
3223 startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT,
3224 originalIntent);
3225 }
3226
3227 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003228 * Called by a profile owner of a managed profile to set whether bluetooth
3229 * devices can access enterprise contacts.
3230 * <p>
3231 * The calling device admin must be a profile owner. If it is not, a
3232 * security exception will be thrown.
3233 * <p>
3234 * This API works on managed profile only.
3235 *
Robin Lee25e26452015-06-02 09:56:29 -07003236 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003237 * with.
3238 * @param disabled If true, bluetooth devices cannot access enterprise
3239 * contacts.
3240 */
Robin Lee25e26452015-06-02 09:56:29 -07003241 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003242 if (mService != null) {
3243 try {
Robin Lee25e26452015-06-02 09:56:29 -07003244 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003245 } catch (RemoteException e) {
3246 Log.w(TAG, "Failed talking with device policy service", e);
3247 }
3248 }
3249 }
3250
3251 /**
3252 * Called by a profile owner of a managed profile to determine whether or
3253 * not Bluetooth devices cannot access enterprise contacts.
3254 * <p>
3255 * The calling device admin must be a profile owner. If it is not, a
3256 * security exception will be thrown.
3257 * <p>
3258 * This API works on managed profile only.
3259 *
Robin Lee25e26452015-06-02 09:56:29 -07003260 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003261 * with.
3262 */
Robin Lee25e26452015-06-02 09:56:29 -07003263 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003264 if (mService != null) {
3265 try {
Robin Lee25e26452015-06-02 09:56:29 -07003266 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003267 } catch (RemoteException e) {
3268 Log.w(TAG, "Failed talking with device policy service", e);
3269 }
3270 }
3271 return true;
3272 }
3273
3274 /**
3275 * Determine whether or not Bluetooth devices cannot access contacts.
3276 * <p>
3277 * This API works on managed profile UserHandle only.
3278 *
3279 * @param userHandle The user for whom to check the caller-id permission
3280 * @hide
3281 */
3282 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3283 if (mService != null) {
3284 try {
3285 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3286 .getIdentifier());
3287 } catch (RemoteException e) {
3288 Log.w(TAG, "Failed talking with device policy service", e);
3289 }
3290 }
3291 return true;
3292 }
3293
3294 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003295 * Called by the profile owner of a managed profile so that some intents sent in the managed
3296 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003297 * Only activity intents are supported.
3298 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003300 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3301 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003302 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3303 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003304 */
Robin Lee25e26452015-06-02 09:56:29 -07003305 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003306 if (mService != null) {
3307 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003308 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003309 } catch (RemoteException e) {
3310 Log.w(TAG, "Failed talking with device policy service", e);
3311 }
3312 }
3313 }
3314
3315 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003316 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3317 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003318 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003319 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3320 */
Robin Lee25e26452015-06-02 09:56:29 -07003321 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003322 if (mService != null) {
3323 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003324 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003325 } catch (RemoteException e) {
3326 Log.w(TAG, "Failed talking with device policy service", e);
3327 }
3328 }
3329 }
3330
3331 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003332 * Called by a profile or device owner to set the permitted accessibility services. When
3333 * set by a device owner or profile owner the restriction applies to all profiles of the
3334 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003335 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003336 * By default the user can use any accessiblity service. When zero or more packages have
3337 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003338 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003339 *
3340 * <p> Calling with a null value for the list disables the restriction so that all services
3341 * can be used, calling with an empty list only allows the builtin system's services.
3342 *
3343 * <p> System accesibility services are always available to the user the list can't modify
3344 * this.
3345 *
3346 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3347 * @param packageNames List of accessibility service package names.
3348 *
3349 * @return true if setting the restriction succeeded. It fail if there is
3350 * one or more non-system accessibility services enabled, that are not in the list.
3351 */
Robin Lee25e26452015-06-02 09:56:29 -07003352 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003353 List<String> packageNames) {
3354 if (mService != null) {
3355 try {
3356 return mService.setPermittedAccessibilityServices(admin, packageNames);
3357 } catch (RemoteException e) {
3358 Log.w(TAG, "Failed talking with device policy service", e);
3359 }
3360 }
3361 return false;
3362 }
3363
3364 /**
3365 * Returns the list of permitted accessibility services set by this device or profile owner.
3366 *
3367 * <p>An empty list means no accessibility services except system services are allowed.
3368 * Null means all accessibility services are allowed.
3369 *
3370 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3371 * @return List of accessiblity service package names.
3372 */
Robin Lee25e26452015-06-02 09:56:29 -07003373 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003374 if (mService != null) {
3375 try {
3376 return mService.getPermittedAccessibilityServices(admin);
3377 } catch (RemoteException e) {
3378 Log.w(TAG, "Failed talking with device policy service", e);
3379 }
3380 }
3381 return null;
3382 }
3383
3384 /**
3385 * Returns the list of accessibility services permitted by the device or profiles
3386 * owners of this user.
3387 *
3388 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3389 * it will contain the intersection of the permitted lists for any device or profile
3390 * owners that apply to this user. It will also include any system accessibility services.
3391 *
3392 * @param userId which user to check for.
3393 * @return List of accessiblity service package names.
3394 * @hide
3395 */
3396 @SystemApi
3397 public List<String> getPermittedAccessibilityServices(int userId) {
3398 if (mService != null) {
3399 try {
3400 return mService.getPermittedAccessibilityServicesForUser(userId);
3401 } catch (RemoteException e) {
3402 Log.w(TAG, "Failed talking with device policy service", e);
3403 }
3404 }
3405 return null;
3406 }
3407
3408 /**
3409 * Called by a profile or device owner to set the permitted input methods services. When
3410 * set by a device owner or profile owner the restriction applies to all profiles of the
3411 * user the device owner or profile owner is an admin for.
3412 *
3413 * By default the user can use any input method. When zero or more packages have
3414 * been added, input method that are not in the list and not part of the system
3415 * can not be enabled by the user.
3416 *
3417 * This method will fail if it is called for a admin that is not for the foreground user
3418 * or a profile of the foreground user.
3419 *
3420 * <p> Calling with a null value for the list disables the restriction so that all input methods
3421 * can be used, calling with an empty list disables all but the system's own input methods.
3422 *
3423 * <p> System input methods are always available to the user this method can't modify this.
3424 *
3425 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3426 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003427 * @return true if setting the restriction succeeded. It will fail if there are
3428 * one or more non-system input methods currently enabled that are not in
3429 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003430 */
Robin Lee25e26452015-06-02 09:56:29 -07003431 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003432 if (mService != null) {
3433 try {
3434 return mService.setPermittedInputMethods(admin, packageNames);
3435 } catch (RemoteException e) {
3436 Log.w(TAG, "Failed talking with device policy service", e);
3437 }
3438 }
3439 return false;
3440 }
3441
3442
3443 /**
3444 * Returns the list of permitted input methods set by this device or profile owner.
3445 *
3446 * <p>An empty list means no input methods except system input methods are allowed.
3447 * Null means all input methods are allowed.
3448 *
3449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3450 * @return List of input method package names.
3451 */
Robin Lee25e26452015-06-02 09:56:29 -07003452 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003453 if (mService != null) {
3454 try {
3455 return mService.getPermittedInputMethods(admin);
3456 } catch (RemoteException e) {
3457 Log.w(TAG, "Failed talking with device policy service", e);
3458 }
3459 }
3460 return null;
3461 }
3462
3463 /**
3464 * Returns the list of input methods permitted by the device or profiles
3465 * owners of the current user.
3466 *
3467 * <p>Null means all input methods are allowed, if a non-null list is returned
3468 * it will contain the intersection of the permitted lists for any device or profile
3469 * owners that apply to this user. It will also include any system input methods.
3470 *
3471 * @return List of input method package names.
3472 * @hide
3473 */
3474 @SystemApi
3475 public List<String> getPermittedInputMethodsForCurrentUser() {
3476 if (mService != null) {
3477 try {
3478 return mService.getPermittedInputMethodsForCurrentUser();
3479 } catch (RemoteException e) {
3480 Log.w(TAG, "Failed talking with device policy service", e);
3481 }
3482 }
3483 return null;
3484 }
3485
3486 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003487 * Called by a device owner to create a user with the specified name. The UserHandle returned
3488 * by this method should not be persisted as user handles are recycled as users are removed and
3489 * created. If you need to persist an identifier for this user, use
3490 * {@link UserManager#getSerialNumberForUser}.
3491 *
3492 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3493 * @param name the user's name
3494 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003495 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3496 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003497 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003498 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003499 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003500 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003501 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003502 try {
3503 return mService.createUser(admin, name);
3504 } catch (RemoteException re) {
3505 Log.w(TAG, "Could not create a user", re);
3506 }
3507 return null;
3508 }
3509
3510 /**
Jason Monk03978a42014-06-10 15:05:30 -04003511 * Called by a device owner to create a user with the specified name. The UserHandle returned
3512 * by this method should not be persisted as user handles are recycled as users are removed and
3513 * created. If you need to persist an identifier for this user, use
3514 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3515 * immediately.
3516 *
3517 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3518 * as registered as an active admin on the new user. The profile owner package will be
3519 * installed on the new user if it already is installed on the device.
3520 *
3521 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3522 * profileOwnerComponent when onEnable is called.
3523 *
3524 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3525 * @param name the user's name
3526 * @param ownerName the human readable name of the organisation associated with this DPM.
3527 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3528 * the user.
3529 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3530 * on the new user.
3531 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003532 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3533 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003534 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003535 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003536 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003537 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003538 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3539 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003540 try {
3541 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3542 adminExtras);
3543 } catch (RemoteException re) {
3544 Log.w(TAG, "Could not create a user", re);
3545 }
3546 return null;
3547 }
3548
3549 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003550 * Called by a device owner to remove a user and all associated data. The primary user can
3551 * not be removed.
3552 *
3553 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3554 * @param userHandle the user to remove.
3555 * @return {@code true} if the user was removed, {@code false} otherwise.
3556 */
Robin Lee25e26452015-06-02 09:56:29 -07003557 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003558 try {
3559 return mService.removeUser(admin, userHandle);
3560 } catch (RemoteException re) {
3561 Log.w(TAG, "Could not remove user ", re);
3562 return false;
3563 }
3564 }
3565
3566 /**
Jason Monk582d9112014-07-09 19:57:08 -04003567 * Called by a device owner to switch the specified user to the foreground.
3568 *
3569 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3570 * @param userHandle the user to switch to; null will switch to primary.
3571 * @return {@code true} if the switch was successful, {@code false} otherwise.
3572 *
3573 * @see Intent#ACTION_USER_FOREGROUND
3574 */
Robin Lee25e26452015-06-02 09:56:29 -07003575 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003576 try {
3577 return mService.switchUser(admin, userHandle);
3578 } catch (RemoteException re) {
3579 Log.w(TAG, "Could not switch user ", re);
3580 return false;
3581 }
3582 }
3583
3584 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003585 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003586 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003587 *
3588 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3589 * exception will be thrown.
3590 *
3591 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3592 * @param packageName The name of the package to fetch restricted settings of.
3593 * @return {@link Bundle} of settings corresponding to what was set last time
3594 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3595 * if no restrictions have been set.
3596 */
Robin Lee25e26452015-06-02 09:56:29 -07003597 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003598 if (mService != null) {
3599 try {
3600 return mService.getApplicationRestrictions(admin, packageName);
3601 } catch (RemoteException e) {
3602 Log.w(TAG, "Failed talking with device policy service", e);
3603 }
3604 }
3605 return null;
3606 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003607
3608 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003609 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003610 * <p>
3611 * The calling device admin must be a profile or device owner; if it is not,
3612 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003613 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003614 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3615 * with.
3616 * @param key The key of the restriction. See the constants in
3617 * {@link android.os.UserManager} for the list of keys.
3618 */
Robin Lee25e26452015-06-02 09:56:29 -07003619 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003620 if (mService != null) {
3621 try {
3622 mService.setUserRestriction(admin, key, true);
3623 } catch (RemoteException e) {
3624 Log.w(TAG, "Failed talking with device policy service", e);
3625 }
3626 }
3627 }
3628
3629 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003630 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003631 * <p>
3632 * The calling device admin must be a profile or device owner; if it is not,
3633 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003634 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003635 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3636 * with.
3637 * @param key The key of the restriction. See the constants in
3638 * {@link android.os.UserManager} for the list of keys.
3639 */
Robin Lee25e26452015-06-02 09:56:29 -07003640 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003641 if (mService != null) {
3642 try {
3643 mService.setUserRestriction(admin, key, false);
3644 } catch (RemoteException e) {
3645 Log.w(TAG, "Failed talking with device policy service", e);
3646 }
3647 }
3648 }
Adam Connors010cfd42014-04-16 12:48:13 +01003649
3650 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003651 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003652 * is unavailable for use, but the data and actual package file remain.
3653 *
3654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003655 * @param packageName The name of the package to hide or unhide.
3656 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3657 * unhidden.
3658 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003659 */
Robin Lee25e26452015-06-02 09:56:29 -07003660 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003661 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003662 if (mService != null) {
3663 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003664 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003665 } catch (RemoteException e) {
3666 Log.w(TAG, "Failed talking with device policy service", e);
3667 }
3668 }
3669 return false;
3670 }
3671
3672 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003673 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003674 *
3675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003676 * @param packageName The name of the package to retrieve the hidden status of.
3677 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003678 */
Robin Lee25e26452015-06-02 09:56:29 -07003679 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003680 if (mService != null) {
3681 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003682 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003683 } catch (RemoteException e) {
3684 Log.w(TAG, "Failed talking with device policy service", e);
3685 }
3686 }
3687 return false;
3688 }
3689
3690 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003691 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003692 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003693 *
3694 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3695 * @param packageName The package to be re-enabled in the current profile.
3696 */
Robin Lee25e26452015-06-02 09:56:29 -07003697 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003698 if (mService != null) {
3699 try {
3700 mService.enableSystemApp(admin, packageName);
3701 } catch (RemoteException e) {
3702 Log.w(TAG, "Failed to install package: " + packageName);
3703 }
3704 }
3705 }
3706
3707 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003708 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003709 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003710 *
3711 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3712 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3713 * intent will be re-enabled in the current profile.
3714 * @return int The number of activities that matched the intent and were installed.
3715 */
Robin Lee25e26452015-06-02 09:56:29 -07003716 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003717 if (mService != null) {
3718 try {
3719 return mService.enableSystemAppWithIntent(admin, intent);
3720 } catch (RemoteException e) {
3721 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3722 }
3723 }
3724 return 0;
3725 }
3726
3727 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003728 * Called by a device owner or profile owner to disable account management for a specific type
3729 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003730 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003731 * <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 +01003732 * security exception will be thrown.
3733 *
3734 * <p>When account management is disabled for an account type, adding or removing an account
3735 * of that type will not be possible.
3736 *
3737 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3738 * @param accountType For which account management is disabled or enabled.
3739 * @param disabled The boolean indicating that account management will be disabled (true) or
3740 * enabled (false).
3741 */
Robin Lee25e26452015-06-02 09:56:29 -07003742 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003743 boolean disabled) {
3744 if (mService != null) {
3745 try {
3746 mService.setAccountManagementDisabled(admin, accountType, disabled);
3747 } catch (RemoteException e) {
3748 Log.w(TAG, "Failed talking with device policy service", e);
3749 }
3750 }
3751 }
3752
3753 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003754 * Gets the array of accounts for which account management is disabled by the profile owner.
3755 *
3756 * <p> Account management can be disabled/enabled by calling
3757 * {@link #setAccountManagementDisabled}.
3758 *
3759 * @return a list of account types for which account management has been disabled.
3760 *
3761 * @see #setAccountManagementDisabled
3762 */
3763 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003764 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003765 }
3766
3767 /**
3768 * @see #getAccountTypesWithManagementDisabled()
3769 * @hide
3770 */
3771 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003772 if (mService != null) {
3773 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003774 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003775 } catch (RemoteException e) {
3776 Log.w(TAG, "Failed talking with device policy service", e);
3777 }
3778 }
3779
3780 return null;
3781 }
justinzhang511e0d82014-03-24 16:09:24 -04003782
3783 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003784 * Sets which packages may enter lock task mode.
3785 *
3786 * <p>Any packages that shares uid with an allowed package will also be allowed
3787 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003788 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003789 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003790 * package list results in locked tasks belonging to those packages to be finished.
3791 *
Jason Monkc5185f22014-06-24 11:12:42 -04003792 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003793 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003794 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003795 *
3796 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003797 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3798 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003799 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003800 */
Robin Lee25e26452015-06-02 09:56:29 -07003801 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003802 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003803 if (mService != null) {
3804 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003805 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003806 } catch (RemoteException e) {
3807 Log.w(TAG, "Failed talking with device policy service", e);
3808 }
3809 }
3810 }
3811
3812 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003813 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003814 *
3815 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003816 * @hide
3817 */
Robin Lee25e26452015-06-02 09:56:29 -07003818 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003819 if (mService != null) {
3820 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003821 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003822 } catch (RemoteException e) {
3823 Log.w(TAG, "Failed talking with device policy service", e);
3824 }
3825 }
3826 return null;
3827 }
3828
3829 /**
3830 * This function lets the caller know whether the given component is allowed to start the
3831 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003832 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003833 */
Jason Monkd7b86212014-06-16 13:15:38 -04003834 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003835 if (mService != null) {
3836 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003837 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003838 } catch (RemoteException e) {
3839 Log.w(TAG, "Failed talking with device policy service", e);
3840 }
3841 }
3842 return false;
3843 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003844
3845 /**
3846 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3847 * 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 -04003848 * <p>The settings that can be updated with this method are:
3849 * <ul>
3850 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3851 * <li>{@link Settings.Global#AUTO_TIME}</li>
3852 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003853 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003854 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003855 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003856 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003857 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003858 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01003859 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003860 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01003861 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003862 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003863 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003864 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003865 * <ul>
3866 * <li>{@link Settings.Global#BLUETOOTH_ON}.
3867 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
3868 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
3869 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3870 * <li>{@link Settings.Global#MODE_RINGER}.
3871 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
3872 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3873 * <li>{@link Settings.Global#WIFI_ON}.
3874 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
3875 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003876 *
3877 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3878 * @param setting The name of the setting to update.
3879 * @param value The value to update the setting to.
3880 */
Robin Lee25e26452015-06-02 09:56:29 -07003881 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003882 if (mService != null) {
3883 try {
3884 mService.setGlobalSetting(admin, setting, value);
3885 } catch (RemoteException e) {
3886 Log.w(TAG, "Failed talking with device policy service", e);
3887 }
3888 }
3889 }
3890
3891 /**
3892 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3893 * that the value of the setting is in the correct form for the setting type should be performed
3894 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003895 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003896 * <ul>
3897 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003898 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003899 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3900 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003901 * <p>A device owner can additionally update the following settings:
3902 * <ul>
3903 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3904 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3906 * @param setting The name of the setting to update.
3907 * @param value The value to update the setting to.
3908 */
Robin Lee25e26452015-06-02 09:56:29 -07003909 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003910 if (mService != null) {
3911 try {
3912 mService.setSecureSetting(admin, setting, value);
3913 } catch (RemoteException e) {
3914 Log.w(TAG, "Failed talking with device policy service", e);
3915 }
3916 }
3917 }
3918
Amith Yamasanif20d6402014-05-24 15:34:37 -07003919 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003920 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003921 * making permission requests of a local or remote administrator of the user.
3922 * <p/>
3923 * Only a profile owner can designate the restrictions provider.
3924 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003925 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003926 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003927 * it removes the restrictions provider previously assigned.
3928 */
Robin Lee25e26452015-06-02 09:56:29 -07003929 public void setRestrictionsProvider(@NonNull ComponentName admin,
3930 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003931 if (mService != null) {
3932 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003933 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003934 } catch (RemoteException re) {
3935 Log.w(TAG, "Failed to set permission provider on device policy service");
3936 }
3937 }
3938 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003939
3940 /**
3941 * Called by profile or device owners to set the master volume mute on or off.
3942 *
3943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3944 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3945 */
Robin Lee25e26452015-06-02 09:56:29 -07003946 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003947 if (mService != null) {
3948 try {
3949 mService.setMasterVolumeMuted(admin, on);
3950 } catch (RemoteException re) {
3951 Log.w(TAG, "Failed to setMasterMute on device policy service");
3952 }
3953 }
3954 }
3955
3956 /**
3957 * Called by profile or device owners to check whether the master volume mute is on or off.
3958 *
3959 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3960 * @return {@code true} if master volume is muted, {@code false} if it's not.
3961 */
Robin Lee25e26452015-06-02 09:56:29 -07003962 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003963 if (mService != null) {
3964 try {
3965 return mService.isMasterVolumeMuted(admin);
3966 } catch (RemoteException re) {
3967 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3968 }
3969 }
3970 return false;
3971 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003972
3973 /**
3974 * Called by profile or device owners to change whether a user can uninstall
3975 * a package.
3976 *
3977 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3978 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003979 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003980 */
Robin Lee25e26452015-06-02 09:56:29 -07003981 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003982 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003983 if (mService != null) {
3984 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003985 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003986 } catch (RemoteException re) {
3987 Log.w(TAG, "Failed to call block uninstall on device policy service");
3988 }
3989 }
3990 }
3991
3992 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003993 * Check whether the current user has been blocked by device policy from uninstalling a package.
3994 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00003995 * <p>
3996 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07003997 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00003998 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07003999 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004000 *
Robin Lee25e26452015-06-02 09:56:29 -07004001 * @param admin The name of the admin component whose blocking policy will be checked, or
4002 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004003 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004004 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004005 */
Robin Lee25e26452015-06-02 09:56:29 -07004006 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004007 if (mService != null) {
4008 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004009 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004010 } catch (RemoteException re) {
4011 Log.w(TAG, "Failed to call block uninstall on device policy service");
4012 }
4013 }
4014 return false;
4015 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004016
4017 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004018 * Called by the profile owner of a managed profile to enable widget providers from a
4019 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004020 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004021 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004022 * a package may have zero or more provider components, where each component
4023 * provides a different widget type.
4024 * <p>
4025 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004026 *
4027 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4028 * @param packageName The package from which widget providers are white-listed.
4029 * @return Whether the package was added.
4030 *
4031 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4032 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4033 */
Robin Lee25e26452015-06-02 09:56:29 -07004034 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004035 if (mService != null) {
4036 try {
4037 return mService.addCrossProfileWidgetProvider(admin, packageName);
4038 } catch (RemoteException re) {
4039 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4040 }
4041 }
4042 return false;
4043 }
4044
4045 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004046 * Called by the profile owner of a managed profile to disable widget providers from a given
4047 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004048 * package should have been added via {@link #addCrossProfileWidgetProvider(
4049 * android.content.ComponentName, String)}.
4050 * <p>
4051 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004052 *
4053 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4054 * @param packageName The package from which widget providers are no longer
4055 * white-listed.
4056 * @return Whether the package was removed.
4057 *
4058 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4059 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4060 */
Robin Lee25e26452015-06-02 09:56:29 -07004061 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004062 if (mService != null) {
4063 try {
4064 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4065 } catch (RemoteException re) {
4066 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4067 }
4068 }
4069 return false;
4070 }
4071
4072 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004073 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004074 * available in the parent profile.
4075 *
4076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4077 * @return The white-listed package list.
4078 *
4079 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4080 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4081 */
Robin Lee25e26452015-06-02 09:56:29 -07004082 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004083 if (mService != null) {
4084 try {
4085 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4086 if (providers != null) {
4087 return providers;
4088 }
4089 } catch (RemoteException re) {
4090 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4091 }
4092 }
4093 return Collections.emptyList();
4094 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004095
4096 /**
4097 * Called by profile or device owners to set the current user's photo.
4098 *
4099 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4100 * @param icon the bitmap to set as the photo.
4101 */
Robin Lee25e26452015-06-02 09:56:29 -07004102 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004103 try {
4104 mService.setUserIcon(admin, icon);
4105 } catch (RemoteException re) {
4106 Log.w(TAG, "Could not set the user icon ", re);
4107 }
4108 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004109
4110 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004111 * Called by device owners to set a local system update policy. When a new policy is set,
4112 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004113 *
Robin Lee25e26452015-06-02 09:56:29 -07004114 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4115 * components in the device owner package can set system update policies and the
4116 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004117 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004118 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004119 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004120 */
Robin Lee25e26452015-06-02 09:56:29 -07004121 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004122 if (mService != null) {
4123 try {
Robin Lee25e26452015-06-02 09:56:29 -07004124 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004125 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004126 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004127 }
4128 }
4129 }
4130
4131 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004132 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004133 *
Robin Lee25e26452015-06-02 09:56:29 -07004134 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004135 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004136 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004137 if (mService != null) {
4138 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004139 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004140 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004141 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004142 }
4143 }
4144 return null;
4145 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004146
4147 /**
4148 * Called by a device owner to disable the keyguard altogether.
4149 *
4150 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4151 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4152 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4153 * being disabled.
4154 *
4155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004156 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004157 *
4158 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004159 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004160 */
Robin Lee25e26452015-06-02 09:56:29 -07004161 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004162 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004163 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004164 } catch (RemoteException re) {
4165 Log.w(TAG, "Failed talking with device policy service", re);
4166 return false;
4167 }
4168 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004169
4170 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004171 * Called by device owner to disable the status bar. Disabling the status bar blocks
4172 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004173 * a single use device.
4174 *
4175 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004176 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4177 *
4178 * @return {@code false} if attempting to disable the status bar failed.
4179 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004180 */
Robin Lee25e26452015-06-02 09:56:29 -07004181 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004182 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004183 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004184 } catch (RemoteException re) {
4185 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004186 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004187 }
4188 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004189
4190 /**
4191 * Callable by the system update service to notify device owners about pending updates.
4192 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4193 * permission.
4194 *
4195 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4196 * when the current pending update was first available. -1 if no update is available.
4197 * @hide
4198 */
4199 @SystemApi
4200 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4201 if (mService != null) {
4202 try {
4203 mService.notifyPendingSystemUpdate(updateReceivedTime);
4204 } catch (RemoteException re) {
4205 Log.w(TAG, "Could not notify device owner about pending system update", re);
4206 }
4207 }
4208 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004209
4210 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004211 * Called by profile or device owners to set the default response for future runtime permission
4212 * requests by applications. The policy can allow for normal operation which prompts the
4213 * user to grant a permission, or can allow automatic granting or denying of runtime
4214 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004215 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4216 * the permission grant state via {@link #setPermissionGrantState}.
4217 *
4218 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004219 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004220 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004221 * @param admin Which profile or device owner this request is associated with.
4222 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4223 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004224 *
4225 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004226 */
Robin Lee25e26452015-06-02 09:56:29 -07004227 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004228 try {
4229 mService.setPermissionPolicy(admin, policy);
4230 } catch (RemoteException re) {
4231 Log.w(TAG, "Failed talking with device policy service", re);
4232 }
4233 }
4234
4235 /**
4236 * Returns the current runtime permission policy set by the device or profile owner. The
4237 * default is {@link #PERMISSION_POLICY_PROMPT}.
4238 * @param admin Which profile or device owner this request is associated with.
4239 * @return the current policy for future permission requests.
4240 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004241 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004242 try {
4243 return mService.getPermissionPolicy(admin);
4244 } catch (RemoteException re) {
4245 return PERMISSION_POLICY_PROMPT;
4246 }
4247 }
4248
4249 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004250 * Sets the grant state of a runtime permission for a specific application. The state
4251 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4252 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4253 * is denied and the user cannot manage it through the UI, and {@link
4254 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4255 * user cannot manage it through the UI. This might affect all permissions in a
4256 * group that the runtime permission belongs to. This method can only be called
4257 * by a profile or device owner.
4258 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004259 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4260 * revoke the permission. It retains the previous grant, if any.
4261 *
4262 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004263 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004264 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004265 * @param admin Which profile or device owner this request is associated with.
4266 * @param packageName The application to grant or revoke a permission to.
4267 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004268 * @param grantState The permission grant state which is one of {@link
4269 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4270 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4271 * @return whether the permission was successfully granted or revoked.
4272 *
4273 * @see #PERMISSION_GRANT_STATE_DENIED
4274 * @see #PERMISSION_GRANT_STATE_DEFAULT
4275 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004276 */
Robin Lee25e26452015-06-02 09:56:29 -07004277 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004278 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004279 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004280 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004281 } catch (RemoteException re) {
4282 Log.w(TAG, "Failed talking with device policy service", re);
4283 return false;
4284 }
4285 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004286
4287 /**
4288 * Returns the current grant state of a runtime permission for a specific application.
4289 *
4290 * @param admin Which profile or device owner this request is associated with.
4291 * @param packageName The application to check the grant state for.
4292 * @param permission The permission to check for.
4293 * @return the current grant state specified by device policy. If the profile or device owner
4294 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4295 * This does not indicate whether or not the permission is currently granted for the package.
4296 *
4297 * <p/>If a grant state was set by the profile or device owner, then the return value will
4298 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4299 * which indicates if the permission is currently denied or granted.
4300 *
4301 * @see #setPermissionGrantState(ComponentName, String, String, int)
4302 * @see PackageManager#checkPermission(String, String)
4303 */
Robin Lee25e26452015-06-02 09:56:29 -07004304 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004305 String permission) {
4306 try {
4307 return mService.getPermissionGrantState(admin, packageName, permission);
4308 } catch (RemoteException re) {
4309 Log.w(TAG, "Failed talking with device policy service", re);
4310 return PERMISSION_GRANT_STATE_DEFAULT;
4311 }
4312 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004313}