blob: bd0635de3927284548b2acd900e2415ca8e2c72b [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 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400623 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100624 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400625 * <p>During device owner provisioning a device admin app is set as the owner of the device.
626 * A device owner has full control over the device. The device owner can not be modified by the
627 * user and the only way of resetting the device is if the device owner app calls a factory
628 * reset.
629 *
630 * <p> A typical use case would be a device that is owned by a company, but used by either an
631 * employee or client.
632 *
633 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100634 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000635 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100636 * contains the following properties:
637 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400638 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
639 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100640 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400641 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100642 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
643 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
644 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
645 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
646 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
647 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
648 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
649 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
650 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
651 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100652 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
653 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
654 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100655 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000656 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700657 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400658 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
659 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
660 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400661 */
662 public static final String MIME_TYPE_PROVISIONING_NFC
663 = "application/com.android.managedprovisioning";
664
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100665 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800666 * Activity action: ask the user to add a new device administrator to the system.
667 * The desired policy is the ComponentName of the policy in the
668 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
669 * bring the user through adding the device administrator to the system (or
670 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700671 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800672 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
673 * field to provide the user with additional explanation (in addition
674 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800675 *
676 * <p>If your administrator is already active, this will ordinarily return immediately (without
677 * user intervention). However, if your administrator has been updated and is requesting
678 * additional uses-policy flags, the user will be presented with the new list. New policies
679 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800680 */
681 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
682 public static final String ACTION_ADD_DEVICE_ADMIN
683 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700684
Dianne Hackbornd6847842010-01-12 18:14:19 -0800685 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700686 * @hide
687 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700688 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700689 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700690 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
691 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700692 * to remotely control restrictions on the user.
693 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800694 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700695 * result of whether or not the user approved the action. If approved, the result will
696 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
697 * as a profile owner.
698 *
699 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
700 * field to provide the user with additional explanation (in addition
701 * to your component's description) about what is being added.
702 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700703 * <p>If there is already a profile owner active or the caller is not a system app, the
704 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700705 */
706 @SystemApi
707 public static final String ACTION_SET_PROFILE_OWNER
708 = "android.app.action.SET_PROFILE_OWNER";
709
710 /**
711 * @hide
712 * Name of the profile owner admin that controls the user.
713 */
714 @SystemApi
715 public static final String EXTRA_PROFILE_OWNER_NAME
716 = "android.app.extra.PROFILE_OWNER_NAME";
717
718 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100719 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700720 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700721 *
Jim Miller284b62e2010-06-08 14:27:42 -0700722 * @hide
723 */
724 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
725 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
726
727 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100728 * Broadcast action: sent when the device owner is set or changed.
729 *
730 * This broadcast is sent only to the primary user.
731 * @see #ACTION_PROVISION_MANAGED_DEVICE
732 */
733 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
734 public static final String ACTION_DEVICE_OWNER_CHANGED
735 = "android.app.action.DEVICE_OWNER_CHANGED";
736
737 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800738 * The ComponentName of the administrator component.
739 *
740 * @see #ACTION_ADD_DEVICE_ADMIN
741 */
742 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700743
Dianne Hackbornd6847842010-01-12 18:14:19 -0800744 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800745 * An optional CharSequence providing additional explanation for why the
746 * admin is being added.
747 *
748 * @see #ACTION_ADD_DEVICE_ADMIN
749 */
750 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700751
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800752 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700753 * Activity action: have the user enter a new password. This activity should
754 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
755 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
756 * enter a new password that meets the current requirements. You can use
757 * {@link #isActivePasswordSufficient()} to determine whether you need to
758 * have the user select a new password in order to meet the current
759 * constraints. Upon being resumed from this activity, you can check the new
760 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800761 */
762 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
763 public static final String ACTION_SET_NEW_PASSWORD
764 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700765
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000766 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000767 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
768 * the parent profile to access intents sent from the managed profile.
769 * That is, when an app in the managed profile calls
770 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
771 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000772 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100773 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000774
775 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000776 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
777 * the managed profile to access intents sent from the parent profile.
778 * That is, when an app in the parent profile calls
779 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
780 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000781 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100782 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700783
Dianne Hackbornd6847842010-01-12 18:14:19 -0800784 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100785 * Broadcast action: notify that a new local system update policy has been set by the device
786 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000787 */
788 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100789 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
790 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000791
Amith Yamasanid49489b2015-04-28 14:00:26 -0700792 /**
793 * Permission policy to prompt user for new permission requests for runtime permissions.
794 * Already granted or denied permissions are not affected by this.
795 */
796 public static final int PERMISSION_POLICY_PROMPT = 0;
797
798 /**
799 * Permission policy to always grant new permission requests for runtime permissions.
800 * Already granted or denied permissions are not affected by this.
801 */
802 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
803
804 /**
805 * Permission policy to always deny new permission requests for runtime permissions.
806 * Already granted or denied permissions are not affected by this.
807 */
808 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
809
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700810 /**
811 * Runtime permission state: The user can manage the permission
812 * through the UI.
813 */
814 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
815
816 /**
817 * Runtime permission state: The permission is granted to the app
818 * and the user cannot manage the permission through the UI.
819 */
820 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
821
822 /**
823 * Runtime permission state: The permission is denied to the app
824 * and the user cannot manage the permission through the UI.
825 */
826 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000827
828 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800829 * Return true if the given administrator component is currently
830 * active (enabled) in the system.
831 */
Robin Lee25e26452015-06-02 09:56:29 -0700832 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700833 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100834 }
835
836 /**
837 * @see #isAdminActive(ComponentName)
838 * @hide
839 */
Robin Lee25e26452015-06-02 09:56:29 -0700840 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800841 if (mService != null) {
842 try {
Robin Lee25e26452015-06-02 09:56:29 -0700843 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800844 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800845 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800846 }
847 }
848 return false;
849 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800850 /**
851 * Return true if the given administrator component is currently being removed
852 * for the user.
853 * @hide
854 */
Robin Lee25e26452015-06-02 09:56:29 -0700855 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800856 if (mService != null) {
857 try {
Robin Lee25e26452015-06-02 09:56:29 -0700858 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800859 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800860 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800861 }
862 }
863 return false;
864 }
865
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700866
Dianne Hackbornd6847842010-01-12 18:14:19 -0800867 /**
Robin Lee25e26452015-06-02 09:56:29 -0700868 * Return a list of all currently active device administrators' component
869 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800870 * returned.
871 */
872 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700873 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100874 }
875
876 /**
877 * @see #getActiveAdmins()
878 * @hide
879 */
880 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800881 if (mService != null) {
882 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100883 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800884 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800885 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800886 }
887 }
888 return null;
889 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700890
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800891 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700892 * Used by package administration code to determine if a package can be stopped
893 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800894 * @hide
895 */
896 public boolean packageHasActiveAdmins(String packageName) {
897 if (mService != null) {
898 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700899 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800900 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800901 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800902 }
903 }
904 return false;
905 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700906
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800907 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800908 * Remove a current administration component. This can only be called
909 * by the application that owns the administration component; if you
910 * try to remove someone else's component, a security exception will be
911 * thrown.
912 */
Robin Lee25e26452015-06-02 09:56:29 -0700913 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800914 if (mService != null) {
915 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700916 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800917 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800918 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800919 }
920 }
921 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700922
Dianne Hackbornd6847842010-01-12 18:14:19 -0800923 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800924 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700925 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800926 * but requires additional policies after an upgrade.
927 *
928 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
929 * an active administrator, or an exception will be thrown.
930 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
931 */
Robin Lee25e26452015-06-02 09:56:29 -0700932 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800933 if (mService != null) {
934 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700935 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800936 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800937 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800938 }
939 }
940 return false;
941 }
942
943 /**
Clara Bayarria1771112015-12-18 16:29:18 +0000944 * Returns true if the Profile Challenge is available to use for the given profile user.
945 *
946 * @hide
947 */
948 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
949 if (mService != null) {
950 try {
951 return mService.isSeparateProfileChallengeAllowed(userHandle);
952 } catch (RemoteException e) {
953 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
954 }
955 }
956 return false;
957 }
958
959 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800960 * Constant for {@link #setPasswordQuality}: the policy has no requirements
961 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800962 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800963 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800964 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700965
Dianne Hackbornd6847842010-01-12 18:14:19 -0800966 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700967 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
968 * recognition technology. This implies technologies that can recognize the identity of
969 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
970 * Note that quality constants are ordered so that higher values are more restrictive.
971 */
972 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
973
974 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800975 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100976 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800977 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800978 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800979 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700980
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800981 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800982 * Constant for {@link #setPasswordQuality}: the user must have entered a
983 * password containing at least numeric characters. Note that quality
984 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800985 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800986 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700987
Dianne Hackbornd6847842010-01-12 18:14:19 -0800988 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800989 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800990 * password containing at least numeric characters with no repeating (4444)
991 * or ordered (1234, 4321, 2468) sequences. Note that quality
992 * constants are ordered so that higher values are more restrictive.
993 */
994 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
995
996 /**
997 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700998 * password containing at least alphabetic (or other symbol) characters.
999 * Note that quality constants are ordered so that higher values are more
1000 * restrictive.
1001 */
1002 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001003
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001004 /**
1005 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001006 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001007 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001008 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001010 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001011
Dianne Hackbornd6847842010-01-12 18:14:19 -08001012 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001013 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001014 * password containing at least a letter, a numerical digit and a special
1015 * symbol, by default. With this password quality, passwords can be
1016 * restricted to contain various sets of characters, like at least an
1017 * uppercase letter, etc. These are specified using various methods,
1018 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1019 * that quality constants are ordered so that higher values are more
1020 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001021 */
1022 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1023
1024 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001025 * Called by an application that is administering the device to set the
1026 * password restrictions it is imposing. After setting this, the user
1027 * will not be able to enter a new password that is not at least as
1028 * restrictive as what has been set. Note that the current password
1029 * will remain until the user has set a new one, so the change does not
1030 * take place immediately. To prompt the user for a new password, use
1031 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001032 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001033 * <p>Quality constants are ordered so that higher values are more restrictive;
1034 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001035 * the user's preference, and any other considerations) is the one that
1036 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001037 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001038 * <p>The calling device admin must have requested
1039 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1040 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001041 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001042 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001043 * @param quality The new desired quality. One of
1044 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001045 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1046 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1047 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 */
Robin Lee25e26452015-06-02 09:56:29 -07001049 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001050 if (mService != null) {
1051 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001052 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001053 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001054 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001055 }
1056 }
1057 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001058
Dianne Hackbornd6847842010-01-12 18:14:19 -08001059 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001060 * Retrieve the current minimum password quality for all admins of this user
1061 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001062 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001063 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001064 */
Robin Lee25e26452015-06-02 09:56:29 -07001065 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001066 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001067 }
1068
1069 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001070 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001071 if (mService != null) {
1072 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001073 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001074 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001075 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001076 }
1077 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001078 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001080
Dianne Hackbornd6847842010-01-12 18:14:19 -08001081 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001082 * Called by an application that is administering the device to set the
1083 * minimum allowed password length. After setting this, the user
1084 * will not be able to enter a new password that is not at least as
1085 * restrictive as what has been set. Note that the current password
1086 * will remain until the user has set a new one, so the change does not
1087 * take place immediately. To prompt the user for a new password, use
1088 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1089 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001090 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1091 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1092 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001093 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001094 * <p>The calling device admin must have requested
1095 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1096 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001097 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001099 * @param length The new desired minimum password length. A value of 0
1100 * means there is no restriction.
1101 */
Robin Lee25e26452015-06-02 09:56:29 -07001102 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001103 if (mService != null) {
1104 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001105 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001106 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001107 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001108 }
1109 }
1110 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001111
Dianne Hackbornd6847842010-01-12 18:14:19 -08001112 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001113 * Retrieve the current minimum password length for all admins of this
1114 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001115 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001116 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001117 */
Robin Lee25e26452015-06-02 09:56:29 -07001118 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001119 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001120 }
1121
1122 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001123 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001124 if (mService != null) {
1125 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001126 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001127 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001128 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001129 }
1130 }
1131 return 0;
1132 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001133
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001134 /**
1135 * Called by an application that is administering the device to set the
1136 * minimum number of upper case letters required in the password. After
1137 * setting this, the user will not be able to enter a new password that is
1138 * not at least as restrictive as what has been set. Note that the current
1139 * password will remain until the user has set a new one, so the change does
1140 * not take place immediately. To prompt the user for a new password, use
1141 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1142 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001143 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1144 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001145 * <p>
1146 * The calling device admin must have requested
1147 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1148 * this method; if it has not, a security exception will be thrown.
1149 *
1150 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1151 * with.
1152 * @param length The new desired minimum number of upper case letters
1153 * required in the password. A value of 0 means there is no
1154 * restriction.
1155 */
Robin Lee25e26452015-06-02 09:56:29 -07001156 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001157 if (mService != null) {
1158 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001159 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001160 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001161 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001162 }
1163 }
1164 }
1165
1166 /**
1167 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001168 * password for all admins of this user and its profiles or a particular one.
1169 * This is the same value as set by
1170 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001171 * and only applies when the password quality is
1172 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001173 *
Robin Lee25e26452015-06-02 09:56:29 -07001174 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001175 * aggregate all admins.
1176 * @return The minimum number of upper case letters required in the
1177 * password.
1178 */
Robin Lee25e26452015-06-02 09:56:29 -07001179 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001180 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001181 }
1182
1183 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001184 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001185 if (mService != null) {
1186 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001187 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001189 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001190 }
1191 }
1192 return 0;
1193 }
1194
1195 /**
1196 * Called by an application that is administering the device to set the
1197 * minimum number of lower case letters required in the password. After
1198 * setting this, the user will not be able to enter a new password that is
1199 * not at least as restrictive as what has been set. Note that the current
1200 * password will remain until the user has set a new one, so the change does
1201 * not take place immediately. To prompt the user for a new password, use
1202 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1203 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001204 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1205 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001206 * <p>
1207 * The calling device admin must have requested
1208 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1209 * this method; if it has not, a security exception will be thrown.
1210 *
1211 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1212 * with.
1213 * @param length The new desired minimum number of lower case letters
1214 * required in the password. A value of 0 means there is no
1215 * restriction.
1216 */
Robin Lee25e26452015-06-02 09:56:29 -07001217 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001218 if (mService != null) {
1219 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001220 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001221 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001222 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001223 }
1224 }
1225 }
1226
1227 /**
1228 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001229 * password for all admins of this user and its profiles or a particular one.
1230 * This is the same value as set by
1231 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001232 * and only applies when the password quality is
1233 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001234 *
Robin Lee25e26452015-06-02 09:56:29 -07001235 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001236 * aggregate all admins.
1237 * @return The minimum number of lower case letters required in the
1238 * password.
1239 */
Robin Lee25e26452015-06-02 09:56:29 -07001240 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001241 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001242 }
1243
1244 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001245 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001246 if (mService != null) {
1247 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001248 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001249 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001250 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001251 }
1252 }
1253 return 0;
1254 }
1255
1256 /**
1257 * Called by an application that is administering the device to set the
1258 * minimum number of letters required in the password. After setting this,
1259 * the user will not be able to enter a new password that is not at least as
1260 * restrictive as what has been set. Note that the current password will
1261 * remain until the user has set a new one, so the change does not take
1262 * place immediately. To prompt the user for a new password, use
1263 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1264 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001265 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1266 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001267 * <p>
1268 * The calling device admin must have requested
1269 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1270 * this method; if it has not, a security exception will be thrown.
1271 *
1272 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1273 * with.
1274 * @param length The new desired minimum number of letters required in the
1275 * password. A value of 0 means there is no restriction.
1276 */
Robin Lee25e26452015-06-02 09:56:29 -07001277 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001278 if (mService != null) {
1279 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001280 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001281 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001282 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001283 }
1284 }
1285 }
1286
1287 /**
1288 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001289 * admins or a particular one. This is the same value as
1290 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1291 * and only applies when the password quality is
1292 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001293 *
Robin Lee25e26452015-06-02 09:56:29 -07001294 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001295 * aggregate all admins.
1296 * @return The minimum number of letters required in the password.
1297 */
Robin Lee25e26452015-06-02 09:56:29 -07001298 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001299 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001300 }
1301
1302 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001303 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001304 if (mService != null) {
1305 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001306 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001307 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001308 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001309 }
1310 }
1311 return 0;
1312 }
1313
1314 /**
1315 * Called by an application that is administering the device to set the
1316 * minimum number of numerical digits required in the password. After
1317 * setting this, the user will not be able to enter a new password that is
1318 * not at least as restrictive as what has been set. Note that the current
1319 * password will remain until the user has set a new one, so the change does
1320 * not take place immediately. To prompt the user for a new password, use
1321 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1322 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001323 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1324 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001325 * <p>
1326 * The calling device admin must have requested
1327 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1328 * this method; if it has not, a security exception will be thrown.
1329 *
1330 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1331 * with.
1332 * @param length The new desired minimum number of numerical digits required
1333 * in the password. A value of 0 means there is no restriction.
1334 */
Robin Lee25e26452015-06-02 09:56:29 -07001335 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001336 if (mService != null) {
1337 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001338 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001339 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001340 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001341 }
1342 }
1343 }
1344
1345 /**
1346 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001347 * for all admins of this user and its profiles or a particular one.
1348 * This is the same value as set by
1349 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001350 * and only applies when the password quality is
1351 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001352 *
Robin Lee25e26452015-06-02 09:56:29 -07001353 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001354 * aggregate all admins.
1355 * @return The minimum number of numerical digits required in the password.
1356 */
Robin Lee25e26452015-06-02 09:56:29 -07001357 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001358 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001359 }
1360
1361 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001362 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001363 if (mService != null) {
1364 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001365 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001366 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001367 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001368 }
1369 }
1370 return 0;
1371 }
1372
1373 /**
1374 * Called by an application that is administering the device to set the
1375 * minimum number of symbols required in the password. After setting this,
1376 * the user will not be able to enter a new password that is not at least as
1377 * restrictive as what has been set. Note that the current password will
1378 * remain until the user has set a new one, so the change does not take
1379 * place immediately. To prompt the user for a new password, use
1380 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1381 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001382 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1383 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001384 * <p>
1385 * The calling device admin must have requested
1386 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1387 * this method; if it has not, a security exception will be thrown.
1388 *
1389 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1390 * with.
1391 * @param length The new desired minimum number of symbols required in the
1392 * password. A value of 0 means there is no restriction.
1393 */
Robin Lee25e26452015-06-02 09:56:29 -07001394 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001395 if (mService != null) {
1396 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001397 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001398 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001399 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001400 }
1401 }
1402 }
1403
1404 /**
1405 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001406 * admins or a particular one. This is the same value as
1407 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1408 * and only applies when the password quality is
1409 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001410 *
Robin Lee25e26452015-06-02 09:56:29 -07001411 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001412 * aggregate all admins.
1413 * @return The minimum number of symbols required in the password.
1414 */
Robin Lee25e26452015-06-02 09:56:29 -07001415 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001416 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001417 }
1418
1419 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001420 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001421 if (mService != null) {
1422 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001423 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001424 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001425 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001426 }
1427 }
1428 return 0;
1429 }
1430
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001431 /**
1432 * Called by an application that is administering the device to set the
1433 * minimum number of non-letter characters (numerical digits or symbols)
1434 * required in the password. After setting this, the user will not be able
1435 * to enter a new password that is not at least as restrictive as what has
1436 * been set. Note that the current password will remain until the user has
1437 * set a new one, so the change does not take place immediately. To prompt
1438 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1439 * setting this value. This constraint is only imposed if the administrator
1440 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1441 * {@link #setPasswordQuality}. The default value is 0.
1442 * <p>
1443 * The calling device admin must have requested
1444 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1445 * this method; if it has not, a security exception will be thrown.
1446 *
1447 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1448 * with.
1449 * @param length The new desired minimum number of letters required in the
1450 * password. A value of 0 means there is no restriction.
1451 */
Robin Lee25e26452015-06-02 09:56:29 -07001452 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001453 if (mService != null) {
1454 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001455 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001456 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001457 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001458 }
1459 }
1460 }
1461
1462 /**
1463 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001464 * password for all admins of this user and its profiles or a particular one.
1465 * This is the same value as set by
1466 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001467 * and only applies when the password quality is
1468 * {@link #PASSWORD_QUALITY_COMPLEX}.
1469 *
Robin Lee25e26452015-06-02 09:56:29 -07001470 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001471 * aggregate all admins.
1472 * @return The minimum number of letters required in the password.
1473 */
Robin Lee25e26452015-06-02 09:56:29 -07001474 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001475 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001476 }
1477
1478 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001479 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001480 if (mService != null) {
1481 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001482 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001483 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001484 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001485 }
1486 }
1487 return 0;
1488 }
1489
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001490 /**
1491 * Called by an application that is administering the device to set the length
1492 * of the password history. After setting this, the user will not be able to
1493 * enter a new password that is the same as any password in the history. Note
1494 * that the current password will remain until the user has set a new one, so
1495 * the change does not take place immediately. To prompt the user for a new
1496 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1497 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001498 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1499 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1500 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001501 *
1502 * <p>
1503 * The calling device admin must have requested
1504 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1505 * method; if it has not, a security exception will be thrown.
1506 *
1507 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1508 * with.
1509 * @param length The new desired length of password history. A value of 0
1510 * means there is no restriction.
1511 */
Robin Lee25e26452015-06-02 09:56:29 -07001512 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001513 if (mService != null) {
1514 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001515 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001516 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001517 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001518 }
1519 }
1520 }
1521
1522 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001523 * Called by a device admin to set the password expiration timeout. Calling this method
1524 * will restart the countdown for password expiration for the given admin, as will changing
1525 * the device password (for all admins).
1526 *
1527 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1528 * For example, to have the password expire 5 days from now, timeout would be
1529 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1530 *
1531 * <p>To disable password expiration, a value of 0 may be used for timeout.
1532 *
Jim Millera4e28d12010-11-08 16:15:47 -08001533 * <p>The calling device admin must have requested
1534 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1535 * method; if it has not, a security exception will be thrown.
1536 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001537 * <p> Note that setting the password will automatically reset the expiration time for all
1538 * active admins. Active admins do not need to explicitly call this method in that case.
1539 *
Jim Millera4e28d12010-11-08 16:15:47 -08001540 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1541 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1542 * means there is no restriction (unlimited).
1543 */
Robin Lee25e26452015-06-02 09:56:29 -07001544 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001545 if (mService != null) {
1546 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001547 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001548 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001549 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001550 }
1551 }
1552 }
1553
1554 /**
Jim Miller6b857682011-02-16 16:27:41 -08001555 * Get the password expiration timeout for the given admin. The expiration timeout is the
1556 * recurring expiration timeout provided in the call to
1557 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001558 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001559 *
Robin Lee25e26452015-06-02 09:56:29 -07001560 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001561 * @return The timeout for the given admin or the minimum of all timeouts
1562 */
Robin Lee25e26452015-06-02 09:56:29 -07001563 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001564 if (mService != null) {
1565 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001566 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001567 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001568 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001569 }
1570 }
1571 return 0;
1572 }
1573
1574 /**
1575 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001576 * all admins of this user and its profiles if admin is null. If the password is
1577 * expired, this will return the time since the password expired as a negative number.
1578 * If admin is null, then a composite of all expiration timeouts is returned
1579 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001580 *
Robin Lee25e26452015-06-02 09:56:29 -07001581 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001582 * @return The password expiration time, in ms.
1583 */
Robin Lee25e26452015-06-02 09:56:29 -07001584 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001585 if (mService != null) {
1586 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001587 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001588 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001589 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001590 }
1591 }
1592 return 0;
1593 }
1594
1595 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001596 * Retrieve the current password history length for all admins of this
1597 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001598 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001599 * all admins.
1600 * @return The length of the password history
1601 */
Robin Lee25e26452015-06-02 09:56:29 -07001602 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001603 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001604 }
1605
1606 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001607 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001608 if (mService != null) {
1609 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001610 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001611 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001612 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001613 }
1614 }
1615 return 0;
1616 }
1617
Dianne Hackbornd6847842010-01-12 18:14:19 -08001618 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001619 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001620 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001621 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001622 * @return Returns the maximum length that the user can enter.
1623 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001624 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001625 // Kind-of arbitrary.
1626 return 16;
1627 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001628
Dianne Hackborn254cb442010-01-27 19:23:59 -08001629 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001630 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001631 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001632 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001633 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001634 * <p>The calling device admin must have requested
1635 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1636 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001637 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001638 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001639 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001640 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001641 if (mService != null) {
1642 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001643 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001644 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001645 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001646 }
1647 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001648 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001649 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001650
Dianne Hackbornd6847842010-01-12 18:14:19 -08001651 /**
1652 * Retrieve the number of times the user has failed at entering a
1653 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001654 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001655 * <p>The calling device admin must have requested
1656 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1657 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001658 */
1659 public int getCurrentFailedPasswordAttempts() {
1660 if (mService != null) {
1661 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001662 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001663 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001664 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001665 }
1666 }
1667 return -1;
1668 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001669
1670 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001671 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001672 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001673 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001674 * @hide
1675 */
1676 public boolean getDoNotAskCredentialsOnBoot() {
1677 if (mService != null) {
1678 try {
1679 return mService.getDoNotAskCredentialsOnBoot();
1680 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001681 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001682 }
1683 }
1684 return false;
1685 }
1686
1687 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001688 * Setting this to a value greater than zero enables a built-in policy
1689 * that will perform a device wipe after too many incorrect
1690 * device-unlock passwords have been entered. This built-in policy combines
1691 * watching for failed passwords and wiping the device, and requires
1692 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001693 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001694 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001695 * <p>To implement any other policy (e.g. wiping data for a particular
1696 * application only, erasing or revoking credentials, or reporting the
1697 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001698 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001699 * instead. Do not use this API, because if the maximum count is reached,
1700 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001701 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001703 * @param num The number of failed password attempts at which point the
1704 * device will wipe its data.
1705 */
Robin Lee25e26452015-06-02 09:56:29 -07001706 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001707 if (mService != null) {
1708 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001709 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001710 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001711 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001712 }
1713 }
1714 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001715
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001716 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001717 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001718 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001719 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001720 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001721 * all admins.
1722 */
Robin Lee25e26452015-06-02 09:56:29 -07001723 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001724 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001725 }
1726
1727 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001728 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001729 if (mService != null) {
1730 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001731 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001732 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001733 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001734 }
1735 }
1736 return 0;
1737 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001738
Dianne Hackborn254cb442010-01-27 19:23:59 -08001739 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001740 * Returns the profile with the smallest maximum failed passwords for wipe,
1741 * for the given user. So for primary user, it might return the primary or
1742 * a managed profile. For a secondary user, it would be the same as the
1743 * user passed in.
1744 * @hide Used only by Keyguard
1745 */
1746 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1747 if (mService != null) {
1748 try {
1749 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1750 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001751 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001752 }
1753 }
1754 return UserHandle.USER_NULL;
1755 }
1756
1757 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001758 * Flag for {@link #resetPassword}: don't allow other admins to change
1759 * the password again until the user has entered it.
1760 */
1761 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001762
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001763 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001764 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1765 * If the flag is set, the device can be booted without asking for user password.
1766 * The absence of this flag does not change the current boot requirements. This flag
1767 * can be set by the device owner only. If the app is not the device owner, the flag
1768 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1769 * device to factory defaults.
1770 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001771 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001772
1773 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001774 * Force a new device unlock password (the password needed to access the
1775 * entire device, not for individual accounts) on the user. This takes
1776 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001777 *
1778 * <p>Calling this from a managed profile that shares the password with the owner profile
1779 * will throw a security exception.
1780 *
1781 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1782 * device admins that are not device owner and not profile owner.
1783 * The password can now only be changed if there is currently no password set. Device owner
1784 * and profile owner can still do this.</em>
1785 *
1786 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001787 * current password quality and length constraints as returned by
1788 * {@link #getPasswordQuality(ComponentName)} and
1789 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1790 * these constraints, then it will be rejected and false returned. Note
1791 * that the password may be a stronger quality (containing alphanumeric
1792 * characters when the requested quality is only numeric), in which case
1793 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001794 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001795 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001796 * pattern or password if the current password constraints allow it. <em>Note: This will not
1797 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1798 * device owner and not profile owner. Once set, the password cannot be changed to null or
1799 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001800 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001801 * <p>The calling device admin must have requested
1802 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1803 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001804 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001805 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001806 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001807 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001808 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001809 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001810 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001811 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001812 if (mParentInstance) {
1813 throw new SecurityException("Reset password does not work across profiles.");
1814 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001815 if (mService != null) {
1816 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001817 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001818 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001819 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001820 }
1821 }
1822 return false;
1823 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001824
Dianne Hackbornd6847842010-01-12 18:14:19 -08001825 /**
1826 * Called by an application that is administering the device to set the
1827 * maximum time for user activity until the device will lock. This limits
1828 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001829 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001830 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001831 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001832 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001833 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001835 * @param timeMs The new desired maximum time to lock in milliseconds.
1836 * A value of 0 means there is no restriction.
1837 */
Robin Lee25e26452015-06-02 09:56:29 -07001838 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001839 if (mService != null) {
1840 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001841 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001842 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001843 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 }
1845 }
1846 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001847
Dianne Hackbornd6847842010-01-12 18:14:19 -08001848 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001849 * Retrieve the current maximum time to unlock for all admins of this user
1850 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001851 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001852 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001853 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001854 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001855 */
Robin Lee25e26452015-06-02 09:56:29 -07001856 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001857 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001858 }
1859
1860 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001861 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001862 if (mService != null) {
1863 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001864 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001865 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001866 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001867 }
1868 }
1869 return 0;
1870 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001871
Dianne Hackbornd6847842010-01-12 18:14:19 -08001872 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001873 * Make the device lock immediately, as if the lock screen timeout has
1874 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001875 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001876 * <p>The calling device admin must have requested
1877 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1878 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001879 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001880 public void lockNow() {
1881 if (mService != null) {
1882 try {
1883 mService.lockNow();
1884 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001885 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001886 }
1887 }
1888 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001889
Dianne Hackbornd6847842010-01-12 18:14:19 -08001890 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001891 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001892 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001893 */
1894 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1895
1896 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001897 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1898 * data.
1899 *
Paul Crowley2934b262014-12-02 11:21:13 +00001900 * <p>This flag may only be set by device owner admins; if it is set by
1901 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001902 */
1903 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1904
1905 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001906 * Ask the user data be wiped. Wiping the primary user will cause the
1907 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001908 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001909 * <p>The calling device admin must have requested
1910 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1911 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001912 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001913 * @param flags Bit mask of additional options: currently supported flags
1914 * are {@link #WIPE_EXTERNAL_STORAGE} and
1915 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001916 */
1917 public void wipeData(int flags) {
1918 if (mService != null) {
1919 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08001920 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001921 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001922 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001923 }
1924 }
1925 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001926
Dianne Hackbornd6847842010-01-12 18:14:19 -08001927 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001928 * Called by an application that is administering the device to set the
1929 * global proxy and exclusion list.
1930 * <p>
1931 * The calling device admin must have requested
1932 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1933 * this method; if it has not, a security exception will be thrown.
1934 * Only the first device admin can set the proxy. If a second admin attempts
1935 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001936 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001937 * be returned.
1938 * The method can be called repeatedly by the device admin alrady setting the
1939 * proxy to update the proxy and exclusion list.
1940 *
Robin Lee25e26452015-06-02 09:56:29 -07001941 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001942 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1943 * Pass Proxy.NO_PROXY to reset the proxy.
1944 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001945 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1946 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001947 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001948 */
Robin Lee25e26452015-06-02 09:56:29 -07001949 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001950 List<String> exclusionList ) {
1951 if (proxySpec == null) {
1952 throw new NullPointerException();
1953 }
1954 if (mService != null) {
1955 try {
1956 String hostSpec;
1957 String exclSpec;
1958 if (proxySpec.equals(Proxy.NO_PROXY)) {
1959 hostSpec = null;
1960 exclSpec = null;
1961 } else {
1962 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1963 throw new IllegalArgumentException();
1964 }
1965 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1966 String hostName = sa.getHostName();
1967 int port = sa.getPort();
1968 StringBuilder hostBuilder = new StringBuilder();
1969 hostSpec = hostBuilder.append(hostName)
1970 .append(":").append(Integer.toString(port)).toString();
1971 if (exclusionList == null) {
1972 exclSpec = "";
1973 } else {
1974 StringBuilder listBuilder = new StringBuilder();
1975 boolean firstDomain = true;
1976 for (String exclDomain : exclusionList) {
1977 if (!firstDomain) {
1978 listBuilder = listBuilder.append(",");
1979 } else {
1980 firstDomain = false;
1981 }
1982 listBuilder = listBuilder.append(exclDomain.trim());
1983 }
1984 exclSpec = listBuilder.toString();
1985 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001986 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1987 != android.net.Proxy.PROXY_VALID)
1988 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001989 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001990 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001991 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001992 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001993 }
1994 }
1995 return null;
1996 }
1997
1998 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001999 * Set a network-independent global HTTP proxy. This is not normally what you want
2000 * for typical HTTP proxies - they are generally network dependent. However if you're
2001 * doing something unusual like general internal filtering this may be useful. On
2002 * a private network where the proxy is not accessible, you may break HTTP using this.
2003 *
2004 * <p>This method requires the caller to be the device owner.
2005 *
2006 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2007 * @see ProxyInfo
2008 *
2009 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2010 * with.
2011 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2012 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2013 */
Robin Lee25e26452015-06-02 09:56:29 -07002014 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2015 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002016 if (mService != null) {
2017 try {
2018 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2019 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002020 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002021 }
2022 }
2023 }
2024
2025 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002026 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002027 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2028 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002029 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002030 */
2031 public ComponentName getGlobalProxyAdmin() {
2032 if (mService != null) {
2033 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002034 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002035 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002036 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002037 }
2038 }
2039 return null;
2040 }
2041
2042 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002043 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002044 * indicating that encryption is not supported.
2045 */
2046 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2047
2048 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002049 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002050 * indicating that encryption is supported, but is not currently active.
2051 */
2052 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2053
2054 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002055 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002056 * indicating that encryption is not currently active, but is currently
2057 * being activated. This is only reported by devices that support
2058 * encryption of data and only when the storage is currently
2059 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2060 * to become encrypted will never return this value.
2061 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002062 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002063
2064 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002065 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002066 * indicating that encryption is active.
2067 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002068 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002069
2070 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002071 * Result code for {@link #getStorageEncryptionStatus}:
2072 * indicating that encryption is active, but an encryption key has not
2073 * been set by the user.
2074 */
2075 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2076
2077 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002078 * Activity action: begin the process of encrypting data on the device. This activity should
2079 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2080 * After resuming from this activity, use {@link #getStorageEncryption}
2081 * to check encryption status. However, on some devices this activity may never return, as
2082 * it may trigger a reboot and in some cases a complete data wipe of the device.
2083 */
2084 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2085 public static final String ACTION_START_ENCRYPTION
2086 = "android.app.action.START_ENCRYPTION";
2087
2088 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002089 * Widgets are enabled in keyguard
2090 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002091 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002092
2093 /**
Jim Miller50e62182014-04-23 17:25:00 -07002094 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002095 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002096 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2097
2098 /**
2099 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2100 */
2101 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2102
2103 /**
Jim Miller50e62182014-04-23 17:25:00 -07002104 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2105 */
2106 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2107
2108 /**
2109 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2110 */
2111 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2112
2113 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002114 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002115 * (e.g. PIN/Pattern/Password).
2116 */
2117 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2118
2119 /**
Jim Miller06e34502014-07-17 14:46:05 -07002120 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2121 */
2122 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2123
2124 /**
Jim Miller35207742012-11-02 15:33:20 -07002125 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002126 */
2127 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002128
2129 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002130 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002131 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002132 *
2133 * <p>When multiple device administrators attempt to control device
2134 * encryption, the most secure, supported setting will always be
2135 * used. If any device administrator requests device encryption,
2136 * it will be enabled; Conversely, if a device administrator
2137 * attempts to disable device encryption while another
2138 * device administrator has enabled it, the call to disable will
2139 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2140 *
2141 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002142 * written to other storage areas may or may not be encrypted, and this policy does not require
2143 * or control the encryption of any other storage areas.
2144 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2145 * {@code true}, then the directory returned by
2146 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2147 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002148 *
2149 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2150 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2151 * the encryption key may not be fully secured. For maximum security, the administrator should
2152 * also require (and check for) a pattern, PIN, or password.
2153 *
2154 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2155 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002156 * @return the new request status (for all active admins) - will be one of
2157 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2158 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2159 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002160 */
Robin Lee25e26452015-06-02 09:56:29 -07002161 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002162 if (mService != null) {
2163 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002164 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002165 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002166 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002167 }
2168 }
2169 return ENCRYPTION_STATUS_UNSUPPORTED;
2170 }
2171
2172 /**
2173 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002174 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002175 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002176 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2177 * this will return the requested encryption setting as an aggregate of all active
2178 * administrators.
2179 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002180 */
Robin Lee25e26452015-06-02 09:56:29 -07002181 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002182 if (mService != null) {
2183 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002184 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002185 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002186 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002187 }
2188 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002189 return false;
2190 }
2191
2192 /**
2193 * Called by an application that is administering the device to
2194 * determine the current encryption status of the device.
2195 *
2196 * Depending on the returned status code, the caller may proceed in different
2197 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2198 * storage system does not support encryption. If the
2199 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2200 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002201 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2202 * storage system has enabled encryption but no password is set so further action
2203 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002204 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2205 *
Robin Lee7e678712014-07-24 16:41:31 +01002206 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002207 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002208 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2209 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002210 */
2211 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002212 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002213 }
2214
2215 /** @hide per-user version */
2216 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002217 if (mService != null) {
2218 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002219 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002220 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002221 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002222 }
2223 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002224 return ENCRYPTION_STATUS_UNSUPPORTED;
2225 }
2226
2227 /**
Robin Lee7e678712014-07-24 16:41:31 +01002228 * Installs the given certificate as a user CA.
2229 *
Robin Lee25e26452015-06-02 09:56:29 -07002230 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2231 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002232 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002233 *
2234 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002235 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002236 */
Robin Lee25e26452015-06-02 09:56:29 -07002237 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002238 if (mService != null) {
2239 try {
Robin Lee7e678712014-07-24 16:41:31 +01002240 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002241 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002242 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002243 }
2244 }
2245 return false;
2246 }
2247
2248 /**
Robin Lee7e678712014-07-24 16:41:31 +01002249 * Uninstalls the given certificate from trusted user CAs, if present.
2250 *
Robin Lee25e26452015-06-02 09:56:29 -07002251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2252 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002253 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002254 */
Robin Lee25e26452015-06-02 09:56:29 -07002255 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002256 if (mService != null) {
2257 try {
Robin Lee306fe082014-06-19 14:04:24 +00002258 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002259 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002260 } catch (CertificateException e) {
2261 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002262 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002263 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002264 }
2265 }
2266 }
2267
2268 /**
Robin Lee7e678712014-07-24 16:41:31 +01002269 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2270 * If a user has installed any certificates by other means than device policy these will be
2271 * included too.
2272 *
Robin Lee25e26452015-06-02 09:56:29 -07002273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2274 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002275 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002276 */
Robin Lee25e26452015-06-02 09:56:29 -07002277 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002278 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002279 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002280 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002281 mService.enforceCanManageCaCerts(admin);
2282 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2283 for (String alias : certStore.userAliases()) {
2284 try {
2285 certs.add(certStore.getCertificate(alias).getEncoded());
2286 } catch (CertificateException ce) {
2287 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2288 }
2289 }
2290 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002291 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002292 }
2293 }
2294 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002295 }
2296
2297 /**
Robin Lee7e678712014-07-24 16:41:31 +01002298 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2299 * means other than device policy will also be removed, except for system CA certificates.
2300 *
Robin Lee25e26452015-06-02 09:56:29 -07002301 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2302 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002303 */
Robin Lee25e26452015-06-02 09:56:29 -07002304 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002305 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002306 try {
2307 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2308 .toArray(new String[0]));
2309 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002310 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002311 }
2312 }
2313 }
2314
2315 /**
2316 * Returns whether this certificate is installed as a trusted CA.
2317 *
Robin Lee25e26452015-06-02 09:56:29 -07002318 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2319 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002320 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002321 */
Robin Lee25e26452015-06-02 09:56:29 -07002322 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002323 if (mService != null) {
2324 try {
2325 mService.enforceCanManageCaCerts(admin);
2326 return getCaCertAlias(certBuffer) != null;
2327 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002328 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002329 } catch (CertificateException ce) {
2330 Log.w(TAG, "Could not parse certificate", ce);
2331 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002332 }
2333 return false;
2334 }
2335
2336 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002337 * Called by a device or profile owner to install a certificate and private key pair. The
2338 * keypair will be visible to all apps within the profile.
2339 *
Robin Lee25e26452015-06-02 09:56:29 -07002340 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2341 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002342 * @param privKey The private key to install.
2343 * @param cert The certificate to install.
2344 * @param alias The private key alias under which to install the certificate. If a certificate
2345 * with that alias already exists, it will be overwritten.
2346 * @return {@code true} if the keys were installed, {@code false} otherwise.
2347 */
Robin Leefbc65642015-08-03 16:21:22 +01002348 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2349 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002350 try {
2351 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002352 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2353 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002354 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002355 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002356 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002357 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2358 Log.w(TAG, "Failed to obtain private key material", e);
2359 } catch (CertificateException | IOException e) {
2360 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002361 }
2362 return false;
2363 }
2364
2365 /**
Robin Leefbc65642015-08-03 16:21:22 +01002366 * Called by a device or profile owner to remove all user credentials installed under a given
2367 * alias.
2368 *
2369 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2370 * {@code null} if calling from a delegated certificate installer.
2371 * @param alias The private key alias under which the certificate is installed.
2372 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2373 */
2374 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2375 try {
2376 return mService.removeKeyPair(admin, alias);
2377 } catch (RemoteException e) {
2378 Log.w(TAG, "Failed talking with device policy service", e);
2379 }
2380 return false;
2381 }
2382
2383 /**
Robin Lee25e26452015-06-02 09:56:29 -07002384 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002385 * doesn't exist.
2386 */
2387 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2388 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2389 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2390 new ByteArrayInputStream(certBuffer));
2391 return new TrustedCertificateStore().getCertificateAlias(cert);
2392 }
2393
2394 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002395 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002396 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002397 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002398 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002399 * <p>
2400 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2401 * it is later cleared by calling this method with a null value or uninstallling the certificate
2402 * installer.
2403 *
Robin Lee25e26452015-06-02 09:56:29 -07002404 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002405 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002406 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002407 */
Robin Lee25e26452015-06-02 09:56:29 -07002408 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2409 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002410 if (mService != null) {
2411 try {
Robin Lee25e26452015-06-02 09:56:29 -07002412 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002413 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002414 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002415 }
2416 }
2417 }
2418
2419 /**
2420 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002421 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002422 *
Robin Lee25e26452015-06-02 09:56:29 -07002423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2424 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002425 * if none is set.
2426 */
Robin Lee25e26452015-06-02 09:56:29 -07002427 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002428 if (mService != null) {
2429 try {
Robin Lee25e26452015-06-02 09:56:29 -07002430 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002431 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002432 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002433 }
2434 }
2435 return null;
2436 }
2437
2438 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002439 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002440 * on the device, for this user. After setting this, no applications running as this user
2441 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002442 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002443 * <p>If the caller is device owner, then the restriction will be applied to all users.
2444 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002445 * <p>The calling device admin must have requested
2446 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2447 * this method; if it has not, a security exception will be thrown.
2448 *
2449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2450 * @param disabled Whether or not the camera should be disabled.
2451 */
Robin Lee25e26452015-06-02 09:56:29 -07002452 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002453 if (mService != null) {
2454 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002455 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002456 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002457 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002458 }
2459 }
2460 }
2461
2462 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002463 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002464 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002465 * @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 -07002466 * have disabled the camera
2467 */
Robin Lee25e26452015-06-02 09:56:29 -07002468 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002469 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002470 }
2471
2472 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002473 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002474 if (mService != null) {
2475 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002476 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002477 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002478 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002479 }
2480 }
2481 return false;
2482 }
2483
2484 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002485 * Determine whether or not creating a guest user has been disabled for the device
2486 *
2487 * @hide
2488 */
2489 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2490 // Currently guest users can always be created if multi-user is enabled
2491 // TODO introduce a policy for guest user creation
2492 return false;
2493 }
2494
2495 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002496 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2497 * screen capture also prevents the content from being shown on display devices that do not have
2498 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2499 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002500 *
2501 * <p>The calling device admin must be a device or profile owner. If it is not, a
2502 * security exception will be thrown.
2503 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002504 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002505 * blocks assist requests for all activities of the relevant user.
2506 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002508 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002509 */
Robin Lee25e26452015-06-02 09:56:29 -07002510 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002511 if (mService != null) {
2512 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002513 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002514 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002515 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002516 }
2517 }
2518 }
2519
2520 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002521 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002522 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002523 * @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 +01002524 * have disabled screen capture.
2525 */
Robin Lee25e26452015-06-02 09:56:29 -07002526 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002527 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002528 }
2529
2530 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002531 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002532 if (mService != null) {
2533 try {
2534 return mService.getScreenCaptureDisabled(admin, userHandle);
2535 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002536 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002537 }
2538 }
2539 return false;
2540 }
2541
2542 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002543 * Called by a device owner to set whether auto time is required. If auto time is
2544 * required the user cannot set the date and time, but has to use network date and time.
2545 *
2546 * <p>Note: if auto time is required the user can still manually set the time zone.
2547 *
2548 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2549 * be thrown.
2550 *
2551 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2552 * @param required Whether auto time is set required or not.
2553 */
Robin Lee25e26452015-06-02 09:56:29 -07002554 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002555 if (mService != null) {
2556 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002557 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002558 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002559 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002560 }
2561 }
2562 }
2563
2564 /**
2565 * @return true if auto time is required.
2566 */
2567 public boolean getAutoTimeRequired() {
2568 if (mService != null) {
2569 try {
2570 return mService.getAutoTimeRequired();
2571 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002572 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002573 }
2574 }
2575 return false;
2576 }
2577
2578 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002579 * Called by an application that is administering the device to disable keyguard customizations,
2580 * such as widgets. After setting this, keyguard features will be disabled according to the
2581 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002582 *
2583 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002584 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002585 * this method; if it has not, a security exception will be thrown.
2586 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002587 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002588 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002589 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002590 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002591 * <ul>
2592 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2593 * these will affect the profile's parent user.
2594 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2595 * generated by applications in the managed profile.
2596 * </ul>
2597 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2598 * can check which features have been disabled by calling
2599 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002600 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002601 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002602 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2603 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002604 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002605 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2606 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002607 */
Robin Lee25e26452015-06-02 09:56:29 -07002608 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002609 if (mService != null) {
2610 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002611 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002612 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002613 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002614 }
2615 }
2616 }
2617
2618 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002619 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002620 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002621 * @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 -07002622 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002623 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2624 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002625 */
Robin Lee25e26452015-06-02 09:56:29 -07002626 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002627 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002628 }
2629
2630 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002631 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002632 if (mService != null) {
2633 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002634 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002635 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002636 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002637 }
2638 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002639 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002640 }
2641
2642 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002643 * @hide
2644 */
Robin Lee25e26452015-06-02 09:56:29 -07002645 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2646 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002647 if (mService != null) {
2648 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002649 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002650 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002651 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002652 }
2653 }
2654 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002655
Dianne Hackbornd6847842010-01-12 18:14:19 -08002656 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002657 * @hide
2658 */
Robin Lee25e26452015-06-02 09:56:29 -07002659 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002660 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002661 }
2662
2663 /**
Robin Lee25e26452015-06-02 09:56:29 -07002664 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002665 * @hide
2666 */
Robin Lee25e26452015-06-02 09:56:29 -07002667 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002668 ActivityInfo ai;
2669 try {
2670 ai = mContext.getPackageManager().getReceiverInfo(cn,
2671 PackageManager.GET_META_DATA);
2672 } catch (PackageManager.NameNotFoundException e) {
2673 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2674 return null;
2675 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002676
Dianne Hackbornd6847842010-01-12 18:14:19 -08002677 ResolveInfo ri = new ResolveInfo();
2678 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002679
Dianne Hackbornd6847842010-01-12 18:14:19 -08002680 try {
2681 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002682 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002683 Log.w(TAG, "Unable to parse device policy " + cn, e);
2684 return null;
2685 }
2686 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002687
Dianne Hackbornd6847842010-01-12 18:14:19 -08002688 /**
2689 * @hide
2690 */
Robin Lee25e26452015-06-02 09:56:29 -07002691 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002692 if (mService != null) {
2693 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002694 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002695 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002696 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002697 }
2698 }
2699 }
2700
2701 /**
2702 * @hide
2703 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002704 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002705 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002706 if (mService != null) {
2707 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002708 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002709 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002710 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002711 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002712 }
2713 }
2714 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002715
Dianne Hackbornd6847842010-01-12 18:14:19 -08002716 /**
2717 * @hide
2718 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002719 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002720 if (mService != null) {
2721 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002722 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002723 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002724 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002725 }
2726 }
2727 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002728
Dianne Hackbornd6847842010-01-12 18:14:19 -08002729 /**
2730 * @hide
2731 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002732 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002733 if (mService != null) {
2734 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002735 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002736 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002737 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002738 }
2739 }
2740 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002741
2742 /**
2743 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002744 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002745 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2746 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002747 * @return whether the package was successfully registered as the device owner.
2748 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002749 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002750 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002751 public boolean setDeviceOwner(ComponentName who) {
2752 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002753 }
2754
2755 /**
2756 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002757 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002758 public boolean setDeviceOwner(ComponentName who, int userId) {
2759 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002760 }
2761
2762 /**
2763 * @hide
2764 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002765 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2766 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002767 }
2768
2769 /**
2770 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002771 * Sets the given package as the device owner. The package must already be installed. There
2772 * must not already be a device owner.
2773 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2774 * this method.
2775 * Calling this after the setup phase of the primary user has completed is allowed only if
2776 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002777 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002778 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002779 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002780 * @return whether the package was successfully registered as the device owner.
2781 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002782 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002783 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002784 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002785 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002786 if (mService != null) {
2787 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002788 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002789 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002790 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002791 }
2792 }
2793 return false;
2794 }
2795
2796 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002797 * Used to determine if a particular package has been registered as a Device Owner app.
2798 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002799 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002800 * package is currently registered as the device owner app, pass in the package name from
2801 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002802 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002803 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2804 * the setup process.
2805 * @param packageName the package name of the app, to compare with the registered device owner
2806 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08002807 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002808 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002809 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08002810 return isDeviceOwnerAppOnCallingUser(packageName);
2811 }
2812
2813 /**
2814 * @return true if a package is registered as device owner, only when it's running on the
2815 * calling user.
2816 *
2817 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
2818 * @hide
2819 */
2820 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
2821 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
2822 }
2823
2824 /**
2825 * @return true if a package is registered as device owner, even if it's running on a different
2826 * user.
2827 *
2828 * <p>Requires the MANAGE_USERS permission.
2829 *
2830 * @hide
2831 */
2832 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
2833 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
2834 }
2835
2836 /**
2837 * @return device owner component name, only when it's running on the calling user.
2838 *
2839 * @hide
2840 */
2841 public ComponentName getDeviceOwnerComponentOnCallingUser() {
2842 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
2843 }
2844
2845 /**
2846 * @return device owner component name, even if it's running on a different user.
2847 *
2848 * <p>Requires the MANAGE_USERS permission.
2849 *
2850 * @hide
2851 */
2852 public ComponentName getDeviceOwnerComponentOnAnyUser() {
2853 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
2854 }
2855
2856 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002857 if (packageName == null) {
2858 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07002859 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08002860 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08002861 if (deviceOwner == null) {
2862 return false;
2863 }
2864 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07002865 }
2866
Makoto Onukic8a5a552015-11-19 14:29:12 -08002867 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
2868 if (mService != null) {
2869 try {
2870 return mService.getDeviceOwnerComponent(callingUserOnly);
2871 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002872 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002873 }
2874 }
2875 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002876 }
2877
Jason Monkb0dced82014-06-06 14:36:20 -04002878 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002879 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
2880 * no device owner.
2881 *
2882 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07002883 *
2884 * @hide
2885 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08002886 public int getDeviceOwnerUserId() {
2887 if (mService != null) {
2888 try {
2889 return mService.getDeviceOwnerUserId();
2890 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002891 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002892 }
2893 }
2894 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07002895 }
2896
2897 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002898 * Clears the current device owner. The caller must be the device owner.
2899 *
2900 * This function should be used cautiously as once it is called it cannot
2901 * be undone. The device owner can only be set as a part of device setup
2902 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002903 *
2904 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002905 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002906 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002907 if (mService != null) {
2908 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002909 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002910 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002911 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04002912 }
2913 }
2914 }
2915
Makoto Onukia52562c2015-10-01 16:12:31 -07002916 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002917 * Returns the device owner package name, only if it's running on the calling user.
2918 *
2919 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07002920 *
2921 * @hide
2922 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002923 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002924 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08002925 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
2926 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07002927 }
2928
2929 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002930 * @return true if the device is managed by any device owner.
2931 *
2932 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07002933 *
2934 * @hide
2935 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08002936 public boolean isDeviceManaged() {
2937 return getDeviceOwnerComponentOnAnyUser() != null;
2938 }
2939
2940 /**
2941 * Returns the device owner name. Note this method *will* return the device owner
2942 * name when it's running on a different user.
2943 *
2944 * <p>Requires the MANAGE_USERS permission.
2945 *
2946 * @hide
2947 */
2948 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002949 if (mService != null) {
2950 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002951 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002952 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002953 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002954 }
2955 }
2956 return null;
2957 }
Adam Connors776c5552014-01-09 10:42:56 +00002958
2959 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002960 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002961 * @deprecated Do not use
2962 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002963 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002964 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002965 @SystemApi
2966 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002967 return null;
2968 }
2969
2970 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002971 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002972 * @deprecated Do not use
2973 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002974 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002975 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002976 @SystemApi
2977 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002978 return null;
2979 }
2980
Julia Reynolds20118f12015-02-11 12:34:08 -05002981 /**
Adam Connors776c5552014-01-09 10:42:56 +00002982 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002983 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302984 * Sets the given component as an active admin and registers the package as the profile
2985 * owner for this user. The package must already be installed and there shouldn't be
2986 * an existing profile owner registered for this user. Also, this method must be called
2987 * before the user setup has been completed.
2988 * <p>
2989 * This method can only be called by system apps that hold MANAGE_USERS permission and
2990 * MANAGE_DEVICE_ADMINS permission.
2991 * @param admin The component to register as an active admin and profile owner.
2992 * @param ownerName The user-visible name of the entity that is managing this user.
2993 * @return whether the admin was successfully registered as the profile owner.
2994 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2995 * the user has already been set up.
2996 */
Justin Morey80440cc2014-07-24 09:16:35 -05002997 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002998 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302999 throws IllegalArgumentException {
3000 if (mService != null) {
3001 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003002 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303003 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003004 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303005 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303006 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3007 }
3008 }
3009 return false;
3010 }
3011
3012 /**
3013 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003014 * Clears the active profile owner and removes all user restrictions. The caller must
3015 * be from the same package as the active profile owner for this user, otherwise a
3016 * SecurityException will be thrown.
3017 *
3018 * @param admin The component to remove as the profile owner.
3019 * @return
3020 */
3021 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003022 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003023 if (mService != null) {
3024 try {
3025 mService.clearProfileOwner(admin);
3026 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003027 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003028 }
3029 }
3030 }
3031
3032 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003033 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003034 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003035 */
3036 public boolean hasUserSetupCompleted() {
3037 if (mService != null) {
3038 try {
3039 return mService.hasUserSetupCompleted();
3040 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003041 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003042 }
3043 }
3044 return true;
3045 }
3046
3047 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003048 * @hide
3049 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003050 * already be installed. There must not already be a profile owner for this user.
3051 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3052 * this method.
3053 * Calling this after the setup phase of the specified user has completed is allowed only if:
3054 * - the caller is SYSTEM_UID.
3055 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003056 * @param admin the component name to be registered as profile owner.
3057 * @param ownerName the human readable name of the organisation associated with this DPM.
3058 * @param userHandle the userId to set the profile owner for.
3059 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003060 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3061 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003062 */
Robin Lee25e26452015-06-02 09:56:29 -07003063 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003064 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003065 if (mService != null) {
3066 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003067 if (ownerName == null) {
3068 ownerName = "";
3069 }
3070 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003071 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003072 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003073 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3074 }
3075 }
3076 return false;
3077 }
3078
3079 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003080 * Sets the device owner information to be shown on the lock screen.
3081 *
3082 * <p>If the device owner information is {@code null} or empty then the device owner info is
3083 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003084 * <p>If the device owner information contains only whitespaces then the message on the lock
3085 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003086 *
3087 * @param admin The name of the admin component to check.
3088 * @param info Device owner information which will be displayed instead of the user
3089 * owner info.
3090 * @return Whether the device owner information has been set.
3091 */
3092 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3093 if (mService != null) {
3094 try {
3095 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3096 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003097 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003098 }
3099 }
3100 return false;
3101 }
3102
3103 /**
3104 * @return The device owner information. If it is not set returns {@code null}.
3105 */
3106 public String getDeviceOwnerLockScreenInfo() {
3107 if (mService != null) {
3108 try {
3109 return mService.getDeviceOwnerLockScreenInfo();
3110 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003111 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003112 }
3113 }
3114 return null;
3115 }
3116
3117 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003118 * Called by device or profile owners for setting the package suspended for this user.
3119 * A suspended package will not be started by the package manager, its notifications will
3120 * be hidden and it will not show up in recents. The package must already be installed.
3121 *
3122 * @param admin The name of the admin component to check.
3123 * @param packageName The package name of the app to suspend or unsuspend.
3124 * @param suspended If set to {@code true} than the package will be suspended, if set to
3125 * {@code false} the package will be unsuspended.
3126 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3127 * otherwise.
3128 */
3129 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3130 boolean suspended) {
3131 if (mService != null) {
3132 try {
3133 return mService.setPackageSuspended(admin, packageName, suspended);
3134 } catch (RemoteException re) {
3135 Log.w(TAG, "Failed talking with device policy service", re);
3136 }
3137 }
3138 return false;
3139 }
3140
3141 /**
3142 * Called by device or profile owners to determine if a package is suspended.
3143 *
3144 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3145 * @param packageName The name of the package to retrieve the suspended status of.
3146 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3147 */
3148 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3149 if (mService != null) {
3150 try {
3151 return mService.getPackageSuspended(admin, packageName);
3152 } catch (RemoteException e) {
3153 Log.w(TAG, "Failed talking with device policy service", e);
3154 }
3155 }
3156 return false;
3157 }
3158
3159 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003160 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3161 * be used. Only the profile owner can call this.
3162 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003163 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003164 *
3165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3166 */
Robin Lee25e26452015-06-02 09:56:29 -07003167 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003168 if (mService != null) {
3169 try {
3170 mService.setProfileEnabled(admin);
3171 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003172 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003173 }
3174 }
3175 }
3176
3177 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003178 * Sets the name of the profile. In the device owner case it sets the name of the user
3179 * 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 +01003180 * never called by the profile or device owner, the name will be set to default values.
3181 *
3182 * @see #isProfileOwnerApp
3183 * @see #isDeviceOwnerApp
3184 *
Robin Lee25e26452015-06-02 09:56:29 -07003185 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003186 * @param profileName The name of the profile.
3187 */
Robin Lee25e26452015-06-02 09:56:29 -07003188 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003189 if (mService != null) {
3190 try {
Robin Lee25e26452015-06-02 09:56:29 -07003191 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003192 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003193 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003194 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003195 }
3196 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003197
3198 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003199 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003200 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003201 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003202 *
3203 * @param packageName The package name of the app to compare with the registered profile owner.
3204 * @return Whether or not the package is registered as the profile owner.
3205 */
3206 public boolean isProfileOwnerApp(String packageName) {
3207 if (mService != null) {
3208 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003209 ComponentName profileOwner = mService.getProfileOwner(
3210 Process.myUserHandle().getIdentifier());
3211 return profileOwner != null
3212 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003213 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003214 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003215 }
3216 }
3217 return false;
3218 }
3219
3220 /**
3221 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003222 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003223 * owner has been set for that user.
3224 * @throws IllegalArgumentException if the userId is invalid.
3225 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003226 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003227 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003228 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3229 }
3230
3231 /**
3232 * @see #getProfileOwner()
3233 * @hide
3234 */
3235 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003236 if (mService != null) {
3237 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003238 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003239 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003240 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003241 throw new IllegalArgumentException(
3242 "Requested profile owner for invalid userId", re);
3243 }
3244 }
3245 return null;
3246 }
3247
3248 /**
3249 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003250 * @return the human readable name of the organisation associated with this DPM or {@code null}
3251 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003252 * @throws IllegalArgumentException if the userId is invalid.
3253 */
3254 public String getProfileOwnerName() throws IllegalArgumentException {
3255 if (mService != null) {
3256 try {
3257 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3258 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003259 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003260 throw new IllegalArgumentException(
3261 "Requested profile owner for invalid userId", re);
3262 }
3263 }
3264 return null;
3265 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003266
3267 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003268 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003269 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003270 * @return the human readable name of the organisation associated with this profile owner or
3271 * null if one is not set.
3272 * @throws IllegalArgumentException if the userId is invalid.
3273 */
3274 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003275 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003276 if (mService != null) {
3277 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003278 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003279 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003280 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003281 throw new IllegalArgumentException(
3282 "Requested profile owner for invalid userId", re);
3283 }
3284 }
3285 return null;
3286 }
3287
3288 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003289 * Called by a profile owner or device owner to add a default intent handler activity for
3290 * intents that match a certain intent filter. This activity will remain the default intent
3291 * handler even if the set of potential event handlers for the intent filter changes and if
3292 * the intent preferences are reset.
3293 *
3294 * <p>The default disambiguation mechanism takes over if the activity is not installed
3295 * (anymore). When the activity is (re)installed, it is automatically reset as default
3296 * intent handler for the filter.
3297 *
3298 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3299 * security exception will be thrown.
3300 *
3301 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3302 * @param filter The IntentFilter for which a default handler is added.
3303 * @param activity The Activity that is added as default intent handler.
3304 */
Robin Lee25e26452015-06-02 09:56:29 -07003305 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3306 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003307 if (mService != null) {
3308 try {
3309 mService.addPersistentPreferredActivity(admin, filter, activity);
3310 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003311 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003312 }
3313 }
3314 }
3315
3316 /**
3317 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003318 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003319 *
3320 * <p>The calling device admin must be a profile owner. If it is not, a security
3321 * exception will be thrown.
3322 *
3323 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3324 * @param packageName The name of the package for which preferences are removed.
3325 */
Robin Lee25e26452015-06-02 09:56:29 -07003326 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003327 String packageName) {
3328 if (mService != null) {
3329 try {
3330 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3331 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003332 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003333 }
3334 }
3335 }
Robin Lee66e5d962014-04-09 16:44:21 +01003336
3337 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003338 * Called by a profile owner or device owner to grant permission to a package to manage
3339 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3340 * {@link #getApplicationRestrictions}.
3341 * <p>
3342 * This permission is persistent until it is later cleared by calling this method with a
3343 * {@code null} value or uninstalling the managing package.
3344 *
3345 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3346 * @param packageName The package name which will be given access to application restrictions
3347 * APIs. If {@code null} is given the current package will be cleared.
3348 */
3349 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3350 @Nullable String packageName) {
3351 if (mService != null) {
3352 try {
3353 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3354 } catch (RemoteException e) {
3355 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3356 }
3357 }
3358 }
3359
3360 /**
3361 * Called by a profile owner or device owner to retrieve the application restrictions managing
3362 * package for the current user, or {@code null} if none is set.
3363 *
3364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3365 * @return The package name allowed to manage application restrictions on the current user, or
3366 * {@code null} if none is set.
3367 */
3368 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3369 if (mService != null) {
3370 try {
3371 return mService.getApplicationRestrictionsManagingPackage(admin);
3372 } catch (RemoteException e) {
3373 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3374 }
3375 }
3376 return null;
3377 }
3378
3379 /**
3380 * Returns {@code true} if the calling package has been granted permission via
3381 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3382 * restrictions for the calling user.
3383 */
3384 public boolean isCallerApplicationRestrictionsManagingPackage() {
3385 if (mService != null) {
3386 try {
3387 return mService.isCallerApplicationRestrictionsManagingPackage();
3388 } catch (RemoteException e) {
3389 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3390 }
3391 }
3392 return false;
3393 }
3394
3395 /**
3396 * Sets the application restrictions for a given target application running in the calling user.
3397 *
3398 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3399 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3400 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003401 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003402 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3403 * <ul>
3404 * <li>{@code boolean}
3405 * <li>{@code int}
3406 * <li>{@code String} or {@code String[]}
3407 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3408 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003409 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003410 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003411 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003412 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3413 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003414 * <p>The application restrictions are only made visible to the target application via
3415 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3416 * device owner, and the application restrictions managing package via
3417 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003418 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3420 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003421 * @param packageName The name of the package to update restricted settings for.
3422 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3423 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003424 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003425 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003426 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003427 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003428 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003429 Bundle settings) {
3430 if (mService != null) {
3431 try {
3432 mService.setApplicationRestrictions(admin, packageName, settings);
3433 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003434 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003435 }
3436 }
3437 }
3438
3439 /**
Jim Millere303bf42014-08-26 17:12:29 -07003440 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3441 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3442 * trust agents but those enabled by this function call. If flag
3443 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003444 *
3445 * <p>The calling device admin must have requested
3446 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003447 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003448 *
3449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003450 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003451 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003452 * will be strictly disabled according to the state of the
3453 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3454 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3455 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3456 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003457 */
Robin Lee25e26452015-06-02 09:56:29 -07003458 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3459 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003460 if (mService != null) {
3461 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003462 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003463 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003464 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003465 }
3466 }
3467 }
3468
3469 /**
Jim Millere303bf42014-08-26 17:12:29 -07003470 * Gets configuration for the given trust agent based on aggregating all calls to
3471 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3472 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003473 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003474 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3475 * this function returns a list of configurations for all admins that declare
3476 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3477 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3478 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3479 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003480 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003481 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003482 */
Robin Lee25e26452015-06-02 09:56:29 -07003483 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3484 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003485 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003486 }
3487
3488 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003489 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3490 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003491 if (mService != null) {
3492 try {
Jim Millere303bf42014-08-26 17:12:29 -07003493 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003494 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003495 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003496 }
3497 }
Jim Millere303bf42014-08-26 17:12:29 -07003498 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003499 }
3500
3501 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003502 * Called by a profile owner of a managed profile to set whether caller-Id information from
3503 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003504 *
3505 * <p>The calling device admin must be a profile owner. If it is not, a
3506 * security exception will be thrown.
3507 *
Robin Lee25e26452015-06-02 09:56:29 -07003508 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003509 * @param disabled If true caller-Id information in the managed profile is not displayed.
3510 */
Robin Lee25e26452015-06-02 09:56:29 -07003511 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003512 if (mService != null) {
3513 try {
Robin Lee25e26452015-06-02 09:56:29 -07003514 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003515 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003516 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003517 }
3518 }
3519 }
3520
3521 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003522 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3523 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003524 *
3525 * <p>The calling device admin must be a profile owner. If it is not, a
3526 * security exception will be thrown.
3527 *
Robin Lee25e26452015-06-02 09:56:29 -07003528 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003529 */
Robin Lee25e26452015-06-02 09:56:29 -07003530 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003531 if (mService != null) {
3532 try {
Robin Lee25e26452015-06-02 09:56:29 -07003533 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003534 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003535 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003536 }
3537 }
3538 return false;
3539 }
3540
3541 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003542 * Determine whether or not caller-Id information has been disabled.
3543 *
3544 * @param userHandle The user for whom to check the caller-id permission
3545 * @hide
3546 */
3547 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3548 if (mService != null) {
3549 try {
3550 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3551 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003552 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003553 }
3554 }
3555 return false;
3556 }
3557
3558 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003559 * Called by a profile owner of a managed profile to set whether contacts search from
3560 * the managed profile will be shown in the parent profile, for incoming calls.
3561 *
3562 * <p>The calling device admin must be a profile owner. If it is not, a
3563 * security exception will be thrown.
3564 *
3565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3566 * @param disabled If true contacts search in the managed profile is not displayed.
3567 */
3568 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3569 boolean disabled) {
3570 if (mService != null) {
3571 try {
3572 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3573 } catch (RemoteException e) {
3574 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3575 }
3576 }
3577 }
3578
3579 /**
3580 * Called by a profile owner of a managed profile to determine whether or not contacts search
3581 * has been disabled.
3582 *
3583 * <p>The calling device admin must be a profile owner. If it is not, a
3584 * security exception will be thrown.
3585 *
3586 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3587 */
3588 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3589 if (mService != null) {
3590 try {
3591 return mService.getCrossProfileContactsSearchDisabled(admin);
3592 } catch (RemoteException e) {
3593 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3594 }
3595 }
3596 return false;
3597 }
3598
3599
3600 /**
3601 * Determine whether or not contacts search has been disabled.
3602 *
3603 * @param userHandle The user for whom to check the contacts search permission
3604 * @hide
3605 */
3606 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3607 if (mService != null) {
3608 try {
3609 return mService
3610 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3611 } catch (RemoteException e) {
3612 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3613 }
3614 }
3615 return false;
3616 }
3617
3618 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003619 * Start Quick Contact on the managed profile for the user, if the policy allows.
Makoto Onuki1040da12015-03-19 11:24:00 -07003620 * @hide
3621 */
3622 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Ricky Wai494b95d2015-11-20 16:07:15 +00003623 long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003624 if (mService != null) {
3625 try {
3626 mService.startManagedQuickContact(
Ricky Wai494b95d2015-11-20 16:07:15 +00003627 actualLookupKey, actualContactId, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003628 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003629 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003630 }
3631 }
3632 }
3633
3634 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003635 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003636 * @hide
3637 */
3638 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3639 Intent originalIntent) {
3640 startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT,
3641 originalIntent);
3642 }
3643
3644 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003645 * Called by a profile owner of a managed profile to set whether bluetooth
3646 * devices can access enterprise contacts.
3647 * <p>
3648 * The calling device admin must be a profile owner. If it is not, a
3649 * security exception will be thrown.
3650 * <p>
3651 * This API works on managed profile only.
3652 *
Robin Lee25e26452015-06-02 09:56:29 -07003653 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003654 * with.
3655 * @param disabled If true, bluetooth devices cannot access enterprise
3656 * contacts.
3657 */
Robin Lee25e26452015-06-02 09:56:29 -07003658 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003659 if (mService != null) {
3660 try {
Robin Lee25e26452015-06-02 09:56:29 -07003661 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003662 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003663 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003664 }
3665 }
3666 }
3667
3668 /**
3669 * Called by a profile owner of a managed profile to determine whether or
3670 * not Bluetooth devices cannot access enterprise contacts.
3671 * <p>
3672 * The calling device admin must be a profile owner. If it is not, a
3673 * security exception will be thrown.
3674 * <p>
3675 * This API works on managed profile only.
3676 *
Robin Lee25e26452015-06-02 09:56:29 -07003677 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003678 * with.
3679 */
Robin Lee25e26452015-06-02 09:56:29 -07003680 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003681 if (mService != null) {
3682 try {
Robin Lee25e26452015-06-02 09:56:29 -07003683 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003684 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003685 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003686 }
3687 }
3688 return true;
3689 }
3690
3691 /**
3692 * Determine whether or not Bluetooth devices cannot access contacts.
3693 * <p>
3694 * This API works on managed profile UserHandle only.
3695 *
3696 * @param userHandle The user for whom to check the caller-id permission
3697 * @hide
3698 */
3699 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3700 if (mService != null) {
3701 try {
3702 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3703 .getIdentifier());
3704 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003705 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003706 }
3707 }
3708 return true;
3709 }
3710
3711 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003712 * Called by the profile owner of a managed profile so that some intents sent in the managed
3713 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003714 * Only activity intents are supported.
3715 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003716 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003717 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3718 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003719 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3720 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003721 */
Robin Lee25e26452015-06-02 09:56:29 -07003722 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003723 if (mService != null) {
3724 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003725 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003726 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003727 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003728 }
3729 }
3730 }
3731
3732 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003733 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3734 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003735 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003736 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3737 */
Robin Lee25e26452015-06-02 09:56:29 -07003738 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003739 if (mService != null) {
3740 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003741 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003742 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003743 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003744 }
3745 }
3746 }
3747
3748 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003749 * Called by a profile or device owner to set the permitted accessibility services. When
3750 * set by a device owner or profile owner the restriction applies to all profiles of the
3751 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003752 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003753 * By default the user can use any accessiblity service. When zero or more packages have
3754 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003755 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003756 *
3757 * <p> Calling with a null value for the list disables the restriction so that all services
3758 * can be used, calling with an empty list only allows the builtin system's services.
3759 *
3760 * <p> System accesibility services are always available to the user the list can't modify
3761 * this.
3762 *
3763 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3764 * @param packageNames List of accessibility service package names.
3765 *
3766 * @return true if setting the restriction succeeded. It fail if there is
3767 * one or more non-system accessibility services enabled, that are not in the list.
3768 */
Robin Lee25e26452015-06-02 09:56:29 -07003769 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003770 List<String> packageNames) {
3771 if (mService != null) {
3772 try {
3773 return mService.setPermittedAccessibilityServices(admin, packageNames);
3774 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003775 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003776 }
3777 }
3778 return false;
3779 }
3780
3781 /**
3782 * Returns the list of permitted accessibility services set by this device or profile owner.
3783 *
3784 * <p>An empty list means no accessibility services except system services are allowed.
3785 * Null means all accessibility services are allowed.
3786 *
3787 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3788 * @return List of accessiblity service package names.
3789 */
Robin Lee25e26452015-06-02 09:56:29 -07003790 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003791 if (mService != null) {
3792 try {
3793 return mService.getPermittedAccessibilityServices(admin);
3794 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003795 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003796 }
3797 }
3798 return null;
3799 }
3800
3801 /**
3802 * Returns the list of accessibility services permitted by the device or profiles
3803 * owners of this user.
3804 *
3805 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3806 * it will contain the intersection of the permitted lists for any device or profile
3807 * owners that apply to this user. It will also include any system accessibility services.
3808 *
3809 * @param userId which user to check for.
3810 * @return List of accessiblity service package names.
3811 * @hide
3812 */
3813 @SystemApi
3814 public List<String> getPermittedAccessibilityServices(int userId) {
3815 if (mService != null) {
3816 try {
3817 return mService.getPermittedAccessibilityServicesForUser(userId);
3818 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003819 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003820 }
3821 }
3822 return null;
3823 }
3824
3825 /**
3826 * Called by a profile or device owner to set the permitted input methods services. When
3827 * set by a device owner or profile owner the restriction applies to all profiles of the
3828 * user the device owner or profile owner is an admin for.
3829 *
3830 * By default the user can use any input method. When zero or more packages have
3831 * been added, input method that are not in the list and not part of the system
3832 * can not be enabled by the user.
3833 *
3834 * This method will fail if it is called for a admin that is not for the foreground user
3835 * or a profile of the foreground user.
3836 *
3837 * <p> Calling with a null value for the list disables the restriction so that all input methods
3838 * can be used, calling with an empty list disables all but the system's own input methods.
3839 *
3840 * <p> System input methods are always available to the user this method can't modify this.
3841 *
3842 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3843 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003844 * @return true if setting the restriction succeeded. It will fail if there are
3845 * one or more non-system input methods currently enabled that are not in
3846 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003847 */
Robin Lee25e26452015-06-02 09:56:29 -07003848 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003849 if (mService != null) {
3850 try {
3851 return mService.setPermittedInputMethods(admin, packageNames);
3852 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003853 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003854 }
3855 }
3856 return false;
3857 }
3858
3859
3860 /**
3861 * Returns the list of permitted input methods set by this device or profile owner.
3862 *
3863 * <p>An empty list means no input methods except system input methods are allowed.
3864 * Null means all input methods are allowed.
3865 *
3866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3867 * @return List of input method package names.
3868 */
Robin Lee25e26452015-06-02 09:56:29 -07003869 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003870 if (mService != null) {
3871 try {
3872 return mService.getPermittedInputMethods(admin);
3873 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003874 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003875 }
3876 }
3877 return null;
3878 }
3879
3880 /**
3881 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08003882 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003883 *
3884 * <p>Null means all input methods are allowed, if a non-null list is returned
3885 * it will contain the intersection of the permitted lists for any device or profile
3886 * owners that apply to this user. It will also include any system input methods.
3887 *
3888 * @return List of input method package names.
3889 * @hide
3890 */
3891 @SystemApi
3892 public List<String> getPermittedInputMethodsForCurrentUser() {
3893 if (mService != null) {
3894 try {
3895 return mService.getPermittedInputMethodsForCurrentUser();
3896 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003897 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003898 }
3899 }
3900 return null;
3901 }
3902
3903 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003904 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
3905 * currently installed it.
3906 *
3907 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3908 *
3909 * @return List of package names to keep cached.
3910 * @hide
3911 */
3912 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
3913 if (mService != null) {
3914 try {
3915 return mService.getKeepUninstalledPackages(admin);
3916 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003917 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003918 }
3919 }
3920 return null;
3921 }
3922
3923 /**
3924 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
3925 * currently installed it.
3926 *
3927 * <p>Please note that setting this policy does not imply that specified apps will be
3928 * automatically pre-cached.</p>
3929 *
3930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3931 * @param packageNames List of package names to keep cached.
3932 * @hide
3933 */
3934 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
3935 @NonNull List<String> packageNames) {
3936 if (mService != null) {
3937 try {
3938 mService.setKeepUninstalledPackages(admin, packageNames);
3939 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003940 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003941 }
3942 }
3943 }
3944
3945 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003946 * Called by a device owner to create a user with the specified name. The UserHandle returned
3947 * by this method should not be persisted as user handles are recycled as users are removed and
3948 * created. If you need to persist an identifier for this user, use
3949 * {@link UserManager#getSerialNumberForUser}.
3950 *
3951 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3952 * @param name the user's name
3953 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003954 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3955 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003956 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003957 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003958 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003959 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003960 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003961 try {
3962 return mService.createUser(admin, name);
3963 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003964 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04003965 }
3966 return null;
3967 }
3968
3969 /**
Jason Monk03978a42014-06-10 15:05:30 -04003970 * Called by a device owner to create a user with the specified name. The UserHandle returned
3971 * by this method should not be persisted as user handles are recycled as users are removed and
3972 * created. If you need to persist an identifier for this user, use
3973 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3974 * immediately.
3975 *
3976 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3977 * as registered as an active admin on the new user. The profile owner package will be
3978 * installed on the new user if it already is installed on the device.
3979 *
3980 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3981 * profileOwnerComponent when onEnable is called.
3982 *
3983 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3984 * @param name the user's name
3985 * @param ownerName the human readable name of the organisation associated with this DPM.
3986 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3987 * the user.
3988 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3989 * on the new user.
3990 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003991 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3992 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003993 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003994 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003995 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003996 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003997 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3998 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003999 try {
4000 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4001 adminExtras);
4002 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004003 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004004 }
4005 return null;
4006 }
4007
4008 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004009 * Called by a device owner to remove a user and all associated data. The primary user can
4010 * not be removed.
4011 *
4012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4013 * @param userHandle the user to remove.
4014 * @return {@code true} if the user was removed, {@code false} otherwise.
4015 */
Robin Lee25e26452015-06-02 09:56:29 -07004016 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004017 try {
4018 return mService.removeUser(admin, userHandle);
4019 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004020 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004021 return false;
4022 }
4023 }
4024
4025 /**
Jason Monk582d9112014-07-09 19:57:08 -04004026 * Called by a device owner to switch the specified user to the foreground.
4027 *
4028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4029 * @param userHandle the user to switch to; null will switch to primary.
4030 * @return {@code true} if the switch was successful, {@code false} otherwise.
4031 *
4032 * @see Intent#ACTION_USER_FOREGROUND
4033 */
Robin Lee25e26452015-06-02 09:56:29 -07004034 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004035 try {
4036 return mService.switchUser(admin, userHandle);
4037 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004038 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004039 return false;
4040 }
4041 }
4042
4043 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004044 * Retrieves the application restrictions for a given target application running in the calling
4045 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004046 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004047 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4048 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4049 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004050 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4052 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004053 * @param packageName The name of the package to fetch restricted settings of.
4054 * @return {@link Bundle} of settings corresponding to what was set last time
4055 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4056 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004057 *
4058 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004059 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004060 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004061 if (mService != null) {
4062 try {
4063 return mService.getApplicationRestrictions(admin, packageName);
4064 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004065 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004066 }
4067 }
4068 return null;
4069 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004070
4071 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004072 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004073 * <p>
4074 * The calling device admin must be a profile or device owner; if it is not,
4075 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004076 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004077 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4078 * with.
4079 * @param key The key of the restriction. See the constants in
4080 * {@link android.os.UserManager} for the list of keys.
4081 */
Robin Lee25e26452015-06-02 09:56:29 -07004082 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004083 if (mService != null) {
4084 try {
4085 mService.setUserRestriction(admin, key, true);
4086 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004087 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004088 }
4089 }
4090 }
4091
4092 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004093 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004094 * <p>
4095 * The calling device admin must be a profile or device owner; if it is not,
4096 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004097 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004098 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4099 * with.
4100 * @param key The key of the restriction. See the constants in
4101 * {@link android.os.UserManager} for the list of keys.
4102 */
Robin Lee25e26452015-06-02 09:56:29 -07004103 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004104 if (mService != null) {
4105 try {
4106 mService.setUserRestriction(admin, key, false);
4107 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004108 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004109 }
4110 }
4111 }
Adam Connors010cfd42014-04-16 12:48:13 +01004112
4113 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004114 * Called by a profile or device owner to get user restrictions set with
4115 * {@link #addUserRestriction(ComponentName, String)}.
4116 * <p>
4117 * The target user may have more restrictions set by the system or other device owner / profile
4118 * owner. To get all the user restrictions currently set, use
4119 * {@link UserManager#getUserRestrictions()}.
4120 *
4121 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004122 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004123 */
4124 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004125 return getUserRestrictions(admin, myUserId());
4126 }
4127
4128 /** @hide per-user version */
4129 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004130 Bundle ret = null;
4131 if (mService != null) {
4132 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004133 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004134 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004135 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004136 }
4137 }
4138 return ret == null ? new Bundle() : ret;
4139 }
4140
4141 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004142 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004143 * is unavailable for use, but the data and actual package file remain.
4144 *
4145 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004146 * @param packageName The name of the package to hide or unhide.
4147 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4148 * unhidden.
4149 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004150 */
Robin Lee25e26452015-06-02 09:56:29 -07004151 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004152 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004153 if (mService != null) {
4154 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004155 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004156 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004157 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004158 }
4159 }
4160 return false;
4161 }
4162
4163 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004164 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004165 *
4166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004167 * @param packageName The name of the package to retrieve the hidden status of.
4168 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004169 */
Robin Lee25e26452015-06-02 09:56:29 -07004170 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004171 if (mService != null) {
4172 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004173 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004174 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004175 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004176 }
4177 }
4178 return false;
4179 }
4180
4181 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004182 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004183 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004184 *
4185 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004186 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004187 */
Robin Lee25e26452015-06-02 09:56:29 -07004188 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004189 if (mService != null) {
4190 try {
4191 mService.enableSystemApp(admin, packageName);
4192 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004193 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004194 }
4195 }
4196 }
4197
4198 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004199 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004200 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004201 *
4202 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4203 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004204 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004205 * @return int The number of activities that matched the intent and were installed.
4206 */
Robin Lee25e26452015-06-02 09:56:29 -07004207 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004208 if (mService != null) {
4209 try {
4210 return mService.enableSystemAppWithIntent(admin, intent);
4211 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004212 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004213 }
4214 }
4215 return 0;
4216 }
4217
4218 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004219 * Called by a device owner or profile owner to disable account management for a specific type
4220 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004221 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004222 * <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 +01004223 * security exception will be thrown.
4224 *
4225 * <p>When account management is disabled for an account type, adding or removing an account
4226 * of that type will not be possible.
4227 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004228 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4229 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4230 * management for a specific type is disabled.
4231 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004232 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4233 * @param accountType For which account management is disabled or enabled.
4234 * @param disabled The boolean indicating that account management will be disabled (true) or
4235 * enabled (false).
4236 */
Robin Lee25e26452015-06-02 09:56:29 -07004237 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004238 boolean disabled) {
4239 if (mService != null) {
4240 try {
4241 mService.setAccountManagementDisabled(admin, accountType, disabled);
4242 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004243 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004244 }
4245 }
4246 }
4247
4248 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004249 * Gets the array of accounts for which account management is disabled by the profile owner.
4250 *
4251 * <p> Account management can be disabled/enabled by calling
4252 * {@link #setAccountManagementDisabled}.
4253 *
4254 * @return a list of account types for which account management has been disabled.
4255 *
4256 * @see #setAccountManagementDisabled
4257 */
4258 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004259 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004260 }
4261
4262 /**
4263 * @see #getAccountTypesWithManagementDisabled()
4264 * @hide
4265 */
4266 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004267 if (mService != null) {
4268 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004269 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004270 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004271 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004272 }
4273 }
4274
4275 return null;
4276 }
justinzhang511e0d82014-03-24 16:09:24 -04004277
4278 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004279 * Sets which packages may enter lock task mode.
4280 *
4281 * <p>Any packages that shares uid with an allowed package will also be allowed
4282 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004283 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004284 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004285 * package list results in locked tasks belonging to those packages to be finished.
4286 *
Jason Monkc5185f22014-06-24 11:12:42 -04004287 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004288 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004290 *
4291 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004292 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4293 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004294 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004295 */
Robin Lee25e26452015-06-02 09:56:29 -07004296 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004297 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004298 if (mService != null) {
4299 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004300 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004301 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004302 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004303 }
4304 }
4305 }
4306
4307 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004308 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004309 *
4310 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004311 * @hide
4312 */
Robin Lee25e26452015-06-02 09:56:29 -07004313 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004314 if (mService != null) {
4315 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004316 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004317 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004318 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004319 }
4320 }
4321 return null;
4322 }
4323
4324 /**
4325 * This function lets the caller know whether the given component is allowed to start the
4326 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004327 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004328 */
Jason Monkd7b86212014-06-16 13:15:38 -04004329 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004330 if (mService != null) {
4331 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004332 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004333 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004334 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004335 }
4336 }
4337 return false;
4338 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004339
4340 /**
4341 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4342 * 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 -04004343 * <p>The settings that can be updated with this method are:
4344 * <ul>
4345 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4346 * <li>{@link Settings.Global#AUTO_TIME}</li>
4347 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004348 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004349 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004350 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004351 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004352 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004353 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004354 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004355 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004356 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004357 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004358 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004359 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004360 * <ul>
4361 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4362 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4363 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4364 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4365 * <li>{@link Settings.Global#MODE_RINGER}.
4366 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4367 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4368 * <li>{@link Settings.Global#WIFI_ON}.
4369 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4370 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004371 *
4372 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4373 * @param setting The name of the setting to update.
4374 * @param value The value to update the setting to.
4375 */
Robin Lee25e26452015-06-02 09:56:29 -07004376 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004377 if (mService != null) {
4378 try {
4379 mService.setGlobalSetting(admin, setting, value);
4380 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004381 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004382 }
4383 }
4384 }
4385
4386 /**
4387 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4388 * that the value of the setting is in the correct form for the setting type should be performed
4389 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004390 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004391 * <ul>
4392 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004393 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004394 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4395 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004396 * <p>A device owner can additionally update the following settings:
4397 * <ul>
4398 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4399 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4401 * @param setting The name of the setting to update.
4402 * @param value The value to update the setting to.
4403 */
Robin Lee25e26452015-06-02 09:56:29 -07004404 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004405 if (mService != null) {
4406 try {
4407 mService.setSecureSetting(admin, setting, value);
4408 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004409 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004410 }
4411 }
4412 }
4413
Amith Yamasanif20d6402014-05-24 15:34:37 -07004414 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004415 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004416 * making permission requests of a local or remote administrator of the user.
4417 * <p/>
4418 * Only a profile owner can designate the restrictions provider.
4419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004420 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004421 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004422 * it removes the restrictions provider previously assigned.
4423 */
Robin Lee25e26452015-06-02 09:56:29 -07004424 public void setRestrictionsProvider(@NonNull ComponentName admin,
4425 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004426 if (mService != null) {
4427 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004428 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004429 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004430 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004431 }
4432 }
4433 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004434
4435 /**
4436 * Called by profile or device owners to set the master volume mute on or off.
4437 *
4438 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4439 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4440 */
Robin Lee25e26452015-06-02 09:56:29 -07004441 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004442 if (mService != null) {
4443 try {
4444 mService.setMasterVolumeMuted(admin, on);
4445 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004446 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004447 }
4448 }
4449 }
4450
4451 /**
4452 * Called by profile or device owners to check whether the master volume mute is on or off.
4453 *
4454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4455 * @return {@code true} if master volume is muted, {@code false} if it's not.
4456 */
Robin Lee25e26452015-06-02 09:56:29 -07004457 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004458 if (mService != null) {
4459 try {
4460 return mService.isMasterVolumeMuted(admin);
4461 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004462 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004463 }
4464 }
4465 return false;
4466 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004467
4468 /**
4469 * Called by profile or device owners to change whether a user can uninstall
4470 * a package.
4471 *
4472 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4473 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004474 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004475 */
Robin Lee25e26452015-06-02 09:56:29 -07004476 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004477 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004478 if (mService != null) {
4479 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004480 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004481 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004482 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004483 }
4484 }
4485 }
4486
4487 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004488 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004489 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004490 * <p>
4491 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004492 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004493 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004494 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004495 *
Robin Lee25e26452015-06-02 09:56:29 -07004496 * @param admin The name of the admin component whose blocking policy will be checked, or
4497 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004498 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004499 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004500 */
Robin Lee25e26452015-06-02 09:56:29 -07004501 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004502 if (mService != null) {
4503 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004504 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004505 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004506 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004507 }
4508 }
4509 return false;
4510 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004511
4512 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004513 * Called by the profile owner of a managed profile to enable widget providers from a
4514 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004515 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004516 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004517 * a package may have zero or more provider components, where each component
4518 * provides a different widget type.
4519 * <p>
4520 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004521 *
4522 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4523 * @param packageName The package from which widget providers are white-listed.
4524 * @return Whether the package was added.
4525 *
4526 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4527 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4528 */
Robin Lee25e26452015-06-02 09:56:29 -07004529 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004530 if (mService != null) {
4531 try {
4532 return mService.addCrossProfileWidgetProvider(admin, packageName);
4533 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004534 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004535 }
4536 }
4537 return false;
4538 }
4539
4540 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004541 * Called by the profile owner of a managed profile to disable widget providers from a given
4542 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004543 * package should have been added via {@link #addCrossProfileWidgetProvider(
4544 * android.content.ComponentName, String)}.
4545 * <p>
4546 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004547 *
4548 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4549 * @param packageName The package from which widget providers are no longer
4550 * white-listed.
4551 * @return Whether the package was removed.
4552 *
4553 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4554 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4555 */
Robin Lee25e26452015-06-02 09:56:29 -07004556 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004557 if (mService != null) {
4558 try {
4559 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4560 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004561 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004562 }
4563 }
4564 return false;
4565 }
4566
4567 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004568 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004569 * available in the parent profile.
4570 *
4571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4572 * @return The white-listed package list.
4573 *
4574 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4575 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4576 */
Robin Lee25e26452015-06-02 09:56:29 -07004577 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004578 if (mService != null) {
4579 try {
4580 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4581 if (providers != null) {
4582 return providers;
4583 }
4584 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004585 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004586 }
4587 }
4588 return Collections.emptyList();
4589 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004590
4591 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004592 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004593 *
4594 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4595 * @param icon the bitmap to set as the photo.
4596 */
Robin Lee25e26452015-06-02 09:56:29 -07004597 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004598 try {
4599 mService.setUserIcon(admin, icon);
4600 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004601 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004602 }
4603 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004604
4605 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004606 * Called by device owners to set a local system update policy. When a new policy is set,
4607 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004608 *
Robin Lee25e26452015-06-02 09:56:29 -07004609 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4610 * components in the device owner package can set system update policies and the
4611 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004612 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004613 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004614 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004615 */
Robin Lee25e26452015-06-02 09:56:29 -07004616 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004617 if (mService != null) {
4618 try {
Robin Lee25e26452015-06-02 09:56:29 -07004619 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004620 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004621 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004622 }
4623 }
4624 }
4625
4626 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004627 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004628 *
Robin Lee25e26452015-06-02 09:56:29 -07004629 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004630 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004631 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004632 if (mService != null) {
4633 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004634 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004635 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004636 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004637 }
4638 }
4639 return null;
4640 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004641
4642 /**
4643 * Called by a device owner to disable the keyguard altogether.
4644 *
4645 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4646 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4647 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4648 * being disabled.
4649 *
4650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004651 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004652 *
4653 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004654 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004655 */
Robin Lee25e26452015-06-02 09:56:29 -07004656 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004657 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004658 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004659 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004660 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01004661 return false;
4662 }
4663 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004664
4665 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004666 * Called by device owner to disable the status bar. Disabling the status bar blocks
4667 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004668 * a single use device.
4669 *
4670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004671 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4672 *
4673 * @return {@code false} if attempting to disable the status bar failed.
4674 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004675 */
Robin Lee25e26452015-06-02 09:56:29 -07004676 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004677 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004678 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004679 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004680 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004681 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004682 }
4683 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004684
4685 /**
4686 * Callable by the system update service to notify device owners about pending updates.
4687 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4688 * permission.
4689 *
4690 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4691 * when the current pending update was first available. -1 if no update is available.
4692 * @hide
4693 */
4694 @SystemApi
4695 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4696 if (mService != null) {
4697 try {
4698 mService.notifyPendingSystemUpdate(updateReceivedTime);
4699 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004700 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01004701 }
4702 }
4703 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004704
4705 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004706 * Called by profile or device owners to set the default response for future runtime permission
4707 * requests by applications. The policy can allow for normal operation which prompts the
4708 * user to grant a permission, or can allow automatic granting or denying of runtime
4709 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004710 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4711 * the permission grant state via {@link #setPermissionGrantState}.
4712 *
4713 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004714 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004715 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004716 * @param admin Which profile or device owner this request is associated with.
4717 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4718 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004719 *
4720 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004721 */
Robin Lee25e26452015-06-02 09:56:29 -07004722 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004723 try {
4724 mService.setPermissionPolicy(admin, policy);
4725 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004726 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004727 }
4728 }
4729
4730 /**
4731 * Returns the current runtime permission policy set by the device or profile owner. The
4732 * default is {@link #PERMISSION_POLICY_PROMPT}.
4733 * @param admin Which profile or device owner this request is associated with.
4734 * @return the current policy for future permission requests.
4735 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004736 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004737 try {
4738 return mService.getPermissionPolicy(admin);
4739 } catch (RemoteException re) {
4740 return PERMISSION_POLICY_PROMPT;
4741 }
4742 }
4743
4744 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004745 * Sets the grant state of a runtime permission for a specific application. The state
4746 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4747 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4748 * is denied and the user cannot manage it through the UI, and {@link
4749 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4750 * user cannot manage it through the UI. This might affect all permissions in a
4751 * group that the runtime permission belongs to. This method can only be called
4752 * by a profile or device owner.
4753 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004754 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4755 * revoke the permission. It retains the previous grant, if any.
4756 *
4757 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004758 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004759 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004760 * @param admin Which profile or device owner this request is associated with.
4761 * @param packageName The application to grant or revoke a permission to.
4762 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004763 * @param grantState The permission grant state which is one of {@link
4764 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4765 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4766 * @return whether the permission was successfully granted or revoked.
4767 *
4768 * @see #PERMISSION_GRANT_STATE_DENIED
4769 * @see #PERMISSION_GRANT_STATE_DEFAULT
4770 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004771 */
Robin Lee25e26452015-06-02 09:56:29 -07004772 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004773 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004774 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004775 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004776 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004777 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004778 return false;
4779 }
4780 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004781
4782 /**
4783 * Returns the current grant state of a runtime permission for a specific application.
4784 *
4785 * @param admin Which profile or device owner this request is associated with.
4786 * @param packageName The application to check the grant state for.
4787 * @param permission The permission to check for.
4788 * @return the current grant state specified by device policy. If the profile or device owner
4789 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4790 * This does not indicate whether or not the permission is currently granted for the package.
4791 *
4792 * <p/>If a grant state was set by the profile or device owner, then the return value will
4793 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4794 * which indicates if the permission is currently denied or granted.
4795 *
4796 * @see #setPermissionGrantState(ComponentName, String, String, int)
4797 * @see PackageManager#checkPermission(String, String)
4798 */
Robin Lee25e26452015-06-02 09:56:29 -07004799 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004800 String permission) {
4801 try {
4802 return mService.getPermissionGrantState(admin, packageName, permission);
4803 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004804 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07004805 return PERMISSION_GRANT_STATE_DEFAULT;
4806 }
4807 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004808
4809 /**
4810 * Returns if provisioning a managed profile or device is possible or not.
4811 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4812 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4813 * Note that even if this method returns true, there is a slight possibility that the
4814 * provisioning will not be allowed when it is actually initiated because some event has
4815 * happened in between.
4816 * @return if provisioning a managed profile or device is possible or not.
4817 * @throws IllegalArgumentException if the supplied action is not valid.
4818 */
4819 public boolean isProvisioningAllowed(String action) {
4820 try {
4821 return mService.isProvisioningAllowed(action);
4822 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004823 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004824 return false;
4825 }
4826 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004827
4828 /**
4829 * @hide
4830 * Return if this user is a managed profile of another user. An admin can become the profile
4831 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
4832 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
4833 * @param admin Which profile owner this request is associated with.
4834 * @return if this user is a managed profile of another user.
4835 */
4836 public boolean isManagedProfile(@NonNull ComponentName admin) {
4837 try {
4838 return mService.isManagedProfile(admin);
4839 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004840 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004841 return false;
4842 }
4843 }
4844
4845 /**
4846 * @hide
4847 * Return if this user is a system-only user. An admin can manage a device from a system only
4848 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
4849 * @param admin Which device owner this request is associated with.
4850 * @return if this user is a system-only user.
4851 */
4852 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
4853 try {
4854 return mService.isSystemOnlyUser(admin);
4855 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004856 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004857 return false;
4858 }
4859 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004860
4861 /**
4862 * Called by device owner to get the MAC address of the Wi-Fi device.
4863 *
4864 * @return the MAC address of the Wi-Fi device, or null when the information is not
4865 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
4866 *
4867 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
4868 */
4869 public String getWifiMacAddress() {
4870 try {
4871 return mService.getWifiMacAddress();
4872 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004873 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004874 return null;
4875 }
4876 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00004877
4878 /**
4879 * Called by device owner to reboot the device.
4880 */
4881 public void reboot(@NonNull ComponentName admin) {
4882 try {
4883 mService.reboot(admin);
4884 } catch (RemoteException re) {
4885 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4886 }
4887 }
Kenny Guy06de4e72015-12-22 12:07:39 +00004888
4889 /**
4890 * Called by a device admin to set the short support message. This will
4891 * be displayed to the user in settings screens where funtionality has
4892 * been disabled by the admin.
4893 *
4894 * The message should be limited to a short statement such as
4895 * "This setting is disabled by your administrator. Contact someone@example.com
4896 * for support."
4897 * If the message is longer than 200 characters it may be truncated.
4898 *
4899 * @see #setLongSupportMessage
4900 *
4901 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4902 * @param message Short message to be displayed to the user in settings or null to
4903 * clear the existing message.
4904 */
4905 public void setShortSupportMessage(@NonNull ComponentName admin,
4906 @Nullable String message) {
4907 if (mService != null) {
4908 try {
4909 mService.setShortSupportMessage(admin, message);
4910 } catch (RemoteException e) {
4911 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4912 }
4913 }
4914 }
4915
4916 /**
4917 * Called by a device admin to get the short support message.
4918 *
4919 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4920 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
4921 * or null if no message has been set.
4922 */
4923 public String getShortSupportMessage(@NonNull ComponentName admin) {
4924 if (mService != null) {
4925 try {
4926 return mService.getShortSupportMessage(admin);
4927 } catch (RemoteException e) {
4928 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4929 }
4930 }
4931 return null;
4932 }
4933
4934 /**
4935 * Called by a device admin to set the long support message. This will
4936 * be displayed to the user in the device administators settings screen.
4937 *
4938 * @see #setShortSupportMessage
4939 *
4940 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4941 * @param message Long message to be displayed to the user in settings or null to
4942 * clear the existing message.
4943 */
4944 public void setLongSupportMessage(@NonNull ComponentName admin,
4945 @Nullable String message) {
4946 if (mService != null) {
4947 try {
4948 mService.setLongSupportMessage(admin, message);
4949 } catch (RemoteException e) {
4950 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4951 }
4952 }
4953 }
4954
4955 /**
4956 * Called by a device admin to get the long support message.
4957 *
4958 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4959 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
4960 * or null if no message has been set.
4961 */
4962 public String getLongSupportMessage(@NonNull ComponentName admin) {
4963 if (mService != null) {
4964 try {
4965 return mService.getLongSupportMessage(admin);
4966 } catch (RemoteException e) {
4967 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4968 }
4969 }
4970 return null;
4971 }
4972
4973 /**
4974 * Called by the system to get the short support message.
4975 *
4976 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4977 * @param userHandle user id the admin is running as.
4978 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
4979 *
4980 * @hide
4981 */
4982 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
4983 if (mService != null) {
4984 try {
4985 return mService.getShortSupportMessageForUser(admin, userHandle);
4986 } catch (RemoteException e) {
4987 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4988 }
4989 }
4990 return null;
4991 }
4992
4993
4994 /**
4995 * Called by the system to get the long support message.
4996 *
4997 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4998 * @param userHandle user id the admin is running as.
4999 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5000 *
5001 * @hide
5002 */
5003 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5004 if (mService != null) {
5005 try {
5006 return mService.getLongSupportMessageForUser(admin, userHandle);
5007 } catch (RemoteException e) {
5008 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5009 }
5010 }
5011 return null;
5012 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005013
5014 /**
5015 * Obtains a {@link DevicePolicyManager} whose calls act on the parent profile.
5016 *
5017 * <p> Note only some methods will work on the parent Manager.
5018 *
5019 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5020 */
5021 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5022 try {
5023 if (!mService.isManagedProfile(admin)) {
5024 throw new SecurityException("The current user does not have a parent profile.");
5025 }
5026 return new DevicePolicyManager(mContext, true);
5027 } catch (RemoteException re) {
5028 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5029 return null;
5030 }
5031 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005032}