blob: e3959a091079ce18661538d640c2f8db8e1d2aff [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;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000034import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010035import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070036import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000037import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080038import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070041import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040042import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000043import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000044import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010045import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070046import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080047import android.util.Log;
48
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070049import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040050import com.android.org.conscrypt.TrustedCertificateStore;
51
Jessica Hummel91da58d2014-04-10 17:39:43 +010052import org.xmlpull.v1.XmlPullParserException;
53
Maggie Benthallda51e682013-08-08 22:35:44 -040054import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080055import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070056import java.net.InetSocketAddress;
57import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010058import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000059import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010060import java.security.PrivateKey;
61import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040062import java.security.cert.CertificateException;
63import java.security.cert.CertificateFactory;
64import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010065import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000066import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070067import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070068import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080069import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080070
71/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000072 * Public interface for managing policies enforced on a device. Most clients of this class must be
73 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000074 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000075 * a device administrator may be registered as either a profile or device owner. A given method is
76 * accessible to all device administrators unless the documentation for that method specifies that
77 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080078 *
79 * <div class="special reference">
80 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000081 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070083 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080084 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080085 */
86public class DevicePolicyManager {
87 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080088
89 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 private final IDevicePolicyManager mService;
Clara Bayarri3e826ef2015-12-14 17:51:22 +000091 private boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070092
Makoto Onukic8a5a552015-11-19 14:29:12 -080093 private static final String REMOTE_EXCEPTION_MESSAGE =
94 "Failed to talk with device policy manager service";
95
Clara Bayarri3e826ef2015-12-14 17:51:22 +000096 private DevicePolicyManager(Context context, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070097 this(context, IDevicePolicyManager.Stub.asInterface(
98 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Clara Bayarri3e826ef2015-12-14 17:51:22 +000099 mParentInstance = parentInstance;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 }
101
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800102 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700103 @VisibleForTesting
104 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
105 mContext = context;
106 mService = service;
107 }
108
109 /** @hide */
110 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000111 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800112 return me.mService != null ? me : null;
113 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700114
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700115 /** @hide test will override it. */
116 @VisibleForTesting
117 protected int myUserId() {
118 return UserHandle.myUserId();
119 }
120
Dianne Hackbornd6847842010-01-12 18:14:19 -0800121 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000122 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000123 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100124 * <p>A managed profile allows data separation for example for the usage of a
125 * device as a personal and corporate device. The user which provisioning is started from and
126 * the managed profile share a launcher.
127 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800128 * <p>This intent will typically be sent by a mobile device management application (MDM).
129 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
130 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100131 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000132 * <p>It is possible to check if provisioning is allowed or not by querying the method
133 * {@link #isProvisioningAllowed(String)}.
134 *
135 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000136 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700137 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000138 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
139 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000140 *
141 * <p> The intent may also contain the following extras:
142 * <ul>
143 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
144 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
145 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000146 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000147 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
148 * in the provisioning intent. The
149 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
150 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
151 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100152 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100153 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
154 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100155 *
156 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
157 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
158 * the provisioning flow was successful, although this doesn't guarantee the full flow will
159 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
160 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000161 */
162 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
163 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100164 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000165
166 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000167 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000168 * Activity action: Starts the provisioning flow which sets up a managed user.
169 *
170 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800171 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000172 * owner who has full control over the user. Provisioning can only happen before user setup has
173 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
174 * allowed.
175 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000176 * <p>This intent should contain the extra
177 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000178 *
179 * <p> If provisioning fails, the device returns to its previous state.
180 *
181 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
182 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
183 * the provisioning flow was successful, although this doesn't guarantee the full flow will
184 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
185 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000186 */
187 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
188 public static final String ACTION_PROVISION_MANAGED_USER
189 = "android.app.action.PROVISION_MANAGED_USER";
190
191 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100192 * Activity action: Starts the provisioning flow which sets up a managed device.
193 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
194 *
195 * <p> During device owner provisioning a device admin app is set as the owner of the device.
196 * A device owner has full control over the device. The device owner can not be modified by the
197 * user.
198 *
199 * <p> A typical use case would be a device that is owned by a company, but used by either an
200 * employee or client.
201 *
202 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000203 * It is possible to check if provisioning is allowed or not by querying the method
204 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100205 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000206 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100207 * <ul>
208 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
209 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
210 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100211 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000212 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000213 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100214 * </ul>
215 *
216 * <p> When device owner provisioning has completed, an intent of the type
217 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
218 * device owner.
219 *
220 * <p> If provisioning fails, the device is factory reset.
221 *
Alan Treadway4582f812015-07-28 11:49:35 +0100222 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
223 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
224 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
225 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100226 */
227 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
228 public static final String ACTION_PROVISION_MANAGED_DEVICE
229 = "android.app.action.PROVISION_MANAGED_DEVICE";
230
231 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000232 * Activity action: Starts the provisioning flow which sets up a managed device.
233 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
234 *
235 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
236 * management state that is distinct from that reached by
237 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
238 * user, and only has control over device-wide policies, not individual users and their data.
239 * The primary benefit is that multiple non-system users are supported when provisioning using
240 * this form of device management.
241 *
242 * <p> During device owner provisioning a device admin app is set as the owner of the device.
243 * A device owner has full control over the device. The device owner can not be modified by the
244 * user.
245 *
246 * <p> A typical use case would be a device that is owned by a company, but used by either an
247 * employee or client.
248 *
249 * <p> An intent with this action can be sent only on an unprovisioned device.
250 * It is possible to check if provisioning is allowed or not by querying the method
251 * {@link #isProvisioningAllowed(String)}.
252 *
253 * <p>The intent contains the following extras:
254 * <ul>
255 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
256 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
257 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
258 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
259 * </ul>
260 *
261 * <p> When device owner provisioning has completed, an intent of the type
262 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
263 * device owner.
264 *
265 * <p> If provisioning fails, the device is factory reset.
266 *
267 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
268 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
269 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
270 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
271 *
272 * @hide
273 */
274 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
275 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
276 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
277
278 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100279 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100280 * allows a mobile device management application or NFC programmer application which starts
281 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100282 * <p>
283 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
284 * sends the intent to pass data to itself on the newly created profile.
285 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
286 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100287 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
288 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
289 * message should contain a stringified {@link java.util.Properties} instance, whose string
290 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
291 * management application after provisioning.
292 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100293 * <p>
294 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700295 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
296 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100297 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100298 */
299 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100300 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100301
302 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100303 * A String extra holding the package name of the mobile device management application that
304 * will be set as the profile owner or device owner.
305 *
306 * <p>If an application starts provisioning directly via an intent with action
307 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
308 * application that started provisioning. The package will be set as profile owner in that case.
309 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000310 * <p>This package is set as device owner when device owner provisioning is started by an NFC
311 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000312 *
313 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700314 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000315
316 * @see DeviceAdminReceiver
317 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100318 * supported, but only if there is only one device admin receiver in the package that requires
319 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000320 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000321 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000322 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100323 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000324
325 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000326 * A ComponentName extra indicating the device admin receiver of the mobile device management
327 * application that will be set as the profile owner or device owner and active admin.
328 *
329 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100330 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
331 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
332 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000333 *
334 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100335 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
336 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400337 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000338 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000339 *
340 * @see DeviceAdminReceiver
341 */
342 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
343 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
344
345 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000346 * An {@link android.accounts.Account} extra holding the account to migrate during managed
347 * profile provisioning. If the account supplied is present in the primary user, it will be
348 * copied, along with its credentials to the managed profile and removed from the primary user.
349 *
350 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
351 */
352
353 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
354 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
355
356 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100357 * A String extra that, holds the email address of the account which a managed profile is
358 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
359 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100360 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100361 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
362 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100363 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
364 * contains this extra, it is forwarded in the
365 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
366 * device management application that was set as the profile owner during provisioning.
367 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100368 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100369 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
370 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100371
372 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000373 * A integer extra indicating the predominant color to show during the provisioning.
374 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000375 *
376 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
377 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
378 */
379 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
380 "android.app.extra.PROVISIONING_MAIN_COLOR";
381
382 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000383 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700384 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000385 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100386 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
387 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000388 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000389 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
390 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000391
392 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100393 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
394 * will be set to.
395 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000396 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
397 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100398 */
399 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100400 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100401
402 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100403 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
404 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100405 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000406 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
407 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100408 */
409 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100410 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100411
412 /**
413 * A String extra holding the {@link java.util.Locale} that the device will be set to.
414 * Format: xx_yy, where xx is the language code, and yy the country code.
415 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000416 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
417 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100418 */
419 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100420 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100421
422 /**
423 * A String extra holding the ssid of the wifi network that should be used during nfc device
424 * owner provisioning for downloading the mobile device management application.
425 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000426 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
427 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100428 */
429 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100430 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100431
432 /**
433 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
434 * is hidden or not.
435 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000436 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
437 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100438 */
439 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100440 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100441
442 /**
443 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100444 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
445 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100446 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000447 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
448 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100449 */
450 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100451 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100452
453 /**
454 * A String extra holding the password of the wifi network in
455 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
456 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000457 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
458 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100459 */
460 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100461 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100462
463 /**
464 * A String extra holding the proxy host for the wifi network in
465 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
466 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000467 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
468 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100469 */
470 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100471 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100472
473 /**
474 * An int extra holding the proxy port for the wifi network in
475 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
476 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000477 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
478 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100479 */
480 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100481 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100482
483 /**
484 * A String extra holding the proxy bypass for the wifi network in
485 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
486 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000487 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
488 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100489 */
490 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100491 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100492
493 /**
494 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
495 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
496 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000497 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
498 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100499 */
500 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100501 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100502
503 /**
504 * A String extra holding a url that specifies the download location of the device admin
505 * package. When not provided it is assumed that the device admin package is already installed.
506 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000507 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
508 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509 */
510 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100511 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100512
513 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400514 * An int extra holding a minimum required version code for the device admin package. If the
515 * device admin is already installed on the device, it will only be re-downloaded from
516 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
517 * installed package is less than this version code.
518 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400519 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400520 * provisioning via an NFC bump.
521 */
522 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
523 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
524
525 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100526 * A String extra holding a http cookie header which should be used in the http request to the
527 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
528 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000529 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
530 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100531 */
532 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100533 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100534
535 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100536 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
537 * the file at download location specified in
538 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100539 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100540 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100541 * present. The provided checksum should match the checksum of the file at the download
542 * location. If the checksum doesn't match an error will be shown to the user and the user will
543 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100544 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
546 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100547 *
548 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
549 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700550 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100551 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100552 */
553 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100554 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100555
556 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100557 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100558 * android package archive at the download location specified in {@link
559 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
560 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100561 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100562 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
563 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
564 *
565 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100566 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100567 * the download location. If the checksum does not match an error will be shown to the user and
568 * the user will be asked to factory reset the device.
569 *
570 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
571 * provisioning via an NFC bump.
572 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100573 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
574 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100575
576 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000577 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
578 * has completed successfully.
579 *
580 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700581 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000582 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800583 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000584 * corresponds to the account requested to be migrated at provisioning time, if any.
585 */
586 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
587 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
588 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
589
590 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400591 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500592 * provisioning.
593 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400594 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100595 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500596 */
597 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
598 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
599
600 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000601 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
602 * provisioning. If this extra is not passed, a default image will be shown.
603 * <h5>The following URI schemes are accepted:</h5>
604 * <ul>
605 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
606 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
607 * </ul>
608 *
609 * <p> It is the responsability of the caller to provide an image with a reasonable
610 * pixed density for the device.
611 *
612 * <p> If a content: URI is passed, the intent should have the flag
613 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
614 * {@link android.content.ClipData} of the intent too.
615 *
616 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
617 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
618 */
619 public static final String EXTRA_PROVISIONING_LOGO_URI =
620 "android.app.extra.PROVISIONING_LOGO_URI";
621
622 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000623 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
624 * during setup-wizard.
625 *
626 * <p>If unspecified, defaults to {@code true} to match the behavior in
627 * {@link android.os.Build.VERSION_CODES#M} and earlier.
628 *
629 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE},
630 * {@link #ACTION_PROVISION_MANAGED_DEVICE} or {@link #ACTION_PROVISION_MANAGED_USER}.
631 *
632 * @hide
633 */
634 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
635 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
636
637 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400638 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100639 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400640 * <p>During device owner provisioning a device admin app is set as the owner of the device.
641 * A device owner has full control over the device. The device owner can not be modified by the
642 * user and the only way of resetting the device is if the device owner app calls a factory
643 * reset.
644 *
645 * <p> A typical use case would be a device that is owned by a company, but used by either an
646 * employee or client.
647 *
648 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100649 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000650 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100651 * contains the following properties:
652 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400653 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
654 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100655 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400656 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100657 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
658 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
659 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
660 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
661 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
662 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
663 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
664 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
665 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
666 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100667 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
668 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
669 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100670 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000671 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700672 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400673 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
674 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
675 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400676 */
677 public static final String MIME_TYPE_PROVISIONING_NFC
678 = "application/com.android.managedprovisioning";
679
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100680 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800681 * Activity action: ask the user to add a new device administrator to the system.
682 * The desired policy is the ComponentName of the policy in the
683 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
684 * bring the user through adding the device administrator to the system (or
685 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700686 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800687 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
688 * field to provide the user with additional explanation (in addition
689 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800690 *
691 * <p>If your administrator is already active, this will ordinarily return immediately (without
692 * user intervention). However, if your administrator has been updated and is requesting
693 * additional uses-policy flags, the user will be presented with the new list. New policies
694 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800695 */
696 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
697 public static final String ACTION_ADD_DEVICE_ADMIN
698 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700699
Dianne Hackbornd6847842010-01-12 18:14:19 -0800700 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700701 * @hide
702 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700703 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700704 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700705 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
706 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700707 * to remotely control restrictions on the user.
708 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800709 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700710 * result of whether or not the user approved the action. If approved, the result will
711 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
712 * as a profile owner.
713 *
714 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
715 * field to provide the user with additional explanation (in addition
716 * to your component's description) about what is being added.
717 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700718 * <p>If there is already a profile owner active or the caller is not a system app, the
719 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700720 */
721 @SystemApi
722 public static final String ACTION_SET_PROFILE_OWNER
723 = "android.app.action.SET_PROFILE_OWNER";
724
725 /**
726 * @hide
727 * Name of the profile owner admin that controls the user.
728 */
729 @SystemApi
730 public static final String EXTRA_PROFILE_OWNER_NAME
731 = "android.app.extra.PROFILE_OWNER_NAME";
732
733 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100734 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700735 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700736 *
Jim Miller284b62e2010-06-08 14:27:42 -0700737 * @hide
738 */
739 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
740 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
741
742 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100743 * Broadcast action: sent when the device owner is set or changed.
744 *
745 * This broadcast is sent only to the primary user.
746 * @see #ACTION_PROVISION_MANAGED_DEVICE
747 */
748 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
749 public static final String ACTION_DEVICE_OWNER_CHANGED
750 = "android.app.action.DEVICE_OWNER_CHANGED";
751
752 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800753 * The ComponentName of the administrator component.
754 *
755 * @see #ACTION_ADD_DEVICE_ADMIN
756 */
757 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700758
Dianne Hackbornd6847842010-01-12 18:14:19 -0800759 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800760 * An optional CharSequence providing additional explanation for why the
761 * admin is being added.
762 *
763 * @see #ACTION_ADD_DEVICE_ADMIN
764 */
765 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700766
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800767 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700768 * Activity action: have the user enter a new password. This activity should
769 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
770 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
771 * enter a new password that meets the current requirements. You can use
772 * {@link #isActivePasswordSufficient()} to determine whether you need to
773 * have the user select a new password in order to meet the current
774 * constraints. Upon being resumed from this activity, you can check the new
775 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000776 *
777 * If the intent is launched from within a managed profile with a profile
778 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
779 * this will trigger entering a new password for the parent of the profile.
780 * For all other cases it will trigger entering a new password for the user
781 * or profile it is launched from.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800782 */
783 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
784 public static final String ACTION_SET_NEW_PASSWORD
785 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700786
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000787 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000788 * Activity action: have the user enter a new password for the parent profile.
789 * If the intent is launched from within a managed profile, this will trigger
790 * entering a new password for the parent of the profile. In all other cases
791 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
792 */
793 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
794 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
795 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
796
797 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000798 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
799 * the parent profile to access intents sent from the managed profile.
800 * That is, when an app in the managed profile calls
801 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
802 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000803 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100804 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000805
806 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000807 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
808 * the managed profile to access intents sent from the parent profile.
809 * That is, when an app in the parent profile calls
810 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
811 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000812 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100813 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700814
Dianne Hackbornd6847842010-01-12 18:14:19 -0800815 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100816 * Broadcast action: notify that a new local system update policy has been set by the device
817 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000818 */
819 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100820 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
821 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000822
Amith Yamasanid49489b2015-04-28 14:00:26 -0700823 /**
824 * Permission policy to prompt user for new permission requests for runtime permissions.
825 * Already granted or denied permissions are not affected by this.
826 */
827 public static final int PERMISSION_POLICY_PROMPT = 0;
828
829 /**
830 * Permission policy to always grant new permission requests for runtime permissions.
831 * Already granted or denied permissions are not affected by this.
832 */
833 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
834
835 /**
836 * Permission policy to always deny new permission requests for runtime permissions.
837 * Already granted or denied permissions are not affected by this.
838 */
839 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
840
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700841 /**
842 * Runtime permission state: The user can manage the permission
843 * through the UI.
844 */
845 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
846
847 /**
848 * Runtime permission state: The permission is granted to the app
849 * and the user cannot manage the permission through the UI.
850 */
851 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
852
853 /**
854 * Runtime permission state: The permission is denied to the app
855 * and the user cannot manage the permission through the UI.
856 */
857 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000858
859 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800860 * Return true if the given administrator component is currently
861 * active (enabled) in the system.
862 */
Robin Lee25e26452015-06-02 09:56:29 -0700863 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700864 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100865 }
866
867 /**
868 * @see #isAdminActive(ComponentName)
869 * @hide
870 */
Robin Lee25e26452015-06-02 09:56:29 -0700871 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800872 if (mService != null) {
873 try {
Robin Lee25e26452015-06-02 09:56:29 -0700874 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800875 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800876 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800877 }
878 }
879 return false;
880 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800881 /**
882 * Return true if the given administrator component is currently being removed
883 * for the user.
884 * @hide
885 */
Robin Lee25e26452015-06-02 09:56:29 -0700886 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800887 if (mService != null) {
888 try {
Robin Lee25e26452015-06-02 09:56:29 -0700889 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800890 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800891 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800892 }
893 }
894 return false;
895 }
896
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700897
Dianne Hackbornd6847842010-01-12 18:14:19 -0800898 /**
Robin Lee25e26452015-06-02 09:56:29 -0700899 * Return a list of all currently active device administrators' component
900 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800901 * returned.
902 */
903 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700904 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100905 }
906
907 /**
908 * @see #getActiveAdmins()
909 * @hide
910 */
911 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800912 if (mService != null) {
913 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100914 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800915 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800916 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800917 }
918 }
919 return null;
920 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700921
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800922 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700923 * Used by package administration code to determine if a package can be stopped
924 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800925 * @hide
926 */
927 public boolean packageHasActiveAdmins(String packageName) {
928 if (mService != null) {
929 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700930 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800931 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800932 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800933 }
934 }
935 return false;
936 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700937
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800938 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800939 * Remove a current administration component. This can only be called
940 * by the application that owns the administration component; if you
941 * try to remove someone else's component, a security exception will be
942 * thrown.
943 */
Robin Lee25e26452015-06-02 09:56:29 -0700944 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800945 if (mService != null) {
946 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700947 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800948 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800949 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800950 }
951 }
952 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700953
Dianne Hackbornd6847842010-01-12 18:14:19 -0800954 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800955 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700956 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800957 * but requires additional policies after an upgrade.
958 *
959 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
960 * an active administrator, or an exception will be thrown.
961 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
962 */
Robin Lee25e26452015-06-02 09:56:29 -0700963 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800964 if (mService != null) {
965 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700966 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800967 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800968 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800969 }
970 }
971 return false;
972 }
973
974 /**
Clara Bayarria1771112015-12-18 16:29:18 +0000975 * Returns true if the Profile Challenge is available to use for the given profile user.
976 *
977 * @hide
978 */
979 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
980 if (mService != null) {
981 try {
982 return mService.isSeparateProfileChallengeAllowed(userHandle);
983 } catch (RemoteException e) {
984 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
985 }
986 }
987 return false;
988 }
989
990 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800991 * Constant for {@link #setPasswordQuality}: the policy has no requirements
992 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800993 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800994 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800995 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700996
Dianne Hackbornd6847842010-01-12 18:14:19 -0800997 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700998 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
999 * recognition technology. This implies technologies that can recognize the identity of
1000 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1001 * Note that quality constants are ordered so that higher values are more restrictive.
1002 */
1003 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1004
1005 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001006 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001007 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001008 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001010 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001011
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001012 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001013 * Constant for {@link #setPasswordQuality}: the user must have entered a
1014 * password containing at least numeric characters. Note that quality
1015 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001016 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001017 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001018
Dianne Hackbornd6847842010-01-12 18:14:19 -08001019 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001020 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001021 * password containing at least numeric characters with no repeating (4444)
1022 * or ordered (1234, 4321, 2468) sequences. Note that quality
1023 * constants are ordered so that higher values are more restrictive.
1024 */
1025 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1026
1027 /**
1028 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001029 * password containing at least alphabetic (or other symbol) characters.
1030 * Note that quality constants are ordered so that higher values are more
1031 * restrictive.
1032 */
1033 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001034
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001035 /**
1036 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001037 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001038 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001039 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001040 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001041 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001042
Dianne Hackbornd6847842010-01-12 18:14:19 -08001043 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001044 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001045 * password containing at least a letter, a numerical digit and a special
1046 * symbol, by default. With this password quality, passwords can be
1047 * restricted to contain various sets of characters, like at least an
1048 * uppercase letter, etc. These are specified using various methods,
1049 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1050 * that quality constants are ordered so that higher values are more
1051 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001052 */
1053 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1054
1055 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001056 * Called by an application that is administering the device to set the
1057 * password restrictions it is imposing. After setting this, the user
1058 * will not be able to enter a new password that is not at least as
1059 * restrictive as what has been set. Note that the current password
1060 * will remain until the user has set a new one, so the change does not
1061 * take place immediately. To prompt the user for a new password, use
1062 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001063 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001064 * <p>Quality constants are ordered so that higher values are more restrictive;
1065 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001066 * the user's preference, and any other considerations) is the one that
1067 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001068 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001069 * <p>The calling device admin must have requested
1070 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1071 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001072 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001073 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001074 * @param quality The new desired quality. One of
1075 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001076 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1077 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1078 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 */
Robin Lee25e26452015-06-02 09:56:29 -07001080 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001081 if (mService != null) {
1082 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001083 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001084 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001085 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001086 }
1087 }
1088 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001089
Dianne Hackbornd6847842010-01-12 18:14:19 -08001090 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001091 * Retrieve the current minimum password quality for all admins of this user
1092 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001093 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001094 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001095 */
Robin Lee25e26452015-06-02 09:56:29 -07001096 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001097 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001098 }
1099
1100 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001101 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001102 if (mService != null) {
1103 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001104 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001105 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001106 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001107 }
1108 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001109 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001110 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001111
Dianne Hackbornd6847842010-01-12 18:14:19 -08001112 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001113 * Called by an application that is administering the device to set the
1114 * minimum allowed password length. After setting this, the user
1115 * will not be able to enter a new password that is not at least as
1116 * restrictive as what has been set. Note that the current password
1117 * will remain until the user has set a new one, so the change does not
1118 * take place immediately. To prompt the user for a new password, use
1119 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1120 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001121 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1122 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1123 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001124 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001125 * <p>The calling device admin must have requested
1126 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1127 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001128 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001129 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001130 * @param length The new desired minimum password length. A value of 0
1131 * means there is no restriction.
1132 */
Robin Lee25e26452015-06-02 09:56:29 -07001133 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001134 if (mService != null) {
1135 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001136 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001137 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001138 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001139 }
1140 }
1141 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001142
Dianne Hackbornd6847842010-01-12 18:14:19 -08001143 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001144 * Retrieve the current minimum password length for all admins of this
1145 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001146 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001147 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001148 */
Robin Lee25e26452015-06-02 09:56:29 -07001149 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001150 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001151 }
1152
1153 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001154 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001155 if (mService != null) {
1156 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001157 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001158 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001159 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001160 }
1161 }
1162 return 0;
1163 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001164
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001165 /**
1166 * Called by an application that is administering the device to set the
1167 * minimum number of upper case letters required in the password. After
1168 * setting this, the user will not be able to enter a new password that is
1169 * not at least as restrictive as what has been set. Note that the current
1170 * password will remain until the user has set a new one, so the change does
1171 * not take place immediately. To prompt the user for a new password, use
1172 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1173 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001174 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1175 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001176 * <p>
1177 * The calling device admin must have requested
1178 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1179 * this method; if it has not, a security exception will be thrown.
1180 *
1181 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1182 * with.
1183 * @param length The new desired minimum number of upper case letters
1184 * required in the password. A value of 0 means there is no
1185 * restriction.
1186 */
Robin Lee25e26452015-06-02 09:56:29 -07001187 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 if (mService != null) {
1189 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001190 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001191 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001192 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001193 }
1194 }
1195 }
1196
1197 /**
1198 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001199 * password for all admins of this user and its profiles or a particular one.
1200 * This is the same value as set by
1201 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001202 * and only applies when the password quality is
1203 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001204 *
Robin Lee25e26452015-06-02 09:56:29 -07001205 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001206 * aggregate all admins.
1207 * @return The minimum number of upper case letters required in the
1208 * password.
1209 */
Robin Lee25e26452015-06-02 09:56:29 -07001210 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001211 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001212 }
1213
1214 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001215 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001216 if (mService != null) {
1217 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001218 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001219 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001220 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001221 }
1222 }
1223 return 0;
1224 }
1225
1226 /**
1227 * Called by an application that is administering the device to set the
1228 * minimum number of lower case letters required in the password. After
1229 * setting this, the user will not be able to enter a new password that is
1230 * not at least as restrictive as what has been set. Note that the current
1231 * password will remain until the user has set a new one, so the change does
1232 * not take place immediately. To prompt the user for a new password, use
1233 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1234 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001235 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1236 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001237 * <p>
1238 * The calling device admin must have requested
1239 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1240 * this method; if it has not, a security exception will be thrown.
1241 *
1242 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1243 * with.
1244 * @param length The new desired minimum number of lower case letters
1245 * required in the password. A value of 0 means there is no
1246 * restriction.
1247 */
Robin Lee25e26452015-06-02 09:56:29 -07001248 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001249 if (mService != null) {
1250 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001251 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001252 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001253 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001254 }
1255 }
1256 }
1257
1258 /**
1259 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001260 * password for all admins of this user and its profiles or a particular one.
1261 * This is the same value as set by
1262 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001263 * and only applies when the password quality is
1264 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001265 *
Robin Lee25e26452015-06-02 09:56:29 -07001266 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001267 * aggregate all admins.
1268 * @return The minimum number of lower case letters required in the
1269 * password.
1270 */
Robin Lee25e26452015-06-02 09:56:29 -07001271 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001272 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001273 }
1274
1275 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001276 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001277 if (mService != null) {
1278 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001279 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001280 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001281 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001282 }
1283 }
1284 return 0;
1285 }
1286
1287 /**
1288 * Called by an application that is administering the device to set the
1289 * minimum number of letters required in the password. After setting this,
1290 * the user will not be able to enter a new password that is not at least as
1291 * restrictive as what has been set. Note that the current password will
1292 * remain until the user has set a new one, so the change does not take
1293 * place immediately. To prompt the user for a new password, use
1294 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1295 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001296 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1297 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001298 * <p>
1299 * The calling device admin must have requested
1300 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1301 * this method; if it has not, a security exception will be thrown.
1302 *
1303 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1304 * with.
1305 * @param length The new desired minimum number of letters required in the
1306 * password. A value of 0 means there is no restriction.
1307 */
Robin Lee25e26452015-06-02 09:56:29 -07001308 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001309 if (mService != null) {
1310 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001311 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001312 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001313 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001314 }
1315 }
1316 }
1317
1318 /**
1319 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001320 * admins or a particular one. This is the same value as
1321 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1322 * and only applies when the password quality is
1323 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001324 *
Robin Lee25e26452015-06-02 09:56:29 -07001325 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001326 * aggregate all admins.
1327 * @return The minimum number of letters required in the password.
1328 */
Robin Lee25e26452015-06-02 09:56:29 -07001329 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001330 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001331 }
1332
1333 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001334 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001335 if (mService != null) {
1336 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001337 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001338 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001339 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001340 }
1341 }
1342 return 0;
1343 }
1344
1345 /**
1346 * Called by an application that is administering the device to set the
1347 * minimum number of numerical digits required in the password. After
1348 * setting this, the user will not be able to enter a new password that is
1349 * not at least as restrictive as what has been set. Note that the current
1350 * password will remain until the user has set a new one, so the change does
1351 * not take place immediately. To prompt the user for a new password, use
1352 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1353 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001354 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1355 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001356 * <p>
1357 * The calling device admin must have requested
1358 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1359 * this method; if it has not, a security exception will be thrown.
1360 *
1361 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1362 * with.
1363 * @param length The new desired minimum number of numerical digits required
1364 * in the password. A value of 0 means there is no restriction.
1365 */
Robin Lee25e26452015-06-02 09:56:29 -07001366 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001367 if (mService != null) {
1368 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001369 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001370 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001371 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001372 }
1373 }
1374 }
1375
1376 /**
1377 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001378 * for all admins of this user and its profiles or a particular one.
1379 * This is the same value as set by
1380 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001381 * and only applies when the password quality is
1382 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001383 *
Robin Lee25e26452015-06-02 09:56:29 -07001384 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001385 * aggregate all admins.
1386 * @return The minimum number of numerical digits required in the password.
1387 */
Robin Lee25e26452015-06-02 09:56:29 -07001388 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001389 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001390 }
1391
1392 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001393 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001394 if (mService != null) {
1395 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001396 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001397 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001398 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001399 }
1400 }
1401 return 0;
1402 }
1403
1404 /**
1405 * Called by an application that is administering the device to set the
1406 * minimum number of symbols required in the password. After setting this,
1407 * the user will not be able to enter a new password that is not at least as
1408 * restrictive as what has been set. Note that the current password will
1409 * remain until the user has set a new one, so the change does not take
1410 * place immediately. To prompt the user for a new password, use
1411 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1412 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001413 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1414 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001415 * <p>
1416 * The calling device admin must have requested
1417 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1418 * this method; if it has not, a security exception will be thrown.
1419 *
1420 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1421 * with.
1422 * @param length The new desired minimum number of symbols required in the
1423 * password. A value of 0 means there is no restriction.
1424 */
Robin Lee25e26452015-06-02 09:56:29 -07001425 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001426 if (mService != null) {
1427 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001428 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001429 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001430 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001431 }
1432 }
1433 }
1434
1435 /**
1436 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001437 * admins or a particular one. This is the same value as
1438 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1439 * and only applies when the password quality is
1440 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001441 *
Robin Lee25e26452015-06-02 09:56:29 -07001442 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001443 * aggregate all admins.
1444 * @return The minimum number of symbols required in the password.
1445 */
Robin Lee25e26452015-06-02 09:56:29 -07001446 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001447 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001448 }
1449
1450 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001451 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001452 if (mService != null) {
1453 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001454 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001455 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001456 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001457 }
1458 }
1459 return 0;
1460 }
1461
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001462 /**
1463 * Called by an application that is administering the device to set the
1464 * minimum number of non-letter characters (numerical digits or symbols)
1465 * required in the password. After setting this, the user will not be able
1466 * to enter a new password that is not at least as restrictive as what has
1467 * been set. Note that the current password will remain until the user has
1468 * set a new one, so the change does not take place immediately. To prompt
1469 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1470 * setting this value. This constraint is only imposed if the administrator
1471 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1472 * {@link #setPasswordQuality}. The default value is 0.
1473 * <p>
1474 * The calling device admin must have requested
1475 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1476 * this method; if it has not, a security exception will be thrown.
1477 *
1478 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1479 * with.
1480 * @param length The new desired minimum number of letters required in the
1481 * password. A value of 0 means there is no restriction.
1482 */
Robin Lee25e26452015-06-02 09:56:29 -07001483 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001484 if (mService != null) {
1485 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001486 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001487 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001488 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001489 }
1490 }
1491 }
1492
1493 /**
1494 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001495 * password for all admins of this user and its profiles or a particular one.
1496 * This is the same value as set by
1497 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001498 * and only applies when the password quality is
1499 * {@link #PASSWORD_QUALITY_COMPLEX}.
1500 *
Robin Lee25e26452015-06-02 09:56:29 -07001501 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001502 * aggregate all admins.
1503 * @return The minimum number of letters required in the password.
1504 */
Robin Lee25e26452015-06-02 09:56:29 -07001505 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001506 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001507 }
1508
1509 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001510 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001511 if (mService != null) {
1512 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001513 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001514 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001515 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001516 }
1517 }
1518 return 0;
1519 }
1520
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001521 /**
1522 * Called by an application that is administering the device to set the length
1523 * of the password history. After setting this, the user will not be able to
1524 * enter a new password that is the same as any password in the history. Note
1525 * that the current password will remain until the user has set a new one, so
1526 * the change does not take place immediately. To prompt the user for a new
1527 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1528 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001529 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1530 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1531 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001532 *
1533 * <p>
1534 * The calling device admin must have requested
1535 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1536 * method; if it has not, a security exception will be thrown.
1537 *
1538 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1539 * with.
1540 * @param length The new desired length of password history. A value of 0
1541 * means there is no restriction.
1542 */
Robin Lee25e26452015-06-02 09:56:29 -07001543 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001544 if (mService != null) {
1545 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001546 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001547 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001548 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001549 }
1550 }
1551 }
1552
1553 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001554 * Called by a device admin to set the password expiration timeout. Calling this method
1555 * will restart the countdown for password expiration for the given admin, as will changing
1556 * the device password (for all admins).
1557 *
1558 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1559 * For example, to have the password expire 5 days from now, timeout would be
1560 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1561 *
1562 * <p>To disable password expiration, a value of 0 may be used for timeout.
1563 *
Jim Millera4e28d12010-11-08 16:15:47 -08001564 * <p>The calling device admin must have requested
1565 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1566 * method; if it has not, a security exception will be thrown.
1567 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001568 * <p> Note that setting the password will automatically reset the expiration time for all
1569 * active admins. Active admins do not need to explicitly call this method in that case.
1570 *
Jim Millera4e28d12010-11-08 16:15:47 -08001571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1572 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1573 * means there is no restriction (unlimited).
1574 */
Robin Lee25e26452015-06-02 09:56:29 -07001575 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001576 if (mService != null) {
1577 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001578 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001579 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001580 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001581 }
1582 }
1583 }
1584
1585 /**
Jim Miller6b857682011-02-16 16:27:41 -08001586 * Get the password expiration timeout for the given admin. The expiration timeout is the
1587 * recurring expiration timeout provided in the call to
1588 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001589 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001590 *
Robin Lee25e26452015-06-02 09:56:29 -07001591 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001592 * @return The timeout for the given admin or the minimum of all timeouts
1593 */
Robin Lee25e26452015-06-02 09:56:29 -07001594 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001595 if (mService != null) {
1596 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001597 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001598 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001599 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001600 }
1601 }
1602 return 0;
1603 }
1604
1605 /**
1606 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001607 * all admins of this user and its profiles if admin is null. If the password is
1608 * expired, this will return the time since the password expired as a negative number.
1609 * If admin is null, then a composite of all expiration timeouts is returned
1610 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001611 *
Robin Lee25e26452015-06-02 09:56:29 -07001612 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001613 * @return The password expiration time, in ms.
1614 */
Robin Lee25e26452015-06-02 09:56:29 -07001615 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001616 if (mService != null) {
1617 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001618 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001619 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001620 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001621 }
1622 }
1623 return 0;
1624 }
1625
1626 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001627 * Retrieve the current password history length for all admins of this
1628 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001629 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001630 * all admins.
1631 * @return The length of the password history
1632 */
Robin Lee25e26452015-06-02 09:56:29 -07001633 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001634 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001635 }
1636
1637 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001638 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001639 if (mService != null) {
1640 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001641 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001642 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001643 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001644 }
1645 }
1646 return 0;
1647 }
1648
Dianne Hackbornd6847842010-01-12 18:14:19 -08001649 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001650 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001651 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001652 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001653 * @return Returns the maximum length that the user can enter.
1654 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001655 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001656 // Kind-of arbitrary.
1657 return 16;
1658 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001659
Dianne Hackborn254cb442010-01-27 19:23:59 -08001660 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001661 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001662 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001663 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001664 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001665 * <p>The calling device admin must have requested
1666 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1667 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001668 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001669 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001670 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001671 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001672 if (mService != null) {
1673 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001674 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001675 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001676 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001677 }
1678 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001679 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001680 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001681
Dianne Hackbornd6847842010-01-12 18:14:19 -08001682 /**
1683 * Retrieve the number of times the user has failed at entering a
1684 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001685 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001686 * <p>The calling device admin must have requested
1687 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1688 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001689 */
1690 public int getCurrentFailedPasswordAttempts() {
1691 if (mService != null) {
1692 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001693 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001694 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001695 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001696 }
1697 }
1698 return -1;
1699 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001700
1701 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001702 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001703 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001704 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001705 * @hide
1706 */
1707 public boolean getDoNotAskCredentialsOnBoot() {
1708 if (mService != null) {
1709 try {
1710 return mService.getDoNotAskCredentialsOnBoot();
1711 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001712 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001713 }
1714 }
1715 return false;
1716 }
1717
1718 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001719 * Setting this to a value greater than zero enables a built-in policy
1720 * that will perform a device wipe after too many incorrect
1721 * device-unlock passwords have been entered. This built-in policy combines
1722 * watching for failed passwords and wiping the device, and requires
1723 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001724 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001725 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001726 * <p>To implement any other policy (e.g. wiping data for a particular
1727 * application only, erasing or revoking credentials, or reporting the
1728 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001729 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001730 * instead. Do not use this API, because if the maximum count is reached,
1731 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001732 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001733 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001734 * @param num The number of failed password attempts at which point the
1735 * device will wipe its data.
1736 */
Robin Lee25e26452015-06-02 09:56:29 -07001737 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001738 if (mService != null) {
1739 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001740 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001741 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001742 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001743 }
1744 }
1745 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001746
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001747 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001748 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001749 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001750 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001751 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001752 * all admins.
1753 */
Robin Lee25e26452015-06-02 09:56:29 -07001754 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001755 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001756 }
1757
1758 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001759 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001760 if (mService != null) {
1761 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001762 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001763 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001764 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001765 }
1766 }
1767 return 0;
1768 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001769
Dianne Hackborn254cb442010-01-27 19:23:59 -08001770 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001771 * Returns the profile with the smallest maximum failed passwords for wipe,
1772 * for the given user. So for primary user, it might return the primary or
1773 * a managed profile. For a secondary user, it would be the same as the
1774 * user passed in.
1775 * @hide Used only by Keyguard
1776 */
1777 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1778 if (mService != null) {
1779 try {
1780 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1781 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001782 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001783 }
1784 }
1785 return UserHandle.USER_NULL;
1786 }
1787
1788 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001789 * Flag for {@link #resetPassword}: don't allow other admins to change
1790 * the password again until the user has entered it.
1791 */
1792 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001793
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001794 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001795 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1796 * If the flag is set, the device can be booted without asking for user password.
1797 * The absence of this flag does not change the current boot requirements. This flag
1798 * can be set by the device owner only. If the app is not the device owner, the flag
1799 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1800 * device to factory defaults.
1801 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001802 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001803
1804 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001805 * Force a new device unlock password (the password needed to access the
1806 * entire device, not for individual accounts) on the user. This takes
1807 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001808 *
1809 * <p>Calling this from a managed profile that shares the password with the owner profile
1810 * will throw a security exception.
1811 *
1812 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1813 * device admins that are not device owner and not profile owner.
1814 * The password can now only be changed if there is currently no password set. Device owner
1815 * and profile owner can still do this.</em>
1816 *
1817 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001818 * current password quality and length constraints as returned by
1819 * {@link #getPasswordQuality(ComponentName)} and
1820 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1821 * these constraints, then it will be rejected and false returned. Note
1822 * that the password may be a stronger quality (containing alphanumeric
1823 * characters when the requested quality is only numeric), in which case
1824 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001825 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001826 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001827 * pattern or password if the current password constraints allow it. <em>Note: This will not
1828 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1829 * device owner and not profile owner. Once set, the password cannot be changed to null or
1830 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001831 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001832 * <p>The calling device admin must have requested
1833 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1834 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001835 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001836 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001837 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001838 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001839 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001840 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001841 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001842 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001843 if (mParentInstance) {
1844 throw new SecurityException("Reset password does not work across profiles.");
1845 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001846 if (mService != null) {
1847 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001848 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001849 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001850 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001851 }
1852 }
1853 return false;
1854 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001855
Dianne Hackbornd6847842010-01-12 18:14:19 -08001856 /**
1857 * Called by an application that is administering the device to set the
1858 * maximum time for user activity until the device will lock. This limits
1859 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001860 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001861 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001862 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001863 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001864 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001866 * @param timeMs The new desired maximum time to lock in milliseconds.
1867 * A value of 0 means there is no restriction.
1868 */
Robin Lee25e26452015-06-02 09:56:29 -07001869 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001870 if (mService != null) {
1871 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001872 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001873 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001874 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001875 }
1876 }
1877 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001878
Dianne Hackbornd6847842010-01-12 18:14:19 -08001879 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001880 * Retrieve the current maximum time to unlock for all admins of this user
1881 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001882 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001883 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001884 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001885 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001886 */
Robin Lee25e26452015-06-02 09:56:29 -07001887 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001888 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001889 }
1890
1891 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001892 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001893 if (mService != null) {
1894 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001895 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001896 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001897 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001898 }
1899 }
1900 return 0;
1901 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001902
Dianne Hackbornd6847842010-01-12 18:14:19 -08001903 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001904 * Make the device lock immediately, as if the lock screen timeout has
1905 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001906 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001907 * <p>The calling device admin must have requested
1908 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1909 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001910 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001911 public void lockNow() {
1912 if (mService != null) {
1913 try {
1914 mService.lockNow();
1915 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001916 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001917 }
1918 }
1919 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001920
Dianne Hackbornd6847842010-01-12 18:14:19 -08001921 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001922 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001923 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001924 */
1925 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1926
1927 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001928 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1929 * data.
1930 *
Paul Crowley2934b262014-12-02 11:21:13 +00001931 * <p>This flag may only be set by device owner admins; if it is set by
1932 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001933 */
1934 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1935
1936 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001937 * Ask the user data be wiped. Wiping the primary user will cause the
1938 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001939 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001940 * <p>The calling device admin must have requested
1941 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1942 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001943 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001944 * @param flags Bit mask of additional options: currently supported flags
1945 * are {@link #WIPE_EXTERNAL_STORAGE} and
1946 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001947 */
1948 public void wipeData(int flags) {
1949 if (mService != null) {
1950 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08001951 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001952 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001953 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001954 }
1955 }
1956 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001957
Dianne Hackbornd6847842010-01-12 18:14:19 -08001958 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001959 * Called by an application that is administering the device to set the
1960 * global proxy and exclusion list.
1961 * <p>
1962 * The calling device admin must have requested
1963 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1964 * this method; if it has not, a security exception will be thrown.
1965 * Only the first device admin can set the proxy. If a second admin attempts
1966 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001967 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001968 * be returned.
1969 * The method can be called repeatedly by the device admin alrady setting the
1970 * proxy to update the proxy and exclusion list.
1971 *
Robin Lee25e26452015-06-02 09:56:29 -07001972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001973 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1974 * Pass Proxy.NO_PROXY to reset the proxy.
1975 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001976 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1977 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001978 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001979 */
Robin Lee25e26452015-06-02 09:56:29 -07001980 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001981 List<String> exclusionList ) {
1982 if (proxySpec == null) {
1983 throw new NullPointerException();
1984 }
1985 if (mService != null) {
1986 try {
1987 String hostSpec;
1988 String exclSpec;
1989 if (proxySpec.equals(Proxy.NO_PROXY)) {
1990 hostSpec = null;
1991 exclSpec = null;
1992 } else {
1993 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1994 throw new IllegalArgumentException();
1995 }
1996 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1997 String hostName = sa.getHostName();
1998 int port = sa.getPort();
1999 StringBuilder hostBuilder = new StringBuilder();
2000 hostSpec = hostBuilder.append(hostName)
2001 .append(":").append(Integer.toString(port)).toString();
2002 if (exclusionList == null) {
2003 exclSpec = "";
2004 } else {
2005 StringBuilder listBuilder = new StringBuilder();
2006 boolean firstDomain = true;
2007 for (String exclDomain : exclusionList) {
2008 if (!firstDomain) {
2009 listBuilder = listBuilder.append(",");
2010 } else {
2011 firstDomain = false;
2012 }
2013 listBuilder = listBuilder.append(exclDomain.trim());
2014 }
2015 exclSpec = listBuilder.toString();
2016 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002017 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2018 != android.net.Proxy.PROXY_VALID)
2019 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002020 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002021 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002022 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002023 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002024 }
2025 }
2026 return null;
2027 }
2028
2029 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002030 * Set a network-independent global HTTP proxy. This is not normally what you want
2031 * for typical HTTP proxies - they are generally network dependent. However if you're
2032 * doing something unusual like general internal filtering this may be useful. On
2033 * a private network where the proxy is not accessible, you may break HTTP using this.
2034 *
2035 * <p>This method requires the caller to be the device owner.
2036 *
2037 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2038 * @see ProxyInfo
2039 *
2040 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2041 * with.
2042 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2043 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2044 */
Robin Lee25e26452015-06-02 09:56:29 -07002045 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2046 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002047 if (mService != null) {
2048 try {
2049 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2050 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002051 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002052 }
2053 }
2054 }
2055
2056 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002057 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002058 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2059 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002060 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002061 */
2062 public ComponentName getGlobalProxyAdmin() {
2063 if (mService != null) {
2064 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002065 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002066 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002067 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002068 }
2069 }
2070 return null;
2071 }
2072
2073 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002074 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002075 * indicating that encryption is not supported.
2076 */
2077 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2078
2079 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002080 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002081 * indicating that encryption is supported, but is not currently active.
2082 */
2083 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2084
2085 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002086 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002087 * indicating that encryption is not currently active, but is currently
2088 * being activated. This is only reported by devices that support
2089 * encryption of data and only when the storage is currently
2090 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2091 * to become encrypted will never return this value.
2092 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002093 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002094
2095 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002096 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002097 * indicating that encryption is active.
2098 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002099 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002100
2101 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002102 * Result code for {@link #getStorageEncryptionStatus}:
2103 * indicating that encryption is active, but an encryption key has not
2104 * been set by the user.
2105 */
2106 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2107
2108 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002109 * Activity action: begin the process of encrypting data on the device. This activity should
2110 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2111 * After resuming from this activity, use {@link #getStorageEncryption}
2112 * to check encryption status. However, on some devices this activity may never return, as
2113 * it may trigger a reboot and in some cases a complete data wipe of the device.
2114 */
2115 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2116 public static final String ACTION_START_ENCRYPTION
2117 = "android.app.action.START_ENCRYPTION";
2118
2119 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002120 * Widgets are enabled in keyguard
2121 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002122 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002123
2124 /**
Jim Miller50e62182014-04-23 17:25:00 -07002125 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002126 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002127 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2128
2129 /**
2130 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2131 */
2132 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2133
2134 /**
Jim Miller50e62182014-04-23 17:25:00 -07002135 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2136 */
2137 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2138
2139 /**
2140 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2141 */
2142 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2143
2144 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002145 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002146 * (e.g. PIN/Pattern/Password).
2147 */
2148 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2149
2150 /**
Jim Miller06e34502014-07-17 14:46:05 -07002151 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2152 */
2153 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2154
2155 /**
Jim Miller35207742012-11-02 15:33:20 -07002156 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002157 */
2158 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002159
2160 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002161 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002162 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002163 *
2164 * <p>When multiple device administrators attempt to control device
2165 * encryption, the most secure, supported setting will always be
2166 * used. If any device administrator requests device encryption,
2167 * it will be enabled; Conversely, if a device administrator
2168 * attempts to disable device encryption while another
2169 * device administrator has enabled it, the call to disable will
2170 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2171 *
2172 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002173 * written to other storage areas may or may not be encrypted, and this policy does not require
2174 * or control the encryption of any other storage areas.
2175 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2176 * {@code true}, then the directory returned by
2177 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2178 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002179 *
2180 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2181 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2182 * the encryption key may not be fully secured. For maximum security, the administrator should
2183 * also require (and check for) a pattern, PIN, or password.
2184 *
2185 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2186 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002187 * @return the new request status (for all active admins) - will be one of
2188 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2189 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2190 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002191 */
Robin Lee25e26452015-06-02 09:56:29 -07002192 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002193 if (mService != null) {
2194 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002195 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002196 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002197 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002198 }
2199 }
2200 return ENCRYPTION_STATUS_UNSUPPORTED;
2201 }
2202
2203 /**
2204 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002205 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002206 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002207 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2208 * this will return the requested encryption setting as an aggregate of all active
2209 * administrators.
2210 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002211 */
Robin Lee25e26452015-06-02 09:56:29 -07002212 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002213 if (mService != null) {
2214 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002215 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002216 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002217 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002218 }
2219 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002220 return false;
2221 }
2222
2223 /**
2224 * Called by an application that is administering the device to
2225 * determine the current encryption status of the device.
2226 *
2227 * Depending on the returned status code, the caller may proceed in different
2228 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2229 * storage system does not support encryption. If the
2230 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2231 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002232 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2233 * storage system has enabled encryption but no password is set so further action
2234 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002235 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2236 *
Robin Lee7e678712014-07-24 16:41:31 +01002237 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002238 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002239 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2240 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002241 */
2242 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002243 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002244 }
2245
2246 /** @hide per-user version */
2247 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002248 if (mService != null) {
2249 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002250 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002251 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002252 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002253 }
2254 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002255 return ENCRYPTION_STATUS_UNSUPPORTED;
2256 }
2257
2258 /**
Robin Lee7e678712014-07-24 16:41:31 +01002259 * Installs the given certificate as a user CA.
2260 *
Robin Lee25e26452015-06-02 09:56:29 -07002261 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2262 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002263 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002264 *
2265 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002266 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002267 */
Robin Lee25e26452015-06-02 09:56:29 -07002268 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002269 if (mService != null) {
2270 try {
Robin Lee7e678712014-07-24 16:41:31 +01002271 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002272 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002273 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002274 }
2275 }
2276 return false;
2277 }
2278
2279 /**
Robin Lee7e678712014-07-24 16:41:31 +01002280 * Uninstalls the given certificate from trusted user CAs, if present.
2281 *
Robin Lee25e26452015-06-02 09:56:29 -07002282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2283 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002284 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002285 */
Robin Lee25e26452015-06-02 09:56:29 -07002286 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002287 if (mService != null) {
2288 try {
Robin Lee306fe082014-06-19 14:04:24 +00002289 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002290 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002291 } catch (CertificateException e) {
2292 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002293 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002294 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002295 }
2296 }
2297 }
2298
2299 /**
Robin Lee7e678712014-07-24 16:41:31 +01002300 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2301 * If a user has installed any certificates by other means than device policy these will be
2302 * included too.
2303 *
Robin Lee25e26452015-06-02 09:56:29 -07002304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2305 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002306 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002307 */
Robin Lee25e26452015-06-02 09:56:29 -07002308 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002309 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002310 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002311 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002312 mService.enforceCanManageCaCerts(admin);
2313 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2314 for (String alias : certStore.userAliases()) {
2315 try {
2316 certs.add(certStore.getCertificate(alias).getEncoded());
2317 } catch (CertificateException ce) {
2318 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2319 }
2320 }
2321 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002322 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002323 }
2324 }
2325 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002326 }
2327
2328 /**
Robin Lee7e678712014-07-24 16:41:31 +01002329 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2330 * means other than device policy will also be removed, except for system CA certificates.
2331 *
Robin Lee25e26452015-06-02 09:56:29 -07002332 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2333 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002334 */
Robin Lee25e26452015-06-02 09:56:29 -07002335 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002336 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002337 try {
2338 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2339 .toArray(new String[0]));
2340 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002341 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002342 }
2343 }
2344 }
2345
2346 /**
2347 * Returns whether this certificate is installed as a trusted CA.
2348 *
Robin Lee25e26452015-06-02 09:56:29 -07002349 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2350 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002351 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002352 */
Robin Lee25e26452015-06-02 09:56:29 -07002353 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002354 if (mService != null) {
2355 try {
2356 mService.enforceCanManageCaCerts(admin);
2357 return getCaCertAlias(certBuffer) != null;
2358 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002359 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002360 } catch (CertificateException ce) {
2361 Log.w(TAG, "Could not parse certificate", ce);
2362 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002363 }
2364 return false;
2365 }
2366
2367 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002368 * Called by a device or profile owner to install a certificate and private key pair. The
2369 * keypair will be visible to all apps within the profile.
2370 *
Robin Lee25e26452015-06-02 09:56:29 -07002371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2372 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002373 * @param privKey The private key to install.
2374 * @param cert The certificate to install.
2375 * @param alias The private key alias under which to install the certificate. If a certificate
2376 * with that alias already exists, it will be overwritten.
2377 * @return {@code true} if the keys were installed, {@code false} otherwise.
2378 */
Robin Leefbc65642015-08-03 16:21:22 +01002379 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2380 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002381 try {
2382 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002383 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2384 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002385 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002386 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002387 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002388 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2389 Log.w(TAG, "Failed to obtain private key material", e);
2390 } catch (CertificateException | IOException e) {
2391 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002392 }
2393 return false;
2394 }
2395
2396 /**
Robin Leefbc65642015-08-03 16:21:22 +01002397 * Called by a device or profile owner to remove all user credentials installed under a given
2398 * alias.
2399 *
2400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2401 * {@code null} if calling from a delegated certificate installer.
2402 * @param alias The private key alias under which the certificate is installed.
2403 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2404 */
2405 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2406 try {
2407 return mService.removeKeyPair(admin, alias);
2408 } catch (RemoteException e) {
2409 Log.w(TAG, "Failed talking with device policy service", e);
2410 }
2411 return false;
2412 }
2413
2414 /**
Robin Lee25e26452015-06-02 09:56:29 -07002415 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002416 * doesn't exist.
2417 */
2418 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2419 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2420 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2421 new ByteArrayInputStream(certBuffer));
2422 return new TrustedCertificateStore().getCertificateAlias(cert);
2423 }
2424
2425 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002426 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002427 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002428 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002429 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002430 * <p>
2431 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2432 * it is later cleared by calling this method with a null value or uninstallling the certificate
2433 * installer.
2434 *
Robin Lee25e26452015-06-02 09:56:29 -07002435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002436 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002437 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002438 */
Robin Lee25e26452015-06-02 09:56:29 -07002439 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2440 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002441 if (mService != null) {
2442 try {
Robin Lee25e26452015-06-02 09:56:29 -07002443 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002444 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002445 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002446 }
2447 }
2448 }
2449
2450 /**
2451 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002452 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002453 *
Robin Lee25e26452015-06-02 09:56:29 -07002454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2455 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002456 * if none is set.
2457 */
Robin Lee25e26452015-06-02 09:56:29 -07002458 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002459 if (mService != null) {
2460 try {
Robin Lee25e26452015-06-02 09:56:29 -07002461 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002462 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002463 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002464 }
2465 }
2466 return null;
2467 }
2468
2469 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002470 * Called by a device or profile owner to configure an always-on VPN connection through a
2471 * specific application for the current user.
2472 * This connection is automatically granted and persisted after a reboot.
2473 *
2474 * <p>The designated package should declare a {@link android.net.VpnService} in its
2475 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2476 * otherwise the call will fail.
2477 *
2478 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2479 * to remove an existing always-on VPN configuration.
2480 *
2481 * @return {@code true} if the package is set as always-on VPN controller;
2482 * {@code false} otherwise.
2483 */
2484 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2485 @Nullable String vpnPackage) {
2486 if (mService != null) {
2487 try {
2488 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2489 } catch (RemoteException e) {
2490 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2491 }
2492 }
2493 return false;
2494 }
2495
2496 /**
2497 * Called by a device or profile owner to read the name of the package administering an
2498 * always-on VPN connection for the current user.
2499 * If there is no such package, or the always-on VPN is provided by the system instead
2500 * of by an application, {@code null} will be returned.
2501 *
2502 * @return Package name of VPN controller responsible for always-on VPN,
2503 * or {@code null} if none is set.
2504 */
2505 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2506 if (mService != null) {
2507 try {
2508 return mService.getAlwaysOnVpnPackage(admin);
2509 } catch (RemoteException e) {
2510 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2511 }
2512 }
2513 return null;
2514 }
2515
2516 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002517 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002518 * on the device, for this user. After setting this, no applications running as this user
2519 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002520 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002521 * <p>If the caller is device owner, then the restriction will be applied to all users.
2522 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002523 * <p>The calling device admin must have requested
2524 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2525 * this method; if it has not, a security exception will be thrown.
2526 *
2527 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2528 * @param disabled Whether or not the camera should be disabled.
2529 */
Robin Lee25e26452015-06-02 09:56:29 -07002530 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002531 if (mService != null) {
2532 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002533 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002534 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002535 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002536 }
2537 }
2538 }
2539
2540 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002541 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002542 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002543 * @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 -07002544 * have disabled the camera
2545 */
Robin Lee25e26452015-06-02 09:56:29 -07002546 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002547 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002548 }
2549
2550 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002551 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002552 if (mService != null) {
2553 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002554 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002555 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002556 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002557 }
2558 }
2559 return false;
2560 }
2561
2562 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002563 * Called by a device owner to request a bugreport.
2564 *
2565 * <p>There must be only one user on the device, managed by the device owner.
2566 * Otherwise a security exception will be thrown.
2567 *
2568 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2569 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2570 * if it wasn't triggered because a previous bugreport operation is still active
2571 * (either the bugreport is still running or waiting for the user to share or decline)
2572 */
2573 public boolean requestBugreport(@NonNull ComponentName admin) {
2574 if (mService != null) {
2575 try {
2576 return mService.requestBugreport(admin);
2577 } catch (RemoteException e) {
2578 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2579 }
2580 }
2581 return false;
2582 }
2583
2584 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002585 * Determine whether or not creating a guest user has been disabled for the device
2586 *
2587 * @hide
2588 */
2589 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2590 // Currently guest users can always be created if multi-user is enabled
2591 // TODO introduce a policy for guest user creation
2592 return false;
2593 }
2594
2595 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002596 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2597 * screen capture also prevents the content from being shown on display devices that do not have
2598 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2599 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002600 *
2601 * <p>The calling device admin must be a device or profile owner. If it is not, a
2602 * security exception will be thrown.
2603 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002604 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002605 * blocks assist requests for all activities of the relevant user.
2606 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002607 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002608 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002609 */
Robin Lee25e26452015-06-02 09:56:29 -07002610 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002611 if (mService != null) {
2612 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002613 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002614 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002615 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002616 }
2617 }
2618 }
2619
2620 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002621 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002622 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002623 * @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 +01002624 * have disabled screen capture.
2625 */
Robin Lee25e26452015-06-02 09:56:29 -07002626 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002627 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002628 }
2629
2630 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002631 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002632 if (mService != null) {
2633 try {
2634 return mService.getScreenCaptureDisabled(admin, userHandle);
2635 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002636 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002637 }
2638 }
2639 return false;
2640 }
2641
2642 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002643 * Called by a device owner to set whether auto time is required. If auto time is
2644 * required the user cannot set the date and time, but has to use network date and time.
2645 *
2646 * <p>Note: if auto time is required the user can still manually set the time zone.
2647 *
2648 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2649 * be thrown.
2650 *
2651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2652 * @param required Whether auto time is set required or not.
2653 */
Robin Lee25e26452015-06-02 09:56:29 -07002654 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002655 if (mService != null) {
2656 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002657 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002658 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002659 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002660 }
2661 }
2662 }
2663
2664 /**
2665 * @return true if auto time is required.
2666 */
2667 public boolean getAutoTimeRequired() {
2668 if (mService != null) {
2669 try {
2670 return mService.getAutoTimeRequired();
2671 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002672 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002673 }
2674 }
2675 return false;
2676 }
2677
2678 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002679 * Called by an application that is administering the device to disable keyguard customizations,
2680 * such as widgets. After setting this, keyguard features will be disabled according to the
2681 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002682 *
2683 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002684 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002685 * this method; if it has not, a security exception will be thrown.
2686 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002687 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002688 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002689 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002690 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002691 * <ul>
2692 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2693 * these will affect the profile's parent user.
2694 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2695 * generated by applications in the managed profile.
2696 * </ul>
2697 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2698 * can check which features have been disabled by calling
2699 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002700 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002701 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002702 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2703 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002704 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002705 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2706 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002707 */
Robin Lee25e26452015-06-02 09:56:29 -07002708 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002709 if (mService != null) {
2710 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002711 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002712 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002713 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002714 }
2715 }
2716 }
2717
2718 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002719 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002720 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002721 * @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 -07002722 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002723 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2724 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002725 */
Robin Lee25e26452015-06-02 09:56:29 -07002726 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002727 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002728 }
2729
2730 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002731 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002732 if (mService != null) {
2733 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002734 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002735 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002736 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002737 }
2738 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002739 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002740 }
2741
2742 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002743 * @hide
2744 */
Robin Lee25e26452015-06-02 09:56:29 -07002745 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2746 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002747 if (mService != null) {
2748 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002749 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002750 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002751 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002752 }
2753 }
2754 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002755
Dianne Hackbornd6847842010-01-12 18:14:19 -08002756 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002757 * @hide
2758 */
Robin Lee25e26452015-06-02 09:56:29 -07002759 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002760 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002761 }
2762
2763 /**
Robin Lee25e26452015-06-02 09:56:29 -07002764 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002765 * @hide
2766 */
Robin Lee25e26452015-06-02 09:56:29 -07002767 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002768 ActivityInfo ai;
2769 try {
2770 ai = mContext.getPackageManager().getReceiverInfo(cn,
2771 PackageManager.GET_META_DATA);
2772 } catch (PackageManager.NameNotFoundException e) {
2773 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2774 return null;
2775 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002776
Dianne Hackbornd6847842010-01-12 18:14:19 -08002777 ResolveInfo ri = new ResolveInfo();
2778 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002779
Dianne Hackbornd6847842010-01-12 18:14:19 -08002780 try {
2781 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002782 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002783 Log.w(TAG, "Unable to parse device policy " + cn, e);
2784 return null;
2785 }
2786 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002787
Dianne Hackbornd6847842010-01-12 18:14:19 -08002788 /**
2789 * @hide
2790 */
Robin Lee25e26452015-06-02 09:56:29 -07002791 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002792 if (mService != null) {
2793 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002794 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002795 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002796 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002797 }
2798 }
2799 }
2800
2801 /**
2802 * @hide
2803 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002804 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002805 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002806 if (mService != null) {
2807 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002808 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002809 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002810 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002811 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002812 }
2813 }
2814 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002815
Dianne Hackbornd6847842010-01-12 18:14:19 -08002816 /**
2817 * @hide
2818 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002819 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002820 if (mService != null) {
2821 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002822 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002823 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002824 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002825 }
2826 }
2827 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002828
Dianne Hackbornd6847842010-01-12 18:14:19 -08002829 /**
2830 * @hide
2831 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002832 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002833 if (mService != null) {
2834 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002835 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002836 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002837 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002838 }
2839 }
2840 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002841
2842 /**
2843 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002844 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002845 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2846 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002847 * @return whether the package was successfully registered as the device owner.
2848 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002849 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002850 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002851 public boolean setDeviceOwner(ComponentName who) {
2852 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002853 }
2854
2855 /**
2856 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002857 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002858 public boolean setDeviceOwner(ComponentName who, int userId) {
2859 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002860 }
2861
2862 /**
2863 * @hide
2864 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002865 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2866 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002867 }
2868
2869 /**
2870 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002871 * Sets the given package as the device owner. The package must already be installed. There
2872 * must not already be a device owner.
2873 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2874 * this method.
2875 * Calling this after the setup phase of the primary user has completed is allowed only if
2876 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002877 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002878 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002879 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002880 * @return whether the package was successfully registered as the device owner.
2881 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002882 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002883 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002884 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002885 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002886 if (mService != null) {
2887 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002888 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002889 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002890 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002891 }
2892 }
2893 return false;
2894 }
2895
2896 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002897 * Used to determine if a particular package has been registered as a Device Owner app.
2898 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002899 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002900 * package is currently registered as the device owner app, pass in the package name from
2901 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002902 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002903 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2904 * the setup process.
2905 * @param packageName the package name of the app, to compare with the registered device owner
2906 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08002907 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002908 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002909 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08002910 return isDeviceOwnerAppOnCallingUser(packageName);
2911 }
2912
2913 /**
2914 * @return true if a package is registered as device owner, only when it's running on the
2915 * calling user.
2916 *
2917 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
2918 * @hide
2919 */
2920 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
2921 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
2922 }
2923
2924 /**
2925 * @return true if a package is registered as device owner, even if it's running on a different
2926 * user.
2927 *
2928 * <p>Requires the MANAGE_USERS permission.
2929 *
2930 * @hide
2931 */
2932 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
2933 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
2934 }
2935
2936 /**
2937 * @return device owner component name, only when it's running on the calling user.
2938 *
2939 * @hide
2940 */
2941 public ComponentName getDeviceOwnerComponentOnCallingUser() {
2942 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
2943 }
2944
2945 /**
2946 * @return device owner component name, even if it's running on a different user.
2947 *
2948 * <p>Requires the MANAGE_USERS permission.
2949 *
2950 * @hide
2951 */
2952 public ComponentName getDeviceOwnerComponentOnAnyUser() {
2953 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
2954 }
2955
2956 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002957 if (packageName == null) {
2958 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07002959 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08002960 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08002961 if (deviceOwner == null) {
2962 return false;
2963 }
2964 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07002965 }
2966
Makoto Onukic8a5a552015-11-19 14:29:12 -08002967 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
2968 if (mService != null) {
2969 try {
2970 return mService.getDeviceOwnerComponent(callingUserOnly);
2971 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002972 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002973 }
2974 }
2975 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002976 }
2977
Jason Monkb0dced82014-06-06 14:36:20 -04002978 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002979 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
2980 * no device owner.
2981 *
2982 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07002983 *
2984 * @hide
2985 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08002986 public int getDeviceOwnerUserId() {
2987 if (mService != null) {
2988 try {
2989 return mService.getDeviceOwnerUserId();
2990 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002991 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002992 }
2993 }
2994 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07002995 }
2996
2997 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002998 * Clears the current device owner. The caller must be the device owner.
2999 *
3000 * This function should be used cautiously as once it is called it cannot
3001 * be undone. The device owner can only be set as a part of device setup
3002 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003003 *
3004 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003005 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003006 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003007 if (mService != null) {
3008 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003009 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003010 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003011 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04003012 }
3013 }
3014 }
3015
Makoto Onukia52562c2015-10-01 16:12:31 -07003016 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003017 * Returns the device owner package name, only if it's running on the calling user.
3018 *
3019 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003020 *
3021 * @hide
3022 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003023 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003024 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003025 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3026 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003027 }
3028
3029 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003030 * @return true if the device is managed by any device owner.
3031 *
3032 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003033 *
3034 * @hide
3035 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003036 public boolean isDeviceManaged() {
3037 return getDeviceOwnerComponentOnAnyUser() != null;
3038 }
3039
3040 /**
3041 * Returns the device owner name. Note this method *will* return the device owner
3042 * name when it's running on a different user.
3043 *
3044 * <p>Requires the MANAGE_USERS permission.
3045 *
3046 * @hide
3047 */
3048 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003049 if (mService != null) {
3050 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003051 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003052 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003053 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003054 }
3055 }
3056 return null;
3057 }
Adam Connors776c5552014-01-09 10:42:56 +00003058
3059 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003060 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003061 * @deprecated Do not use
3062 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003063 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003064 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003065 @SystemApi
3066 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003067 return null;
3068 }
3069
3070 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003071 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003072 * @deprecated Do not use
3073 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003074 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003075 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003076 @SystemApi
3077 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003078 return null;
3079 }
3080
Julia Reynolds20118f12015-02-11 12:34:08 -05003081 /**
Adam Connors776c5552014-01-09 10:42:56 +00003082 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003083 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303084 * Sets the given component as an active admin and registers the package as the profile
3085 * owner for this user. The package must already be installed and there shouldn't be
3086 * an existing profile owner registered for this user. Also, this method must be called
3087 * before the user setup has been completed.
3088 * <p>
3089 * This method can only be called by system apps that hold MANAGE_USERS permission and
3090 * MANAGE_DEVICE_ADMINS permission.
3091 * @param admin The component to register as an active admin and profile owner.
3092 * @param ownerName The user-visible name of the entity that is managing this user.
3093 * @return whether the admin was successfully registered as the profile owner.
3094 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3095 * the user has already been set up.
3096 */
Justin Morey80440cc2014-07-24 09:16:35 -05003097 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003098 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303099 throws IllegalArgumentException {
3100 if (mService != null) {
3101 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003102 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303103 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003104 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303105 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303106 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3107 }
3108 }
3109 return false;
3110 }
3111
3112 /**
3113 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003114 * Clears the active profile owner and removes all user restrictions. The caller must
3115 * be from the same package as the active profile owner for this user, otherwise a
3116 * SecurityException will be thrown.
3117 *
3118 * @param admin The component to remove as the profile owner.
3119 * @return
3120 */
3121 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003122 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003123 if (mService != null) {
3124 try {
3125 mService.clearProfileOwner(admin);
3126 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003127 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003128 }
3129 }
3130 }
3131
3132 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003133 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003134 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003135 */
3136 public boolean hasUserSetupCompleted() {
3137 if (mService != null) {
3138 try {
3139 return mService.hasUserSetupCompleted();
3140 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003141 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003142 }
3143 }
3144 return true;
3145 }
3146
3147 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003148 * @hide
3149 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003150 * already be installed. There must not already be a profile owner for this user.
3151 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3152 * this method.
3153 * Calling this after the setup phase of the specified user has completed is allowed only if:
3154 * - the caller is SYSTEM_UID.
3155 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003156 * @param admin the component name to be registered as profile owner.
3157 * @param ownerName the human readable name of the organisation associated with this DPM.
3158 * @param userHandle the userId to set the profile owner for.
3159 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003160 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3161 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003162 */
Robin Lee25e26452015-06-02 09:56:29 -07003163 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003164 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003165 if (mService != null) {
3166 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003167 if (ownerName == null) {
3168 ownerName = "";
3169 }
3170 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003171 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003172 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003173 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3174 }
3175 }
3176 return false;
3177 }
3178
3179 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003180 * Sets the device owner information to be shown on the lock screen.
3181 *
3182 * <p>If the device owner information is {@code null} or empty then the device owner info is
3183 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003184 * <p>If the device owner information contains only whitespaces then the message on the lock
3185 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003186 *
3187 * @param admin The name of the admin component to check.
3188 * @param info Device owner information which will be displayed instead of the user
3189 * owner info.
3190 * @return Whether the device owner information has been set.
3191 */
3192 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3193 if (mService != null) {
3194 try {
3195 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3196 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003197 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003198 }
3199 }
3200 return false;
3201 }
3202
3203 /**
3204 * @return The device owner information. If it is not set returns {@code null}.
3205 */
3206 public String getDeviceOwnerLockScreenInfo() {
3207 if (mService != null) {
3208 try {
3209 return mService.getDeviceOwnerLockScreenInfo();
3210 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003211 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003212 }
3213 }
3214 return null;
3215 }
3216
3217 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003218 * Called by device or profile owners for setting the package suspended for this user.
3219 * A suspended package will not be started by the package manager, its notifications will
3220 * be hidden and it will not show up in recents. The package must already be installed.
3221 *
3222 * @param admin The name of the admin component to check.
3223 * @param packageName The package name of the app to suspend or unsuspend.
3224 * @param suspended If set to {@code true} than the package will be suspended, if set to
3225 * {@code false} the package will be unsuspended.
3226 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3227 * otherwise.
3228 */
3229 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3230 boolean suspended) {
3231 if (mService != null) {
3232 try {
3233 return mService.setPackageSuspended(admin, packageName, suspended);
3234 } catch (RemoteException re) {
3235 Log.w(TAG, "Failed talking with device policy service", re);
3236 }
3237 }
3238 return false;
3239 }
3240
3241 /**
3242 * Called by device or profile owners to determine if a package is suspended.
3243 *
3244 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3245 * @param packageName The name of the package to retrieve the suspended status of.
3246 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3247 */
3248 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3249 if (mService != null) {
3250 try {
3251 return mService.getPackageSuspended(admin, packageName);
3252 } catch (RemoteException e) {
3253 Log.w(TAG, "Failed talking with device policy service", e);
3254 }
3255 }
3256 return false;
3257 }
3258
3259 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003260 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3261 * be used. Only the profile owner can call this.
3262 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003263 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003264 *
3265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3266 */
Robin Lee25e26452015-06-02 09:56:29 -07003267 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003268 if (mService != null) {
3269 try {
3270 mService.setProfileEnabled(admin);
3271 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003272 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003273 }
3274 }
3275 }
3276
3277 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003278 * Sets the name of the profile. In the device owner case it sets the name of the user
3279 * 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 +01003280 * never called by the profile or device owner, the name will be set to default values.
3281 *
3282 * @see #isProfileOwnerApp
3283 * @see #isDeviceOwnerApp
3284 *
Robin Lee25e26452015-06-02 09:56:29 -07003285 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003286 * @param profileName The name of the profile.
3287 */
Robin Lee25e26452015-06-02 09:56:29 -07003288 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003289 if (mService != null) {
3290 try {
Robin Lee25e26452015-06-02 09:56:29 -07003291 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003292 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003293 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003294 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003295 }
3296 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003297
3298 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003299 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003300 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003301 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003302 *
3303 * @param packageName The package name of the app to compare with the registered profile owner.
3304 * @return Whether or not the package is registered as the profile owner.
3305 */
3306 public boolean isProfileOwnerApp(String packageName) {
3307 if (mService != null) {
3308 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003309 ComponentName profileOwner = mService.getProfileOwner(
3310 Process.myUserHandle().getIdentifier());
3311 return profileOwner != null
3312 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003313 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003314 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003315 }
3316 }
3317 return false;
3318 }
3319
3320 /**
3321 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003322 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003323 * owner has been set for that user.
3324 * @throws IllegalArgumentException if the userId is invalid.
3325 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003326 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003327 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003328 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3329 }
3330
3331 /**
3332 * @see #getProfileOwner()
3333 * @hide
3334 */
3335 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003336 if (mService != null) {
3337 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003338 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003339 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003340 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003341 throw new IllegalArgumentException(
3342 "Requested profile owner for invalid userId", re);
3343 }
3344 }
3345 return null;
3346 }
3347
3348 /**
3349 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003350 * @return the human readable name of the organisation associated with this DPM or {@code null}
3351 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003352 * @throws IllegalArgumentException if the userId is invalid.
3353 */
3354 public String getProfileOwnerName() throws IllegalArgumentException {
3355 if (mService != null) {
3356 try {
3357 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3358 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003359 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003360 throw new IllegalArgumentException(
3361 "Requested profile owner for invalid userId", re);
3362 }
3363 }
3364 return null;
3365 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003366
3367 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003368 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003369 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003370 * @return the human readable name of the organisation associated with this profile owner or
3371 * null if one is not set.
3372 * @throws IllegalArgumentException if the userId is invalid.
3373 */
3374 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003375 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003376 if (mService != null) {
3377 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003378 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003379 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003380 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003381 throw new IllegalArgumentException(
3382 "Requested profile owner for invalid userId", re);
3383 }
3384 }
3385 return null;
3386 }
3387
3388 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003389 * Called by a profile owner or device owner to add a default intent handler activity for
3390 * intents that match a certain intent filter. This activity will remain the default intent
3391 * handler even if the set of potential event handlers for the intent filter changes and if
3392 * the intent preferences are reset.
3393 *
3394 * <p>The default disambiguation mechanism takes over if the activity is not installed
3395 * (anymore). When the activity is (re)installed, it is automatically reset as default
3396 * intent handler for the filter.
3397 *
3398 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3399 * security exception will be thrown.
3400 *
3401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3402 * @param filter The IntentFilter for which a default handler is added.
3403 * @param activity The Activity that is added as default intent handler.
3404 */
Robin Lee25e26452015-06-02 09:56:29 -07003405 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3406 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003407 if (mService != null) {
3408 try {
3409 mService.addPersistentPreferredActivity(admin, filter, activity);
3410 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003411 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003412 }
3413 }
3414 }
3415
3416 /**
3417 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003418 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003419 *
3420 * <p>The calling device admin must be a profile owner. If it is not, a security
3421 * exception will be thrown.
3422 *
3423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3424 * @param packageName The name of the package for which preferences are removed.
3425 */
Robin Lee25e26452015-06-02 09:56:29 -07003426 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003427 String packageName) {
3428 if (mService != null) {
3429 try {
3430 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3431 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003432 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003433 }
3434 }
3435 }
Robin Lee66e5d962014-04-09 16:44:21 +01003436
3437 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003438 * Called by a profile owner or device owner to grant permission to a package to manage
3439 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3440 * {@link #getApplicationRestrictions}.
3441 * <p>
3442 * This permission is persistent until it is later cleared by calling this method with a
3443 * {@code null} value or uninstalling the managing package.
3444 *
3445 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3446 * @param packageName The package name which will be given access to application restrictions
3447 * APIs. If {@code null} is given the current package will be cleared.
3448 */
3449 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3450 @Nullable String packageName) {
3451 if (mService != null) {
3452 try {
3453 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3454 } catch (RemoteException e) {
3455 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3456 }
3457 }
3458 }
3459
3460 /**
3461 * Called by a profile owner or device owner to retrieve the application restrictions managing
3462 * package for the current user, or {@code null} if none is set.
3463 *
3464 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3465 * @return The package name allowed to manage application restrictions on the current user, or
3466 * {@code null} if none is set.
3467 */
3468 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3469 if (mService != null) {
3470 try {
3471 return mService.getApplicationRestrictionsManagingPackage(admin);
3472 } catch (RemoteException e) {
3473 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3474 }
3475 }
3476 return null;
3477 }
3478
3479 /**
3480 * Returns {@code true} if the calling package has been granted permission via
3481 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3482 * restrictions for the calling user.
3483 */
3484 public boolean isCallerApplicationRestrictionsManagingPackage() {
3485 if (mService != null) {
3486 try {
3487 return mService.isCallerApplicationRestrictionsManagingPackage();
3488 } catch (RemoteException e) {
3489 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3490 }
3491 }
3492 return false;
3493 }
3494
3495 /**
3496 * Sets the application restrictions for a given target application running in the calling user.
3497 *
3498 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3499 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3500 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003501 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003502 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3503 * <ul>
3504 * <li>{@code boolean}
3505 * <li>{@code int}
3506 * <li>{@code String} or {@code String[]}
3507 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3508 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003509 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003510 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003511 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003512 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3513 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003514 * <p>The application restrictions are only made visible to the target application via
3515 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3516 * device owner, and the application restrictions managing package via
3517 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003518 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003519 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3520 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003521 * @param packageName The name of the package to update restricted settings for.
3522 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3523 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003524 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003525 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003526 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003527 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003528 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003529 Bundle settings) {
3530 if (mService != null) {
3531 try {
3532 mService.setApplicationRestrictions(admin, packageName, settings);
3533 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003534 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003535 }
3536 }
3537 }
3538
3539 /**
Jim Millere303bf42014-08-26 17:12:29 -07003540 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3541 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3542 * trust agents but those enabled by this function call. If flag
3543 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003544 *
3545 * <p>The calling device admin must have requested
3546 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003547 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003548 *
3549 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003550 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003551 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003552 * will be strictly disabled according to the state of the
3553 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3554 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3555 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3556 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003557 */
Robin Lee25e26452015-06-02 09:56:29 -07003558 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3559 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003560 if (mService != null) {
3561 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003562 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003563 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003564 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003565 }
3566 }
3567 }
3568
3569 /**
Jim Millere303bf42014-08-26 17:12:29 -07003570 * Gets configuration for the given trust agent based on aggregating all calls to
3571 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3572 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003573 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003574 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3575 * this function returns a list of configurations for all admins that declare
3576 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3577 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3578 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3579 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003580 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003581 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003582 */
Robin Lee25e26452015-06-02 09:56:29 -07003583 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3584 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003585 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003586 }
3587
3588 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003589 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3590 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003591 if (mService != null) {
3592 try {
Jim Millere303bf42014-08-26 17:12:29 -07003593 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003594 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003595 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003596 }
3597 }
Jim Millere303bf42014-08-26 17:12:29 -07003598 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003599 }
3600
3601 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003602 * Called by a profile owner of a managed profile to set whether caller-Id information from
3603 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003604 *
3605 * <p>The calling device admin must be a profile owner. If it is not, a
3606 * security exception will be thrown.
3607 *
Robin Lee25e26452015-06-02 09:56:29 -07003608 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003609 * @param disabled If true caller-Id information in the managed profile is not displayed.
3610 */
Robin Lee25e26452015-06-02 09:56:29 -07003611 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003612 if (mService != null) {
3613 try {
Robin Lee25e26452015-06-02 09:56:29 -07003614 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003615 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003616 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003617 }
3618 }
3619 }
3620
3621 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003622 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3623 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003624 *
3625 * <p>The calling device admin must be a profile owner. If it is not, a
3626 * security exception will be thrown.
3627 *
Robin Lee25e26452015-06-02 09:56:29 -07003628 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003629 */
Robin Lee25e26452015-06-02 09:56:29 -07003630 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003631 if (mService != null) {
3632 try {
Robin Lee25e26452015-06-02 09:56:29 -07003633 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003634 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003635 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003636 }
3637 }
3638 return false;
3639 }
3640
3641 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003642 * Determine whether or not caller-Id information has been disabled.
3643 *
3644 * @param userHandle The user for whom to check the caller-id permission
3645 * @hide
3646 */
3647 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3648 if (mService != null) {
3649 try {
3650 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3651 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003652 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003653 }
3654 }
3655 return false;
3656 }
3657
3658 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003659 * Called by a profile owner of a managed profile to set whether contacts search from
3660 * the managed profile will be shown in the parent profile, for incoming calls.
3661 *
3662 * <p>The calling device admin must be a profile owner. If it is not, a
3663 * security exception will be thrown.
3664 *
3665 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3666 * @param disabled If true contacts search in the managed profile is not displayed.
3667 */
3668 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3669 boolean disabled) {
3670 if (mService != null) {
3671 try {
3672 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3673 } catch (RemoteException e) {
3674 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3675 }
3676 }
3677 }
3678
3679 /**
3680 * Called by a profile owner of a managed profile to determine whether or not contacts search
3681 * has been disabled.
3682 *
3683 * <p>The calling device admin must be a profile owner. If it is not, a
3684 * security exception will be thrown.
3685 *
3686 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3687 */
3688 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3689 if (mService != null) {
3690 try {
3691 return mService.getCrossProfileContactsSearchDisabled(admin);
3692 } catch (RemoteException e) {
3693 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3694 }
3695 }
3696 return false;
3697 }
3698
3699
3700 /**
3701 * Determine whether or not contacts search has been disabled.
3702 *
3703 * @param userHandle The user for whom to check the contacts search permission
3704 * @hide
3705 */
3706 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3707 if (mService != null) {
3708 try {
3709 return mService
3710 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3711 } catch (RemoteException e) {
3712 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3713 }
3714 }
3715 return false;
3716 }
3717
3718 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003719 * Start Quick Contact on the managed profile for the user, if the policy allows.
Makoto Onuki1040da12015-03-19 11:24:00 -07003720 * @hide
3721 */
3722 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Ricky Wai494b95d2015-11-20 16:07:15 +00003723 long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003724 if (mService != null) {
3725 try {
3726 mService.startManagedQuickContact(
Ricky Wai494b95d2015-11-20 16:07:15 +00003727 actualLookupKey, actualContactId, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003728 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003729 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003730 }
3731 }
3732 }
3733
3734 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003735 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003736 * @hide
3737 */
3738 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3739 Intent originalIntent) {
3740 startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT,
3741 originalIntent);
3742 }
3743
3744 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003745 * Called by a profile owner of a managed profile to set whether bluetooth
3746 * devices can access enterprise contacts.
3747 * <p>
3748 * The calling device admin must be a profile owner. If it is not, a
3749 * security exception will be thrown.
3750 * <p>
3751 * This API works on managed profile only.
3752 *
Robin Lee25e26452015-06-02 09:56:29 -07003753 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003754 * with.
3755 * @param disabled If true, bluetooth devices cannot access enterprise
3756 * contacts.
3757 */
Robin Lee25e26452015-06-02 09:56:29 -07003758 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003759 if (mService != null) {
3760 try {
Robin Lee25e26452015-06-02 09:56:29 -07003761 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003762 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003763 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003764 }
3765 }
3766 }
3767
3768 /**
3769 * Called by a profile owner of a managed profile to determine whether or
3770 * not Bluetooth devices cannot access enterprise contacts.
3771 * <p>
3772 * The calling device admin must be a profile owner. If it is not, a
3773 * security exception will be thrown.
3774 * <p>
3775 * This API works on managed profile only.
3776 *
Robin Lee25e26452015-06-02 09:56:29 -07003777 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003778 * with.
3779 */
Robin Lee25e26452015-06-02 09:56:29 -07003780 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003781 if (mService != null) {
3782 try {
Robin Lee25e26452015-06-02 09:56:29 -07003783 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003784 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003785 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003786 }
3787 }
3788 return true;
3789 }
3790
3791 /**
3792 * Determine whether or not Bluetooth devices cannot access contacts.
3793 * <p>
3794 * This API works on managed profile UserHandle only.
3795 *
3796 * @param userHandle The user for whom to check the caller-id permission
3797 * @hide
3798 */
3799 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3800 if (mService != null) {
3801 try {
3802 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3803 .getIdentifier());
3804 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003805 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003806 }
3807 }
3808 return true;
3809 }
3810
3811 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003812 * Called by the profile owner of a managed profile so that some intents sent in the managed
3813 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003814 * Only activity intents are supported.
3815 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003816 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003817 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3818 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003819 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3820 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003821 */
Robin Lee25e26452015-06-02 09:56:29 -07003822 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003823 if (mService != null) {
3824 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003825 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003826 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003827 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003828 }
3829 }
3830 }
3831
3832 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003833 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3834 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003835 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003836 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3837 */
Robin Lee25e26452015-06-02 09:56:29 -07003838 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003839 if (mService != null) {
3840 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003841 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003842 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003843 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003844 }
3845 }
3846 }
3847
3848 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003849 * Called by a profile or device owner to set the permitted accessibility services. When
3850 * set by a device owner or profile owner the restriction applies to all profiles of the
3851 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003852 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003853 * By default the user can use any accessiblity service. When zero or more packages have
3854 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003855 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003856 *
3857 * <p> Calling with a null value for the list disables the restriction so that all services
3858 * can be used, calling with an empty list only allows the builtin system's services.
3859 *
3860 * <p> System accesibility services are always available to the user the list can't modify
3861 * this.
3862 *
3863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3864 * @param packageNames List of accessibility service package names.
3865 *
3866 * @return true if setting the restriction succeeded. It fail if there is
3867 * one or more non-system accessibility services enabled, that are not in the list.
3868 */
Robin Lee25e26452015-06-02 09:56:29 -07003869 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003870 List<String> packageNames) {
3871 if (mService != null) {
3872 try {
3873 return mService.setPermittedAccessibilityServices(admin, packageNames);
3874 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003875 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003876 }
3877 }
3878 return false;
3879 }
3880
3881 /**
3882 * Returns the list of permitted accessibility services set by this device or profile owner.
3883 *
3884 * <p>An empty list means no accessibility services except system services are allowed.
3885 * Null means all accessibility services are allowed.
3886 *
3887 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3888 * @return List of accessiblity service package names.
3889 */
Robin Lee25e26452015-06-02 09:56:29 -07003890 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003891 if (mService != null) {
3892 try {
3893 return mService.getPermittedAccessibilityServices(admin);
3894 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003895 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003896 }
3897 }
3898 return null;
3899 }
3900
3901 /**
3902 * Returns the list of accessibility services permitted by the device or profiles
3903 * owners of this user.
3904 *
3905 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3906 * it will contain the intersection of the permitted lists for any device or profile
3907 * owners that apply to this user. It will also include any system accessibility services.
3908 *
3909 * @param userId which user to check for.
3910 * @return List of accessiblity service package names.
3911 * @hide
3912 */
3913 @SystemApi
3914 public List<String> getPermittedAccessibilityServices(int userId) {
3915 if (mService != null) {
3916 try {
3917 return mService.getPermittedAccessibilityServicesForUser(userId);
3918 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003919 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003920 }
3921 }
3922 return null;
3923 }
3924
3925 /**
3926 * Called by a profile or device owner to set the permitted input methods services. When
3927 * set by a device owner or profile owner the restriction applies to all profiles of the
3928 * user the device owner or profile owner is an admin for.
3929 *
3930 * By default the user can use any input method. When zero or more packages have
3931 * been added, input method that are not in the list and not part of the system
3932 * can not be enabled by the user.
3933 *
3934 * This method will fail if it is called for a admin that is not for the foreground user
3935 * or a profile of the foreground user.
3936 *
3937 * <p> Calling with a null value for the list disables the restriction so that all input methods
3938 * can be used, calling with an empty list disables all but the system's own input methods.
3939 *
3940 * <p> System input methods are always available to the user this method can't modify this.
3941 *
3942 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3943 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003944 * @return true if setting the restriction succeeded. It will fail if there are
3945 * one or more non-system input methods currently enabled that are not in
3946 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003947 */
Robin Lee25e26452015-06-02 09:56:29 -07003948 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003949 if (mService != null) {
3950 try {
3951 return mService.setPermittedInputMethods(admin, packageNames);
3952 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003953 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003954 }
3955 }
3956 return false;
3957 }
3958
3959
3960 /**
3961 * Returns the list of permitted input methods set by this device or profile owner.
3962 *
3963 * <p>An empty list means no input methods except system input methods are allowed.
3964 * Null means all input methods are allowed.
3965 *
3966 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3967 * @return List of input method package names.
3968 */
Robin Lee25e26452015-06-02 09:56:29 -07003969 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003970 if (mService != null) {
3971 try {
3972 return mService.getPermittedInputMethods(admin);
3973 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003974 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003975 }
3976 }
3977 return null;
3978 }
3979
3980 /**
3981 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08003982 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003983 *
3984 * <p>Null means all input methods are allowed, if a non-null list is returned
3985 * it will contain the intersection of the permitted lists for any device or profile
3986 * owners that apply to this user. It will also include any system input methods.
3987 *
3988 * @return List of input method package names.
3989 * @hide
3990 */
3991 @SystemApi
3992 public List<String> getPermittedInputMethodsForCurrentUser() {
3993 if (mService != null) {
3994 try {
3995 return mService.getPermittedInputMethodsForCurrentUser();
3996 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003997 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003998 }
3999 }
4000 return null;
4001 }
4002
4003 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004004 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4005 * currently installed it.
4006 *
4007 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4008 *
4009 * @return List of package names to keep cached.
4010 * @hide
4011 */
4012 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4013 if (mService != null) {
4014 try {
4015 return mService.getKeepUninstalledPackages(admin);
4016 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004017 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004018 }
4019 }
4020 return null;
4021 }
4022
4023 /**
4024 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4025 * currently installed it.
4026 *
4027 * <p>Please note that setting this policy does not imply that specified apps will be
4028 * automatically pre-cached.</p>
4029 *
4030 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4031 * @param packageNames List of package names to keep cached.
4032 * @hide
4033 */
4034 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4035 @NonNull List<String> packageNames) {
4036 if (mService != null) {
4037 try {
4038 mService.setKeepUninstalledPackages(admin, packageNames);
4039 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004040 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004041 }
4042 }
4043 }
4044
4045 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004046 * Called by a device owner to create a user with the specified name. The UserHandle returned
4047 * by this method should not be persisted as user handles are recycled as users are removed and
4048 * created. If you need to persist an identifier for this user, use
4049 * {@link UserManager#getSerialNumberForUser}.
4050 *
4051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4052 * @param name the user's name
4053 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004054 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4055 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004056 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004057 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04004058 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004059 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004060 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004061 try {
4062 return mService.createUser(admin, name);
4063 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004064 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004065 }
4066 return null;
4067 }
4068
4069 /**
Jason Monk03978a42014-06-10 15:05:30 -04004070 * Called by a device owner to create a user with the specified name. The UserHandle returned
4071 * by this method should not be persisted as user handles are recycled as users are removed and
4072 * created. If you need to persist an identifier for this user, use
4073 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4074 * immediately.
4075 *
4076 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4077 * as registered as an active admin on the new user. The profile owner package will be
4078 * installed on the new user if it already is installed on the device.
4079 *
4080 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4081 * profileOwnerComponent when onEnable is called.
4082 *
4083 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4084 * @param name the user's name
4085 * @param ownerName the human readable name of the organisation associated with this DPM.
4086 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4087 * the user.
4088 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4089 * on the new user.
4090 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004091 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4092 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004093 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004094 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004095 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004096 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004097 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4098 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004099 try {
4100 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4101 adminExtras);
4102 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004103 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004104 }
4105 return null;
4106 }
4107
4108 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004109 * Called by a device owner to remove a user and all associated data. The primary user can
4110 * not be removed.
4111 *
4112 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4113 * @param userHandle the user to remove.
4114 * @return {@code true} if the user was removed, {@code false} otherwise.
4115 */
Robin Lee25e26452015-06-02 09:56:29 -07004116 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004117 try {
4118 return mService.removeUser(admin, userHandle);
4119 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004120 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004121 return false;
4122 }
4123 }
4124
4125 /**
Jason Monk582d9112014-07-09 19:57:08 -04004126 * Called by a device owner to switch the specified user to the foreground.
4127 *
4128 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4129 * @param userHandle the user to switch to; null will switch to primary.
4130 * @return {@code true} if the switch was successful, {@code false} otherwise.
4131 *
4132 * @see Intent#ACTION_USER_FOREGROUND
4133 */
Robin Lee25e26452015-06-02 09:56:29 -07004134 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004135 try {
4136 return mService.switchUser(admin, userHandle);
4137 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004138 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004139 return false;
4140 }
4141 }
4142
4143 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004144 * Retrieves the application restrictions for a given target application running in the calling
4145 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004146 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004147 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4148 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4149 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004150 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004151 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4152 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004153 * @param packageName The name of the package to fetch restricted settings of.
4154 * @return {@link Bundle} of settings corresponding to what was set last time
4155 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4156 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004157 *
4158 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004159 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004160 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004161 if (mService != null) {
4162 try {
4163 return mService.getApplicationRestrictions(admin, packageName);
4164 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004165 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004166 }
4167 }
4168 return null;
4169 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004170
4171 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004172 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004173 * <p>
4174 * The calling device admin must be a profile or device owner; if it is not,
4175 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004176 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004177 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4178 * with.
4179 * @param key The key of the restriction. See the constants in
4180 * {@link android.os.UserManager} for the list of keys.
4181 */
Robin Lee25e26452015-06-02 09:56:29 -07004182 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004183 if (mService != null) {
4184 try {
4185 mService.setUserRestriction(admin, key, true);
4186 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004187 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004188 }
4189 }
4190 }
4191
4192 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004193 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004194 * <p>
4195 * The calling device admin must be a profile or device owner; if it is not,
4196 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004197 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004198 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4199 * with.
4200 * @param key The key of the restriction. See the constants in
4201 * {@link android.os.UserManager} for the list of keys.
4202 */
Robin Lee25e26452015-06-02 09:56:29 -07004203 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004204 if (mService != null) {
4205 try {
4206 mService.setUserRestriction(admin, key, false);
4207 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004208 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004209 }
4210 }
4211 }
Adam Connors010cfd42014-04-16 12:48:13 +01004212
4213 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004214 * Called by a profile or device owner to get user restrictions set with
4215 * {@link #addUserRestriction(ComponentName, String)}.
4216 * <p>
4217 * The target user may have more restrictions set by the system or other device owner / profile
4218 * owner. To get all the user restrictions currently set, use
4219 * {@link UserManager#getUserRestrictions()}.
4220 *
4221 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004222 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004223 */
4224 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004225 return getUserRestrictions(admin, myUserId());
4226 }
4227
4228 /** @hide per-user version */
4229 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004230 Bundle ret = null;
4231 if (mService != null) {
4232 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004233 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004234 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004235 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004236 }
4237 }
4238 return ret == null ? new Bundle() : ret;
4239 }
4240
4241 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004242 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004243 * is unavailable for use, but the data and actual package file remain.
4244 *
4245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004246 * @param packageName The name of the package to hide or unhide.
4247 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4248 * unhidden.
4249 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004250 */
Robin Lee25e26452015-06-02 09:56:29 -07004251 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004252 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004253 if (mService != null) {
4254 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004255 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004256 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004257 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004258 }
4259 }
4260 return false;
4261 }
4262
4263 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004264 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004265 *
4266 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004267 * @param packageName The name of the package to retrieve the hidden status of.
4268 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004269 */
Robin Lee25e26452015-06-02 09:56:29 -07004270 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004271 if (mService != null) {
4272 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004273 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004274 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004275 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004276 }
4277 }
4278 return false;
4279 }
4280
4281 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004282 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004283 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004284 *
4285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004286 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004287 */
Robin Lee25e26452015-06-02 09:56:29 -07004288 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004289 if (mService != null) {
4290 try {
4291 mService.enableSystemApp(admin, packageName);
4292 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004293 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004294 }
4295 }
4296 }
4297
4298 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004299 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004300 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004301 *
4302 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4303 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004304 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004305 * @return int The number of activities that matched the intent and were installed.
4306 */
Robin Lee25e26452015-06-02 09:56:29 -07004307 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004308 if (mService != null) {
4309 try {
4310 return mService.enableSystemAppWithIntent(admin, intent);
4311 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004312 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004313 }
4314 }
4315 return 0;
4316 }
4317
4318 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004319 * Called by a device owner or profile owner to disable account management for a specific type
4320 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004321 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004322 * <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 +01004323 * security exception will be thrown.
4324 *
4325 * <p>When account management is disabled for an account type, adding or removing an account
4326 * of that type will not be possible.
4327 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004328 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4329 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4330 * management for a specific type is disabled.
4331 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004332 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4333 * @param accountType For which account management is disabled or enabled.
4334 * @param disabled The boolean indicating that account management will be disabled (true) or
4335 * enabled (false).
4336 */
Robin Lee25e26452015-06-02 09:56:29 -07004337 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004338 boolean disabled) {
4339 if (mService != null) {
4340 try {
4341 mService.setAccountManagementDisabled(admin, accountType, disabled);
4342 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004343 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004344 }
4345 }
4346 }
4347
4348 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004349 * Gets the array of accounts for which account management is disabled by the profile owner.
4350 *
4351 * <p> Account management can be disabled/enabled by calling
4352 * {@link #setAccountManagementDisabled}.
4353 *
4354 * @return a list of account types for which account management has been disabled.
4355 *
4356 * @see #setAccountManagementDisabled
4357 */
4358 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004359 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004360 }
4361
4362 /**
4363 * @see #getAccountTypesWithManagementDisabled()
4364 * @hide
4365 */
4366 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004367 if (mService != null) {
4368 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004369 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004370 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004371 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004372 }
4373 }
4374
4375 return null;
4376 }
justinzhang511e0d82014-03-24 16:09:24 -04004377
4378 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004379 * Sets which packages may enter lock task mode.
4380 *
4381 * <p>Any packages that shares uid with an allowed package will also be allowed
4382 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004383 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004384 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004385 * package list results in locked tasks belonging to those packages to be finished.
4386 *
Jason Monkc5185f22014-06-24 11:12:42 -04004387 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004388 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004389 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004390 *
4391 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004392 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4393 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004394 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004395 */
Robin Lee25e26452015-06-02 09:56:29 -07004396 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004397 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004398 if (mService != null) {
4399 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004400 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004401 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004402 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004403 }
4404 }
4405 }
4406
4407 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004408 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004409 *
4410 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004411 * @hide
4412 */
Robin Lee25e26452015-06-02 09:56:29 -07004413 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004414 if (mService != null) {
4415 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004416 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004417 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004418 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004419 }
4420 }
4421 return null;
4422 }
4423
4424 /**
4425 * This function lets the caller know whether the given component is allowed to start the
4426 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004427 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004428 */
Jason Monkd7b86212014-06-16 13:15:38 -04004429 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004430 if (mService != null) {
4431 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004432 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004433 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004434 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004435 }
4436 }
4437 return false;
4438 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004439
4440 /**
4441 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4442 * 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 -04004443 * <p>The settings that can be updated with this method are:
4444 * <ul>
4445 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4446 * <li>{@link Settings.Global#AUTO_TIME}</li>
4447 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004448 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004449 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004450 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004451 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004452 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004453 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004454 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004455 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004456 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004457 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004458 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004459 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004460 * <ul>
4461 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4462 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4463 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4464 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4465 * <li>{@link Settings.Global#MODE_RINGER}.
4466 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4467 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4468 * <li>{@link Settings.Global#WIFI_ON}.
4469 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4470 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004471 *
4472 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4473 * @param setting The name of the setting to update.
4474 * @param value The value to update the setting to.
4475 */
Robin Lee25e26452015-06-02 09:56:29 -07004476 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004477 if (mService != null) {
4478 try {
4479 mService.setGlobalSetting(admin, setting, value);
4480 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004481 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004482 }
4483 }
4484 }
4485
4486 /**
4487 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4488 * that the value of the setting is in the correct form for the setting type should be performed
4489 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004490 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004491 * <ul>
4492 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004493 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004494 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4495 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004496 * <p>A device owner can additionally update the following settings:
4497 * <ul>
4498 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4499 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4501 * @param setting The name of the setting to update.
4502 * @param value The value to update the setting to.
4503 */
Robin Lee25e26452015-06-02 09:56:29 -07004504 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004505 if (mService != null) {
4506 try {
4507 mService.setSecureSetting(admin, setting, value);
4508 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004509 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004510 }
4511 }
4512 }
4513
Amith Yamasanif20d6402014-05-24 15:34:37 -07004514 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004515 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004516 * making permission requests of a local or remote administrator of the user.
4517 * <p/>
4518 * Only a profile owner can designate the restrictions provider.
4519 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004520 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004521 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004522 * it removes the restrictions provider previously assigned.
4523 */
Robin Lee25e26452015-06-02 09:56:29 -07004524 public void setRestrictionsProvider(@NonNull ComponentName admin,
4525 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004526 if (mService != null) {
4527 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004528 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004529 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004530 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004531 }
4532 }
4533 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004534
4535 /**
4536 * Called by profile or device owners to set the master volume mute on or off.
4537 *
4538 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4539 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4540 */
Robin Lee25e26452015-06-02 09:56:29 -07004541 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004542 if (mService != null) {
4543 try {
4544 mService.setMasterVolumeMuted(admin, on);
4545 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004546 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004547 }
4548 }
4549 }
4550
4551 /**
4552 * Called by profile or device owners to check whether the master volume mute is on or off.
4553 *
4554 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4555 * @return {@code true} if master volume is muted, {@code false} if it's not.
4556 */
Robin Lee25e26452015-06-02 09:56:29 -07004557 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004558 if (mService != null) {
4559 try {
4560 return mService.isMasterVolumeMuted(admin);
4561 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004562 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004563 }
4564 }
4565 return false;
4566 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004567
4568 /**
4569 * Called by profile or device owners to change whether a user can uninstall
4570 * a package.
4571 *
4572 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4573 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004574 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004575 */
Robin Lee25e26452015-06-02 09:56:29 -07004576 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004577 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004578 if (mService != null) {
4579 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004580 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004581 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004582 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004583 }
4584 }
4585 }
4586
4587 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004588 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004589 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004590 * <p>
4591 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004592 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004593 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004594 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004595 *
Robin Lee25e26452015-06-02 09:56:29 -07004596 * @param admin The name of the admin component whose blocking policy will be checked, or
4597 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004598 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004599 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004600 */
Robin Lee25e26452015-06-02 09:56:29 -07004601 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004602 if (mService != null) {
4603 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004604 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004605 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004606 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004607 }
4608 }
4609 return false;
4610 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004611
4612 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004613 * Called by the profile owner of a managed profile to enable widget providers from a
4614 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004615 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004616 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004617 * a package may have zero or more provider components, where each component
4618 * provides a different widget type.
4619 * <p>
4620 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004621 *
4622 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4623 * @param packageName The package from which widget providers are white-listed.
4624 * @return Whether the package was added.
4625 *
4626 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4627 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4628 */
Robin Lee25e26452015-06-02 09:56:29 -07004629 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004630 if (mService != null) {
4631 try {
4632 return mService.addCrossProfileWidgetProvider(admin, packageName);
4633 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004634 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004635 }
4636 }
4637 return false;
4638 }
4639
4640 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004641 * Called by the profile owner of a managed profile to disable widget providers from a given
4642 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004643 * package should have been added via {@link #addCrossProfileWidgetProvider(
4644 * android.content.ComponentName, String)}.
4645 * <p>
4646 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004647 *
4648 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4649 * @param packageName The package from which widget providers are no longer
4650 * white-listed.
4651 * @return Whether the package was removed.
4652 *
4653 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4654 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4655 */
Robin Lee25e26452015-06-02 09:56:29 -07004656 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004657 if (mService != null) {
4658 try {
4659 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4660 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004661 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004662 }
4663 }
4664 return false;
4665 }
4666
4667 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004668 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004669 * available in the parent profile.
4670 *
4671 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4672 * @return The white-listed package list.
4673 *
4674 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4675 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4676 */
Robin Lee25e26452015-06-02 09:56:29 -07004677 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004678 if (mService != null) {
4679 try {
4680 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4681 if (providers != null) {
4682 return providers;
4683 }
4684 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004685 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004686 }
4687 }
4688 return Collections.emptyList();
4689 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004690
4691 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004692 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004693 *
4694 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4695 * @param icon the bitmap to set as the photo.
4696 */
Robin Lee25e26452015-06-02 09:56:29 -07004697 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004698 try {
4699 mService.setUserIcon(admin, icon);
4700 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004701 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004702 }
4703 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004704
4705 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004706 * Called by device owners to set a local system update policy. When a new policy is set,
4707 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004708 *
Robin Lee25e26452015-06-02 09:56:29 -07004709 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4710 * components in the device owner package can set system update policies and the
4711 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004712 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004713 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004714 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004715 */
Robin Lee25e26452015-06-02 09:56:29 -07004716 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004717 if (mService != null) {
4718 try {
Robin Lee25e26452015-06-02 09:56:29 -07004719 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004720 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004721 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004722 }
4723 }
4724 }
4725
4726 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004727 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004728 *
Robin Lee25e26452015-06-02 09:56:29 -07004729 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004730 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004731 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004732 if (mService != null) {
4733 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004734 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004735 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004736 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004737 }
4738 }
4739 return null;
4740 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004741
4742 /**
4743 * Called by a device owner to disable the keyguard altogether.
4744 *
4745 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4746 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4747 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4748 * being disabled.
4749 *
4750 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004751 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004752 *
4753 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004754 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004755 */
Robin Lee25e26452015-06-02 09:56:29 -07004756 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004757 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004758 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004759 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004760 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01004761 return false;
4762 }
4763 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004764
4765 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004766 * Called by device owner to disable the status bar. Disabling the status bar blocks
4767 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004768 * a single use device.
4769 *
4770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004771 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4772 *
4773 * @return {@code false} if attempting to disable the status bar failed.
4774 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004775 */
Robin Lee25e26452015-06-02 09:56:29 -07004776 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004777 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004778 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004779 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004780 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004781 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004782 }
4783 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004784
4785 /**
4786 * Callable by the system update service to notify device owners about pending updates.
4787 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4788 * permission.
4789 *
4790 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4791 * when the current pending update was first available. -1 if no update is available.
4792 * @hide
4793 */
4794 @SystemApi
4795 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4796 if (mService != null) {
4797 try {
4798 mService.notifyPendingSystemUpdate(updateReceivedTime);
4799 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004800 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01004801 }
4802 }
4803 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004804
4805 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004806 * Called by profile or device owners to set the default response for future runtime permission
4807 * requests by applications. The policy can allow for normal operation which prompts the
4808 * user to grant a permission, or can allow automatic granting or denying of runtime
4809 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004810 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4811 * the permission grant state via {@link #setPermissionGrantState}.
4812 *
4813 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004814 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004815 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004816 * @param admin Which profile or device owner this request is associated with.
4817 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4818 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004819 *
4820 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004821 */
Robin Lee25e26452015-06-02 09:56:29 -07004822 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004823 try {
4824 mService.setPermissionPolicy(admin, policy);
4825 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004826 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004827 }
4828 }
4829
4830 /**
4831 * Returns the current runtime permission policy set by the device or profile owner. The
4832 * default is {@link #PERMISSION_POLICY_PROMPT}.
4833 * @param admin Which profile or device owner this request is associated with.
4834 * @return the current policy for future permission requests.
4835 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004836 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004837 try {
4838 return mService.getPermissionPolicy(admin);
4839 } catch (RemoteException re) {
4840 return PERMISSION_POLICY_PROMPT;
4841 }
4842 }
4843
4844 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004845 * Sets the grant state of a runtime permission for a specific application. The state
4846 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4847 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4848 * is denied and the user cannot manage it through the UI, and {@link
4849 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4850 * user cannot manage it through the UI. This might affect all permissions in a
4851 * group that the runtime permission belongs to. This method can only be called
4852 * by a profile or device owner.
4853 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004854 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4855 * revoke the permission. It retains the previous grant, if any.
4856 *
4857 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004858 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004859 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004860 * @param admin Which profile or device owner this request is associated with.
4861 * @param packageName The application to grant or revoke a permission to.
4862 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004863 * @param grantState The permission grant state which is one of {@link
4864 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4865 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4866 * @return whether the permission was successfully granted or revoked.
4867 *
4868 * @see #PERMISSION_GRANT_STATE_DENIED
4869 * @see #PERMISSION_GRANT_STATE_DEFAULT
4870 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004871 */
Robin Lee25e26452015-06-02 09:56:29 -07004872 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004873 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004874 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004875 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004876 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004877 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004878 return false;
4879 }
4880 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004881
4882 /**
4883 * Returns the current grant state of a runtime permission for a specific application.
4884 *
4885 * @param admin Which profile or device owner this request is associated with.
4886 * @param packageName The application to check the grant state for.
4887 * @param permission The permission to check for.
4888 * @return the current grant state specified by device policy. If the profile or device owner
4889 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4890 * This does not indicate whether or not the permission is currently granted for the package.
4891 *
4892 * <p/>If a grant state was set by the profile or device owner, then the return value will
4893 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4894 * which indicates if the permission is currently denied or granted.
4895 *
4896 * @see #setPermissionGrantState(ComponentName, String, String, int)
4897 * @see PackageManager#checkPermission(String, String)
4898 */
Robin Lee25e26452015-06-02 09:56:29 -07004899 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004900 String permission) {
4901 try {
4902 return mService.getPermissionGrantState(admin, packageName, permission);
4903 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004904 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07004905 return PERMISSION_GRANT_STATE_DEFAULT;
4906 }
4907 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004908
4909 /**
4910 * Returns if provisioning a managed profile or device is possible or not.
4911 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4912 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4913 * Note that even if this method returns true, there is a slight possibility that the
4914 * provisioning will not be allowed when it is actually initiated because some event has
4915 * happened in between.
4916 * @return if provisioning a managed profile or device is possible or not.
4917 * @throws IllegalArgumentException if the supplied action is not valid.
4918 */
4919 public boolean isProvisioningAllowed(String action) {
4920 try {
4921 return mService.isProvisioningAllowed(action);
4922 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004923 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004924 return false;
4925 }
4926 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004927
4928 /**
4929 * @hide
4930 * Return if this user is a managed profile of another user. An admin can become the profile
4931 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
4932 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
4933 * @param admin Which profile owner this request is associated with.
4934 * @return if this user is a managed profile of another user.
4935 */
4936 public boolean isManagedProfile(@NonNull ComponentName admin) {
4937 try {
4938 return mService.isManagedProfile(admin);
4939 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004940 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004941 return false;
4942 }
4943 }
4944
4945 /**
4946 * @hide
4947 * Return if this user is a system-only user. An admin can manage a device from a system only
4948 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
4949 * @param admin Which device owner this request is associated with.
4950 * @return if this user is a system-only user.
4951 */
4952 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
4953 try {
4954 return mService.isSystemOnlyUser(admin);
4955 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004956 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004957 return false;
4958 }
4959 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004960
4961 /**
4962 * Called by device owner to get the MAC address of the Wi-Fi device.
4963 *
4964 * @return the MAC address of the Wi-Fi device, or null when the information is not
4965 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
4966 *
4967 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
4968 */
4969 public String getWifiMacAddress() {
4970 try {
4971 return mService.getWifiMacAddress();
4972 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004973 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004974 return null;
4975 }
4976 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00004977
4978 /**
4979 * Called by device owner to reboot the device.
4980 */
4981 public void reboot(@NonNull ComponentName admin) {
4982 try {
4983 mService.reboot(admin);
4984 } catch (RemoteException re) {
4985 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4986 }
4987 }
Kenny Guy06de4e72015-12-22 12:07:39 +00004988
4989 /**
4990 * Called by a device admin to set the short support message. This will
4991 * be displayed to the user in settings screens where funtionality has
4992 * been disabled by the admin.
4993 *
4994 * The message should be limited to a short statement such as
4995 * "This setting is disabled by your administrator. Contact someone@example.com
4996 * for support."
4997 * If the message is longer than 200 characters it may be truncated.
4998 *
4999 * @see #setLongSupportMessage
5000 *
5001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5002 * @param message Short message to be displayed to the user in settings or null to
5003 * clear the existing message.
5004 */
5005 public void setShortSupportMessage(@NonNull ComponentName admin,
5006 @Nullable String message) {
5007 if (mService != null) {
5008 try {
5009 mService.setShortSupportMessage(admin, message);
5010 } catch (RemoteException e) {
5011 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5012 }
5013 }
5014 }
5015
5016 /**
5017 * Called by a device admin to get the short support message.
5018 *
5019 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5020 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5021 * or null if no message has been set.
5022 */
5023 public String getShortSupportMessage(@NonNull ComponentName admin) {
5024 if (mService != null) {
5025 try {
5026 return mService.getShortSupportMessage(admin);
5027 } catch (RemoteException e) {
5028 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5029 }
5030 }
5031 return null;
5032 }
5033
5034 /**
5035 * Called by a device admin to set the long support message. This will
5036 * be displayed to the user in the device administators settings screen.
5037 *
5038 * @see #setShortSupportMessage
5039 *
5040 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5041 * @param message Long message to be displayed to the user in settings or null to
5042 * clear the existing message.
5043 */
5044 public void setLongSupportMessage(@NonNull ComponentName admin,
5045 @Nullable String message) {
5046 if (mService != null) {
5047 try {
5048 mService.setLongSupportMessage(admin, message);
5049 } catch (RemoteException e) {
5050 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5051 }
5052 }
5053 }
5054
5055 /**
5056 * Called by a device admin to get the long support message.
5057 *
5058 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5059 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5060 * or null if no message has been set.
5061 */
5062 public String getLongSupportMessage(@NonNull ComponentName admin) {
5063 if (mService != null) {
5064 try {
5065 return mService.getLongSupportMessage(admin);
5066 } catch (RemoteException e) {
5067 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5068 }
5069 }
5070 return null;
5071 }
5072
5073 /**
5074 * Called by the system to get the short support message.
5075 *
5076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5077 * @param userHandle user id the admin is running as.
5078 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5079 *
5080 * @hide
5081 */
5082 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5083 if (mService != null) {
5084 try {
5085 return mService.getShortSupportMessageForUser(admin, userHandle);
5086 } catch (RemoteException e) {
5087 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5088 }
5089 }
5090 return null;
5091 }
5092
5093
5094 /**
5095 * Called by the system to get the long support message.
5096 *
5097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5098 * @param userHandle user id the admin is running as.
5099 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5100 *
5101 * @hide
5102 */
5103 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5104 if (mService != null) {
5105 try {
5106 return mService.getLongSupportMessageForUser(admin, userHandle);
5107 } catch (RemoteException e) {
5108 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5109 }
5110 }
5111 return null;
5112 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005113
5114 /**
5115 * Obtains a {@link DevicePolicyManager} whose calls act on the parent profile.
5116 *
5117 * <p> Note only some methods will work on the parent Manager.
5118 *
5119 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5120 */
5121 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5122 try {
5123 if (!mService.isManagedProfile(admin)) {
5124 throw new SecurityException("The current user does not have a parent profile.");
5125 }
5126 return new DevicePolicyManager(mContext, true);
5127 } catch (RemoteException re) {
5128 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5129 return null;
5130 }
5131 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005132
5133 /**
5134 * Called by a profile owner of a managed profile to set the color used for customization.
5135 * This color is used as background color of the confirm credentials screen for that user.
5136 * The default color is {@link android.graphics.Color#GRAY}.
5137 *
5138 * <p>The confirm credentials screen can be created using
5139 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5140 *
5141 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5142 * @param color The 32bit representation of the color to be used.
5143 */
5144 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5145 try {
5146 mService.setOrganizationColor(admin, color);
5147 } catch (RemoteException re) {
5148 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5149 }
5150 }
5151
5152 /**
5153 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5154 * This color is used as background color of the confirm credentials screen for that user.
5155 *
5156 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5157 * @return The 32bit representation of the color to be used.
5158 */
5159 public int getOrganizationColor(@NonNull ComponentName admin) {
5160 try {
5161 return mService.getOrganizationColor(admin);
5162 } catch (RemoteException re) {
5163 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5164 return 0;
5165 }
5166 }
5167
5168 /**
5169 * @hide
5170 * Retrieve the customization color for a given user.
5171 *
5172 * @param userHandle The user id of the user we're interested in.
5173 * @return The 32bit representation of the color to be used.
5174 */
5175 public int getOrganizationColorForUser(int userHandle) {
5176 try {
5177 return mService.getOrganizationColorForUser(userHandle);
5178 } catch (RemoteException re) {
5179 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5180 return 0;
5181 }
5182 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005183}