blob: ca5a923a6aaa3818b4d91778c65e9a0b8674433e [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000034import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010035import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070036import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000037import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080038import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070041import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040042import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000043import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000044import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010045import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070046import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080047import android.util.Log;
48
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070049import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040050import com.android.org.conscrypt.TrustedCertificateStore;
51
Jessica Hummel91da58d2014-04-10 17:39:43 +010052import org.xmlpull.v1.XmlPullParserException;
53
Maggie Benthallda51e682013-08-08 22:35:44 -040054import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080055import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070056import java.net.InetSocketAddress;
57import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010058import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000059import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010060import java.security.PrivateKey;
61import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040062import java.security.cert.CertificateException;
63import java.security.cert.CertificateFactory;
64import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010065import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000066import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070067import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070068import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080069import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080070
71/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000072 * Public interface for managing policies enforced on a device. Most clients of this class must be
73 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000074 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000075 * a device administrator may be registered as either a profile or device owner. A given method is
76 * accessible to all device administrators unless the documentation for that method specifies that
77 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080078 *
79 * <div class="special reference">
80 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000081 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070083 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080084 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080085 */
86public class DevicePolicyManager {
87 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080088
89 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 private final IDevicePolicyManager mService;
Clara Bayarri3e826ef2015-12-14 17:51:22 +000091 private boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070092
Makoto Onukic8a5a552015-11-19 14:29:12 -080093 private static final String REMOTE_EXCEPTION_MESSAGE =
94 "Failed to talk with device policy manager service";
95
Clara Bayarri3e826ef2015-12-14 17:51:22 +000096 private DevicePolicyManager(Context context, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070097 this(context, IDevicePolicyManager.Stub.asInterface(
98 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Clara Bayarri3e826ef2015-12-14 17:51:22 +000099 mParentInstance = parentInstance;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 }
101
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800102 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700103 @VisibleForTesting
104 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
105 mContext = context;
106 mService = service;
107 }
108
109 /** @hide */
110 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000111 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800112 return me.mService != null ? me : null;
113 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700114
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700115 /** @hide test will override it. */
116 @VisibleForTesting
117 protected int myUserId() {
118 return UserHandle.myUserId();
119 }
120
Dianne Hackbornd6847842010-01-12 18:14:19 -0800121 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000122 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000123 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100124 * <p>A managed profile allows data separation for example for the usage of a
125 * device as a personal and corporate device. The user which provisioning is started from and
126 * the managed profile share a launcher.
127 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800128 * <p>This intent will typically be sent by a mobile device management application (MDM).
129 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
130 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100131 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000132 * <p>It is possible to check if provisioning is allowed or not by querying the method
133 * {@link #isProvisioningAllowed(String)}.
134 *
135 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000136 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700137 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000138 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
139 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000140 *
141 * <p> The intent may also contain the following extras:
142 * <ul>
143 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
144 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
145 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000146 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000147 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
148 * in the provisioning intent. The
149 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
150 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
151 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100152 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100153 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
154 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100155 *
156 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
157 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
158 * the provisioning flow was successful, although this doesn't guarantee the full flow will
159 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
160 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000161 */
162 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
163 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100164 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000165
166 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000167 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000168 * Activity action: Starts the provisioning flow which sets up a managed user.
169 *
170 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800171 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000172 * owner who has full control over the user. Provisioning can only happen before user setup has
173 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
174 * allowed.
175 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000176 * <p>This intent should contain the extra
177 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000178 *
179 * <p> If provisioning fails, the device returns to its previous state.
180 *
181 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
182 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
183 * the provisioning flow was successful, although this doesn't guarantee the full flow will
184 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
185 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000186 */
187 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
188 public static final String ACTION_PROVISION_MANAGED_USER
189 = "android.app.action.PROVISION_MANAGED_USER";
190
191 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100192 * Activity action: Starts the provisioning flow which sets up a managed device.
193 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
194 *
195 * <p> During device owner provisioning a device admin app is set as the owner of the device.
196 * A device owner has full control over the device. The device owner can not be modified by the
197 * user.
198 *
199 * <p> A typical use case would be a device that is owned by a company, but used by either an
200 * employee or client.
201 *
202 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000203 * It is possible to check if provisioning is allowed or not by querying the method
204 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100205 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000206 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100207 * <ul>
208 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
209 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
210 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100211 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000212 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000213 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100214 * </ul>
215 *
216 * <p> When device owner provisioning has completed, an intent of the type
217 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
218 * device owner.
219 *
220 * <p> If provisioning fails, the device is factory reset.
221 *
Alan Treadway4582f812015-07-28 11:49:35 +0100222 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
223 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
224 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
225 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100226 */
227 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
228 public static final String ACTION_PROVISION_MANAGED_DEVICE
229 = "android.app.action.PROVISION_MANAGED_DEVICE";
230
231 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000232 * Activity action: Starts the provisioning flow which sets up a managed device.
233 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
234 *
235 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
236 * management state that is distinct from that reached by
237 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
238 * user, and only has control over device-wide policies, not individual users and their data.
239 * The primary benefit is that multiple non-system users are supported when provisioning using
240 * this form of device management.
241 *
242 * <p> During device owner provisioning a device admin app is set as the owner of the device.
243 * A device owner has full control over the device. The device owner can not be modified by the
244 * user.
245 *
246 * <p> A typical use case would be a device that is owned by a company, but used by either an
247 * employee or client.
248 *
249 * <p> An intent with this action can be sent only on an unprovisioned device.
250 * It is possible to check if provisioning is allowed or not by querying the method
251 * {@link #isProvisioningAllowed(String)}.
252 *
253 * <p>The intent contains the following extras:
254 * <ul>
255 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
256 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
257 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
258 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
259 * </ul>
260 *
261 * <p> When device owner provisioning has completed, an intent of the type
262 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
263 * device owner.
264 *
265 * <p> If provisioning fails, the device is factory reset.
266 *
267 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
268 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
269 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
270 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
271 *
272 * @hide
273 */
274 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
275 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
276 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
277
278 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100279 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100280 * allows a mobile device management application or NFC programmer application which starts
281 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100282 * <p>
283 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
284 * sends the intent to pass data to itself on the newly created profile.
285 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
286 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100287 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
288 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
289 * message should contain a stringified {@link java.util.Properties} instance, whose string
290 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
291 * management application after provisioning.
292 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100293 * <p>
294 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700295 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
296 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100297 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100298 */
299 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100300 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100301
302 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100303 * A String extra holding the package name of the mobile device management application that
304 * will be set as the profile owner or device owner.
305 *
306 * <p>If an application starts provisioning directly via an intent with action
307 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
308 * application that started provisioning. The package will be set as profile owner in that case.
309 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000310 * <p>This package is set as device owner when device owner provisioning is started by an NFC
311 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000312 *
313 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700314 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000315
316 * @see DeviceAdminReceiver
317 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100318 * supported, but only if there is only one device admin receiver in the package that requires
319 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000320 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000321 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000322 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100323 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000324
325 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000326 * A ComponentName extra indicating the device admin receiver of the mobile device management
327 * application that will be set as the profile owner or device owner and active admin.
328 *
329 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100330 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
331 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
332 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000333 *
334 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100335 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
336 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400337 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000338 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000339 *
340 * @see DeviceAdminReceiver
341 */
342 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
343 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
344
345 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000346 * An {@link android.accounts.Account} extra holding the account to migrate during managed
347 * profile provisioning. If the account supplied is present in the primary user, it will be
348 * copied, along with its credentials to the managed profile and removed from the primary user.
349 *
350 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
351 */
352
353 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
354 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
355
356 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100357 * A String extra that, holds the email address of the account which a managed profile is
358 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
359 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100360 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100361 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
362 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100363 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
364 * contains this extra, it is forwarded in the
365 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
366 * device management application that was set as the profile owner during provisioning.
367 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100368 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100369 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
370 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100371
372 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000373 * A integer extra indicating the predominant color to show during the provisioning.
374 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000375 *
376 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
377 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
378 */
379 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
380 "android.app.extra.PROVISIONING_MAIN_COLOR";
381
382 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000383 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700384 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000385 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100386 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
387 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000388 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000389 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
390 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000391
392 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100393 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
394 * will be set to.
395 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000396 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
397 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100398 */
399 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100400 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100401
402 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100403 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
404 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100405 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000406 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
407 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100408 */
409 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100410 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100411
412 /**
413 * A String extra holding the {@link java.util.Locale} that the device will be set to.
414 * Format: xx_yy, where xx is the language code, and yy the country code.
415 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000416 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
417 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100418 */
419 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100420 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100421
422 /**
423 * A String extra holding the ssid of the wifi network that should be used during nfc device
424 * owner provisioning for downloading the mobile device management application.
425 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000426 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
427 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100428 */
429 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100430 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100431
432 /**
433 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
434 * is hidden or not.
435 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000436 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
437 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100438 */
439 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100440 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100441
442 /**
443 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100444 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
445 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100446 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000447 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
448 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100449 */
450 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100451 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100452
453 /**
454 * A String extra holding the password of the wifi network in
455 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
456 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000457 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
458 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100459 */
460 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100461 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100462
463 /**
464 * A String extra holding the proxy host for the wifi network in
465 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
466 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000467 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
468 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100469 */
470 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100471 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100472
473 /**
474 * An int extra holding the proxy port for the wifi network in
475 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
476 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000477 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
478 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100479 */
480 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100481 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100482
483 /**
484 * A String extra holding the proxy bypass for the wifi network in
485 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
486 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000487 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
488 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100489 */
490 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100491 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100492
493 /**
494 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
495 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
496 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000497 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
498 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100499 */
500 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100501 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100502
503 /**
504 * A String extra holding a url that specifies the download location of the device admin
505 * package. When not provided it is assumed that the device admin package is already installed.
506 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000507 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
508 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509 */
510 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100511 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100512
513 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400514 * An int extra holding a minimum required version code for the device admin package. If the
515 * device admin is already installed on the device, it will only be re-downloaded from
516 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
517 * installed package is less than this version code.
518 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400519 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400520 * provisioning via an NFC bump.
521 */
522 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
523 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
524
525 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100526 * A String extra holding a http cookie header which should be used in the http request to the
527 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
528 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000529 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
530 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100531 */
532 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100533 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100534
535 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100536 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
537 * the file at download location specified in
538 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100539 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100540 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100541 * present. The provided checksum should match the checksum of the file at the download
542 * location. If the checksum doesn't match an error will be shown to the user and the user will
543 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100544 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
546 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100547 *
548 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
549 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700550 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100551 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100552 */
553 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100554 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100555
556 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100557 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100558 * android package archive at the download location specified in {@link
559 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
560 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100561 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100562 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
563 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
564 *
565 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100566 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100567 * the download location. If the checksum does not match an error will be shown to the user and
568 * the user will be asked to factory reset the device.
569 *
570 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
571 * provisioning via an NFC bump.
572 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100573 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
574 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100575
576 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000577 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
578 * has completed successfully.
579 *
580 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700581 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000582 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800583 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000584 * corresponds to the account requested to be migrated at provisioning time, if any.
585 */
586 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
587 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
588 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
589
590 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400591 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500592 * provisioning.
593 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400594 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100595 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500596 */
597 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
598 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
599
600 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000601 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
602 * provisioning. If this extra is not passed, a default image will be shown.
603 * <h5>The following URI schemes are accepted:</h5>
604 * <ul>
605 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
606 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
607 * </ul>
608 *
609 * <p> It is the responsability of the caller to provide an image with a reasonable
610 * pixed density for the device.
611 *
612 * <p> If a content: URI is passed, the intent should have the flag
613 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
614 * {@link android.content.ClipData} of the intent too.
615 *
616 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
617 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
618 */
619 public static final String EXTRA_PROVISIONING_LOGO_URI =
620 "android.app.extra.PROVISIONING_LOGO_URI";
621
622 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000623 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
624 * during setup-wizard.
625 *
626 * <p>If unspecified, defaults to {@code true} to match the behavior in
627 * {@link android.os.Build.VERSION_CODES#M} and earlier.
628 *
629 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE},
630 * {@link #ACTION_PROVISION_MANAGED_DEVICE} or {@link #ACTION_PROVISION_MANAGED_USER}.
631 *
632 * @hide
633 */
634 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
635 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
636
637 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400638 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100639 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400640 * <p>During device owner provisioning a device admin app is set as the owner of the device.
641 * A device owner has full control over the device. The device owner can not be modified by the
642 * user and the only way of resetting the device is if the device owner app calls a factory
643 * reset.
644 *
645 * <p> A typical use case would be a device that is owned by a company, but used by either an
646 * employee or client.
647 *
648 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100649 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000650 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100651 * contains the following properties:
652 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400653 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
654 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100655 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400656 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100657 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
658 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
659 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
660 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
661 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
662 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
663 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
664 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
665 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
666 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100667 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
668 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
669 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100670 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000671 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700672 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400673 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
674 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
675 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400676 */
677 public static final String MIME_TYPE_PROVISIONING_NFC
678 = "application/com.android.managedprovisioning";
679
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100680 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800681 * Activity action: ask the user to add a new device administrator to the system.
682 * The desired policy is the ComponentName of the policy in the
683 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
684 * bring the user through adding the device administrator to the system (or
685 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700686 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800687 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
688 * field to provide the user with additional explanation (in addition
689 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800690 *
691 * <p>If your administrator is already active, this will ordinarily return immediately (without
692 * user intervention). However, if your administrator has been updated and is requesting
693 * additional uses-policy flags, the user will be presented with the new list. New policies
694 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800695 */
696 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
697 public static final String ACTION_ADD_DEVICE_ADMIN
698 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700699
Dianne Hackbornd6847842010-01-12 18:14:19 -0800700 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700701 * @hide
702 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700703 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700704 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700705 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
706 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700707 * to remotely control restrictions on the user.
708 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800709 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700710 * result of whether or not the user approved the action. If approved, the result will
711 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
712 * as a profile owner.
713 *
714 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
715 * field to provide the user with additional explanation (in addition
716 * to your component's description) about what is being added.
717 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700718 * <p>If there is already a profile owner active or the caller is not a system app, the
719 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700720 */
721 @SystemApi
722 public static final String ACTION_SET_PROFILE_OWNER
723 = "android.app.action.SET_PROFILE_OWNER";
724
725 /**
726 * @hide
727 * Name of the profile owner admin that controls the user.
728 */
729 @SystemApi
730 public static final String EXTRA_PROFILE_OWNER_NAME
731 = "android.app.extra.PROFILE_OWNER_NAME";
732
733 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100734 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700735 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700736 *
Jim Miller284b62e2010-06-08 14:27:42 -0700737 * @hide
738 */
739 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
740 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
741
742 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100743 * Broadcast action: sent when the device owner is set or changed.
744 *
745 * This broadcast is sent only to the primary user.
746 * @see #ACTION_PROVISION_MANAGED_DEVICE
747 */
748 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
749 public static final String ACTION_DEVICE_OWNER_CHANGED
750 = "android.app.action.DEVICE_OWNER_CHANGED";
751
752 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800753 * The ComponentName of the administrator component.
754 *
755 * @see #ACTION_ADD_DEVICE_ADMIN
756 */
757 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700758
Dianne Hackbornd6847842010-01-12 18:14:19 -0800759 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800760 * An optional CharSequence providing additional explanation for why the
761 * admin is being added.
762 *
763 * @see #ACTION_ADD_DEVICE_ADMIN
764 */
765 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700766
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800767 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700768 * Activity action: have the user enter a new password. This activity should
769 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
770 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
771 * enter a new password that meets the current requirements. You can use
772 * {@link #isActivePasswordSufficient()} to determine whether you need to
773 * have the user select a new password in order to meet the current
774 * constraints. Upon being resumed from this activity, you can check the new
775 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800776 */
777 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
778 public static final String ACTION_SET_NEW_PASSWORD
779 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700780
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000781 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000782 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
783 * the parent profile to access intents sent from the managed profile.
784 * That is, when an app in the managed profile calls
785 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
786 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000787 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100788 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000789
790 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000791 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
792 * the managed profile to access intents sent from the parent profile.
793 * That is, when an app in the parent profile calls
794 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
795 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000796 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100797 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700798
Dianne Hackbornd6847842010-01-12 18:14:19 -0800799 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100800 * Broadcast action: notify that a new local system update policy has been set by the device
801 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000802 */
803 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100804 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
805 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000806
Amith Yamasanid49489b2015-04-28 14:00:26 -0700807 /**
808 * Permission policy to prompt user for new permission requests for runtime permissions.
809 * Already granted or denied permissions are not affected by this.
810 */
811 public static final int PERMISSION_POLICY_PROMPT = 0;
812
813 /**
814 * Permission policy to always grant new permission requests for runtime permissions.
815 * Already granted or denied permissions are not affected by this.
816 */
817 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
818
819 /**
820 * Permission policy to always deny new permission requests for runtime permissions.
821 * Already granted or denied permissions are not affected by this.
822 */
823 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
824
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700825 /**
826 * Runtime permission state: The user can manage the permission
827 * through the UI.
828 */
829 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
830
831 /**
832 * Runtime permission state: The permission is granted to the app
833 * and the user cannot manage the permission through the UI.
834 */
835 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
836
837 /**
838 * Runtime permission state: The permission is denied to the app
839 * and the user cannot manage the permission through the UI.
840 */
841 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000842
843 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800844 * Return true if the given administrator component is currently
845 * active (enabled) in the system.
846 */
Robin Lee25e26452015-06-02 09:56:29 -0700847 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700848 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100849 }
850
851 /**
852 * @see #isAdminActive(ComponentName)
853 * @hide
854 */
Robin Lee25e26452015-06-02 09:56:29 -0700855 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800856 if (mService != null) {
857 try {
Robin Lee25e26452015-06-02 09:56:29 -0700858 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800859 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800860 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800861 }
862 }
863 return false;
864 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800865 /**
866 * Return true if the given administrator component is currently being removed
867 * for the user.
868 * @hide
869 */
Robin Lee25e26452015-06-02 09:56:29 -0700870 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800871 if (mService != null) {
872 try {
Robin Lee25e26452015-06-02 09:56:29 -0700873 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800874 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800875 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800876 }
877 }
878 return false;
879 }
880
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700881
Dianne Hackbornd6847842010-01-12 18:14:19 -0800882 /**
Robin Lee25e26452015-06-02 09:56:29 -0700883 * Return a list of all currently active device administrators' component
884 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800885 * returned.
886 */
887 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700888 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100889 }
890
891 /**
892 * @see #getActiveAdmins()
893 * @hide
894 */
895 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800896 if (mService != null) {
897 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100898 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800899 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800900 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800901 }
902 }
903 return null;
904 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700905
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800906 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700907 * Used by package administration code to determine if a package can be stopped
908 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800909 * @hide
910 */
911 public boolean packageHasActiveAdmins(String packageName) {
912 if (mService != null) {
913 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700914 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800915 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800916 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800917 }
918 }
919 return false;
920 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700921
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800922 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800923 * Remove a current administration component. This can only be called
924 * by the application that owns the administration component; if you
925 * try to remove someone else's component, a security exception will be
926 * thrown.
927 */
Robin Lee25e26452015-06-02 09:56:29 -0700928 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800929 if (mService != null) {
930 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700931 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800932 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800933 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800934 }
935 }
936 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700937
Dianne Hackbornd6847842010-01-12 18:14:19 -0800938 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800939 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700940 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800941 * but requires additional policies after an upgrade.
942 *
943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
944 * an active administrator, or an exception will be thrown.
945 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
946 */
Robin Lee25e26452015-06-02 09:56:29 -0700947 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800948 if (mService != null) {
949 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700950 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800951 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800952 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800953 }
954 }
955 return false;
956 }
957
958 /**
Clara Bayarria1771112015-12-18 16:29:18 +0000959 * Returns true if the Profile Challenge is available to use for the given profile user.
960 *
961 * @hide
962 */
963 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
964 if (mService != null) {
965 try {
966 return mService.isSeparateProfileChallengeAllowed(userHandle);
967 } catch (RemoteException e) {
968 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
969 }
970 }
971 return false;
972 }
973
974 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800975 * Constant for {@link #setPasswordQuality}: the policy has no requirements
976 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800977 * 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_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700980
Dianne Hackbornd6847842010-01-12 18:14:19 -0800981 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700982 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
983 * recognition technology. This implies technologies that can recognize the identity of
984 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
985 * Note that quality constants are ordered so that higher values are more restrictive.
986 */
987 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
988
989 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800990 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100991 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800992 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800993 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800994 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700995
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800996 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800997 * Constant for {@link #setPasswordQuality}: the user must have entered a
998 * password containing at least numeric characters. Note that quality
999 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001000 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001001 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001002
Dianne Hackbornd6847842010-01-12 18:14:19 -08001003 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001004 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001005 * password containing at least numeric characters with no repeating (4444)
1006 * or ordered (1234, 4321, 2468) sequences. Note that quality
1007 * constants are ordered so that higher values are more restrictive.
1008 */
1009 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1010
1011 /**
1012 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001013 * password containing at least alphabetic (or other symbol) characters.
1014 * Note that quality constants are ordered so that higher values are more
1015 * restrictive.
1016 */
1017 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001018
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001019 /**
1020 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001021 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001022 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001023 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001024 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001025 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001026
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001028 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001029 * password containing at least a letter, a numerical digit and a special
1030 * symbol, by default. With this password quality, passwords can be
1031 * restricted to contain various sets of characters, like at least an
1032 * uppercase letter, etc. These are specified using various methods,
1033 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1034 * that quality constants are ordered so that higher values are more
1035 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001036 */
1037 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1038
1039 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001040 * Called by an application that is administering the device to set the
1041 * password restrictions it is imposing. After setting this, the user
1042 * will not be able to enter a new password that is not at least as
1043 * restrictive as what has been set. Note that the current password
1044 * will remain until the user has set a new one, so the change does not
1045 * take place immediately. To prompt the user for a new password, use
1046 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001047 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001048 * <p>Quality constants are ordered so that higher values are more restrictive;
1049 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001050 * the user's preference, and any other considerations) is the one that
1051 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001052 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001053 * <p>The calling device admin must have requested
1054 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1055 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001056 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001057 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001058 * @param quality The new desired quality. One of
1059 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001060 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1061 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1062 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001063 */
Robin Lee25e26452015-06-02 09:56:29 -07001064 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001065 if (mService != null) {
1066 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001067 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001068 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001069 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001070 }
1071 }
1072 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001073
Dianne Hackbornd6847842010-01-12 18:14:19 -08001074 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001075 * Retrieve the current minimum password quality for all admins of this user
1076 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001077 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001078 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 */
Robin Lee25e26452015-06-02 09:56:29 -07001080 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001081 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001082 }
1083
1084 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001085 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001086 if (mService != null) {
1087 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001088 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001089 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001090 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001091 }
1092 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001093 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001094 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001095
Dianne Hackbornd6847842010-01-12 18:14:19 -08001096 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001097 * Called by an application that is administering the device to set the
1098 * minimum allowed password length. After setting this, the user
1099 * will not be able to enter a new password that is not at least as
1100 * restrictive as what has been set. Note that the current password
1101 * will remain until the user has set a new one, so the change does not
1102 * take place immediately. To prompt the user for a new password, use
1103 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1104 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001105 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1106 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1107 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001108 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001109 * <p>The calling device admin must have requested
1110 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1111 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001112 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001114 * @param length The new desired minimum password length. A value of 0
1115 * means there is no restriction.
1116 */
Robin Lee25e26452015-06-02 09:56:29 -07001117 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001118 if (mService != null) {
1119 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001120 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001121 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001122 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001123 }
1124 }
1125 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001126
Dianne Hackbornd6847842010-01-12 18:14:19 -08001127 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001128 * Retrieve the current minimum password length for all admins of this
1129 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001130 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001131 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001132 */
Robin Lee25e26452015-06-02 09:56:29 -07001133 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001134 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001135 }
1136
1137 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001138 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001139 if (mService != null) {
1140 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001141 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001142 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001143 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001144 }
1145 }
1146 return 0;
1147 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001148
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001149 /**
1150 * Called by an application that is administering the device to set the
1151 * minimum number of upper case letters required in the password. After
1152 * setting this, the user will not be able to enter a new password that is
1153 * not at least as restrictive as what has been set. Note that the current
1154 * password will remain until the user has set a new one, so the change does
1155 * not take place immediately. To prompt the user for a new password, use
1156 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1157 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001158 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1159 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001160 * <p>
1161 * The calling device admin must have requested
1162 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1163 * this method; if it has not, a security exception will be thrown.
1164 *
1165 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1166 * with.
1167 * @param length The new desired minimum number of upper case letters
1168 * required in the password. A value of 0 means there is no
1169 * restriction.
1170 */
Robin Lee25e26452015-06-02 09:56:29 -07001171 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001172 if (mService != null) {
1173 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001174 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001175 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001176 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001177 }
1178 }
1179 }
1180
1181 /**
1182 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001183 * password for all admins of this user and its profiles or a particular one.
1184 * This is the same value as set by
1185 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001186 * and only applies when the password quality is
1187 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 *
Robin Lee25e26452015-06-02 09:56:29 -07001189 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001190 * aggregate all admins.
1191 * @return The minimum number of upper case letters required in the
1192 * password.
1193 */
Robin Lee25e26452015-06-02 09:56:29 -07001194 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001195 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001196 }
1197
1198 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001199 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001200 if (mService != null) {
1201 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001202 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001203 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001204 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001205 }
1206 }
1207 return 0;
1208 }
1209
1210 /**
1211 * Called by an application that is administering the device to set the
1212 * minimum number of lower case letters required in the password. After
1213 * setting this, the user will not be able to enter a new password that is
1214 * not at least as restrictive as what has been set. Note that the current
1215 * password will remain until the user has set a new one, so the change does
1216 * not take place immediately. To prompt the user for a new password, use
1217 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1218 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001219 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1220 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001221 * <p>
1222 * The calling device admin must have requested
1223 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1224 * this method; if it has not, a security exception will be thrown.
1225 *
1226 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1227 * with.
1228 * @param length The new desired minimum number of lower case letters
1229 * required in the password. A value of 0 means there is no
1230 * restriction.
1231 */
Robin Lee25e26452015-06-02 09:56:29 -07001232 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001233 if (mService != null) {
1234 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001235 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001236 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001237 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001238 }
1239 }
1240 }
1241
1242 /**
1243 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001244 * password for all admins of this user and its profiles or a particular one.
1245 * This is the same value as set by
1246 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001247 * and only applies when the password quality is
1248 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001249 *
Robin Lee25e26452015-06-02 09:56:29 -07001250 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001251 * aggregate all admins.
1252 * @return The minimum number of lower case letters required in the
1253 * password.
1254 */
Robin Lee25e26452015-06-02 09:56:29 -07001255 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001256 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001257 }
1258
1259 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001260 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001261 if (mService != null) {
1262 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001263 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001264 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001265 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001266 }
1267 }
1268 return 0;
1269 }
1270
1271 /**
1272 * Called by an application that is administering the device to set the
1273 * minimum number of letters required in the password. After setting this,
1274 * the user will not be able to enter a new password that is not at least as
1275 * restrictive as what has been set. Note that the current password will
1276 * remain until the user has set a new one, so the change does not take
1277 * place immediately. To prompt the user for a new password, use
1278 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1279 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001280 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1281 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001282 * <p>
1283 * The calling device admin must have requested
1284 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1285 * this method; if it has not, a security exception will be thrown.
1286 *
1287 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1288 * with.
1289 * @param length The new desired minimum number of letters required in the
1290 * password. A value of 0 means there is no restriction.
1291 */
Robin Lee25e26452015-06-02 09:56:29 -07001292 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001293 if (mService != null) {
1294 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001295 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001296 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001297 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001298 }
1299 }
1300 }
1301
1302 /**
1303 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001304 * admins or a particular one. This is the same value as
1305 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1306 * and only applies when the password quality is
1307 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001308 *
Robin Lee25e26452015-06-02 09:56:29 -07001309 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001310 * aggregate all admins.
1311 * @return The minimum number of letters required in the password.
1312 */
Robin Lee25e26452015-06-02 09:56:29 -07001313 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001314 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001315 }
1316
1317 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001318 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001319 if (mService != null) {
1320 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001321 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001322 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001323 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001324 }
1325 }
1326 return 0;
1327 }
1328
1329 /**
1330 * Called by an application that is administering the device to set the
1331 * minimum number of numerical digits required in the password. After
1332 * setting this, the user will not be able to enter a new password that is
1333 * not at least as restrictive as what has been set. Note that the current
1334 * password will remain until the user has set a new one, so the change does
1335 * not take place immediately. To prompt the user for a new password, use
1336 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1337 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001338 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1339 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001340 * <p>
1341 * The calling device admin must have requested
1342 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1343 * this method; if it has not, a security exception will be thrown.
1344 *
1345 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1346 * with.
1347 * @param length The new desired minimum number of numerical digits required
1348 * in the password. A value of 0 means there is no restriction.
1349 */
Robin Lee25e26452015-06-02 09:56:29 -07001350 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001351 if (mService != null) {
1352 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001353 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001354 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001355 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001356 }
1357 }
1358 }
1359
1360 /**
1361 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001362 * for all admins of this user and its profiles or a particular one.
1363 * This is the same value as set by
1364 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001365 * and only applies when the password quality is
1366 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001367 *
Robin Lee25e26452015-06-02 09:56:29 -07001368 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001369 * aggregate all admins.
1370 * @return The minimum number of numerical digits required in the password.
1371 */
Robin Lee25e26452015-06-02 09:56:29 -07001372 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001373 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001374 }
1375
1376 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001377 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001378 if (mService != null) {
1379 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001380 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001381 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001382 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001383 }
1384 }
1385 return 0;
1386 }
1387
1388 /**
1389 * Called by an application that is administering the device to set the
1390 * minimum number of symbols required in the password. After setting this,
1391 * the user will not be able to enter a new password that is not at least as
1392 * restrictive as what has been set. Note that the current password will
1393 * remain until the user has set a new one, so the change does not take
1394 * place immediately. To prompt the user for a new password, use
1395 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1396 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001397 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1398 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001399 * <p>
1400 * The calling device admin must have requested
1401 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1402 * this method; if it has not, a security exception will be thrown.
1403 *
1404 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1405 * with.
1406 * @param length The new desired minimum number of symbols required in the
1407 * password. A value of 0 means there is no restriction.
1408 */
Robin Lee25e26452015-06-02 09:56:29 -07001409 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001410 if (mService != null) {
1411 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001412 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001413 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001414 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001415 }
1416 }
1417 }
1418
1419 /**
1420 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001421 * admins or a particular one. This is the same value as
1422 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1423 * and only applies when the password quality is
1424 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001425 *
Robin Lee25e26452015-06-02 09:56:29 -07001426 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001427 * aggregate all admins.
1428 * @return The minimum number of symbols required in the password.
1429 */
Robin Lee25e26452015-06-02 09:56:29 -07001430 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001431 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001432 }
1433
1434 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001435 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001436 if (mService != null) {
1437 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001438 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001439 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001440 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001441 }
1442 }
1443 return 0;
1444 }
1445
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001446 /**
1447 * Called by an application that is administering the device to set the
1448 * minimum number of non-letter characters (numerical digits or symbols)
1449 * required in the password. After setting this, the user will not be able
1450 * to enter a new password that is not at least as restrictive as what has
1451 * been set. Note that the current password will remain until the user has
1452 * set a new one, so the change does not take place immediately. To prompt
1453 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1454 * setting this value. This constraint is only imposed if the administrator
1455 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1456 * {@link #setPasswordQuality}. The default value is 0.
1457 * <p>
1458 * The calling device admin must have requested
1459 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1460 * this method; if it has not, a security exception will be thrown.
1461 *
1462 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1463 * with.
1464 * @param length The new desired minimum number of letters required in the
1465 * password. A value of 0 means there is no restriction.
1466 */
Robin Lee25e26452015-06-02 09:56:29 -07001467 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001468 if (mService != null) {
1469 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001470 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001471 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001472 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001473 }
1474 }
1475 }
1476
1477 /**
1478 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001479 * password for all admins of this user and its profiles or a particular one.
1480 * This is the same value as set by
1481 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001482 * and only applies when the password quality is
1483 * {@link #PASSWORD_QUALITY_COMPLEX}.
1484 *
Robin Lee25e26452015-06-02 09:56:29 -07001485 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001486 * aggregate all admins.
1487 * @return The minimum number of letters required in the password.
1488 */
Robin Lee25e26452015-06-02 09:56:29 -07001489 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001490 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001491 }
1492
1493 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001494 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001495 if (mService != null) {
1496 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001497 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001498 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001499 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001500 }
1501 }
1502 return 0;
1503 }
1504
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001505 /**
1506 * Called by an application that is administering the device to set the length
1507 * of the password history. After setting this, the user will not be able to
1508 * enter a new password that is the same as any password in the history. Note
1509 * that the current password will remain until the user has set a new one, so
1510 * the change does not take place immediately. To prompt the user for a new
1511 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1512 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001513 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1514 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1515 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001516 *
1517 * <p>
1518 * The calling device admin must have requested
1519 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1520 * method; if it has not, a security exception will be thrown.
1521 *
1522 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1523 * with.
1524 * @param length The new desired length of password history. A value of 0
1525 * means there is no restriction.
1526 */
Robin Lee25e26452015-06-02 09:56:29 -07001527 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001528 if (mService != null) {
1529 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001530 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001531 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001532 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001533 }
1534 }
1535 }
1536
1537 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001538 * Called by a device admin to set the password expiration timeout. Calling this method
1539 * will restart the countdown for password expiration for the given admin, as will changing
1540 * the device password (for all admins).
1541 *
1542 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1543 * For example, to have the password expire 5 days from now, timeout would be
1544 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1545 *
1546 * <p>To disable password expiration, a value of 0 may be used for timeout.
1547 *
Jim Millera4e28d12010-11-08 16:15:47 -08001548 * <p>The calling device admin must have requested
1549 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1550 * method; if it has not, a security exception will be thrown.
1551 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001552 * <p> Note that setting the password will automatically reset the expiration time for all
1553 * active admins. Active admins do not need to explicitly call this method in that case.
1554 *
Jim Millera4e28d12010-11-08 16:15:47 -08001555 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1556 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1557 * means there is no restriction (unlimited).
1558 */
Robin Lee25e26452015-06-02 09:56:29 -07001559 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001560 if (mService != null) {
1561 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001562 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001563 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001564 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001565 }
1566 }
1567 }
1568
1569 /**
Jim Miller6b857682011-02-16 16:27:41 -08001570 * Get the password expiration timeout for the given admin. The expiration timeout is the
1571 * recurring expiration timeout provided in the call to
1572 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001573 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001574 *
Robin Lee25e26452015-06-02 09:56:29 -07001575 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001576 * @return The timeout for the given admin or the minimum of all timeouts
1577 */
Robin Lee25e26452015-06-02 09:56:29 -07001578 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001579 if (mService != null) {
1580 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001581 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001582 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001583 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001584 }
1585 }
1586 return 0;
1587 }
1588
1589 /**
1590 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001591 * all admins of this user and its profiles if admin is null. If the password is
1592 * expired, this will return the time since the password expired as a negative number.
1593 * If admin is null, then a composite of all expiration timeouts is returned
1594 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001595 *
Robin Lee25e26452015-06-02 09:56:29 -07001596 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001597 * @return The password expiration time, in ms.
1598 */
Robin Lee25e26452015-06-02 09:56:29 -07001599 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001600 if (mService != null) {
1601 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001602 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001603 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001604 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001605 }
1606 }
1607 return 0;
1608 }
1609
1610 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001611 * Retrieve the current password history length for all admins of this
1612 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001613 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001614 * all admins.
1615 * @return The length of the password history
1616 */
Robin Lee25e26452015-06-02 09:56:29 -07001617 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001618 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001619 }
1620
1621 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001622 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001623 if (mService != null) {
1624 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001625 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001626 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001627 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001628 }
1629 }
1630 return 0;
1631 }
1632
Dianne Hackbornd6847842010-01-12 18:14:19 -08001633 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001634 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001635 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001636 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001637 * @return Returns the maximum length that the user can enter.
1638 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001639 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001640 // Kind-of arbitrary.
1641 return 16;
1642 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001643
Dianne Hackborn254cb442010-01-27 19:23:59 -08001644 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001645 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001646 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001647 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001648 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001649 * <p>The calling device admin must have requested
1650 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1651 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001652 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001653 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001654 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001655 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001656 if (mService != null) {
1657 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001658 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001659 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001660 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001661 }
1662 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001663 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001664 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001665
Dianne Hackbornd6847842010-01-12 18:14:19 -08001666 /**
1667 * Retrieve the number of times the user has failed at entering a
1668 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001669 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001670 * <p>The calling device admin must have requested
1671 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1672 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001673 */
1674 public int getCurrentFailedPasswordAttempts() {
1675 if (mService != null) {
1676 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001677 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001678 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001679 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001680 }
1681 }
1682 return -1;
1683 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001684
1685 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001686 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001687 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001688 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001689 * @hide
1690 */
1691 public boolean getDoNotAskCredentialsOnBoot() {
1692 if (mService != null) {
1693 try {
1694 return mService.getDoNotAskCredentialsOnBoot();
1695 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001696 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001697 }
1698 }
1699 return false;
1700 }
1701
1702 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001703 * Setting this to a value greater than zero enables a built-in policy
1704 * that will perform a device wipe after too many incorrect
1705 * device-unlock passwords have been entered. This built-in policy combines
1706 * watching for failed passwords and wiping the device, and requires
1707 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001708 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001709 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001710 * <p>To implement any other policy (e.g. wiping data for a particular
1711 * application only, erasing or revoking credentials, or reporting the
1712 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001713 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001714 * instead. Do not use this API, because if the maximum count is reached,
1715 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001716 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001717 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001718 * @param num The number of failed password attempts at which point the
1719 * device will wipe its data.
1720 */
Robin Lee25e26452015-06-02 09:56:29 -07001721 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001722 if (mService != null) {
1723 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001724 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001725 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001726 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001727 }
1728 }
1729 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001730
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001731 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001732 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001733 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001734 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001735 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001736 * all admins.
1737 */
Robin Lee25e26452015-06-02 09:56:29 -07001738 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001739 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001740 }
1741
1742 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001743 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001744 if (mService != null) {
1745 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001746 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001747 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001748 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001749 }
1750 }
1751 return 0;
1752 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001753
Dianne Hackborn254cb442010-01-27 19:23:59 -08001754 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001755 * Returns the profile with the smallest maximum failed passwords for wipe,
1756 * for the given user. So for primary user, it might return the primary or
1757 * a managed profile. For a secondary user, it would be the same as the
1758 * user passed in.
1759 * @hide Used only by Keyguard
1760 */
1761 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1762 if (mService != null) {
1763 try {
1764 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1765 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001766 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001767 }
1768 }
1769 return UserHandle.USER_NULL;
1770 }
1771
1772 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001773 * Flag for {@link #resetPassword}: don't allow other admins to change
1774 * the password again until the user has entered it.
1775 */
1776 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001777
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001778 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001779 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1780 * If the flag is set, the device can be booted without asking for user password.
1781 * The absence of this flag does not change the current boot requirements. This flag
1782 * can be set by the device owner only. If the app is not the device owner, the flag
1783 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1784 * device to factory defaults.
1785 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001786 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001787
1788 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001789 * Force a new device unlock password (the password needed to access the
1790 * entire device, not for individual accounts) on the user. This takes
1791 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001792 *
1793 * <p>Calling this from a managed profile that shares the password with the owner profile
1794 * will throw a security exception.
1795 *
1796 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1797 * device admins that are not device owner and not profile owner.
1798 * The password can now only be changed if there is currently no password set. Device owner
1799 * and profile owner can still do this.</em>
1800 *
1801 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001802 * current password quality and length constraints as returned by
1803 * {@link #getPasswordQuality(ComponentName)} and
1804 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1805 * these constraints, then it will be rejected and false returned. Note
1806 * that the password may be a stronger quality (containing alphanumeric
1807 * characters when the requested quality is only numeric), in which case
1808 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001809 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001810 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001811 * pattern or password if the current password constraints allow it. <em>Note: This will not
1812 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1813 * device owner and not profile owner. Once set, the password cannot be changed to null or
1814 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001815 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001816 * <p>The calling device admin must have requested
1817 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1818 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001819 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001820 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001821 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001822 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001823 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001824 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001825 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001826 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001827 if (mParentInstance) {
1828 throw new SecurityException("Reset password does not work across profiles.");
1829 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001830 if (mService != null) {
1831 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001832 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001833 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001834 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001835 }
1836 }
1837 return false;
1838 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001839
Dianne Hackbornd6847842010-01-12 18:14:19 -08001840 /**
1841 * Called by an application that is administering the device to set the
1842 * maximum time for user activity until the device will lock. This limits
1843 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001844 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001845 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001846 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001847 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001848 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001850 * @param timeMs The new desired maximum time to lock in milliseconds.
1851 * A value of 0 means there is no restriction.
1852 */
Robin Lee25e26452015-06-02 09:56:29 -07001853 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001854 if (mService != null) {
1855 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001856 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001857 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001858 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001859 }
1860 }
1861 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001862
Dianne Hackbornd6847842010-01-12 18:14:19 -08001863 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001864 * Retrieve the current maximum time to unlock for all admins of this user
1865 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001866 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001867 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001868 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001869 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001870 */
Robin Lee25e26452015-06-02 09:56:29 -07001871 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001872 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001873 }
1874
1875 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001876 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001877 if (mService != null) {
1878 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001879 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001880 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001881 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001882 }
1883 }
1884 return 0;
1885 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001886
Dianne Hackbornd6847842010-01-12 18:14:19 -08001887 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001888 * Make the device lock immediately, as if the lock screen timeout has
1889 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001890 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001891 * <p>The calling device admin must have requested
1892 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1893 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001894 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001895 public void lockNow() {
1896 if (mService != null) {
1897 try {
1898 mService.lockNow();
1899 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001900 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001901 }
1902 }
1903 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001904
Dianne Hackbornd6847842010-01-12 18:14:19 -08001905 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001906 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001907 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001908 */
1909 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1910
1911 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001912 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1913 * data.
1914 *
Paul Crowley2934b262014-12-02 11:21:13 +00001915 * <p>This flag may only be set by device owner admins; if it is set by
1916 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001917 */
1918 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1919
1920 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001921 * Ask the user data be wiped. Wiping the primary user will cause the
1922 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001923 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001924 * <p>The calling device admin must have requested
1925 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1926 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001927 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001928 * @param flags Bit mask of additional options: currently supported flags
1929 * are {@link #WIPE_EXTERNAL_STORAGE} and
1930 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001931 */
1932 public void wipeData(int flags) {
1933 if (mService != null) {
1934 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08001935 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001936 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001937 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001938 }
1939 }
1940 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001941
Dianne Hackbornd6847842010-01-12 18:14:19 -08001942 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001943 * Called by an application that is administering the device to set the
1944 * global proxy and exclusion list.
1945 * <p>
1946 * The calling device admin must have requested
1947 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1948 * this method; if it has not, a security exception will be thrown.
1949 * Only the first device admin can set the proxy. If a second admin attempts
1950 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001951 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001952 * be returned.
1953 * The method can be called repeatedly by the device admin alrady setting the
1954 * proxy to update the proxy and exclusion list.
1955 *
Robin Lee25e26452015-06-02 09:56:29 -07001956 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001957 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1958 * Pass Proxy.NO_PROXY to reset the proxy.
1959 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001960 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1961 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001962 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001963 */
Robin Lee25e26452015-06-02 09:56:29 -07001964 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001965 List<String> exclusionList ) {
1966 if (proxySpec == null) {
1967 throw new NullPointerException();
1968 }
1969 if (mService != null) {
1970 try {
1971 String hostSpec;
1972 String exclSpec;
1973 if (proxySpec.equals(Proxy.NO_PROXY)) {
1974 hostSpec = null;
1975 exclSpec = null;
1976 } else {
1977 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1978 throw new IllegalArgumentException();
1979 }
1980 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1981 String hostName = sa.getHostName();
1982 int port = sa.getPort();
1983 StringBuilder hostBuilder = new StringBuilder();
1984 hostSpec = hostBuilder.append(hostName)
1985 .append(":").append(Integer.toString(port)).toString();
1986 if (exclusionList == null) {
1987 exclSpec = "";
1988 } else {
1989 StringBuilder listBuilder = new StringBuilder();
1990 boolean firstDomain = true;
1991 for (String exclDomain : exclusionList) {
1992 if (!firstDomain) {
1993 listBuilder = listBuilder.append(",");
1994 } else {
1995 firstDomain = false;
1996 }
1997 listBuilder = listBuilder.append(exclDomain.trim());
1998 }
1999 exclSpec = listBuilder.toString();
2000 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002001 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2002 != android.net.Proxy.PROXY_VALID)
2003 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002004 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002005 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002006 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002007 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002008 }
2009 }
2010 return null;
2011 }
2012
2013 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002014 * Set a network-independent global HTTP proxy. This is not normally what you want
2015 * for typical HTTP proxies - they are generally network dependent. However if you're
2016 * doing something unusual like general internal filtering this may be useful. On
2017 * a private network where the proxy is not accessible, you may break HTTP using this.
2018 *
2019 * <p>This method requires the caller to be the device owner.
2020 *
2021 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2022 * @see ProxyInfo
2023 *
2024 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2025 * with.
2026 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2027 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2028 */
Robin Lee25e26452015-06-02 09:56:29 -07002029 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2030 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002031 if (mService != null) {
2032 try {
2033 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2034 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002035 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002036 }
2037 }
2038 }
2039
2040 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002041 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002042 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2043 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002044 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002045 */
2046 public ComponentName getGlobalProxyAdmin() {
2047 if (mService != null) {
2048 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002049 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002050 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002051 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002052 }
2053 }
2054 return null;
2055 }
2056
2057 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002058 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002059 * indicating that encryption is not supported.
2060 */
2061 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2062
2063 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002064 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002065 * indicating that encryption is supported, but is not currently active.
2066 */
2067 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2068
2069 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002070 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002071 * indicating that encryption is not currently active, but is currently
2072 * being activated. This is only reported by devices that support
2073 * encryption of data and only when the storage is currently
2074 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2075 * to become encrypted will never return this value.
2076 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002077 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002078
2079 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002080 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002081 * indicating that encryption is active.
2082 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002083 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002084
2085 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002086 * Result code for {@link #getStorageEncryptionStatus}:
2087 * indicating that encryption is active, but an encryption key has not
2088 * been set by the user.
2089 */
2090 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2091
2092 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002093 * Activity action: begin the process of encrypting data on the device. This activity should
2094 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2095 * After resuming from this activity, use {@link #getStorageEncryption}
2096 * to check encryption status. However, on some devices this activity may never return, as
2097 * it may trigger a reboot and in some cases a complete data wipe of the device.
2098 */
2099 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2100 public static final String ACTION_START_ENCRYPTION
2101 = "android.app.action.START_ENCRYPTION";
2102
2103 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002104 * Widgets are enabled in keyguard
2105 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002106 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002107
2108 /**
Jim Miller50e62182014-04-23 17:25:00 -07002109 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002110 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002111 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2112
2113 /**
2114 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2115 */
2116 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2117
2118 /**
Jim Miller50e62182014-04-23 17:25:00 -07002119 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2120 */
2121 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2122
2123 /**
2124 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2125 */
2126 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2127
2128 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002129 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002130 * (e.g. PIN/Pattern/Password).
2131 */
2132 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2133
2134 /**
Jim Miller06e34502014-07-17 14:46:05 -07002135 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2136 */
2137 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2138
2139 /**
Jim Miller35207742012-11-02 15:33:20 -07002140 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002141 */
2142 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002143
2144 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002145 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002146 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002147 *
2148 * <p>When multiple device administrators attempt to control device
2149 * encryption, the most secure, supported setting will always be
2150 * used. If any device administrator requests device encryption,
2151 * it will be enabled; Conversely, if a device administrator
2152 * attempts to disable device encryption while another
2153 * device administrator has enabled it, the call to disable will
2154 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2155 *
2156 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002157 * written to other storage areas may or may not be encrypted, and this policy does not require
2158 * or control the encryption of any other storage areas.
2159 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2160 * {@code true}, then the directory returned by
2161 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2162 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002163 *
2164 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2165 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2166 * the encryption key may not be fully secured. For maximum security, the administrator should
2167 * also require (and check for) a pattern, PIN, or password.
2168 *
2169 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2170 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002171 * @return the new request status (for all active admins) - will be one of
2172 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2173 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2174 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002175 */
Robin Lee25e26452015-06-02 09:56:29 -07002176 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002177 if (mService != null) {
2178 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002179 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002180 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002181 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002182 }
2183 }
2184 return ENCRYPTION_STATUS_UNSUPPORTED;
2185 }
2186
2187 /**
2188 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002189 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002190 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002191 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2192 * this will return the requested encryption setting as an aggregate of all active
2193 * administrators.
2194 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002195 */
Robin Lee25e26452015-06-02 09:56:29 -07002196 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002197 if (mService != null) {
2198 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002199 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002200 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002201 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002202 }
2203 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002204 return false;
2205 }
2206
2207 /**
2208 * Called by an application that is administering the device to
2209 * determine the current encryption status of the device.
2210 *
2211 * Depending on the returned status code, the caller may proceed in different
2212 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2213 * storage system does not support encryption. If the
2214 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2215 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002216 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2217 * storage system has enabled encryption but no password is set so further action
2218 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002219 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2220 *
Robin Lee7e678712014-07-24 16:41:31 +01002221 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002222 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002223 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2224 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002225 */
2226 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002227 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002228 }
2229
2230 /** @hide per-user version */
2231 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002232 if (mService != null) {
2233 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002234 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002235 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002236 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002237 }
2238 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002239 return ENCRYPTION_STATUS_UNSUPPORTED;
2240 }
2241
2242 /**
Robin Lee7e678712014-07-24 16:41:31 +01002243 * Installs the given certificate as a user CA.
2244 *
Robin Lee25e26452015-06-02 09:56:29 -07002245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2246 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002247 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002248 *
2249 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002250 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002251 */
Robin Lee25e26452015-06-02 09:56:29 -07002252 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002253 if (mService != null) {
2254 try {
Robin Lee7e678712014-07-24 16:41:31 +01002255 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002256 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002257 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002258 }
2259 }
2260 return false;
2261 }
2262
2263 /**
Robin Lee7e678712014-07-24 16:41:31 +01002264 * Uninstalls the given certificate from trusted user CAs, if present.
2265 *
Robin Lee25e26452015-06-02 09:56:29 -07002266 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2267 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002268 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002269 */
Robin Lee25e26452015-06-02 09:56:29 -07002270 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002271 if (mService != null) {
2272 try {
Robin Lee306fe082014-06-19 14:04:24 +00002273 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002274 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002275 } catch (CertificateException e) {
2276 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002277 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002278 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002279 }
2280 }
2281 }
2282
2283 /**
Robin Lee7e678712014-07-24 16:41:31 +01002284 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2285 * If a user has installed any certificates by other means than device policy these will be
2286 * included too.
2287 *
Robin Lee25e26452015-06-02 09:56:29 -07002288 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2289 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002290 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002291 */
Robin Lee25e26452015-06-02 09:56:29 -07002292 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002293 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002294 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002295 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002296 mService.enforceCanManageCaCerts(admin);
2297 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2298 for (String alias : certStore.userAliases()) {
2299 try {
2300 certs.add(certStore.getCertificate(alias).getEncoded());
2301 } catch (CertificateException ce) {
2302 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2303 }
2304 }
2305 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002306 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002307 }
2308 }
2309 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002310 }
2311
2312 /**
Robin Lee7e678712014-07-24 16:41:31 +01002313 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2314 * means other than device policy will also be removed, except for system CA certificates.
2315 *
Robin Lee25e26452015-06-02 09:56:29 -07002316 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2317 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002318 */
Robin Lee25e26452015-06-02 09:56:29 -07002319 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002320 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002321 try {
2322 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2323 .toArray(new String[0]));
2324 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002325 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002326 }
2327 }
2328 }
2329
2330 /**
2331 * Returns whether this certificate is installed as a trusted CA.
2332 *
Robin Lee25e26452015-06-02 09:56:29 -07002333 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2334 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002335 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002336 */
Robin Lee25e26452015-06-02 09:56:29 -07002337 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002338 if (mService != null) {
2339 try {
2340 mService.enforceCanManageCaCerts(admin);
2341 return getCaCertAlias(certBuffer) != null;
2342 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002343 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002344 } catch (CertificateException ce) {
2345 Log.w(TAG, "Could not parse certificate", ce);
2346 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002347 }
2348 return false;
2349 }
2350
2351 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002352 * Called by a device or profile owner to install a certificate and private key pair. The
2353 * keypair will be visible to all apps within the profile.
2354 *
Robin Lee25e26452015-06-02 09:56:29 -07002355 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2356 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002357 * @param privKey The private key to install.
2358 * @param cert The certificate to install.
2359 * @param alias The private key alias under which to install the certificate. If a certificate
2360 * with that alias already exists, it will be overwritten.
2361 * @return {@code true} if the keys were installed, {@code false} otherwise.
2362 */
Robin Leefbc65642015-08-03 16:21:22 +01002363 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2364 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002365 try {
2366 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002367 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2368 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002369 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002370 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002371 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002372 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2373 Log.w(TAG, "Failed to obtain private key material", e);
2374 } catch (CertificateException | IOException e) {
2375 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002376 }
2377 return false;
2378 }
2379
2380 /**
Robin Leefbc65642015-08-03 16:21:22 +01002381 * Called by a device or profile owner to remove all user credentials installed under a given
2382 * alias.
2383 *
2384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2385 * {@code null} if calling from a delegated certificate installer.
2386 * @param alias The private key alias under which the certificate is installed.
2387 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2388 */
2389 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2390 try {
2391 return mService.removeKeyPair(admin, alias);
2392 } catch (RemoteException e) {
2393 Log.w(TAG, "Failed talking with device policy service", e);
2394 }
2395 return false;
2396 }
2397
2398 /**
Robin Lee25e26452015-06-02 09:56:29 -07002399 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002400 * doesn't exist.
2401 */
2402 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2403 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2404 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2405 new ByteArrayInputStream(certBuffer));
2406 return new TrustedCertificateStore().getCertificateAlias(cert);
2407 }
2408
2409 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002410 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002411 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002412 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002413 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002414 * <p>
2415 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2416 * it is later cleared by calling this method with a null value or uninstallling the certificate
2417 * installer.
2418 *
Robin Lee25e26452015-06-02 09:56:29 -07002419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002420 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002421 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002422 */
Robin Lee25e26452015-06-02 09:56:29 -07002423 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2424 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002425 if (mService != null) {
2426 try {
Robin Lee25e26452015-06-02 09:56:29 -07002427 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002428 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002429 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002430 }
2431 }
2432 }
2433
2434 /**
2435 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002436 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002437 *
Robin Lee25e26452015-06-02 09:56:29 -07002438 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2439 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002440 * if none is set.
2441 */
Robin Lee25e26452015-06-02 09:56:29 -07002442 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002443 if (mService != null) {
2444 try {
Robin Lee25e26452015-06-02 09:56:29 -07002445 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002446 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002447 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002448 }
2449 }
2450 return null;
2451 }
2452
2453 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002454 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002455 * on the device, for this user. After setting this, no applications running as this user
2456 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002457 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002458 * <p>If the caller is device owner, then the restriction will be applied to all users.
2459 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002460 * <p>The calling device admin must have requested
2461 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2462 * this method; if it has not, a security exception will be thrown.
2463 *
2464 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2465 * @param disabled Whether or not the camera should be disabled.
2466 */
Robin Lee25e26452015-06-02 09:56:29 -07002467 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002468 if (mService != null) {
2469 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002470 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002471 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002472 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002473 }
2474 }
2475 }
2476
2477 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002478 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002479 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002480 * @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 -07002481 * have disabled the camera
2482 */
Robin Lee25e26452015-06-02 09:56:29 -07002483 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002484 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002485 }
2486
2487 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002488 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002489 if (mService != null) {
2490 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002491 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002492 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002493 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002494 }
2495 }
2496 return false;
2497 }
2498
2499 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002500 * Called by a device owner to request a bugreport.
2501 *
2502 * <p>There must be only one user on the device, managed by the device owner.
2503 * Otherwise a security exception will be thrown.
2504 *
2505 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2506 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2507 * if it wasn't triggered because a previous bugreport operation is still active
2508 * (either the bugreport is still running or waiting for the user to share or decline)
2509 */
2510 public boolean requestBugreport(@NonNull ComponentName admin) {
2511 if (mService != null) {
2512 try {
2513 return mService.requestBugreport(admin);
2514 } catch (RemoteException e) {
2515 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2516 }
2517 }
2518 return false;
2519 }
2520
2521 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002522 * Determine whether or not creating a guest user has been disabled for the device
2523 *
2524 * @hide
2525 */
2526 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2527 // Currently guest users can always be created if multi-user is enabled
2528 // TODO introduce a policy for guest user creation
2529 return false;
2530 }
2531
2532 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002533 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2534 * screen capture also prevents the content from being shown on display devices that do not have
2535 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2536 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002537 *
2538 * <p>The calling device admin must be a device or profile owner. If it is not, a
2539 * security exception will be thrown.
2540 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002541 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002542 * blocks assist requests for all activities of the relevant user.
2543 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002544 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002545 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002546 */
Robin Lee25e26452015-06-02 09:56:29 -07002547 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002548 if (mService != null) {
2549 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002550 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002551 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002552 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002553 }
2554 }
2555 }
2556
2557 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002558 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002559 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002560 * @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 +01002561 * have disabled screen capture.
2562 */
Robin Lee25e26452015-06-02 09:56:29 -07002563 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002564 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002565 }
2566
2567 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002568 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002569 if (mService != null) {
2570 try {
2571 return mService.getScreenCaptureDisabled(admin, userHandle);
2572 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002573 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002574 }
2575 }
2576 return false;
2577 }
2578
2579 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002580 * Called by a device owner to set whether auto time is required. If auto time is
2581 * required the user cannot set the date and time, but has to use network date and time.
2582 *
2583 * <p>Note: if auto time is required the user can still manually set the time zone.
2584 *
2585 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2586 * be thrown.
2587 *
2588 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2589 * @param required Whether auto time is set required or not.
2590 */
Robin Lee25e26452015-06-02 09:56:29 -07002591 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002592 if (mService != null) {
2593 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002594 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002595 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002596 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002597 }
2598 }
2599 }
2600
2601 /**
2602 * @return true if auto time is required.
2603 */
2604 public boolean getAutoTimeRequired() {
2605 if (mService != null) {
2606 try {
2607 return mService.getAutoTimeRequired();
2608 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002609 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002610 }
2611 }
2612 return false;
2613 }
2614
2615 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002616 * Called by an application that is administering the device to disable keyguard customizations,
2617 * such as widgets. After setting this, keyguard features will be disabled according to the
2618 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002619 *
2620 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002621 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002622 * this method; if it has not, a security exception will be thrown.
2623 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002624 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002625 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002626 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002627 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002628 * <ul>
2629 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2630 * these will affect the profile's parent user.
2631 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2632 * generated by applications in the managed profile.
2633 * </ul>
2634 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2635 * can check which features have been disabled by calling
2636 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002637 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002638 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002639 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2640 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002641 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002642 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2643 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002644 */
Robin Lee25e26452015-06-02 09:56:29 -07002645 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002646 if (mService != null) {
2647 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002648 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002649 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002650 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002651 }
2652 }
2653 }
2654
2655 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002656 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002657 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002658 * @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 -07002659 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002660 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2661 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002662 */
Robin Lee25e26452015-06-02 09:56:29 -07002663 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002664 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002665 }
2666
2667 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002668 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002669 if (mService != null) {
2670 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002671 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002672 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002673 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002674 }
2675 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002676 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002677 }
2678
2679 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002680 * @hide
2681 */
Robin Lee25e26452015-06-02 09:56:29 -07002682 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2683 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002684 if (mService != null) {
2685 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002686 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002687 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002688 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002689 }
2690 }
2691 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002692
Dianne Hackbornd6847842010-01-12 18:14:19 -08002693 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002694 * @hide
2695 */
Robin Lee25e26452015-06-02 09:56:29 -07002696 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002697 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002698 }
2699
2700 /**
Robin Lee25e26452015-06-02 09:56:29 -07002701 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002702 * @hide
2703 */
Robin Lee25e26452015-06-02 09:56:29 -07002704 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002705 ActivityInfo ai;
2706 try {
2707 ai = mContext.getPackageManager().getReceiverInfo(cn,
2708 PackageManager.GET_META_DATA);
2709 } catch (PackageManager.NameNotFoundException e) {
2710 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2711 return null;
2712 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002713
Dianne Hackbornd6847842010-01-12 18:14:19 -08002714 ResolveInfo ri = new ResolveInfo();
2715 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002716
Dianne Hackbornd6847842010-01-12 18:14:19 -08002717 try {
2718 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002719 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002720 Log.w(TAG, "Unable to parse device policy " + cn, e);
2721 return null;
2722 }
2723 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002724
Dianne Hackbornd6847842010-01-12 18:14:19 -08002725 /**
2726 * @hide
2727 */
Robin Lee25e26452015-06-02 09:56:29 -07002728 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002729 if (mService != null) {
2730 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002731 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002732 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002733 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002734 }
2735 }
2736 }
2737
2738 /**
2739 * @hide
2740 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002741 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002742 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002743 if (mService != null) {
2744 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002745 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002746 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002747 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002748 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002749 }
2750 }
2751 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002752
Dianne Hackbornd6847842010-01-12 18:14:19 -08002753 /**
2754 * @hide
2755 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002756 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002757 if (mService != null) {
2758 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002759 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002760 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002761 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002762 }
2763 }
2764 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002765
Dianne Hackbornd6847842010-01-12 18:14:19 -08002766 /**
2767 * @hide
2768 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002769 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002770 if (mService != null) {
2771 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002772 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002773 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002774 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002775 }
2776 }
2777 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002778
2779 /**
2780 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002781 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002782 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2783 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002784 * @return whether the package was successfully registered as the device owner.
2785 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002786 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002787 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002788 public boolean setDeviceOwner(ComponentName who) {
2789 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002790 }
2791
2792 /**
2793 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002794 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002795 public boolean setDeviceOwner(ComponentName who, int userId) {
2796 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002797 }
2798
2799 /**
2800 * @hide
2801 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002802 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2803 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002804 }
2805
2806 /**
2807 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002808 * Sets the given package as the device owner. The package must already be installed. There
2809 * must not already be a device owner.
2810 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2811 * this method.
2812 * Calling this after the setup phase of the primary user has completed is allowed only if
2813 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002814 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002815 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002816 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002817 * @return whether the package was successfully registered as the device owner.
2818 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002819 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002820 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002821 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002822 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002823 if (mService != null) {
2824 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002825 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002826 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002827 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002828 }
2829 }
2830 return false;
2831 }
2832
2833 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002834 * Used to determine if a particular package has been registered as a Device Owner app.
2835 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002836 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002837 * package is currently registered as the device owner app, pass in the package name from
2838 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002839 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002840 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2841 * the setup process.
2842 * @param packageName the package name of the app, to compare with the registered device owner
2843 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08002844 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002845 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002846 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08002847 return isDeviceOwnerAppOnCallingUser(packageName);
2848 }
2849
2850 /**
2851 * @return true if a package is registered as device owner, only when it's running on the
2852 * calling user.
2853 *
2854 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
2855 * @hide
2856 */
2857 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
2858 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
2859 }
2860
2861 /**
2862 * @return true if a package is registered as device owner, even if it's running on a different
2863 * user.
2864 *
2865 * <p>Requires the MANAGE_USERS permission.
2866 *
2867 * @hide
2868 */
2869 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
2870 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
2871 }
2872
2873 /**
2874 * @return device owner component name, only when it's running on the calling user.
2875 *
2876 * @hide
2877 */
2878 public ComponentName getDeviceOwnerComponentOnCallingUser() {
2879 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
2880 }
2881
2882 /**
2883 * @return device owner component name, even if it's running on a different user.
2884 *
2885 * <p>Requires the MANAGE_USERS permission.
2886 *
2887 * @hide
2888 */
2889 public ComponentName getDeviceOwnerComponentOnAnyUser() {
2890 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
2891 }
2892
2893 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002894 if (packageName == null) {
2895 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07002896 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08002897 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08002898 if (deviceOwner == null) {
2899 return false;
2900 }
2901 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07002902 }
2903
Makoto Onukic8a5a552015-11-19 14:29:12 -08002904 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
2905 if (mService != null) {
2906 try {
2907 return mService.getDeviceOwnerComponent(callingUserOnly);
2908 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002909 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002910 }
2911 }
2912 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002913 }
2914
Jason Monkb0dced82014-06-06 14:36:20 -04002915 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002916 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
2917 * no device owner.
2918 *
2919 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07002920 *
2921 * @hide
2922 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08002923 public int getDeviceOwnerUserId() {
2924 if (mService != null) {
2925 try {
2926 return mService.getDeviceOwnerUserId();
2927 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002928 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002929 }
2930 }
2931 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07002932 }
2933
2934 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002935 * Clears the current device owner. The caller must be the device owner.
2936 *
2937 * This function should be used cautiously as once it is called it cannot
2938 * be undone. The device owner can only be set as a part of device setup
2939 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002940 *
2941 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002942 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002943 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002944 if (mService != null) {
2945 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002946 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002947 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002948 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04002949 }
2950 }
2951 }
2952
Makoto Onukia52562c2015-10-01 16:12:31 -07002953 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002954 * Returns the device owner package name, only if it's running on the calling user.
2955 *
2956 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07002957 *
2958 * @hide
2959 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002960 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002961 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08002962 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
2963 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07002964 }
2965
2966 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002967 * @return true if the device is managed by any device owner.
2968 *
2969 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07002970 *
2971 * @hide
2972 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08002973 public boolean isDeviceManaged() {
2974 return getDeviceOwnerComponentOnAnyUser() != null;
2975 }
2976
2977 /**
2978 * Returns the device owner name. Note this method *will* return the device owner
2979 * name when it's running on a different user.
2980 *
2981 * <p>Requires the MANAGE_USERS permission.
2982 *
2983 * @hide
2984 */
2985 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002986 if (mService != null) {
2987 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002988 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002989 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002990 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002991 }
2992 }
2993 return null;
2994 }
Adam Connors776c5552014-01-09 10:42:56 +00002995
2996 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002997 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002998 * @deprecated Do not use
2999 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003000 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003001 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003002 @SystemApi
3003 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003004 return null;
3005 }
3006
3007 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003008 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003009 * @deprecated Do not use
3010 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003011 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003012 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003013 @SystemApi
3014 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003015 return null;
3016 }
3017
Julia Reynolds20118f12015-02-11 12:34:08 -05003018 /**
Adam Connors776c5552014-01-09 10:42:56 +00003019 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003020 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303021 * Sets the given component as an active admin and registers the package as the profile
3022 * owner for this user. The package must already be installed and there shouldn't be
3023 * an existing profile owner registered for this user. Also, this method must be called
3024 * before the user setup has been completed.
3025 * <p>
3026 * This method can only be called by system apps that hold MANAGE_USERS permission and
3027 * MANAGE_DEVICE_ADMINS permission.
3028 * @param admin The component to register as an active admin and profile owner.
3029 * @param ownerName The user-visible name of the entity that is managing this user.
3030 * @return whether the admin was successfully registered as the profile owner.
3031 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3032 * the user has already been set up.
3033 */
Justin Morey80440cc2014-07-24 09:16:35 -05003034 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003035 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303036 throws IllegalArgumentException {
3037 if (mService != null) {
3038 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003039 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303040 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003041 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303042 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303043 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3044 }
3045 }
3046 return false;
3047 }
3048
3049 /**
3050 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003051 * Clears the active profile owner and removes all user restrictions. The caller must
3052 * be from the same package as the active profile owner for this user, otherwise a
3053 * SecurityException will be thrown.
3054 *
3055 * @param admin The component to remove as the profile owner.
3056 * @return
3057 */
3058 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003059 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003060 if (mService != null) {
3061 try {
3062 mService.clearProfileOwner(admin);
3063 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003064 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003065 }
3066 }
3067 }
3068
3069 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003070 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003071 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003072 */
3073 public boolean hasUserSetupCompleted() {
3074 if (mService != null) {
3075 try {
3076 return mService.hasUserSetupCompleted();
3077 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003078 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003079 }
3080 }
3081 return true;
3082 }
3083
3084 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003085 * @hide
3086 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003087 * already be installed. There must not already be a profile owner for this user.
3088 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3089 * this method.
3090 * Calling this after the setup phase of the specified user has completed is allowed only if:
3091 * - the caller is SYSTEM_UID.
3092 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003093 * @param admin the component name to be registered as profile owner.
3094 * @param ownerName the human readable name of the organisation associated with this DPM.
3095 * @param userHandle the userId to set the profile owner for.
3096 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003097 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3098 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003099 */
Robin Lee25e26452015-06-02 09:56:29 -07003100 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003101 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003102 if (mService != null) {
3103 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003104 if (ownerName == null) {
3105 ownerName = "";
3106 }
3107 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003108 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003109 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003110 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3111 }
3112 }
3113 return false;
3114 }
3115
3116 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003117 * Sets the device owner information to be shown on the lock screen.
3118 *
3119 * <p>If the device owner information is {@code null} or empty then the device owner info is
3120 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003121 * <p>If the device owner information contains only whitespaces then the message on the lock
3122 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003123 *
3124 * @param admin The name of the admin component to check.
3125 * @param info Device owner information which will be displayed instead of the user
3126 * owner info.
3127 * @return Whether the device owner information has been set.
3128 */
3129 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3130 if (mService != null) {
3131 try {
3132 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3133 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003134 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003135 }
3136 }
3137 return false;
3138 }
3139
3140 /**
3141 * @return The device owner information. If it is not set returns {@code null}.
3142 */
3143 public String getDeviceOwnerLockScreenInfo() {
3144 if (mService != null) {
3145 try {
3146 return mService.getDeviceOwnerLockScreenInfo();
3147 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003148 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003149 }
3150 }
3151 return null;
3152 }
3153
3154 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003155 * Called by device or profile owners for setting the package suspended for this user.
3156 * A suspended package will not be started by the package manager, its notifications will
3157 * be hidden and it will not show up in recents. The package must already be installed.
3158 *
3159 * @param admin The name of the admin component to check.
3160 * @param packageName The package name of the app to suspend or unsuspend.
3161 * @param suspended If set to {@code true} than the package will be suspended, if set to
3162 * {@code false} the package will be unsuspended.
3163 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3164 * otherwise.
3165 */
3166 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3167 boolean suspended) {
3168 if (mService != null) {
3169 try {
3170 return mService.setPackageSuspended(admin, packageName, suspended);
3171 } catch (RemoteException re) {
3172 Log.w(TAG, "Failed talking with device policy service", re);
3173 }
3174 }
3175 return false;
3176 }
3177
3178 /**
3179 * Called by device or profile owners to determine if a package is suspended.
3180 *
3181 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3182 * @param packageName The name of the package to retrieve the suspended status of.
3183 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3184 */
3185 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3186 if (mService != null) {
3187 try {
3188 return mService.getPackageSuspended(admin, packageName);
3189 } catch (RemoteException e) {
3190 Log.w(TAG, "Failed talking with device policy service", e);
3191 }
3192 }
3193 return false;
3194 }
3195
3196 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003197 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3198 * be used. Only the profile owner can call this.
3199 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003200 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003201 *
3202 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3203 */
Robin Lee25e26452015-06-02 09:56:29 -07003204 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003205 if (mService != null) {
3206 try {
3207 mService.setProfileEnabled(admin);
3208 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003209 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003210 }
3211 }
3212 }
3213
3214 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003215 * Sets the name of the profile. In the device owner case it sets the name of the user
3216 * 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 +01003217 * never called by the profile or device owner, the name will be set to default values.
3218 *
3219 * @see #isProfileOwnerApp
3220 * @see #isDeviceOwnerApp
3221 *
Robin Lee25e26452015-06-02 09:56:29 -07003222 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003223 * @param profileName The name of the profile.
3224 */
Robin Lee25e26452015-06-02 09:56:29 -07003225 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003226 if (mService != null) {
3227 try {
Robin Lee25e26452015-06-02 09:56:29 -07003228 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003229 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003230 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003231 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003232 }
3233 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003234
3235 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003236 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003237 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003238 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003239 *
3240 * @param packageName The package name of the app to compare with the registered profile owner.
3241 * @return Whether or not the package is registered as the profile owner.
3242 */
3243 public boolean isProfileOwnerApp(String packageName) {
3244 if (mService != null) {
3245 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003246 ComponentName profileOwner = mService.getProfileOwner(
3247 Process.myUserHandle().getIdentifier());
3248 return profileOwner != null
3249 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003250 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003251 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003252 }
3253 }
3254 return false;
3255 }
3256
3257 /**
3258 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003259 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003260 * owner has been set for that user.
3261 * @throws IllegalArgumentException if the userId is invalid.
3262 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003263 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003264 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003265 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3266 }
3267
3268 /**
3269 * @see #getProfileOwner()
3270 * @hide
3271 */
3272 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003273 if (mService != null) {
3274 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003275 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003276 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003277 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003278 throw new IllegalArgumentException(
3279 "Requested profile owner for invalid userId", re);
3280 }
3281 }
3282 return null;
3283 }
3284
3285 /**
3286 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003287 * @return the human readable name of the organisation associated with this DPM or {@code null}
3288 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003289 * @throws IllegalArgumentException if the userId is invalid.
3290 */
3291 public String getProfileOwnerName() throws IllegalArgumentException {
3292 if (mService != null) {
3293 try {
3294 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3295 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003296 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003297 throw new IllegalArgumentException(
3298 "Requested profile owner for invalid userId", re);
3299 }
3300 }
3301 return null;
3302 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003303
3304 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003305 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003306 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003307 * @return the human readable name of the organisation associated with this profile owner or
3308 * null if one is not set.
3309 * @throws IllegalArgumentException if the userId is invalid.
3310 */
3311 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003312 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003313 if (mService != null) {
3314 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003315 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003316 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003317 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003318 throw new IllegalArgumentException(
3319 "Requested profile owner for invalid userId", re);
3320 }
3321 }
3322 return null;
3323 }
3324
3325 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003326 * Called by a profile owner or device owner to add a default intent handler activity for
3327 * intents that match a certain intent filter. This activity will remain the default intent
3328 * handler even if the set of potential event handlers for the intent filter changes and if
3329 * the intent preferences are reset.
3330 *
3331 * <p>The default disambiguation mechanism takes over if the activity is not installed
3332 * (anymore). When the activity is (re)installed, it is automatically reset as default
3333 * intent handler for the filter.
3334 *
3335 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3336 * security exception will be thrown.
3337 *
3338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3339 * @param filter The IntentFilter for which a default handler is added.
3340 * @param activity The Activity that is added as default intent handler.
3341 */
Robin Lee25e26452015-06-02 09:56:29 -07003342 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3343 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003344 if (mService != null) {
3345 try {
3346 mService.addPersistentPreferredActivity(admin, filter, activity);
3347 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003348 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003349 }
3350 }
3351 }
3352
3353 /**
3354 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003355 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003356 *
3357 * <p>The calling device admin must be a profile owner. If it is not, a security
3358 * exception will be thrown.
3359 *
3360 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3361 * @param packageName The name of the package for which preferences are removed.
3362 */
Robin Lee25e26452015-06-02 09:56:29 -07003363 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003364 String packageName) {
3365 if (mService != null) {
3366 try {
3367 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3368 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003369 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003370 }
3371 }
3372 }
Robin Lee66e5d962014-04-09 16:44:21 +01003373
3374 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003375 * Called by a profile owner or device owner to grant permission to a package to manage
3376 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3377 * {@link #getApplicationRestrictions}.
3378 * <p>
3379 * This permission is persistent until it is later cleared by calling this method with a
3380 * {@code null} value or uninstalling the managing package.
3381 *
3382 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3383 * @param packageName The package name which will be given access to application restrictions
3384 * APIs. If {@code null} is given the current package will be cleared.
3385 */
3386 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3387 @Nullable String packageName) {
3388 if (mService != null) {
3389 try {
3390 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3391 } catch (RemoteException e) {
3392 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3393 }
3394 }
3395 }
3396
3397 /**
3398 * Called by a profile owner or device owner to retrieve the application restrictions managing
3399 * package for the current user, or {@code null} if none is set.
3400 *
3401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3402 * @return The package name allowed to manage application restrictions on the current user, or
3403 * {@code null} if none is set.
3404 */
3405 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3406 if (mService != null) {
3407 try {
3408 return mService.getApplicationRestrictionsManagingPackage(admin);
3409 } catch (RemoteException e) {
3410 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3411 }
3412 }
3413 return null;
3414 }
3415
3416 /**
3417 * Returns {@code true} if the calling package has been granted permission via
3418 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3419 * restrictions for the calling user.
3420 */
3421 public boolean isCallerApplicationRestrictionsManagingPackage() {
3422 if (mService != null) {
3423 try {
3424 return mService.isCallerApplicationRestrictionsManagingPackage();
3425 } catch (RemoteException e) {
3426 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3427 }
3428 }
3429 return false;
3430 }
3431
3432 /**
3433 * Sets the application restrictions for a given target application running in the calling user.
3434 *
3435 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3436 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3437 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003438 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003439 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3440 * <ul>
3441 * <li>{@code boolean}
3442 * <li>{@code int}
3443 * <li>{@code String} or {@code String[]}
3444 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3445 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003446 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003447 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003448 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003449 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3450 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003451 * <p>The application restrictions are only made visible to the target application via
3452 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3453 * device owner, and the application restrictions managing package via
3454 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003455 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003456 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3457 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003458 * @param packageName The name of the package to update restricted settings for.
3459 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3460 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003461 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003462 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003463 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003464 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003465 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003466 Bundle settings) {
3467 if (mService != null) {
3468 try {
3469 mService.setApplicationRestrictions(admin, packageName, settings);
3470 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003471 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003472 }
3473 }
3474 }
3475
3476 /**
Jim Millere303bf42014-08-26 17:12:29 -07003477 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3478 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3479 * trust agents but those enabled by this function call. If flag
3480 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003481 *
3482 * <p>The calling device admin must have requested
3483 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003484 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003485 *
3486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003487 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003488 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003489 * will be strictly disabled according to the state of the
3490 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3491 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3492 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3493 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003494 */
Robin Lee25e26452015-06-02 09:56:29 -07003495 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3496 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003497 if (mService != null) {
3498 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003499 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003500 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003501 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003502 }
3503 }
3504 }
3505
3506 /**
Jim Millere303bf42014-08-26 17:12:29 -07003507 * Gets configuration for the given trust agent based on aggregating all calls to
3508 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3509 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003510 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003511 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3512 * this function returns a list of configurations for all admins that declare
3513 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3514 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3515 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3516 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003517 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003518 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003519 */
Robin Lee25e26452015-06-02 09:56:29 -07003520 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3521 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003522 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003523 }
3524
3525 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003526 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3527 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003528 if (mService != null) {
3529 try {
Jim Millere303bf42014-08-26 17:12:29 -07003530 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003531 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003532 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003533 }
3534 }
Jim Millere303bf42014-08-26 17:12:29 -07003535 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003536 }
3537
3538 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003539 * Called by a profile owner of a managed profile to set whether caller-Id information from
3540 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003541 *
3542 * <p>The calling device admin must be a profile owner. If it is not, a
3543 * security exception will be thrown.
3544 *
Robin Lee25e26452015-06-02 09:56:29 -07003545 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003546 * @param disabled If true caller-Id information in the managed profile is not displayed.
3547 */
Robin Lee25e26452015-06-02 09:56:29 -07003548 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003549 if (mService != null) {
3550 try {
Robin Lee25e26452015-06-02 09:56:29 -07003551 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003552 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003553 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003554 }
3555 }
3556 }
3557
3558 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003559 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3560 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003561 *
3562 * <p>The calling device admin must be a profile owner. If it is not, a
3563 * security exception will be thrown.
3564 *
Robin Lee25e26452015-06-02 09:56:29 -07003565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003566 */
Robin Lee25e26452015-06-02 09:56:29 -07003567 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003568 if (mService != null) {
3569 try {
Robin Lee25e26452015-06-02 09:56:29 -07003570 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003571 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003572 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003573 }
3574 }
3575 return false;
3576 }
3577
3578 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003579 * Determine whether or not caller-Id information has been disabled.
3580 *
3581 * @param userHandle The user for whom to check the caller-id permission
3582 * @hide
3583 */
3584 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3585 if (mService != null) {
3586 try {
3587 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3588 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003589 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003590 }
3591 }
3592 return false;
3593 }
3594
3595 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003596 * Called by a profile owner of a managed profile to set whether contacts search from
3597 * the managed profile will be shown in the parent profile, for incoming calls.
3598 *
3599 * <p>The calling device admin must be a profile owner. If it is not, a
3600 * security exception will be thrown.
3601 *
3602 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3603 * @param disabled If true contacts search in the managed profile is not displayed.
3604 */
3605 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3606 boolean disabled) {
3607 if (mService != null) {
3608 try {
3609 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3610 } catch (RemoteException e) {
3611 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3612 }
3613 }
3614 }
3615
3616 /**
3617 * Called by a profile owner of a managed profile to determine whether or not contacts search
3618 * has been disabled.
3619 *
3620 * <p>The calling device admin must be a profile owner. If it is not, a
3621 * security exception will be thrown.
3622 *
3623 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3624 */
3625 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3626 if (mService != null) {
3627 try {
3628 return mService.getCrossProfileContactsSearchDisabled(admin);
3629 } catch (RemoteException e) {
3630 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3631 }
3632 }
3633 return false;
3634 }
3635
3636
3637 /**
3638 * Determine whether or not contacts search has been disabled.
3639 *
3640 * @param userHandle The user for whom to check the contacts search permission
3641 * @hide
3642 */
3643 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3644 if (mService != null) {
3645 try {
3646 return mService
3647 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3648 } catch (RemoteException e) {
3649 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3650 }
3651 }
3652 return false;
3653 }
3654
3655 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003656 * Start Quick Contact on the managed profile for the user, if the policy allows.
Makoto Onuki1040da12015-03-19 11:24:00 -07003657 * @hide
3658 */
3659 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Ricky Wai494b95d2015-11-20 16:07:15 +00003660 long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003661 if (mService != null) {
3662 try {
3663 mService.startManagedQuickContact(
Ricky Wai494b95d2015-11-20 16:07:15 +00003664 actualLookupKey, actualContactId, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003665 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003666 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003667 }
3668 }
3669 }
3670
3671 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003672 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003673 * @hide
3674 */
3675 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3676 Intent originalIntent) {
3677 startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT,
3678 originalIntent);
3679 }
3680
3681 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003682 * Called by a profile owner of a managed profile to set whether bluetooth
3683 * devices can access enterprise contacts.
3684 * <p>
3685 * The calling device admin must be a profile owner. If it is not, a
3686 * security exception will be thrown.
3687 * <p>
3688 * This API works on managed profile only.
3689 *
Robin Lee25e26452015-06-02 09:56:29 -07003690 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003691 * with.
3692 * @param disabled If true, bluetooth devices cannot access enterprise
3693 * contacts.
3694 */
Robin Lee25e26452015-06-02 09:56:29 -07003695 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003696 if (mService != null) {
3697 try {
Robin Lee25e26452015-06-02 09:56:29 -07003698 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003699 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003700 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003701 }
3702 }
3703 }
3704
3705 /**
3706 * Called by a profile owner of a managed profile to determine whether or
3707 * not Bluetooth devices cannot access enterprise contacts.
3708 * <p>
3709 * The calling device admin must be a profile owner. If it is not, a
3710 * security exception will be thrown.
3711 * <p>
3712 * This API works on managed profile only.
3713 *
Robin Lee25e26452015-06-02 09:56:29 -07003714 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003715 * with.
3716 */
Robin Lee25e26452015-06-02 09:56:29 -07003717 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003718 if (mService != null) {
3719 try {
Robin Lee25e26452015-06-02 09:56:29 -07003720 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003721 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003722 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003723 }
3724 }
3725 return true;
3726 }
3727
3728 /**
3729 * Determine whether or not Bluetooth devices cannot access contacts.
3730 * <p>
3731 * This API works on managed profile UserHandle only.
3732 *
3733 * @param userHandle The user for whom to check the caller-id permission
3734 * @hide
3735 */
3736 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3737 if (mService != null) {
3738 try {
3739 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3740 .getIdentifier());
3741 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003742 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003743 }
3744 }
3745 return true;
3746 }
3747
3748 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003749 * Called by the profile owner of a managed profile so that some intents sent in the managed
3750 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003751 * Only activity intents are supported.
3752 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003753 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003754 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3755 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003756 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3757 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003758 */
Robin Lee25e26452015-06-02 09:56:29 -07003759 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003760 if (mService != null) {
3761 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003762 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003763 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003764 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003765 }
3766 }
3767 }
3768
3769 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003770 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3771 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003772 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003773 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3774 */
Robin Lee25e26452015-06-02 09:56:29 -07003775 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003776 if (mService != null) {
3777 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003778 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003779 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003780 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003781 }
3782 }
3783 }
3784
3785 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003786 * Called by a profile or device owner to set the permitted accessibility services. When
3787 * set by a device owner or profile owner the restriction applies to all profiles of the
3788 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003789 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003790 * By default the user can use any accessiblity service. When zero or more packages have
3791 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003792 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003793 *
3794 * <p> Calling with a null value for the list disables the restriction so that all services
3795 * can be used, calling with an empty list only allows the builtin system's services.
3796 *
3797 * <p> System accesibility services are always available to the user the list can't modify
3798 * this.
3799 *
3800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3801 * @param packageNames List of accessibility service package names.
3802 *
3803 * @return true if setting the restriction succeeded. It fail if there is
3804 * one or more non-system accessibility services enabled, that are not in the list.
3805 */
Robin Lee25e26452015-06-02 09:56:29 -07003806 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003807 List<String> packageNames) {
3808 if (mService != null) {
3809 try {
3810 return mService.setPermittedAccessibilityServices(admin, packageNames);
3811 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003812 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003813 }
3814 }
3815 return false;
3816 }
3817
3818 /**
3819 * Returns the list of permitted accessibility services set by this device or profile owner.
3820 *
3821 * <p>An empty list means no accessibility services except system services are allowed.
3822 * Null means all accessibility services are allowed.
3823 *
3824 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3825 * @return List of accessiblity service package names.
3826 */
Robin Lee25e26452015-06-02 09:56:29 -07003827 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003828 if (mService != null) {
3829 try {
3830 return mService.getPermittedAccessibilityServices(admin);
3831 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003832 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003833 }
3834 }
3835 return null;
3836 }
3837
3838 /**
3839 * Returns the list of accessibility services permitted by the device or profiles
3840 * owners of this user.
3841 *
3842 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3843 * it will contain the intersection of the permitted lists for any device or profile
3844 * owners that apply to this user. It will also include any system accessibility services.
3845 *
3846 * @param userId which user to check for.
3847 * @return List of accessiblity service package names.
3848 * @hide
3849 */
3850 @SystemApi
3851 public List<String> getPermittedAccessibilityServices(int userId) {
3852 if (mService != null) {
3853 try {
3854 return mService.getPermittedAccessibilityServicesForUser(userId);
3855 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003856 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003857 }
3858 }
3859 return null;
3860 }
3861
3862 /**
3863 * Called by a profile or device owner to set the permitted input methods services. When
3864 * set by a device owner or profile owner the restriction applies to all profiles of the
3865 * user the device owner or profile owner is an admin for.
3866 *
3867 * By default the user can use any input method. When zero or more packages have
3868 * been added, input method that are not in the list and not part of the system
3869 * can not be enabled by the user.
3870 *
3871 * This method will fail if it is called for a admin that is not for the foreground user
3872 * or a profile of the foreground user.
3873 *
3874 * <p> Calling with a null value for the list disables the restriction so that all input methods
3875 * can be used, calling with an empty list disables all but the system's own input methods.
3876 *
3877 * <p> System input methods are always available to the user this method can't modify this.
3878 *
3879 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3880 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003881 * @return true if setting the restriction succeeded. It will fail if there are
3882 * one or more non-system input methods currently enabled that are not in
3883 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003884 */
Robin Lee25e26452015-06-02 09:56:29 -07003885 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003886 if (mService != null) {
3887 try {
3888 return mService.setPermittedInputMethods(admin, packageNames);
3889 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003890 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003891 }
3892 }
3893 return false;
3894 }
3895
3896
3897 /**
3898 * Returns the list of permitted input methods set by this device or profile owner.
3899 *
3900 * <p>An empty list means no input methods except system input methods are allowed.
3901 * Null means all input methods are allowed.
3902 *
3903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3904 * @return List of input method package names.
3905 */
Robin Lee25e26452015-06-02 09:56:29 -07003906 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003907 if (mService != null) {
3908 try {
3909 return mService.getPermittedInputMethods(admin);
3910 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003911 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003912 }
3913 }
3914 return null;
3915 }
3916
3917 /**
3918 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08003919 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003920 *
3921 * <p>Null means all input methods are allowed, if a non-null list is returned
3922 * it will contain the intersection of the permitted lists for any device or profile
3923 * owners that apply to this user. It will also include any system input methods.
3924 *
3925 * @return List of input method package names.
3926 * @hide
3927 */
3928 @SystemApi
3929 public List<String> getPermittedInputMethodsForCurrentUser() {
3930 if (mService != null) {
3931 try {
3932 return mService.getPermittedInputMethodsForCurrentUser();
3933 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003934 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003935 }
3936 }
3937 return null;
3938 }
3939
3940 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003941 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
3942 * currently installed it.
3943 *
3944 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3945 *
3946 * @return List of package names to keep cached.
3947 * @hide
3948 */
3949 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
3950 if (mService != null) {
3951 try {
3952 return mService.getKeepUninstalledPackages(admin);
3953 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003954 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003955 }
3956 }
3957 return null;
3958 }
3959
3960 /**
3961 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
3962 * currently installed it.
3963 *
3964 * <p>Please note that setting this policy does not imply that specified apps will be
3965 * automatically pre-cached.</p>
3966 *
3967 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3968 * @param packageNames List of package names to keep cached.
3969 * @hide
3970 */
3971 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
3972 @NonNull List<String> packageNames) {
3973 if (mService != null) {
3974 try {
3975 mService.setKeepUninstalledPackages(admin, packageNames);
3976 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003977 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003978 }
3979 }
3980 }
3981
3982 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003983 * Called by a device owner to create a user with the specified name. The UserHandle returned
3984 * by this method should not be persisted as user handles are recycled as users are removed and
3985 * created. If you need to persist an identifier for this user, use
3986 * {@link UserManager#getSerialNumberForUser}.
3987 *
3988 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3989 * @param name the user's name
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}
Julia Reynolds1e958392014-05-16 14:25:21 -04003995 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003996 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003997 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003998 try {
3999 return mService.createUser(admin, name);
4000 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004001 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004002 }
4003 return null;
4004 }
4005
4006 /**
Jason Monk03978a42014-06-10 15:05:30 -04004007 * Called by a device owner to create a user with the specified name. The UserHandle returned
4008 * by this method should not be persisted as user handles are recycled as users are removed and
4009 * created. If you need to persist an identifier for this user, use
4010 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4011 * immediately.
4012 *
4013 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4014 * as registered as an active admin on the new user. The profile owner package will be
4015 * installed on the new user if it already is installed on the device.
4016 *
4017 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4018 * profileOwnerComponent when onEnable is called.
4019 *
4020 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4021 * @param name the user's name
4022 * @param ownerName the human readable name of the organisation associated with this DPM.
4023 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4024 * the user.
4025 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4026 * on the new user.
4027 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004028 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4029 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004030 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004031 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004032 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004033 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004034 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4035 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004036 try {
4037 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4038 adminExtras);
4039 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004040 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004041 }
4042 return null;
4043 }
4044
4045 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004046 * Called by a device owner to remove a user and all associated data. The primary user can
4047 * not be removed.
4048 *
4049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4050 * @param userHandle the user to remove.
4051 * @return {@code true} if the user was removed, {@code false} otherwise.
4052 */
Robin Lee25e26452015-06-02 09:56:29 -07004053 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004054 try {
4055 return mService.removeUser(admin, userHandle);
4056 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004057 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004058 return false;
4059 }
4060 }
4061
4062 /**
Jason Monk582d9112014-07-09 19:57:08 -04004063 * Called by a device owner to switch the specified user to the foreground.
4064 *
4065 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4066 * @param userHandle the user to switch to; null will switch to primary.
4067 * @return {@code true} if the switch was successful, {@code false} otherwise.
4068 *
4069 * @see Intent#ACTION_USER_FOREGROUND
4070 */
Robin Lee25e26452015-06-02 09:56:29 -07004071 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004072 try {
4073 return mService.switchUser(admin, userHandle);
4074 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004075 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004076 return false;
4077 }
4078 }
4079
4080 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004081 * Retrieves the application restrictions for a given target application running in the calling
4082 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004083 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004084 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4085 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4086 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004087 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4089 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004090 * @param packageName The name of the package to fetch restricted settings of.
4091 * @return {@link Bundle} of settings corresponding to what was set last time
4092 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4093 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004094 *
4095 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004096 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004097 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004098 if (mService != null) {
4099 try {
4100 return mService.getApplicationRestrictions(admin, packageName);
4101 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004102 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004103 }
4104 }
4105 return null;
4106 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004107
4108 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004109 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004110 * <p>
4111 * The calling device admin must be a profile or device owner; if it is not,
4112 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004113 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004114 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4115 * with.
4116 * @param key The key of the restriction. See the constants in
4117 * {@link android.os.UserManager} for the list of keys.
4118 */
Robin Lee25e26452015-06-02 09:56:29 -07004119 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004120 if (mService != null) {
4121 try {
4122 mService.setUserRestriction(admin, key, true);
4123 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004124 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004125 }
4126 }
4127 }
4128
4129 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004130 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004131 * <p>
4132 * The calling device admin must be a profile or device owner; if it is not,
4133 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004134 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004135 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4136 * with.
4137 * @param key The key of the restriction. See the constants in
4138 * {@link android.os.UserManager} for the list of keys.
4139 */
Robin Lee25e26452015-06-02 09:56:29 -07004140 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004141 if (mService != null) {
4142 try {
4143 mService.setUserRestriction(admin, key, false);
4144 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004145 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004146 }
4147 }
4148 }
Adam Connors010cfd42014-04-16 12:48:13 +01004149
4150 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004151 * Called by a profile or device owner to get user restrictions set with
4152 * {@link #addUserRestriction(ComponentName, String)}.
4153 * <p>
4154 * The target user may have more restrictions set by the system or other device owner / profile
4155 * owner. To get all the user restrictions currently set, use
4156 * {@link UserManager#getUserRestrictions()}.
4157 *
4158 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004159 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004160 */
4161 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004162 return getUserRestrictions(admin, myUserId());
4163 }
4164
4165 /** @hide per-user version */
4166 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004167 Bundle ret = null;
4168 if (mService != null) {
4169 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004170 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004171 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004172 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004173 }
4174 }
4175 return ret == null ? new Bundle() : ret;
4176 }
4177
4178 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004179 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004180 * is unavailable for use, but the data and actual package file remain.
4181 *
4182 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004183 * @param packageName The name of the package to hide or unhide.
4184 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4185 * unhidden.
4186 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004187 */
Robin Lee25e26452015-06-02 09:56:29 -07004188 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004189 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004190 if (mService != null) {
4191 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004192 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004193 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004194 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004195 }
4196 }
4197 return false;
4198 }
4199
4200 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004201 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004202 *
4203 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004204 * @param packageName The name of the package to retrieve the hidden status of.
4205 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004206 */
Robin Lee25e26452015-06-02 09:56:29 -07004207 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004208 if (mService != null) {
4209 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004210 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004211 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004212 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004213 }
4214 }
4215 return false;
4216 }
4217
4218 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004219 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004220 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004221 *
4222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004223 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004224 */
Robin Lee25e26452015-06-02 09:56:29 -07004225 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004226 if (mService != null) {
4227 try {
4228 mService.enableSystemApp(admin, packageName);
4229 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004230 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004231 }
4232 }
4233 }
4234
4235 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004236 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004237 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004238 *
4239 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4240 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004241 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004242 * @return int The number of activities that matched the intent and were installed.
4243 */
Robin Lee25e26452015-06-02 09:56:29 -07004244 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004245 if (mService != null) {
4246 try {
4247 return mService.enableSystemAppWithIntent(admin, intent);
4248 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004249 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004250 }
4251 }
4252 return 0;
4253 }
4254
4255 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004256 * Called by a device owner or profile owner to disable account management for a specific type
4257 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004258 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004259 * <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 +01004260 * security exception will be thrown.
4261 *
4262 * <p>When account management is disabled for an account type, adding or removing an account
4263 * of that type will not be possible.
4264 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004265 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4266 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4267 * management for a specific type is disabled.
4268 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004269 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4270 * @param accountType For which account management is disabled or enabled.
4271 * @param disabled The boolean indicating that account management will be disabled (true) or
4272 * enabled (false).
4273 */
Robin Lee25e26452015-06-02 09:56:29 -07004274 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004275 boolean disabled) {
4276 if (mService != null) {
4277 try {
4278 mService.setAccountManagementDisabled(admin, accountType, disabled);
4279 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004280 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004281 }
4282 }
4283 }
4284
4285 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004286 * Gets the array of accounts for which account management is disabled by the profile owner.
4287 *
4288 * <p> Account management can be disabled/enabled by calling
4289 * {@link #setAccountManagementDisabled}.
4290 *
4291 * @return a list of account types for which account management has been disabled.
4292 *
4293 * @see #setAccountManagementDisabled
4294 */
4295 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004296 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004297 }
4298
4299 /**
4300 * @see #getAccountTypesWithManagementDisabled()
4301 * @hide
4302 */
4303 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004304 if (mService != null) {
4305 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004306 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004307 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004308 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004309 }
4310 }
4311
4312 return null;
4313 }
justinzhang511e0d82014-03-24 16:09:24 -04004314
4315 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004316 * Sets which packages may enter lock task mode.
4317 *
4318 * <p>Any packages that shares uid with an allowed package will also be allowed
4319 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004320 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004321 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004322 * package list results in locked tasks belonging to those packages to be finished.
4323 *
Jason Monkc5185f22014-06-24 11:12:42 -04004324 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004325 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004326 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004327 *
4328 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004329 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4330 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004331 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004332 */
Robin Lee25e26452015-06-02 09:56:29 -07004333 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004334 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004335 if (mService != null) {
4336 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004337 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004338 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004339 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004340 }
4341 }
4342 }
4343
4344 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004345 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004346 *
4347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004348 * @hide
4349 */
Robin Lee25e26452015-06-02 09:56:29 -07004350 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004351 if (mService != null) {
4352 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004353 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004354 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004355 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004356 }
4357 }
4358 return null;
4359 }
4360
4361 /**
4362 * This function lets the caller know whether the given component is allowed to start the
4363 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004364 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004365 */
Jason Monkd7b86212014-06-16 13:15:38 -04004366 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004367 if (mService != null) {
4368 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004369 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004370 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004371 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004372 }
4373 }
4374 return false;
4375 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004376
4377 /**
4378 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4379 * 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 -04004380 * <p>The settings that can be updated with this method are:
4381 * <ul>
4382 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4383 * <li>{@link Settings.Global#AUTO_TIME}</li>
4384 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004385 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004386 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004387 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004388 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004389 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004390 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004391 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004392 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004393 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004394 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004395 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004396 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004397 * <ul>
4398 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4399 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4400 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4401 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4402 * <li>{@link Settings.Global#MODE_RINGER}.
4403 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4404 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4405 * <li>{@link Settings.Global#WIFI_ON}.
4406 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4407 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004408 *
4409 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4410 * @param setting The name of the setting to update.
4411 * @param value The value to update the setting to.
4412 */
Robin Lee25e26452015-06-02 09:56:29 -07004413 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004414 if (mService != null) {
4415 try {
4416 mService.setGlobalSetting(admin, setting, value);
4417 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004418 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004419 }
4420 }
4421 }
4422
4423 /**
4424 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4425 * that the value of the setting is in the correct form for the setting type should be performed
4426 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004427 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004428 * <ul>
4429 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004430 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004431 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4432 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004433 * <p>A device owner can additionally update the following settings:
4434 * <ul>
4435 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4436 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004437 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4438 * @param setting The name of the setting to update.
4439 * @param value The value to update the setting to.
4440 */
Robin Lee25e26452015-06-02 09:56:29 -07004441 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004442 if (mService != null) {
4443 try {
4444 mService.setSecureSetting(admin, setting, value);
4445 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004446 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004447 }
4448 }
4449 }
4450
Amith Yamasanif20d6402014-05-24 15:34:37 -07004451 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004452 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004453 * making permission requests of a local or remote administrator of the user.
4454 * <p/>
4455 * Only a profile owner can designate the restrictions provider.
4456 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004457 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004458 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004459 * it removes the restrictions provider previously assigned.
4460 */
Robin Lee25e26452015-06-02 09:56:29 -07004461 public void setRestrictionsProvider(@NonNull ComponentName admin,
4462 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004463 if (mService != null) {
4464 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004465 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004466 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004467 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004468 }
4469 }
4470 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004471
4472 /**
4473 * Called by profile or device owners to set the master volume mute on or off.
4474 *
4475 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4476 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4477 */
Robin Lee25e26452015-06-02 09:56:29 -07004478 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004479 if (mService != null) {
4480 try {
4481 mService.setMasterVolumeMuted(admin, on);
4482 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004483 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004484 }
4485 }
4486 }
4487
4488 /**
4489 * Called by profile or device owners to check whether the master volume mute is on or off.
4490 *
4491 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4492 * @return {@code true} if master volume is muted, {@code false} if it's not.
4493 */
Robin Lee25e26452015-06-02 09:56:29 -07004494 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004495 if (mService != null) {
4496 try {
4497 return mService.isMasterVolumeMuted(admin);
4498 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004499 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004500 }
4501 }
4502 return false;
4503 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004504
4505 /**
4506 * Called by profile or device owners to change whether a user can uninstall
4507 * a package.
4508 *
4509 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4510 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004511 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004512 */
Robin Lee25e26452015-06-02 09:56:29 -07004513 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004514 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004515 if (mService != null) {
4516 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004517 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004518 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004519 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004520 }
4521 }
4522 }
4523
4524 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004525 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004526 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004527 * <p>
4528 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004529 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004530 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004531 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004532 *
Robin Lee25e26452015-06-02 09:56:29 -07004533 * @param admin The name of the admin component whose blocking policy will be checked, or
4534 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004535 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004536 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004537 */
Robin Lee25e26452015-06-02 09:56:29 -07004538 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004539 if (mService != null) {
4540 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004541 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004542 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004543 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004544 }
4545 }
4546 return false;
4547 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004548
4549 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004550 * Called by the profile owner of a managed profile to enable widget providers from a
4551 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004552 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004553 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004554 * a package may have zero or more provider components, where each component
4555 * provides a different widget type.
4556 * <p>
4557 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004558 *
4559 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4560 * @param packageName The package from which widget providers are white-listed.
4561 * @return Whether the package was added.
4562 *
4563 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4564 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4565 */
Robin Lee25e26452015-06-02 09:56:29 -07004566 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004567 if (mService != null) {
4568 try {
4569 return mService.addCrossProfileWidgetProvider(admin, packageName);
4570 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004571 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004572 }
4573 }
4574 return false;
4575 }
4576
4577 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004578 * Called by the profile owner of a managed profile to disable widget providers from a given
4579 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004580 * package should have been added via {@link #addCrossProfileWidgetProvider(
4581 * android.content.ComponentName, String)}.
4582 * <p>
4583 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004584 *
4585 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4586 * @param packageName The package from which widget providers are no longer
4587 * white-listed.
4588 * @return Whether the package was removed.
4589 *
4590 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4591 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4592 */
Robin Lee25e26452015-06-02 09:56:29 -07004593 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004594 if (mService != null) {
4595 try {
4596 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4597 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004598 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004599 }
4600 }
4601 return false;
4602 }
4603
4604 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004605 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004606 * available in the parent profile.
4607 *
4608 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4609 * @return The white-listed package list.
4610 *
4611 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4612 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4613 */
Robin Lee25e26452015-06-02 09:56:29 -07004614 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004615 if (mService != null) {
4616 try {
4617 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4618 if (providers != null) {
4619 return providers;
4620 }
4621 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004622 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004623 }
4624 }
4625 return Collections.emptyList();
4626 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004627
4628 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004629 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004630 *
4631 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4632 * @param icon the bitmap to set as the photo.
4633 */
Robin Lee25e26452015-06-02 09:56:29 -07004634 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004635 try {
4636 mService.setUserIcon(admin, icon);
4637 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004638 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004639 }
4640 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004641
4642 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004643 * Called by device owners to set a local system update policy. When a new policy is set,
4644 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004645 *
Robin Lee25e26452015-06-02 09:56:29 -07004646 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4647 * components in the device owner package can set system update policies and the
4648 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004649 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004650 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004651 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004652 */
Robin Lee25e26452015-06-02 09:56:29 -07004653 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004654 if (mService != null) {
4655 try {
Robin Lee25e26452015-06-02 09:56:29 -07004656 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004657 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004658 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004659 }
4660 }
4661 }
4662
4663 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004664 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004665 *
Robin Lee25e26452015-06-02 09:56:29 -07004666 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004667 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004668 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004669 if (mService != null) {
4670 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004671 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004672 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004673 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004674 }
4675 }
4676 return null;
4677 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004678
4679 /**
4680 * Called by a device owner to disable the keyguard altogether.
4681 *
4682 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4683 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4684 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4685 * being disabled.
4686 *
4687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004688 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004689 *
4690 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004691 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004692 */
Robin Lee25e26452015-06-02 09:56:29 -07004693 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004694 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004695 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004696 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004697 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01004698 return false;
4699 }
4700 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004701
4702 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004703 * Called by device owner to disable the status bar. Disabling the status bar blocks
4704 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004705 * a single use device.
4706 *
4707 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004708 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4709 *
4710 * @return {@code false} if attempting to disable the status bar failed.
4711 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004712 */
Robin Lee25e26452015-06-02 09:56:29 -07004713 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004714 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004715 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004716 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004717 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004718 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004719 }
4720 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004721
4722 /**
4723 * Callable by the system update service to notify device owners about pending updates.
4724 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4725 * permission.
4726 *
4727 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4728 * when the current pending update was first available. -1 if no update is available.
4729 * @hide
4730 */
4731 @SystemApi
4732 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4733 if (mService != null) {
4734 try {
4735 mService.notifyPendingSystemUpdate(updateReceivedTime);
4736 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004737 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01004738 }
4739 }
4740 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004741
4742 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004743 * Called by profile or device owners to set the default response for future runtime permission
4744 * requests by applications. The policy can allow for normal operation which prompts the
4745 * user to grant a permission, or can allow automatic granting or denying of runtime
4746 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004747 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4748 * the permission grant state via {@link #setPermissionGrantState}.
4749 *
4750 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004751 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004752 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004753 * @param admin Which profile or device owner this request is associated with.
4754 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4755 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004756 *
4757 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004758 */
Robin Lee25e26452015-06-02 09:56:29 -07004759 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004760 try {
4761 mService.setPermissionPolicy(admin, policy);
4762 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004763 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004764 }
4765 }
4766
4767 /**
4768 * Returns the current runtime permission policy set by the device or profile owner. The
4769 * default is {@link #PERMISSION_POLICY_PROMPT}.
4770 * @param admin Which profile or device owner this request is associated with.
4771 * @return the current policy for future permission requests.
4772 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004773 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004774 try {
4775 return mService.getPermissionPolicy(admin);
4776 } catch (RemoteException re) {
4777 return PERMISSION_POLICY_PROMPT;
4778 }
4779 }
4780
4781 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004782 * Sets the grant state of a runtime permission for a specific application. The state
4783 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4784 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4785 * is denied and the user cannot manage it through the UI, and {@link
4786 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4787 * user cannot manage it through the UI. This might affect all permissions in a
4788 * group that the runtime permission belongs to. This method can only be called
4789 * by a profile or device owner.
4790 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004791 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4792 * revoke the permission. It retains the previous grant, if any.
4793 *
4794 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004795 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004796 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004797 * @param admin Which profile or device owner this request is associated with.
4798 * @param packageName The application to grant or revoke a permission to.
4799 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004800 * @param grantState The permission grant state which is one of {@link
4801 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4802 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4803 * @return whether the permission was successfully granted or revoked.
4804 *
4805 * @see #PERMISSION_GRANT_STATE_DENIED
4806 * @see #PERMISSION_GRANT_STATE_DEFAULT
4807 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004808 */
Robin Lee25e26452015-06-02 09:56:29 -07004809 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004810 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004811 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004812 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004813 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004814 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004815 return false;
4816 }
4817 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004818
4819 /**
4820 * Returns the current grant state of a runtime permission for a specific application.
4821 *
4822 * @param admin Which profile or device owner this request is associated with.
4823 * @param packageName The application to check the grant state for.
4824 * @param permission The permission to check for.
4825 * @return the current grant state specified by device policy. If the profile or device owner
4826 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4827 * This does not indicate whether or not the permission is currently granted for the package.
4828 *
4829 * <p/>If a grant state was set by the profile or device owner, then the return value will
4830 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4831 * which indicates if the permission is currently denied or granted.
4832 *
4833 * @see #setPermissionGrantState(ComponentName, String, String, int)
4834 * @see PackageManager#checkPermission(String, String)
4835 */
Robin Lee25e26452015-06-02 09:56:29 -07004836 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004837 String permission) {
4838 try {
4839 return mService.getPermissionGrantState(admin, packageName, permission);
4840 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004841 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07004842 return PERMISSION_GRANT_STATE_DEFAULT;
4843 }
4844 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004845
4846 /**
4847 * Returns if provisioning a managed profile or device is possible or not.
4848 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4849 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4850 * Note that even if this method returns true, there is a slight possibility that the
4851 * provisioning will not be allowed when it is actually initiated because some event has
4852 * happened in between.
4853 * @return if provisioning a managed profile or device is possible or not.
4854 * @throws IllegalArgumentException if the supplied action is not valid.
4855 */
4856 public boolean isProvisioningAllowed(String action) {
4857 try {
4858 return mService.isProvisioningAllowed(action);
4859 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004860 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004861 return false;
4862 }
4863 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004864
4865 /**
4866 * @hide
4867 * Return if this user is a managed profile of another user. An admin can become the profile
4868 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
4869 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
4870 * @param admin Which profile owner this request is associated with.
4871 * @return if this user is a managed profile of another user.
4872 */
4873 public boolean isManagedProfile(@NonNull ComponentName admin) {
4874 try {
4875 return mService.isManagedProfile(admin);
4876 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004877 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004878 return false;
4879 }
4880 }
4881
4882 /**
4883 * @hide
4884 * Return if this user is a system-only user. An admin can manage a device from a system only
4885 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
4886 * @param admin Which device owner this request is associated with.
4887 * @return if this user is a system-only user.
4888 */
4889 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
4890 try {
4891 return mService.isSystemOnlyUser(admin);
4892 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004893 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004894 return false;
4895 }
4896 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004897
4898 /**
4899 * Called by device owner to get the MAC address of the Wi-Fi device.
4900 *
4901 * @return the MAC address of the Wi-Fi device, or null when the information is not
4902 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
4903 *
4904 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
4905 */
4906 public String getWifiMacAddress() {
4907 try {
4908 return mService.getWifiMacAddress();
4909 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004910 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004911 return null;
4912 }
4913 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00004914
4915 /**
4916 * Called by device owner to reboot the device.
4917 */
4918 public void reboot(@NonNull ComponentName admin) {
4919 try {
4920 mService.reboot(admin);
4921 } catch (RemoteException re) {
4922 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4923 }
4924 }
Kenny Guy06de4e72015-12-22 12:07:39 +00004925
4926 /**
4927 * Called by a device admin to set the short support message. This will
4928 * be displayed to the user in settings screens where funtionality has
4929 * been disabled by the admin.
4930 *
4931 * The message should be limited to a short statement such as
4932 * "This setting is disabled by your administrator. Contact someone@example.com
4933 * for support."
4934 * If the message is longer than 200 characters it may be truncated.
4935 *
4936 * @see #setLongSupportMessage
4937 *
4938 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4939 * @param message Short message to be displayed to the user in settings or null to
4940 * clear the existing message.
4941 */
4942 public void setShortSupportMessage(@NonNull ComponentName admin,
4943 @Nullable String message) {
4944 if (mService != null) {
4945 try {
4946 mService.setShortSupportMessage(admin, message);
4947 } catch (RemoteException e) {
4948 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4949 }
4950 }
4951 }
4952
4953 /**
4954 * Called by a device admin to get the short support message.
4955 *
4956 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4957 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
4958 * or null if no message has been set.
4959 */
4960 public String getShortSupportMessage(@NonNull ComponentName admin) {
4961 if (mService != null) {
4962 try {
4963 return mService.getShortSupportMessage(admin);
4964 } catch (RemoteException e) {
4965 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4966 }
4967 }
4968 return null;
4969 }
4970
4971 /**
4972 * Called by a device admin to set the long support message. This will
4973 * be displayed to the user in the device administators settings screen.
4974 *
4975 * @see #setShortSupportMessage
4976 *
4977 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4978 * @param message Long message to be displayed to the user in settings or null to
4979 * clear the existing message.
4980 */
4981 public void setLongSupportMessage(@NonNull ComponentName admin,
4982 @Nullable String message) {
4983 if (mService != null) {
4984 try {
4985 mService.setLongSupportMessage(admin, message);
4986 } catch (RemoteException e) {
4987 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4988 }
4989 }
4990 }
4991
4992 /**
4993 * Called by a device admin to get the long support message.
4994 *
4995 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4996 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
4997 * or null if no message has been set.
4998 */
4999 public String getLongSupportMessage(@NonNull ComponentName admin) {
5000 if (mService != null) {
5001 try {
5002 return mService.getLongSupportMessage(admin);
5003 } catch (RemoteException e) {
5004 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5005 }
5006 }
5007 return null;
5008 }
5009
5010 /**
5011 * Called by the system to get the short support message.
5012 *
5013 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5014 * @param userHandle user id the admin is running as.
5015 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5016 *
5017 * @hide
5018 */
5019 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5020 if (mService != null) {
5021 try {
5022 return mService.getShortSupportMessageForUser(admin, userHandle);
5023 } catch (RemoteException e) {
5024 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5025 }
5026 }
5027 return null;
5028 }
5029
5030
5031 /**
5032 * Called by the system to get the long support message.
5033 *
5034 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5035 * @param userHandle user id the admin is running as.
5036 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5037 *
5038 * @hide
5039 */
5040 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5041 if (mService != null) {
5042 try {
5043 return mService.getLongSupportMessageForUser(admin, userHandle);
5044 } catch (RemoteException e) {
5045 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5046 }
5047 }
5048 return null;
5049 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005050
5051 /**
5052 * Obtains a {@link DevicePolicyManager} whose calls act on the parent profile.
5053 *
5054 * <p> Note only some methods will work on the parent Manager.
5055 *
5056 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5057 */
5058 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5059 try {
5060 if (!mService.isManagedProfile(admin)) {
5061 throw new SecurityException("The current user does not have a parent profile.");
5062 }
5063 return new DevicePolicyManager(mContext, true);
5064 } catch (RemoteException re) {
5065 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5066 return null;
5067 }
5068 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005069}