blob: 768da6a41136655439e0674aadbf6c734375e7d9 [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
Alan Treadwayafad8782016-01-19 15:15:08 +000019import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080022import android.annotation.SdkConstant;
23import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050024import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040025import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080026import android.content.ComponentName;
27import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010028import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000029import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080030import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050033import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040034import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000035import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010036import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070037import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000038import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080039import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080040import android.os.RemoteException;
41import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070042import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040043import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000044import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000045import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010046import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070047import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080048import android.util.Log;
49
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070050import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040051import com.android.org.conscrypt.TrustedCertificateStore;
52
Jessica Hummel91da58d2014-04-10 17:39:43 +010053import org.xmlpull.v1.XmlPullParserException;
54
Maggie Benthallda51e682013-08-08 22:35:44 -040055import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080056import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000057import java.lang.annotation.Retention;
58import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070059import java.net.InetSocketAddress;
60import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010061import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000062import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010063import java.security.PrivateKey;
64import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040065import java.security.cert.CertificateException;
66import java.security.cert.CertificateFactory;
67import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010068import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000069import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070070import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070071import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080072import java.util.List;
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +010073import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080074
75/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000076 * Public interface for managing policies enforced on a device. Most clients of this class must be
77 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000078 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000079 * a device administrator may be registered as either a profile or device owner. A given method is
80 * accessible to all device administrators unless the documentation for that method specifies that
81 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 *
83 * <div class="special reference">
84 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000085 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080086 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070087 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080088 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080089 */
90public class DevicePolicyManager {
91 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080092
93 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080094 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +000095 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070096
Makoto Onukic8a5a552015-11-19 14:29:12 -080097 private static final String REMOTE_EXCEPTION_MESSAGE =
98 "Failed to talk with device policy manager service";
99
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000100 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000101 this(context,
102 IDevicePolicyManager.Stub.asInterface(
103 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
104 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800105 }
106
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800107 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700108 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000109 protected DevicePolicyManager(
110 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700111 mContext = context;
112 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000113 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 }
115
116 /** @hide */
117 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000118 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800119 return me.mService != null ? me : null;
120 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700121
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700122 /** @hide test will override it. */
123 @VisibleForTesting
124 protected int myUserId() {
125 return UserHandle.myUserId();
126 }
127
Dianne Hackbornd6847842010-01-12 18:14:19 -0800128 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000129 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100131 * <p>A managed profile allows data separation for example for the usage of a
132 * device as a personal and corporate device. The user which provisioning is started from and
133 * the managed profile share a launcher.
134 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800135 * <p>This intent will typically be sent by a mobile device management application (MDM).
136 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
137 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100138 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000139 * <p>It is possible to check if provisioning is allowed or not by querying the method
140 * {@link #isProvisioningAllowed(String)}.
141 *
142 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000143 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700144 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000145 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
146 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000147 *
148 * <p> The intent may also contain the following extras:
149 * <ul>
150 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
151 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
152 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000153 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000154 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
155 * in the provisioning intent. The
156 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
157 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
158 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100159 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100160 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
161 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100162 *
163 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
164 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
165 * the provisioning flow was successful, although this doesn't guarantee the full flow will
166 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
167 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000168 */
169 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
170 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100171 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000172
173 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000174 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000175 * Activity action: Starts the provisioning flow which sets up a managed user.
176 *
177 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800178 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000179 * owner who has full control over the user. Provisioning can only happen before user setup has
180 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
181 * allowed.
182 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000183 * <p>This intent should contain the extra
184 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000185 *
186 * <p> If provisioning fails, the device returns to its previous state.
187 *
188 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
189 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
190 * the provisioning flow was successful, although this doesn't guarantee the full flow will
191 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
192 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000193 */
194 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
195 public static final String ACTION_PROVISION_MANAGED_USER
196 = "android.app.action.PROVISION_MANAGED_USER";
197
198 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100199 * Activity action: Starts the provisioning flow which sets up a managed device.
200 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
201 *
202 * <p> During device owner provisioning a device admin app is set as the owner of the device.
203 * A device owner has full control over the device. The device owner can not be modified by the
204 * user.
205 *
206 * <p> A typical use case would be a device that is owned by a company, but used by either an
207 * employee or client.
208 *
209 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000210 * It is possible to check if provisioning is allowed or not by querying the method
211 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100212 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000213 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100214 * <ul>
215 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
216 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
217 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100218 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000219 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000220 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100221 * </ul>
222 *
223 * <p> When device owner provisioning has completed, an intent of the type
224 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
225 * device owner.
226 *
227 * <p> If provisioning fails, the device is factory reset.
228 *
Alan Treadway4582f812015-07-28 11:49:35 +0100229 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
230 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
231 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
232 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100233 */
234 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
235 public static final String ACTION_PROVISION_MANAGED_DEVICE
236 = "android.app.action.PROVISION_MANAGED_DEVICE";
237
238 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000239 * Activity action: Starts the provisioning flow which sets up a managed device.
240 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
241 *
242 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
243 * management state that is distinct from that reached by
244 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
245 * user, and only has control over device-wide policies, not individual users and their data.
246 * The primary benefit is that multiple non-system users are supported when provisioning using
247 * this form of device management.
248 *
249 * <p> During device owner provisioning a device admin app is set as the owner of the device.
250 * A device owner has full control over the device. The device owner can not be modified by the
251 * user.
252 *
253 * <p> A typical use case would be a device that is owned by a company, but used by either an
254 * employee or client.
255 *
256 * <p> An intent with this action can be sent only on an unprovisioned device.
257 * It is possible to check if provisioning is allowed or not by querying the method
258 * {@link #isProvisioningAllowed(String)}.
259 *
260 * <p>The intent contains the following extras:
261 * <ul>
262 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
263 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
264 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
266 * </ul>
267 *
268 * <p> When device owner provisioning has completed, an intent of the type
269 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
270 * device owner.
271 *
272 * <p> If provisioning fails, the device is factory reset.
273 *
274 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
275 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
276 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
277 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
278 *
279 * @hide
280 */
281 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
282 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
283 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
284
285 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000286 * Activity action: Finalizes management provisioning, should be used after user-setup
287 * has been completed and {@link #getUserProvisioningState()} returns one of:
288 * <ul>
289 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
290 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
291 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
292 * </ul>
293 *
294 * @hide
295 */
296 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
297 public static final String ACTION_PROVISION_FINALIZATION
298 = "android.app.action.PROVISION_FINALIZATION";
299
300 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100301 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100302 * allows a mobile device management application or NFC programmer application which starts
303 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100304 * <p>
305 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
306 * sends the intent to pass data to itself on the newly created profile.
307 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
308 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100309 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
310 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
311 * message should contain a stringified {@link java.util.Properties} instance, whose string
312 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
313 * management application after provisioning.
314 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100315 * <p>
316 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700317 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
318 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100319 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100320 */
321 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100322 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100323
324 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100325 * A String extra holding the package name of the mobile device management application that
326 * will be set as the profile owner or device owner.
327 *
328 * <p>If an application starts provisioning directly via an intent with action
329 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
330 * application that started provisioning. The package will be set as profile owner in that case.
331 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000332 * <p>This package is set as device owner when device owner provisioning is started by an NFC
333 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000334 *
335 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700336 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000337
338 * @see DeviceAdminReceiver
339 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100340 * supported, but only if there is only one device admin receiver in the package that requires
341 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000342 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000343 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000344 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100345 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000346
347 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000348 * A ComponentName extra indicating the device admin receiver of the mobile device management
349 * application that will be set as the profile owner or device owner and active admin.
350 *
351 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100352 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
353 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
354 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000355 *
356 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100357 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
358 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400359 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000360 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000361 *
362 * @see DeviceAdminReceiver
363 */
364 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
365 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
366
367 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000368 * An {@link android.accounts.Account} extra holding the account to migrate during managed
369 * profile provisioning. If the account supplied is present in the primary user, it will be
370 * copied, along with its credentials to the managed profile and removed from the primary user.
371 *
372 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
373 */
374
375 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
376 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
377
378 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100379 * A String extra that, holds the email address of the account which a managed profile is
380 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
381 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100382 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100383 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
384 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100385 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
386 * contains this extra, it is forwarded in the
387 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
388 * device management application that was set as the profile owner during provisioning.
389 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100390 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100391 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
392 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100393
394 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000395 * A integer extra indicating the predominant color to show during the provisioning.
396 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000397 *
398 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
399 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
400 */
401 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
402 "android.app.extra.PROVISIONING_MAIN_COLOR";
403
404 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000405 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700406 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000407 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100408 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
409 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000410 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000411 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
412 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000413
414 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100415 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
416 * will be set to.
417 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000418 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
419 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100420 */
421 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100422 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100423
424 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100425 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
426 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100427 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000428 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
429 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100430 */
431 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100432 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100433
434 /**
435 * A String extra holding the {@link java.util.Locale} that the device will be set to.
436 * Format: xx_yy, where xx is the language code, and yy the country code.
437 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000438 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
439 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100440 */
441 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100442 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100443
444 /**
445 * A String extra holding the ssid of the wifi network that should be used during nfc device
446 * owner provisioning for downloading the mobile device management application.
447 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000448 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
449 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100450 */
451 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100452 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100453
454 /**
455 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
456 * is hidden or not.
457 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000458 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
459 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100460 */
461 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100462 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100463
464 /**
465 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100466 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
467 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100468 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000469 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
470 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100471 */
472 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100473 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100474
475 /**
476 * A String extra holding the password of the wifi network in
477 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
478 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000479 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
480 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100481 */
482 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100483 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100484
485 /**
486 * A String extra holding the proxy host for the wifi network in
487 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
488 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000489 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
490 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100491 */
492 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100493 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100494
495 /**
496 * An int extra holding the proxy port for the wifi network in
497 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
498 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000499 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
500 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100501 */
502 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100503 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100504
505 /**
506 * A String extra holding the proxy bypass for the wifi network in
507 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
508 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000509 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
510 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100511 */
512 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100513 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100514
515 /**
516 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
517 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
518 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000519 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
520 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100521 */
522 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100523 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100524
525 /**
526 * A String extra holding a url that specifies the download location of the device admin
527 * package. When not provided it is assumed that the device admin package is already installed.
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 Alewijnse1cc4ecc2014-06-23 19:56:52 +0100531 */
532 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100533 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100534
535 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400536 * An int extra holding a minimum required version code for the device admin package. If the
537 * device admin is already installed on the device, it will only be re-downloaded from
538 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
539 * installed package is less than this version code.
540 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400541 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400542 * provisioning via an NFC bump.
543 */
544 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
545 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
546
547 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100548 * A String extra holding a http cookie header which should be used in the http request to the
549 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
550 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000551 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
552 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100553 */
554 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100555 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100556
557 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100558 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
559 * the file at download location specified in
560 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100561 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100562 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100563 * present. The provided checksum should match the checksum of the file at the download
564 * location. If the checksum doesn't match an error will be shown to the user and the user will
565 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100566 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000567 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
568 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100569 *
570 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
571 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700572 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100573 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574 */
575 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100576 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100577
578 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100579 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100580 * android package archive at the download location specified in {@link
581 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
582 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100583 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100584 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
585 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
586 *
587 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100588 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100589 * the download location. If the checksum does not match an error will be shown to the user and
590 * the user will be asked to factory reset the device.
591 *
592 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
593 * provisioning via an NFC bump.
594 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100595 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
596 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100597
598 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000599 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
600 * has completed successfully.
601 *
602 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700603 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000604 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800605 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000606 * corresponds to the account requested to be migrated at provisioning time, if any.
607 */
608 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
609 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
610 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
611
612 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400613 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500614 * provisioning.
615 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400616 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100617 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500618 */
619 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
620 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
621
622 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000623 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
624 * provisioning. If this extra is not passed, a default image will be shown.
625 * <h5>The following URI schemes are accepted:</h5>
626 * <ul>
627 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
628 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
629 * </ul>
630 *
631 * <p> It is the responsability of the caller to provide an image with a reasonable
632 * pixed density for the device.
633 *
634 * <p> If a content: URI is passed, the intent should have the flag
635 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
636 * {@link android.content.ClipData} of the intent too.
637 *
638 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
639 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
640 */
641 public static final String EXTRA_PROVISIONING_LOGO_URI =
642 "android.app.extra.PROVISIONING_LOGO_URI";
643
644 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000645 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
646 * during setup-wizard.
647 *
648 * <p>If unspecified, defaults to {@code true} to match the behavior in
649 * {@link android.os.Build.VERSION_CODES#M} and earlier.
650 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000651 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
652 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000653 *
654 * @hide
655 */
656 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
657 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
658
659 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400660 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100661 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400662 * <p>During device owner provisioning a device admin app is set as the owner of the device.
663 * A device owner has full control over the device. The device owner can not be modified by the
664 * user and the only way of resetting the device is if the device owner app calls a factory
665 * reset.
666 *
667 * <p> A typical use case would be a device that is owned by a company, but used by either an
668 * employee or client.
669 *
670 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100671 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000672 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100673 * contains the following properties:
674 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400675 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
676 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100677 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400678 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100679 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
680 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
681 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
682 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
683 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
684 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
685 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
686 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
687 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
688 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100689 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
690 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
691 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100692 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000693 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700694 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400695 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
696 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
697 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400698 */
699 public static final String MIME_TYPE_PROVISIONING_NFC
700 = "application/com.android.managedprovisioning";
701
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100702 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800703 * Activity action: ask the user to add a new device administrator to the system.
704 * The desired policy is the ComponentName of the policy in the
705 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
706 * bring the user through adding the device administrator to the system (or
707 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700708 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800709 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
710 * field to provide the user with additional explanation (in addition
711 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800712 *
713 * <p>If your administrator is already active, this will ordinarily return immediately (without
714 * user intervention). However, if your administrator has been updated and is requesting
715 * additional uses-policy flags, the user will be presented with the new list. New policies
716 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800717 */
718 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
719 public static final String ACTION_ADD_DEVICE_ADMIN
720 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700721
Dianne Hackbornd6847842010-01-12 18:14:19 -0800722 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700723 * @hide
724 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700725 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700726 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700727 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
728 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700729 * to remotely control restrictions on the user.
730 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800731 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700732 * result of whether or not the user approved the action. If approved, the result will
733 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
734 * as a profile owner.
735 *
736 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
737 * field to provide the user with additional explanation (in addition
738 * to your component's description) about what is being added.
739 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700740 * <p>If there is already a profile owner active or the caller is not a system app, the
741 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700742 */
743 @SystemApi
744 public static final String ACTION_SET_PROFILE_OWNER
745 = "android.app.action.SET_PROFILE_OWNER";
746
747 /**
748 * @hide
749 * Name of the profile owner admin that controls the user.
750 */
751 @SystemApi
752 public static final String EXTRA_PROFILE_OWNER_NAME
753 = "android.app.extra.PROFILE_OWNER_NAME";
754
755 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100756 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700757 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700758 *
Jim Miller284b62e2010-06-08 14:27:42 -0700759 * @hide
760 */
761 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
762 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
763
764 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100765 * Broadcast action: sent when the device owner is set or changed.
766 *
767 * This broadcast is sent only to the primary user.
768 * @see #ACTION_PROVISION_MANAGED_DEVICE
769 */
770 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
771 public static final String ACTION_DEVICE_OWNER_CHANGED
772 = "android.app.action.DEVICE_OWNER_CHANGED";
773
774 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800775 * The ComponentName of the administrator component.
776 *
777 * @see #ACTION_ADD_DEVICE_ADMIN
778 */
779 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700780
Dianne Hackbornd6847842010-01-12 18:14:19 -0800781 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800782 * An optional CharSequence providing additional explanation for why the
783 * admin is being added.
784 *
785 * @see #ACTION_ADD_DEVICE_ADMIN
786 */
787 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700788
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800789 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700790 * Activity action: have the user enter a new password. This activity should
791 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
792 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
793 * enter a new password that meets the current requirements. You can use
794 * {@link #isActivePasswordSufficient()} to determine whether you need to
795 * have the user select a new password in order to meet the current
796 * constraints. Upon being resumed from this activity, you can check the new
797 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000798 *
799 * If the intent is launched from within a managed profile with a profile
800 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
801 * this will trigger entering a new password for the parent of the profile.
802 * For all other cases it will trigger entering a new password for the user
803 * or profile it is launched from.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800804 */
805 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
806 public static final String ACTION_SET_NEW_PASSWORD
807 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700808
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000809 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000810 * Activity action: have the user enter a new password for the parent profile.
811 * If the intent is launched from within a managed profile, this will trigger
812 * entering a new password for the parent of the profile. In all other cases
813 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
814 */
815 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
816 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
817 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
818
819 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000820 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
821 * the parent profile to access intents sent from the managed profile.
822 * That is, when an app in the managed profile calls
823 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
824 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000825 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100826 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000827
828 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000829 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
830 * the managed profile to access intents sent from the parent profile.
831 * That is, when an app in the parent profile calls
832 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
833 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000834 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100835 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700836
Dianne Hackbornd6847842010-01-12 18:14:19 -0800837 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100838 * Broadcast action: notify that a new local system update policy has been set by the device
839 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000840 */
841 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100842 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
843 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000844
Amith Yamasanid49489b2015-04-28 14:00:26 -0700845 /**
846 * Permission policy to prompt user for new permission requests for runtime permissions.
847 * Already granted or denied permissions are not affected by this.
848 */
849 public static final int PERMISSION_POLICY_PROMPT = 0;
850
851 /**
852 * Permission policy to always grant new permission requests for runtime permissions.
853 * Already granted or denied permissions are not affected by this.
854 */
855 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
856
857 /**
858 * Permission policy to always deny new permission requests for runtime permissions.
859 * Already granted or denied permissions are not affected by this.
860 */
861 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
862
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700863 /**
864 * Runtime permission state: The user can manage the permission
865 * through the UI.
866 */
867 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
868
869 /**
870 * Runtime permission state: The permission is granted to the app
871 * and the user cannot manage the permission through the UI.
872 */
873 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
874
875 /**
876 * Runtime permission state: The permission is denied to the app
877 * and the user cannot manage the permission through the UI.
878 */
879 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000880
881 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000882 * No management for current user in-effect. This is the default.
883 * @hide
884 */
885 public static final int STATE_USER_UNMANAGED = 0;
886
887 /**
888 * Management partially setup, user setup needs to be completed.
889 * @hide
890 */
891 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
892
893 /**
894 * Management partially setup, user setup completed.
895 * @hide
896 */
897 public static final int STATE_USER_SETUP_COMPLETE = 2;
898
899 /**
900 * Management setup and active on current user.
901 * @hide
902 */
903 public static final int STATE_USER_SETUP_FINALIZED = 3;
904
905 /**
906 * Management partially setup on a managed profile.
907 * @hide
908 */
909 public static final int STATE_USER_PROFILE_COMPLETE = 4;
910
911 /**
912 * @hide
913 */
914 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
915 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
916 @Retention(RetentionPolicy.SOURCE)
917 public @interface UserProvisioningState {}
918
919 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800920 * Return true if the given administrator component is currently
921 * active (enabled) in the system.
922 */
Robin Lee25e26452015-06-02 09:56:29 -0700923 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700924 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100925 }
926
927 /**
928 * @see #isAdminActive(ComponentName)
929 * @hide
930 */
Robin Lee25e26452015-06-02 09:56:29 -0700931 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800932 if (mService != null) {
933 try {
Robin Lee25e26452015-06-02 09:56:29 -0700934 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800935 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800936 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800937 }
938 }
939 return false;
940 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800941 /**
942 * Return true if the given administrator component is currently being removed
943 * for the user.
944 * @hide
945 */
Robin Lee25e26452015-06-02 09:56:29 -0700946 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800947 if (mService != null) {
948 try {
Robin Lee25e26452015-06-02 09:56:29 -0700949 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800950 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800951 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800952 }
953 }
954 return false;
955 }
956
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700957
Dianne Hackbornd6847842010-01-12 18:14:19 -0800958 /**
Robin Lee25e26452015-06-02 09:56:29 -0700959 * Return a list of all currently active device administrators' component
960 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800961 * returned.
962 */
963 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700964 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100965 }
966
967 /**
968 * @see #getActiveAdmins()
969 * @hide
970 */
971 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800972 if (mService != null) {
973 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100974 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800975 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800976 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800977 }
978 }
979 return null;
980 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700981
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800982 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700983 * Used by package administration code to determine if a package can be stopped
984 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800985 * @hide
986 */
987 public boolean packageHasActiveAdmins(String packageName) {
988 if (mService != null) {
989 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700990 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800991 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800992 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800993 }
994 }
995 return false;
996 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700997
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800998 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800999 * Remove a current administration component. This can only be called
1000 * by the application that owns the administration component; if you
1001 * try to remove someone else's component, a security exception will be
1002 * thrown.
1003 */
Robin Lee25e26452015-06-02 09:56:29 -07001004 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001005 if (mService != null) {
1006 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001007 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001008 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001009 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001010 }
1011 }
1012 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001013
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001015 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001016 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001017 * but requires additional policies after an upgrade.
1018 *
1019 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1020 * an active administrator, or an exception will be thrown.
1021 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1022 */
Robin Lee25e26452015-06-02 09:56:29 -07001023 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001024 if (mService != null) {
1025 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001026 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001027 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001028 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001029 }
1030 }
1031 return false;
1032 }
1033
1034 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001035 * Returns true if the Profile Challenge is available to use for the given profile user.
1036 *
1037 * @hide
1038 */
1039 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1040 if (mService != null) {
1041 try {
1042 return mService.isSeparateProfileChallengeAllowed(userHandle);
1043 } catch (RemoteException e) {
1044 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1045 }
1046 }
1047 return false;
1048 }
1049
1050 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001051 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1052 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001053 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001054 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001055 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001056
Dianne Hackbornd6847842010-01-12 18:14:19 -08001057 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001058 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1059 * recognition technology. This implies technologies that can recognize the identity of
1060 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1061 * Note that quality constants are ordered so that higher values are more restrictive.
1062 */
1063 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1064
1065 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001066 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001067 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001068 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001070 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001071
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001072 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001073 * Constant for {@link #setPasswordQuality}: the user must have entered a
1074 * password containing at least numeric characters. Note that quality
1075 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001076 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001077 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001080 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001081 * password containing at least numeric characters with no repeating (4444)
1082 * or ordered (1234, 4321, 2468) sequences. Note that quality
1083 * constants are ordered so that higher values are more restrictive.
1084 */
1085 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1086
1087 /**
1088 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001089 * password containing at least alphabetic (or other symbol) characters.
1090 * Note that quality constants are ordered so that higher values are more
1091 * restrictive.
1092 */
1093 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001094
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001095 /**
1096 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001097 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001098 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001099 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001100 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001101 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001102
Dianne Hackbornd6847842010-01-12 18:14:19 -08001103 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001104 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001105 * password containing at least a letter, a numerical digit and a special
1106 * symbol, by default. With this password quality, passwords can be
1107 * restricted to contain various sets of characters, like at least an
1108 * uppercase letter, etc. These are specified using various methods,
1109 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1110 * that quality constants are ordered so that higher values are more
1111 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001112 */
1113 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1114
1115 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001116 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1117 * modify password. In case this password quality is set, the password is
1118 * managed by a profile owner. The profile owner can set any password,
1119 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1120 * that quality constants are ordered so that higher values are more
1121 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1122 * the highest.
1123 * @hide
1124 */
1125 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1126
1127 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001128 * Called by an application that is administering the device to set the
1129 * password restrictions it is imposing. After setting this, the user
1130 * will not be able to enter a new password that is not at least as
1131 * restrictive as what has been set. Note that the current password
1132 * will remain until the user has set a new one, so the change does not
1133 * take place immediately. To prompt the user for a new password, use
1134 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001135 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001136 * <p>Quality constants are ordered so that higher values are more restrictive;
1137 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001138 * the user's preference, and any other considerations) is the one that
1139 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001140 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001141 * <p>The calling device admin must have requested
1142 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1143 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001144 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001145 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001146 * @param quality The new desired quality. One of
1147 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001148 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1149 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1150 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001151 */
Robin Lee25e26452015-06-02 09:56:29 -07001152 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001153 if (mService != null) {
1154 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001155 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001156 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001157 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001158 }
1159 }
1160 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001161
Dianne Hackbornd6847842010-01-12 18:14:19 -08001162 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001163 * Retrieve the current minimum password quality for all admins of this user
1164 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001165 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001166 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001167 */
Robin Lee25e26452015-06-02 09:56:29 -07001168 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001169 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001170 }
1171
1172 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001173 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001174 if (mService != null) {
1175 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001176 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001177 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001178 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001179 }
1180 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001181 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001182 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001183
Dianne Hackbornd6847842010-01-12 18:14:19 -08001184 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001185 * Called by an application that is administering the device to set the
1186 * minimum allowed password length. After setting this, the user
1187 * will not be able to enter a new password that is not at least as
1188 * restrictive as what has been set. Note that the current password
1189 * will remain until the user has set a new one, so the change does not
1190 * take place immediately. To prompt the user for a new password, use
1191 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1192 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001193 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1194 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1195 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001196 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001197 * <p>The calling device admin must have requested
1198 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1199 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001200 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001201 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001202 * @param length The new desired minimum password length. A value of 0
1203 * means there is no restriction.
1204 */
Robin Lee25e26452015-06-02 09:56:29 -07001205 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001206 if (mService != null) {
1207 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001208 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001209 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001210 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001211 }
1212 }
1213 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001214
Dianne Hackbornd6847842010-01-12 18:14:19 -08001215 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001216 * Retrieve the current minimum password length for all admins of this
1217 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001218 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001219 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001220 */
Robin Lee25e26452015-06-02 09:56:29 -07001221 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001222 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001223 }
1224
1225 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001226 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001227 if (mService != null) {
1228 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001229 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001230 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001231 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001232 }
1233 }
1234 return 0;
1235 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001236
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001237 /**
1238 * Called by an application that is administering the device to set the
1239 * minimum number of upper case letters required in the password. After
1240 * setting this, the user will not be able to enter a new password that is
1241 * not at least as restrictive as what has been set. Note that the current
1242 * password will remain until the user has set a new one, so the change does
1243 * not take place immediately. To prompt the user for a new password, use
1244 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1245 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001246 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1247 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001248 * <p>
1249 * The calling device admin must have requested
1250 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1251 * this method; if it has not, a security exception will be thrown.
1252 *
1253 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1254 * with.
1255 * @param length The new desired minimum number of upper case letters
1256 * required in the password. A value of 0 means there is no
1257 * restriction.
1258 */
Robin Lee25e26452015-06-02 09:56:29 -07001259 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001260 if (mService != null) {
1261 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001262 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001263 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001264 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001265 }
1266 }
1267 }
1268
1269 /**
1270 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001271 * password for all admins of this user and its profiles or a particular one.
1272 * This is the same value as set by
1273 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001274 * and only applies when the password quality is
1275 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001276 *
Robin Lee25e26452015-06-02 09:56:29 -07001277 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001278 * aggregate all admins.
1279 * @return The minimum number of upper case letters required in the
1280 * password.
1281 */
Robin Lee25e26452015-06-02 09:56:29 -07001282 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001283 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001284 }
1285
1286 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001287 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001288 if (mService != null) {
1289 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001290 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001291 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001292 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001293 }
1294 }
1295 return 0;
1296 }
1297
1298 /**
1299 * Called by an application that is administering the device to set the
1300 * minimum number of lower case letters required in the password. After
1301 * setting this, the user will not be able to enter a new password that is
1302 * not at least as restrictive as what has been set. Note that the current
1303 * password will remain until the user has set a new one, so the change does
1304 * not take place immediately. To prompt the user for a new password, use
1305 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1306 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001307 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1308 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001309 * <p>
1310 * The calling device admin must have requested
1311 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1312 * this method; if it has not, a security exception will be thrown.
1313 *
1314 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1315 * with.
1316 * @param length The new desired minimum number of lower case letters
1317 * required in the password. A value of 0 means there is no
1318 * restriction.
1319 */
Robin Lee25e26452015-06-02 09:56:29 -07001320 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001321 if (mService != null) {
1322 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001323 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001324 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001325 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001326 }
1327 }
1328 }
1329
1330 /**
1331 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001332 * password for all admins of this user and its profiles or a particular one.
1333 * This is the same value as set by
1334 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001335 * and only applies when the password quality is
1336 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001337 *
Robin Lee25e26452015-06-02 09:56:29 -07001338 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001339 * aggregate all admins.
1340 * @return The minimum number of lower case letters required in the
1341 * password.
1342 */
Robin Lee25e26452015-06-02 09:56:29 -07001343 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001344 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001345 }
1346
1347 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001348 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001349 if (mService != null) {
1350 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001351 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001352 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001353 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001354 }
1355 }
1356 return 0;
1357 }
1358
1359 /**
1360 * Called by an application that is administering the device to set the
1361 * minimum number of letters required in the password. After setting this,
1362 * the user will not be able to enter a new password that is not at least as
1363 * restrictive as what has been set. Note that the current password will
1364 * remain until the user has set a new one, so the change does not take
1365 * place immediately. To prompt the user for a new password, use
1366 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1367 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001368 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1369 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001370 * <p>
1371 * The calling device admin must have requested
1372 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1373 * this method; if it has not, a security exception will be thrown.
1374 *
1375 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1376 * with.
1377 * @param length The new desired minimum number of letters required in the
1378 * password. A value of 0 means there is no restriction.
1379 */
Robin Lee25e26452015-06-02 09:56:29 -07001380 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001381 if (mService != null) {
1382 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001383 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001384 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001385 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001386 }
1387 }
1388 }
1389
1390 /**
1391 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001392 * admins or a particular one. This is the same value as
1393 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1394 * and only applies when the password quality is
1395 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001396 *
Robin Lee25e26452015-06-02 09:56:29 -07001397 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001398 * aggregate all admins.
1399 * @return The minimum number of letters required in the password.
1400 */
Robin Lee25e26452015-06-02 09:56:29 -07001401 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001402 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001403 }
1404
1405 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001406 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001407 if (mService != null) {
1408 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001409 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001410 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001411 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001412 }
1413 }
1414 return 0;
1415 }
1416
1417 /**
1418 * Called by an application that is administering the device to set the
1419 * minimum number of numerical digits required in the password. After
1420 * setting this, the user will not be able to enter a new password that is
1421 * not at least as restrictive as what has been set. Note that the current
1422 * password will remain until the user has set a new one, so the change does
1423 * not take place immediately. To prompt the user for a new password, use
1424 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1425 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001426 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1427 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001428 * <p>
1429 * The calling device admin must have requested
1430 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1431 * this method; if it has not, a security exception will be thrown.
1432 *
1433 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1434 * with.
1435 * @param length The new desired minimum number of numerical digits required
1436 * in the password. A value of 0 means there is no restriction.
1437 */
Robin Lee25e26452015-06-02 09:56:29 -07001438 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001439 if (mService != null) {
1440 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001441 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001442 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001443 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001444 }
1445 }
1446 }
1447
1448 /**
1449 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001450 * for all admins of this user and its profiles or a particular one.
1451 * This is the same value as set by
1452 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001453 * and only applies when the password quality is
1454 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001455 *
Robin Lee25e26452015-06-02 09:56:29 -07001456 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001457 * aggregate all admins.
1458 * @return The minimum number of numerical digits required in the password.
1459 */
Robin Lee25e26452015-06-02 09:56:29 -07001460 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001461 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001462 }
1463
1464 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001465 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001466 if (mService != null) {
1467 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001468 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001469 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001470 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001471 }
1472 }
1473 return 0;
1474 }
1475
1476 /**
1477 * Called by an application that is administering the device to set the
1478 * minimum number of symbols required in the password. After setting this,
1479 * the user will not be able to enter a new password that is not at least as
1480 * restrictive as what has been set. Note that the current password will
1481 * remain until the user has set a new one, so the change does not take
1482 * place immediately. To prompt the user for a new password, use
1483 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1484 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001485 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1486 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001487 * <p>
1488 * The calling device admin must have requested
1489 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1490 * this method; if it has not, a security exception will be thrown.
1491 *
1492 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1493 * with.
1494 * @param length The new desired minimum number of symbols required in the
1495 * password. A value of 0 means there is no restriction.
1496 */
Robin Lee25e26452015-06-02 09:56:29 -07001497 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001498 if (mService != null) {
1499 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001500 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001501 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001502 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001503 }
1504 }
1505 }
1506
1507 /**
1508 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001509 * admins or a particular one. This is the same value as
1510 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1511 * and only applies when the password quality is
1512 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001513 *
Robin Lee25e26452015-06-02 09:56:29 -07001514 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001515 * aggregate all admins.
1516 * @return The minimum number of symbols required in the password.
1517 */
Robin Lee25e26452015-06-02 09:56:29 -07001518 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001519 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001520 }
1521
1522 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001523 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001524 if (mService != null) {
1525 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001526 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001527 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001528 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001529 }
1530 }
1531 return 0;
1532 }
1533
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001534 /**
1535 * Called by an application that is administering the device to set the
1536 * minimum number of non-letter characters (numerical digits or symbols)
1537 * required in the password. After setting this, the user will not be able
1538 * to enter a new password that is not at least as restrictive as what has
1539 * been set. Note that the current password will remain until the user has
1540 * set a new one, so the change does not take place immediately. To prompt
1541 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1542 * setting this value. This constraint is only imposed if the administrator
1543 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1544 * {@link #setPasswordQuality}. The default value is 0.
1545 * <p>
1546 * The calling device admin must have requested
1547 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1548 * this method; if it has not, a security exception will be thrown.
1549 *
1550 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1551 * with.
1552 * @param length The new desired minimum number of letters required in the
1553 * password. A value of 0 means there is no restriction.
1554 */
Robin Lee25e26452015-06-02 09:56:29 -07001555 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001556 if (mService != null) {
1557 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001558 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001559 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001560 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001561 }
1562 }
1563 }
1564
1565 /**
1566 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001567 * password for all admins of this user and its profiles or a particular one.
1568 * This is the same value as set by
1569 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001570 * and only applies when the password quality is
1571 * {@link #PASSWORD_QUALITY_COMPLEX}.
1572 *
Robin Lee25e26452015-06-02 09:56:29 -07001573 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001574 * aggregate all admins.
1575 * @return The minimum number of letters required in the password.
1576 */
Robin Lee25e26452015-06-02 09:56:29 -07001577 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001578 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001579 }
1580
1581 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001582 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001583 if (mService != null) {
1584 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001585 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001586 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001587 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001588 }
1589 }
1590 return 0;
1591 }
1592
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001593 /**
1594 * Called by an application that is administering the device to set the length
1595 * of the password history. After setting this, the user will not be able to
1596 * enter a new password that is the same as any password in the history. Note
1597 * that the current password will remain until the user has set a new one, so
1598 * the change does not take place immediately. To prompt the user for a new
1599 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1600 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001601 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1602 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1603 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001604 *
1605 * <p>
1606 * The calling device admin must have requested
1607 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1608 * method; if it has not, a security exception will be thrown.
1609 *
1610 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1611 * with.
1612 * @param length The new desired length of password history. A value of 0
1613 * means there is no restriction.
1614 */
Robin Lee25e26452015-06-02 09:56:29 -07001615 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001616 if (mService != null) {
1617 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001618 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001619 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001620 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001621 }
1622 }
1623 }
1624
1625 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001626 * Called by a device admin to set the password expiration timeout. Calling this method
1627 * will restart the countdown for password expiration for the given admin, as will changing
1628 * the device password (for all admins).
1629 *
1630 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1631 * For example, to have the password expire 5 days from now, timeout would be
1632 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1633 *
1634 * <p>To disable password expiration, a value of 0 may be used for timeout.
1635 *
Jim Millera4e28d12010-11-08 16:15:47 -08001636 * <p>The calling device admin must have requested
1637 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1638 * method; if it has not, a security exception will be thrown.
1639 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001640 * <p> Note that setting the password will automatically reset the expiration time for all
1641 * active admins. Active admins do not need to explicitly call this method in that case.
1642 *
Jim Millera4e28d12010-11-08 16:15:47 -08001643 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1644 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1645 * means there is no restriction (unlimited).
1646 */
Robin Lee25e26452015-06-02 09:56:29 -07001647 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001648 if (mService != null) {
1649 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001650 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001651 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001652 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001653 }
1654 }
1655 }
1656
1657 /**
Jim Miller6b857682011-02-16 16:27:41 -08001658 * Get the password expiration timeout for the given admin. The expiration timeout is the
1659 * recurring expiration timeout provided in the call to
1660 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001661 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001662 *
Robin Lee25e26452015-06-02 09:56:29 -07001663 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001664 * @return The timeout for the given admin or the minimum of all timeouts
1665 */
Robin Lee25e26452015-06-02 09:56:29 -07001666 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001667 if (mService != null) {
1668 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001669 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001670 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001671 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001672 }
1673 }
1674 return 0;
1675 }
1676
1677 /**
1678 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001679 * all admins of this user and its profiles if admin is null. If the password is
1680 * expired, this will return the time since the password expired as a negative number.
1681 * If admin is null, then a composite of all expiration timeouts is returned
1682 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001683 *
Robin Lee25e26452015-06-02 09:56:29 -07001684 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001685 * @return The password expiration time, in ms.
1686 */
Robin Lee25e26452015-06-02 09:56:29 -07001687 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001688 if (mService != null) {
1689 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001690 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001691 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001692 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001693 }
1694 }
1695 return 0;
1696 }
1697
1698 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001699 * Retrieve the current password history length for all admins of this
1700 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001701 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001702 * all admins.
1703 * @return The length of the password history
1704 */
Robin Lee25e26452015-06-02 09:56:29 -07001705 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001706 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001707 }
1708
1709 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001710 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001711 if (mService != null) {
1712 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001713 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001714 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001715 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001716 }
1717 }
1718 return 0;
1719 }
1720
Dianne Hackbornd6847842010-01-12 18:14:19 -08001721 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001722 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001723 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001724 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001725 * @return Returns the maximum length that the user can enter.
1726 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001727 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001728 // Kind-of arbitrary.
1729 return 16;
1730 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001731
Dianne Hackborn254cb442010-01-27 19:23:59 -08001732 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001733 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001734 * to meet the policy requirements (quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00001735 * requested by the admins of this user and its profiles that don't have a separate challenge.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001736 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001737 * <p>The calling device admin must have requested
1738 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1739 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001740 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001741 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001742 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001743 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001744 if (mService != null) {
1745 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001746 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001747 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001748 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001749 }
1750 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001751 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001752 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001753
Dianne Hackbornd6847842010-01-12 18:14:19 -08001754 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00001755 * Determine whether the current profile password the user has set is sufficient
1756 * to meet the policy requirements (quality, minimum length) that have been
1757 * requested by the admins of the parent user and its profiles.
1758 *
1759 * @param userHandle the userId of the profile to check the password for.
1760 * @return Returns true if the password would meet the current requirements, else false.
1761 * @hide
1762 */
1763 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
1764 if (mService != null) {
1765 try {
1766 return mService.isProfileActivePasswordSufficientForParent(userHandle);
1767 } catch (RemoteException e) {
1768 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1769 }
1770 }
1771 return false;
1772 }
1773
1774 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001775 * Retrieve the number of times the user has failed at entering a
1776 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001777 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001778 * <p>The calling device admin must have requested
1779 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1780 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001781 */
1782 public int getCurrentFailedPasswordAttempts() {
1783 if (mService != null) {
1784 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001785 return mService.getCurrentFailedPasswordAttempts(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001786 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001787 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001788 }
1789 }
1790 return -1;
1791 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001792
1793 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001794 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001795 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001796 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001797 * @hide
1798 */
1799 public boolean getDoNotAskCredentialsOnBoot() {
1800 if (mService != null) {
1801 try {
1802 return mService.getDoNotAskCredentialsOnBoot();
1803 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001804 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001805 }
1806 }
1807 return false;
1808 }
1809
1810 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001811 * Setting this to a value greater than zero enables a built-in policy
1812 * that will perform a device wipe after too many incorrect
1813 * device-unlock passwords have been entered. This built-in policy combines
1814 * watching for failed passwords and wiping the device, and requires
1815 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001816 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001817 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001818 * <p>To implement any other policy (e.g. wiping data for a particular
1819 * application only, erasing or revoking credentials, or reporting the
1820 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001821 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001822 * instead. Do not use this API, because if the maximum count is reached,
1823 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001824 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001826 * @param num The number of failed password attempts at which point the
1827 * device will wipe its data.
1828 */
Robin Lee25e26452015-06-02 09:56:29 -07001829 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001830 if (mService != null) {
1831 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001832 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001833 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001834 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001835 }
1836 }
1837 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001838
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001839 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001840 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001841 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001842 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001843 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001844 * all admins.
1845 */
Robin Lee25e26452015-06-02 09:56:29 -07001846 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001847 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001848 }
1849
1850 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001851 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001852 if (mService != null) {
1853 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001854 return mService.getMaximumFailedPasswordsForWipe(
1855 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001856 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001857 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001858 }
1859 }
1860 return 0;
1861 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001862
Dianne Hackborn254cb442010-01-27 19:23:59 -08001863 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001864 * Returns the profile with the smallest maximum failed passwords for wipe,
1865 * for the given user. So for primary user, it might return the primary or
1866 * a managed profile. For a secondary user, it would be the same as the
1867 * user passed in.
1868 * @hide Used only by Keyguard
1869 */
1870 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1871 if (mService != null) {
1872 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001873 return mService.getProfileWithMinimumFailedPasswordsForWipe(
1874 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001875 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001876 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001877 }
1878 }
1879 return UserHandle.USER_NULL;
1880 }
1881
1882 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001883 * Flag for {@link #resetPassword}: don't allow other admins to change
1884 * the password again until the user has entered it.
1885 */
1886 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001887
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001888 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001889 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1890 * If the flag is set, the device can be booted without asking for user password.
1891 * The absence of this flag does not change the current boot requirements. This flag
1892 * can be set by the device owner only. If the app is not the device owner, the flag
1893 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1894 * device to factory defaults.
1895 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001896 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001897
1898 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001899 * Force a new device unlock password (the password needed to access the
1900 * entire device, not for individual accounts) on the user. This takes
1901 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001902 *
1903 * <p>Calling this from a managed profile that shares the password with the owner profile
1904 * will throw a security exception.
1905 *
1906 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1907 * device admins that are not device owner and not profile owner.
1908 * The password can now only be changed if there is currently no password set. Device owner
1909 * and profile owner can still do this.</em>
1910 *
1911 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001912 * current password quality and length constraints as returned by
1913 * {@link #getPasswordQuality(ComponentName)} and
1914 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1915 * these constraints, then it will be rejected and false returned. Note
1916 * that the password may be a stronger quality (containing alphanumeric
1917 * characters when the requested quality is only numeric), in which case
1918 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001919 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001920 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001921 * pattern or password if the current password constraints allow it. <em>Note: This will not
1922 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1923 * device owner and not profile owner. Once set, the password cannot be changed to null or
1924 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001925 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001926 * <p>The calling device admin must have requested
1927 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1928 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001929 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001930 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001931 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001932 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001933 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001934 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001935 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001936 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001937 if (mParentInstance) {
1938 throw new SecurityException("Reset password does not work across profiles.");
1939 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001940 if (mService != null) {
1941 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001942 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001943 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001944 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001945 }
1946 }
1947 return false;
1948 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001949
Dianne Hackbornd6847842010-01-12 18:14:19 -08001950 /**
1951 * Called by an application that is administering the device to set the
1952 * maximum time for user activity until the device will lock. This limits
1953 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001954 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001955 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001956 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001957 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001958 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001959 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001960 * @param timeMs The new desired maximum time to lock in milliseconds.
1961 * A value of 0 means there is no restriction.
1962 */
Robin Lee25e26452015-06-02 09:56:29 -07001963 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001964 if (mService != null) {
1965 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001966 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001967 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001968 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001969 }
1970 }
1971 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001972
Dianne Hackbornd6847842010-01-12 18:14:19 -08001973 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001974 * Retrieve the current maximum time to unlock for all admins of this user
1975 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001976 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001977 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001978 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001979 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001980 */
Robin Lee25e26452015-06-02 09:56:29 -07001981 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001982 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001983 }
1984
1985 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001986 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001987 if (mService != null) {
1988 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001989 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001990 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001991 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001992 }
1993 }
1994 return 0;
1995 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001996
Dianne Hackbornd6847842010-01-12 18:14:19 -08001997 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001998 * Make the device lock immediately, as if the lock screen timeout has
1999 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002000 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002001 * <p>The calling device admin must have requested
2002 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2003 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002004 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002005 public void lockNow() {
2006 if (mService != null) {
2007 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002008 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002009 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002010 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002011 }
2012 }
2013 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002014
Dianne Hackbornd6847842010-01-12 18:14:19 -08002015 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002016 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002017 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002018 */
2019 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2020
2021 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002022 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2023 * data.
2024 *
Paul Crowley2934b262014-12-02 11:21:13 +00002025 * <p>This flag may only be set by device owner admins; if it is set by
2026 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002027 */
2028 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2029
2030 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002031 * Ask the user data be wiped. Wiping the primary user will cause the
2032 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002033 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002034 * <p>The calling device admin must have requested
2035 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2036 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002037 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002038 * @param flags Bit mask of additional options: currently supported flags
2039 * are {@link #WIPE_EXTERNAL_STORAGE} and
2040 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002041 */
2042 public void wipeData(int flags) {
2043 if (mService != null) {
2044 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002045 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002046 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002047 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002048 }
2049 }
2050 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002051
Dianne Hackbornd6847842010-01-12 18:14:19 -08002052 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002053 * Called by an application that is administering the device to set the
2054 * global proxy and exclusion list.
2055 * <p>
2056 * The calling device admin must have requested
2057 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2058 * this method; if it has not, a security exception will be thrown.
2059 * Only the first device admin can set the proxy. If a second admin attempts
2060 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002061 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002062 * be returned.
2063 * The method can be called repeatedly by the device admin alrady setting the
2064 * proxy to update the proxy and exclusion list.
2065 *
Robin Lee25e26452015-06-02 09:56:29 -07002066 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002067 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2068 * Pass Proxy.NO_PROXY to reset the proxy.
2069 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002070 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2071 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002072 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002073 */
Robin Lee25e26452015-06-02 09:56:29 -07002074 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002075 List<String> exclusionList ) {
2076 if (proxySpec == null) {
2077 throw new NullPointerException();
2078 }
2079 if (mService != null) {
2080 try {
2081 String hostSpec;
2082 String exclSpec;
2083 if (proxySpec.equals(Proxy.NO_PROXY)) {
2084 hostSpec = null;
2085 exclSpec = null;
2086 } else {
2087 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2088 throw new IllegalArgumentException();
2089 }
2090 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2091 String hostName = sa.getHostName();
2092 int port = sa.getPort();
2093 StringBuilder hostBuilder = new StringBuilder();
2094 hostSpec = hostBuilder.append(hostName)
2095 .append(":").append(Integer.toString(port)).toString();
2096 if (exclusionList == null) {
2097 exclSpec = "";
2098 } else {
2099 StringBuilder listBuilder = new StringBuilder();
2100 boolean firstDomain = true;
2101 for (String exclDomain : exclusionList) {
2102 if (!firstDomain) {
2103 listBuilder = listBuilder.append(",");
2104 } else {
2105 firstDomain = false;
2106 }
2107 listBuilder = listBuilder.append(exclDomain.trim());
2108 }
2109 exclSpec = listBuilder.toString();
2110 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002111 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2112 != android.net.Proxy.PROXY_VALID)
2113 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002114 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002115 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002116 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002117 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002118 }
2119 }
2120 return null;
2121 }
2122
2123 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002124 * Set a network-independent global HTTP proxy. This is not normally what you want
2125 * for typical HTTP proxies - they are generally network dependent. However if you're
2126 * doing something unusual like general internal filtering this may be useful. On
2127 * a private network where the proxy is not accessible, you may break HTTP using this.
2128 *
2129 * <p>This method requires the caller to be the device owner.
2130 *
2131 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2132 * @see ProxyInfo
2133 *
2134 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2135 * with.
2136 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2137 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2138 */
Robin Lee25e26452015-06-02 09:56:29 -07002139 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2140 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002141 if (mService != null) {
2142 try {
2143 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2144 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002145 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002146 }
2147 }
2148 }
2149
2150 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002151 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002152 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2153 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002154 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002155 */
2156 public ComponentName getGlobalProxyAdmin() {
2157 if (mService != null) {
2158 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002159 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002160 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002161 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002162 }
2163 }
2164 return null;
2165 }
2166
2167 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002168 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002169 * indicating that encryption is not supported.
2170 */
2171 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2172
2173 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002174 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002175 * indicating that encryption is supported, but is not currently active.
2176 */
2177 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2178
2179 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002180 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002181 * indicating that encryption is not currently active, but is currently
2182 * being activated. This is only reported by devices that support
2183 * encryption of data and only when the storage is currently
2184 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2185 * to become encrypted will never return this value.
2186 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002187 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002188
2189 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002190 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002191 * indicating that encryption is active.
2192 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002193 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002194
2195 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002196 * Result code for {@link #getStorageEncryptionStatus}:
2197 * indicating that encryption is active, but an encryption key has not
2198 * been set by the user.
2199 */
2200 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2201
2202 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002203 * Activity action: begin the process of encrypting data on the device. This activity should
2204 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2205 * After resuming from this activity, use {@link #getStorageEncryption}
2206 * to check encryption status. However, on some devices this activity may never return, as
2207 * it may trigger a reboot and in some cases a complete data wipe of the device.
2208 */
2209 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2210 public static final String ACTION_START_ENCRYPTION
2211 = "android.app.action.START_ENCRYPTION";
2212
2213 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002214 * Widgets are enabled in keyguard
2215 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002216 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002217
2218 /**
Jim Miller50e62182014-04-23 17:25:00 -07002219 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002220 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002221 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2222
2223 /**
2224 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2225 */
2226 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2227
2228 /**
Jim Miller50e62182014-04-23 17:25:00 -07002229 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2230 */
2231 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2232
2233 /**
2234 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2235 */
2236 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2237
2238 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002239 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002240 * (e.g. PIN/Pattern/Password).
2241 */
2242 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2243
2244 /**
Jim Miller06e34502014-07-17 14:46:05 -07002245 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2246 */
2247 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2248
2249 /**
Jim Miller35207742012-11-02 15:33:20 -07002250 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002251 */
2252 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002253
2254 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002255 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002256 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002257 *
2258 * <p>When multiple device administrators attempt to control device
2259 * encryption, the most secure, supported setting will always be
2260 * used. If any device administrator requests device encryption,
2261 * it will be enabled; Conversely, if a device administrator
2262 * attempts to disable device encryption while another
2263 * device administrator has enabled it, the call to disable will
2264 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2265 *
2266 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002267 * written to other storage areas may or may not be encrypted, and this policy does not require
2268 * or control the encryption of any other storage areas.
2269 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2270 * {@code true}, then the directory returned by
2271 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2272 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002273 *
2274 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2275 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2276 * the encryption key may not be fully secured. For maximum security, the administrator should
2277 * also require (and check for) a pattern, PIN, or password.
2278 *
2279 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2280 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002281 * @return the new request status (for all active admins) - will be one of
2282 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2283 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2284 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002285 */
Robin Lee25e26452015-06-02 09:56:29 -07002286 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002287 if (mService != null) {
2288 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002289 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002290 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002291 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002292 }
2293 }
2294 return ENCRYPTION_STATUS_UNSUPPORTED;
2295 }
2296
2297 /**
2298 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002299 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002300 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002301 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2302 * this will return the requested encryption setting as an aggregate of all active
2303 * administrators.
2304 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002305 */
Robin Lee25e26452015-06-02 09:56:29 -07002306 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002307 if (mService != null) {
2308 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002309 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002310 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002311 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002312 }
2313 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002314 return false;
2315 }
2316
2317 /**
2318 * Called by an application that is administering the device to
2319 * determine the current encryption status of the device.
2320 *
2321 * Depending on the returned status code, the caller may proceed in different
2322 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2323 * storage system does not support encryption. If the
2324 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2325 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002326 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2327 * storage system has enabled encryption but no password is set so further action
2328 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002329 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2330 *
Robin Lee7e678712014-07-24 16:41:31 +01002331 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002332 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002333 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2334 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002335 */
2336 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002337 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002338 }
2339
2340 /** @hide per-user version */
2341 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002342 if (mService != null) {
2343 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002344 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002345 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002346 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002347 }
2348 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002349 return ENCRYPTION_STATUS_UNSUPPORTED;
2350 }
2351
2352 /**
Robin Lee7e678712014-07-24 16:41:31 +01002353 * Installs the given certificate as a user CA.
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.
Robin Lee7e678712014-07-24 16:41:31 +01002357 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002358 *
2359 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002360 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002361 */
Robin Lee25e26452015-06-02 09:56:29 -07002362 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002363 if (mService != null) {
2364 try {
Robin Lee7e678712014-07-24 16:41:31 +01002365 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002366 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002367 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002368 }
2369 }
2370 return false;
2371 }
2372
2373 /**
Robin Lee7e678712014-07-24 16:41:31 +01002374 * Uninstalls the given certificate from trusted user CAs, if present.
2375 *
Robin Lee25e26452015-06-02 09:56:29 -07002376 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2377 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002378 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002379 */
Robin Lee25e26452015-06-02 09:56:29 -07002380 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002381 if (mService != null) {
2382 try {
Robin Lee306fe082014-06-19 14:04:24 +00002383 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002384 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002385 } catch (CertificateException e) {
2386 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002387 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002388 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002389 }
2390 }
2391 }
2392
2393 /**
Robin Lee7e678712014-07-24 16:41:31 +01002394 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2395 * If a user has installed any certificates by other means than device policy these will be
2396 * included too.
2397 *
Robin Lee25e26452015-06-02 09:56:29 -07002398 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2399 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002400 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002401 */
Robin Lee25e26452015-06-02 09:56:29 -07002402 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002403 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002404 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002405 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002406 mService.enforceCanManageCaCerts(admin);
2407 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2408 for (String alias : certStore.userAliases()) {
2409 try {
2410 certs.add(certStore.getCertificate(alias).getEncoded());
2411 } catch (CertificateException ce) {
2412 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2413 }
2414 }
2415 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002416 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002417 }
2418 }
2419 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002420 }
2421
2422 /**
Robin Lee7e678712014-07-24 16:41:31 +01002423 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2424 * means other than device policy will also be removed, except for system CA certificates.
2425 *
Robin Lee25e26452015-06-02 09:56:29 -07002426 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2427 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002428 */
Robin Lee25e26452015-06-02 09:56:29 -07002429 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002430 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002431 try {
2432 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2433 .toArray(new String[0]));
2434 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002435 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002436 }
2437 }
2438 }
2439
2440 /**
2441 * Returns whether this certificate is installed as a trusted CA.
2442 *
Robin Lee25e26452015-06-02 09:56:29 -07002443 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2444 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002445 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002446 */
Robin Lee25e26452015-06-02 09:56:29 -07002447 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002448 if (mService != null) {
2449 try {
2450 mService.enforceCanManageCaCerts(admin);
2451 return getCaCertAlias(certBuffer) != null;
2452 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002453 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002454 } catch (CertificateException ce) {
2455 Log.w(TAG, "Could not parse certificate", ce);
2456 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002457 }
2458 return false;
2459 }
2460
2461 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002462 * Called by a device or profile owner to install a certificate and private key pair. The
2463 * keypair will be visible to all apps within the profile.
2464 *
Robin Lee25e26452015-06-02 09:56:29 -07002465 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2466 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002467 * @param privKey The private key to install.
2468 * @param cert The certificate to install.
2469 * @param alias The private key alias under which to install the certificate. If a certificate
2470 * with that alias already exists, it will be overwritten.
2471 * @return {@code true} if the keys were installed, {@code false} otherwise.
2472 */
Robin Leefbc65642015-08-03 16:21:22 +01002473 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2474 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002475 try {
2476 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002477 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2478 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002479 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002480 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002481 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002482 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2483 Log.w(TAG, "Failed to obtain private key material", e);
2484 } catch (CertificateException | IOException e) {
2485 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002486 }
2487 return false;
2488 }
2489
2490 /**
Robin Leefbc65642015-08-03 16:21:22 +01002491 * Called by a device or profile owner to remove all user credentials installed under a given
2492 * alias.
2493 *
2494 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2495 * {@code null} if calling from a delegated certificate installer.
2496 * @param alias The private key alias under which the certificate is installed.
2497 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2498 */
2499 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2500 try {
2501 return mService.removeKeyPair(admin, alias);
2502 } catch (RemoteException e) {
2503 Log.w(TAG, "Failed talking with device policy service", e);
2504 }
2505 return false;
2506 }
2507
2508 /**
Robin Lee25e26452015-06-02 09:56:29 -07002509 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002510 * doesn't exist.
2511 */
2512 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2513 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2514 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2515 new ByteArrayInputStream(certBuffer));
2516 return new TrustedCertificateStore().getCertificateAlias(cert);
2517 }
2518
2519 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002520 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002521 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002522 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002523 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002524 * <p>
2525 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2526 * it is later cleared by calling this method with a null value or uninstallling the certificate
2527 * installer.
2528 *
Robin Lee25e26452015-06-02 09:56:29 -07002529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002530 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002531 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002532 */
Robin Lee25e26452015-06-02 09:56:29 -07002533 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2534 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002535 if (mService != null) {
2536 try {
Robin Lee25e26452015-06-02 09:56:29 -07002537 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002538 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002539 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002540 }
2541 }
2542 }
2543
2544 /**
2545 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002546 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002547 *
Robin Lee25e26452015-06-02 09:56:29 -07002548 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2549 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002550 * if none is set.
2551 */
Robin Lee25e26452015-06-02 09:56:29 -07002552 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002553 if (mService != null) {
2554 try {
Robin Lee25e26452015-06-02 09:56:29 -07002555 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002556 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002557 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002558 }
2559 }
2560 return null;
2561 }
2562
2563 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002564 * Called by a device or profile owner to configure an always-on VPN connection through a
2565 * specific application for the current user.
2566 * This connection is automatically granted and persisted after a reboot.
2567 *
2568 * <p>The designated package should declare a {@link android.net.VpnService} in its
2569 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2570 * otherwise the call will fail.
2571 *
2572 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2573 * to remove an existing always-on VPN configuration.
2574 *
2575 * @return {@code true} if the package is set as always-on VPN controller;
2576 * {@code false} otherwise.
2577 */
2578 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2579 @Nullable String vpnPackage) {
2580 if (mService != null) {
2581 try {
2582 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2583 } catch (RemoteException e) {
2584 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2585 }
2586 }
2587 return false;
2588 }
2589
2590 /**
2591 * Called by a device or profile owner to read the name of the package administering an
2592 * always-on VPN connection for the current user.
2593 * If there is no such package, or the always-on VPN is provided by the system instead
2594 * of by an application, {@code null} will be returned.
2595 *
2596 * @return Package name of VPN controller responsible for always-on VPN,
2597 * or {@code null} if none is set.
2598 */
2599 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2600 if (mService != null) {
2601 try {
2602 return mService.getAlwaysOnVpnPackage(admin);
2603 } catch (RemoteException e) {
2604 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2605 }
2606 }
2607 return null;
2608 }
2609
2610 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002611 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002612 * on the device, for this user. After setting this, no applications running as this user
2613 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002614 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002615 * <p>If the caller is device owner, then the restriction will be applied to all users.
2616 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002617 * <p>The calling device admin must have requested
2618 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2619 * this method; if it has not, a security exception will be thrown.
2620 *
2621 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2622 * @param disabled Whether or not the camera should be disabled.
2623 */
Robin Lee25e26452015-06-02 09:56:29 -07002624 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002625 if (mService != null) {
2626 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002627 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002628 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002629 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002630 }
2631 }
2632 }
2633
2634 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002635 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002636 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002637 * @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 -07002638 * have disabled the camera
2639 */
Robin Lee25e26452015-06-02 09:56:29 -07002640 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002641 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002642 }
2643
2644 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002645 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002646 if (mService != null) {
2647 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002648 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002649 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002650 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002651 }
2652 }
2653 return false;
2654 }
2655
2656 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002657 * Called by a device owner to request a bugreport.
2658 *
2659 * <p>There must be only one user on the device, managed by the device owner.
2660 * Otherwise a security exception will be thrown.
2661 *
2662 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2663 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2664 * if it wasn't triggered because a previous bugreport operation is still active
2665 * (either the bugreport is still running or waiting for the user to share or decline)
2666 */
2667 public boolean requestBugreport(@NonNull ComponentName admin) {
2668 if (mService != null) {
2669 try {
2670 return mService.requestBugreport(admin);
2671 } catch (RemoteException e) {
2672 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2673 }
2674 }
2675 return false;
2676 }
2677
2678 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002679 * Determine whether or not creating a guest user has been disabled for the device
2680 *
2681 * @hide
2682 */
2683 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2684 // Currently guest users can always be created if multi-user is enabled
2685 // TODO introduce a policy for guest user creation
2686 return false;
2687 }
2688
2689 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002690 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2691 * screen capture also prevents the content from being shown on display devices that do not have
2692 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2693 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002694 *
2695 * <p>The calling device admin must be a device or profile owner. If it is not, a
2696 * security exception will be thrown.
2697 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002698 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002699 * blocks assist requests for all activities of the relevant user.
2700 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002701 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002702 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002703 */
Robin Lee25e26452015-06-02 09:56:29 -07002704 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002705 if (mService != null) {
2706 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002707 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002708 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002709 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002710 }
2711 }
2712 }
2713
2714 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002715 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002716 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002717 * @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 +01002718 * have disabled screen capture.
2719 */
Robin Lee25e26452015-06-02 09:56:29 -07002720 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002721 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002722 }
2723
2724 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002725 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002726 if (mService != null) {
2727 try {
2728 return mService.getScreenCaptureDisabled(admin, userHandle);
2729 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002730 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002731 }
2732 }
2733 return false;
2734 }
2735
2736 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002737 * Called by a device owner to set whether auto time is required. If auto time is
2738 * required the user cannot set the date and time, but has to use network date and time.
2739 *
2740 * <p>Note: if auto time is required the user can still manually set the time zone.
2741 *
2742 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2743 * be thrown.
2744 *
2745 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2746 * @param required Whether auto time is set required or not.
2747 */
Robin Lee25e26452015-06-02 09:56:29 -07002748 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002749 if (mService != null) {
2750 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002751 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002752 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002753 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002754 }
2755 }
2756 }
2757
2758 /**
2759 * @return true if auto time is required.
2760 */
2761 public boolean getAutoTimeRequired() {
2762 if (mService != null) {
2763 try {
2764 return mService.getAutoTimeRequired();
2765 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002766 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002767 }
2768 }
2769 return false;
2770 }
2771
2772 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01002773 * Called by a device owner to set whether all users created on the device should be ephemeral.
2774 *
2775 * <p>The system user is exempt from this policy - it is never ephemeral.
2776 *
2777 * <p>The calling device admin must be the device owner. If it is not, a security exception will
2778 * be thrown.
2779 *
2780 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2781 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
2782 * subsequently created users will be ephemeral.
2783 * @hide
2784 */
2785 public void setForceEphemeralUsers(
2786 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
2787 if (mService != null) {
2788 try {
2789 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
2790 } catch (RemoteException e) {
2791 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2792 }
2793 }
2794 }
2795
2796 /**
2797 * @return true if all users are created ephemeral.
2798 * @hide
2799 */
2800 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
2801 if (mService != null) {
2802 try {
2803 return mService.getForceEphemeralUsers(admin);
2804 } catch (RemoteException e) {
2805 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2806 }
2807 }
2808 return false;
2809 }
2810
2811 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002812 * Called by an application that is administering the device to disable keyguard customizations,
2813 * such as widgets. After setting this, keyguard features will be disabled according to the
2814 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002815 *
2816 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002817 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002818 * this method; if it has not, a security exception will be thrown.
2819 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002820 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002821 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002822 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002823 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002824 * <ul>
2825 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2826 * these will affect the profile's parent user.
2827 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2828 * generated by applications in the managed profile.
2829 * </ul>
2830 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2831 * can check which features have been disabled by calling
2832 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002833 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002835 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2836 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002837 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002838 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2839 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002840 */
Robin Lee25e26452015-06-02 09:56:29 -07002841 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002842 if (mService != null) {
2843 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002844 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002845 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002846 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002847 }
2848 }
2849 }
2850
2851 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002852 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002853 * admin, if specified, or all admins.
Esteban Talavera62399912016-01-11 15:37:55 +00002854 * @param admin The name of the admin component to check, or {@code null} to check whether any
2855 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002856 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2857 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002858 */
Robin Lee25e26452015-06-02 09:56:29 -07002859 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002860 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002861 }
2862
2863 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002864 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002865 if (mService != null) {
2866 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002867 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002868 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002869 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002870 }
2871 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002872 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002873 }
2874
2875 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002876 * @hide
2877 */
Robin Lee25e26452015-06-02 09:56:29 -07002878 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2879 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002880 if (mService != null) {
2881 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002882 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002883 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002884 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002885 }
2886 }
2887 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002888
Dianne Hackbornd6847842010-01-12 18:14:19 -08002889 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002890 * @hide
2891 */
Robin Lee25e26452015-06-02 09:56:29 -07002892 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002893 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002894 }
2895
2896 /**
Robin Lee25e26452015-06-02 09:56:29 -07002897 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002898 * @hide
2899 */
Robin Lee25e26452015-06-02 09:56:29 -07002900 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002901 ActivityInfo ai;
2902 try {
2903 ai = mContext.getPackageManager().getReceiverInfo(cn,
2904 PackageManager.GET_META_DATA);
2905 } catch (PackageManager.NameNotFoundException e) {
2906 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2907 return null;
2908 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002909
Dianne Hackbornd6847842010-01-12 18:14:19 -08002910 ResolveInfo ri = new ResolveInfo();
2911 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002912
Dianne Hackbornd6847842010-01-12 18:14:19 -08002913 try {
2914 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002915 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002916 Log.w(TAG, "Unable to parse device policy " + cn, e);
2917 return null;
2918 }
2919 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002920
Dianne Hackbornd6847842010-01-12 18:14:19 -08002921 /**
2922 * @hide
2923 */
Robin Lee25e26452015-06-02 09:56:29 -07002924 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002925 if (mService != null) {
2926 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002927 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002928 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002929 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002930 }
2931 }
2932 }
2933
2934 /**
2935 * @hide
2936 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002937 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002938 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002939 if (mService != null) {
2940 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002941 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002942 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002943 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002944 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002945 }
2946 }
2947 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002948
Dianne Hackbornd6847842010-01-12 18:14:19 -08002949 /**
2950 * @hide
2951 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002952 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002953 if (mService != null) {
2954 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002955 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002956 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002957 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002958 }
2959 }
2960 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002961
Dianne Hackbornd6847842010-01-12 18:14:19 -08002962 /**
2963 * @hide
2964 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002965 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002966 if (mService != null) {
2967 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002968 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002969 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002970 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002971 }
2972 }
2973 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002974
2975 /**
2976 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002977 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002978 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2979 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002980 * @return whether the package was successfully registered as the device owner.
2981 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002982 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002983 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002984 public boolean setDeviceOwner(ComponentName who) {
2985 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002986 }
2987
2988 /**
2989 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002990 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002991 public boolean setDeviceOwner(ComponentName who, int userId) {
2992 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002993 }
2994
2995 /**
2996 * @hide
2997 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002998 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2999 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003000 }
3001
3002 /**
3003 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003004 * Sets the given package as the device owner. The package must already be installed. There
3005 * must not already be a device owner.
3006 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3007 * this method.
3008 * Calling this after the setup phase of the primary user has completed is allowed only if
3009 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003010 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003011 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003012 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003013 * @return whether the package was successfully registered as the device owner.
3014 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003015 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003016 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003017 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003018 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003019 if (mService != null) {
3020 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003021 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003022 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003023 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003024 }
3025 }
3026 return false;
3027 }
3028
3029 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003030 * Used to determine if a particular package has been registered as a Device Owner app.
3031 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003032 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003033 * package is currently registered as the device owner app, pass in the package name from
3034 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003035 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003036 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3037 * the setup process.
3038 * @param packageName the package name of the app, to compare with the registered device owner
3039 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003040 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003041 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003042 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003043 return isDeviceOwnerAppOnCallingUser(packageName);
3044 }
3045
3046 /**
3047 * @return true if a package is registered as device owner, only when it's running on the
3048 * calling user.
3049 *
3050 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3051 * @hide
3052 */
3053 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3054 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3055 }
3056
3057 /**
3058 * @return true if a package is registered as device owner, even if it's running on a different
3059 * user.
3060 *
3061 * <p>Requires the MANAGE_USERS permission.
3062 *
3063 * @hide
3064 */
3065 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3066 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3067 }
3068
3069 /**
3070 * @return device owner component name, only when it's running on the calling user.
3071 *
3072 * @hide
3073 */
3074 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3075 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3076 }
3077
3078 /**
3079 * @return device owner component name, even if it's running on a different user.
3080 *
3081 * <p>Requires the MANAGE_USERS permission.
3082 *
3083 * @hide
3084 */
3085 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3086 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3087 }
3088
3089 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003090 if (packageName == null) {
3091 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003092 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003093 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003094 if (deviceOwner == null) {
3095 return false;
3096 }
3097 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003098 }
3099
Makoto Onukic8a5a552015-11-19 14:29:12 -08003100 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3101 if (mService != null) {
3102 try {
3103 return mService.getDeviceOwnerComponent(callingUserOnly);
3104 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003105 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003106 }
3107 }
3108 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003109 }
3110
Jason Monkb0dced82014-06-06 14:36:20 -04003111 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003112 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3113 * no device owner.
3114 *
3115 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003116 *
3117 * @hide
3118 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003119 public int getDeviceOwnerUserId() {
3120 if (mService != null) {
3121 try {
3122 return mService.getDeviceOwnerUserId();
3123 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003124 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003125 }
3126 }
3127 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003128 }
3129
3130 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003131 * Clears the current device owner. The caller must be the device owner.
3132 *
3133 * This function should be used cautiously as once it is called it cannot
3134 * be undone. The device owner can only be set as a part of device setup
3135 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003136 *
3137 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003138 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003139 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003140 if (mService != null) {
3141 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003142 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003143 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003144 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04003145 }
3146 }
3147 }
3148
Makoto Onukia52562c2015-10-01 16:12:31 -07003149 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003150 * Returns the device owner package name, only if it's running on the calling user.
3151 *
3152 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003153 *
3154 * @hide
3155 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003156 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003157 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003158 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3159 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003160 }
3161
3162 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003163 * @return true if the device is managed by any device owner.
3164 *
3165 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003166 *
3167 * @hide
3168 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003169 public boolean isDeviceManaged() {
3170 return getDeviceOwnerComponentOnAnyUser() != null;
3171 }
3172
3173 /**
3174 * Returns the device owner name. Note this method *will* return the device owner
3175 * name when it's running on a different user.
3176 *
3177 * <p>Requires the MANAGE_USERS permission.
3178 *
3179 * @hide
3180 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003181 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003182 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003183 if (mService != null) {
3184 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003185 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003186 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003187 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003188 }
3189 }
3190 return null;
3191 }
Adam Connors776c5552014-01-09 10:42:56 +00003192
3193 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003194 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003195 * @deprecated Do not use
3196 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003197 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003198 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003199 @SystemApi
3200 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003201 return null;
3202 }
3203
3204 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003205 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003206 * @deprecated Do not use
3207 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003208 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003209 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003210 @SystemApi
3211 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003212 return null;
3213 }
3214
Julia Reynolds20118f12015-02-11 12:34:08 -05003215 /**
Adam Connors776c5552014-01-09 10:42:56 +00003216 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003217 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303218 * Sets the given component as an active admin and registers the package as the profile
3219 * owner for this user. The package must already be installed and there shouldn't be
3220 * an existing profile owner registered for this user. Also, this method must be called
3221 * before the user setup has been completed.
3222 * <p>
3223 * This method can only be called by system apps that hold MANAGE_USERS permission and
3224 * MANAGE_DEVICE_ADMINS permission.
3225 * @param admin The component to register as an active admin and profile owner.
3226 * @param ownerName The user-visible name of the entity that is managing this user.
3227 * @return whether the admin was successfully registered as the profile owner.
3228 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3229 * the user has already been set up.
3230 */
Justin Morey80440cc2014-07-24 09:16:35 -05003231 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003232 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303233 throws IllegalArgumentException {
3234 if (mService != null) {
3235 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003236 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303237 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003238 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303239 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303240 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3241 }
3242 }
3243 return false;
3244 }
3245
3246 /**
3247 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003248 * Clears the active profile owner and removes all user restrictions. The caller must
3249 * be from the same package as the active profile owner for this user, otherwise a
3250 * SecurityException will be thrown.
3251 *
3252 * @param admin The component to remove as the profile owner.
3253 * @return
3254 */
3255 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003256 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003257 if (mService != null) {
3258 try {
3259 mService.clearProfileOwner(admin);
3260 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003261 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003262 }
3263 }
3264 }
3265
3266 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003267 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003268 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003269 */
3270 public boolean hasUserSetupCompleted() {
3271 if (mService != null) {
3272 try {
3273 return mService.hasUserSetupCompleted();
3274 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003275 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003276 }
3277 }
3278 return true;
3279 }
3280
3281 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003282 * @hide
3283 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003284 * already be installed. There must not already be a profile owner for this user.
3285 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3286 * this method.
3287 * Calling this after the setup phase of the specified user has completed is allowed only if:
3288 * - the caller is SYSTEM_UID.
3289 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003290 * @param admin the component name to be registered as profile owner.
3291 * @param ownerName the human readable name of the organisation associated with this DPM.
3292 * @param userHandle the userId to set the profile owner for.
3293 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003294 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3295 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003296 */
Robin Lee25e26452015-06-02 09:56:29 -07003297 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003298 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003299 if (mService != null) {
3300 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003301 if (ownerName == null) {
3302 ownerName = "";
3303 }
3304 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003305 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003306 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003307 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3308 }
3309 }
3310 return false;
3311 }
3312
3313 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003314 * Sets the device owner information to be shown on the lock screen.
3315 *
3316 * <p>If the device owner information is {@code null} or empty then the device owner info is
3317 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003318 * <p>If the device owner information contains only whitespaces then the message on the lock
3319 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003320 *
3321 * @param admin The name of the admin component to check.
3322 * @param info Device owner information which will be displayed instead of the user
3323 * owner info.
3324 * @return Whether the device owner information has been set.
3325 */
3326 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3327 if (mService != null) {
3328 try {
3329 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3330 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003331 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003332 }
3333 }
3334 return false;
3335 }
3336
3337 /**
3338 * @return The device owner information. If it is not set returns {@code null}.
3339 */
3340 public String getDeviceOwnerLockScreenInfo() {
3341 if (mService != null) {
3342 try {
3343 return mService.getDeviceOwnerLockScreenInfo();
3344 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003345 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003346 }
3347 }
3348 return null;
3349 }
3350
3351 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003352 * Called by device or profile owners for setting the package suspended for this user.
3353 * A suspended package will not be started by the package manager, its notifications will
3354 * be hidden and it will not show up in recents. The package must already be installed.
3355 *
3356 * @param admin The name of the admin component to check.
3357 * @param packageName The package name of the app to suspend or unsuspend.
3358 * @param suspended If set to {@code true} than the package will be suspended, if set to
3359 * {@code false} the package will be unsuspended.
3360 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3361 * otherwise.
3362 */
3363 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3364 boolean suspended) {
3365 if (mService != null) {
3366 try {
3367 return mService.setPackageSuspended(admin, packageName, suspended);
3368 } catch (RemoteException re) {
3369 Log.w(TAG, "Failed talking with device policy service", re);
3370 }
3371 }
3372 return false;
3373 }
3374
3375 /**
3376 * Called by device or profile owners to determine if a package is suspended.
3377 *
3378 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3379 * @param packageName The name of the package to retrieve the suspended status of.
3380 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3381 */
3382 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3383 if (mService != null) {
3384 try {
3385 return mService.getPackageSuspended(admin, packageName);
3386 } catch (RemoteException e) {
3387 Log.w(TAG, "Failed talking with device policy service", e);
3388 }
3389 }
3390 return false;
3391 }
3392
3393 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003394 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3395 * be used. Only the profile owner can call this.
3396 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003397 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003398 *
3399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3400 */
Robin Lee25e26452015-06-02 09:56:29 -07003401 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003402 if (mService != null) {
3403 try {
3404 mService.setProfileEnabled(admin);
3405 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003406 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003407 }
3408 }
3409 }
3410
3411 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003412 * Sets the name of the profile. In the device owner case it sets the name of the user
3413 * 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 +01003414 * never called by the profile or device owner, the name will be set to default values.
3415 *
3416 * @see #isProfileOwnerApp
3417 * @see #isDeviceOwnerApp
3418 *
Robin Lee25e26452015-06-02 09:56:29 -07003419 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003420 * @param profileName The name of the profile.
3421 */
Robin Lee25e26452015-06-02 09:56:29 -07003422 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003423 if (mService != null) {
3424 try {
Robin Lee25e26452015-06-02 09:56:29 -07003425 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003426 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003427 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003428 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003429 }
3430 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003431
3432 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003433 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003434 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003435 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003436 *
3437 * @param packageName The package name of the app to compare with the registered profile owner.
3438 * @return Whether or not the package is registered as the profile owner.
3439 */
3440 public boolean isProfileOwnerApp(String packageName) {
3441 if (mService != null) {
3442 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003443 ComponentName profileOwner = mService.getProfileOwner(
3444 Process.myUserHandle().getIdentifier());
3445 return profileOwner != null
3446 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003447 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003448 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003449 }
3450 }
3451 return false;
3452 }
3453
3454 /**
3455 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003456 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003457 * owner has been set for that user.
3458 * @throws IllegalArgumentException if the userId is invalid.
3459 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003460 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003461 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003462 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3463 }
3464
3465 /**
3466 * @see #getProfileOwner()
3467 * @hide
3468 */
3469 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003470 if (mService != null) {
3471 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003472 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003473 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003474 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003475 throw new IllegalArgumentException(
3476 "Requested profile owner for invalid userId", re);
3477 }
3478 }
3479 return null;
3480 }
3481
3482 /**
3483 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003484 * @return the human readable name of the organisation associated with this DPM or {@code null}
3485 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003486 * @throws IllegalArgumentException if the userId is invalid.
3487 */
3488 public String getProfileOwnerName() throws IllegalArgumentException {
3489 if (mService != null) {
3490 try {
3491 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3492 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003493 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003494 throw new IllegalArgumentException(
3495 "Requested profile owner for invalid userId", re);
3496 }
3497 }
3498 return null;
3499 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003500
3501 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003502 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003503 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003504 * @return the human readable name of the organisation associated with this profile owner or
3505 * null if one is not set.
3506 * @throws IllegalArgumentException if the userId is invalid.
3507 */
3508 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003509 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003510 if (mService != null) {
3511 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003512 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003513 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003514 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003515 throw new IllegalArgumentException(
3516 "Requested profile owner for invalid userId", re);
3517 }
3518 }
3519 return null;
3520 }
3521
3522 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003523 * Called by a profile owner or device owner to add a default intent handler activity for
3524 * intents that match a certain intent filter. This activity will remain the default intent
3525 * handler even if the set of potential event handlers for the intent filter changes and if
3526 * the intent preferences are reset.
3527 *
3528 * <p>The default disambiguation mechanism takes over if the activity is not installed
3529 * (anymore). When the activity is (re)installed, it is automatically reset as default
3530 * intent handler for the filter.
3531 *
3532 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3533 * security exception will be thrown.
3534 *
3535 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3536 * @param filter The IntentFilter for which a default handler is added.
3537 * @param activity The Activity that is added as default intent handler.
3538 */
Robin Lee25e26452015-06-02 09:56:29 -07003539 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3540 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003541 if (mService != null) {
3542 try {
3543 mService.addPersistentPreferredActivity(admin, filter, activity);
3544 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003545 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003546 }
3547 }
3548 }
3549
3550 /**
3551 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003552 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003553 *
3554 * <p>The calling device admin must be a profile owner. If it is not, a security
3555 * exception will be thrown.
3556 *
3557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3558 * @param packageName The name of the package for which preferences are removed.
3559 */
Robin Lee25e26452015-06-02 09:56:29 -07003560 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003561 String packageName) {
3562 if (mService != null) {
3563 try {
3564 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3565 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003566 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003567 }
3568 }
3569 }
Robin Lee66e5d962014-04-09 16:44:21 +01003570
3571 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003572 * Called by a profile owner or device owner to grant permission to a package to manage
3573 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3574 * {@link #getApplicationRestrictions}.
3575 * <p>
3576 * This permission is persistent until it is later cleared by calling this method with a
3577 * {@code null} value or uninstalling the managing package.
3578 *
3579 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3580 * @param packageName The package name which will be given access to application restrictions
3581 * APIs. If {@code null} is given the current package will be cleared.
3582 */
3583 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3584 @Nullable String packageName) {
3585 if (mService != null) {
3586 try {
3587 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3588 } catch (RemoteException e) {
3589 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3590 }
3591 }
3592 }
3593
3594 /**
3595 * Called by a profile owner or device owner to retrieve the application restrictions managing
3596 * package for the current user, or {@code null} if none is set.
3597 *
3598 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3599 * @return The package name allowed to manage application restrictions on the current user, or
3600 * {@code null} if none is set.
3601 */
3602 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3603 if (mService != null) {
3604 try {
3605 return mService.getApplicationRestrictionsManagingPackage(admin);
3606 } catch (RemoteException e) {
3607 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3608 }
3609 }
3610 return null;
3611 }
3612
3613 /**
3614 * Returns {@code true} if the calling package has been granted permission via
3615 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3616 * restrictions for the calling user.
3617 */
3618 public boolean isCallerApplicationRestrictionsManagingPackage() {
3619 if (mService != null) {
3620 try {
3621 return mService.isCallerApplicationRestrictionsManagingPackage();
3622 } catch (RemoteException e) {
3623 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3624 }
3625 }
3626 return false;
3627 }
3628
3629 /**
3630 * Sets the application restrictions for a given target application running in the calling user.
3631 *
3632 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3633 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3634 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003635 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003636 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3637 * <ul>
3638 * <li>{@code boolean}
3639 * <li>{@code int}
3640 * <li>{@code String} or {@code String[]}
3641 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3642 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003643 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003644 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003645 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003646 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3647 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003648 * <p>The application restrictions are only made visible to the target application via
3649 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3650 * device owner, and the application restrictions managing package via
3651 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003652 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003653 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3654 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003655 * @param packageName The name of the package to update restricted settings for.
3656 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3657 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003658 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003659 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003660 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003661 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003662 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003663 Bundle settings) {
3664 if (mService != null) {
3665 try {
3666 mService.setApplicationRestrictions(admin, packageName, settings);
3667 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003668 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003669 }
3670 }
3671 }
3672
3673 /**
Jim Millere303bf42014-08-26 17:12:29 -07003674 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3675 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3676 * trust agents but those enabled by this function call. If flag
3677 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003678 *
3679 * <p>The calling device admin must have requested
3680 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003681 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003682 *
3683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003684 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003685 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003686 * will be strictly disabled according to the state of the
3687 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3688 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3689 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3690 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003691 */
Robin Lee25e26452015-06-02 09:56:29 -07003692 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3693 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003694 if (mService != null) {
3695 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003696 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003697 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003698 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003699 }
3700 }
3701 }
3702
3703 /**
Jim Millere303bf42014-08-26 17:12:29 -07003704 * Gets configuration for the given trust agent based on aggregating all calls to
3705 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3706 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003707 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003708 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3709 * this function returns a list of configurations for all admins that declare
3710 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3711 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3712 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3713 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003714 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003715 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003716 */
Robin Lee25e26452015-06-02 09:56:29 -07003717 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3718 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003719 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003720 }
3721
3722 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003723 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3724 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003725 if (mService != null) {
3726 try {
Jim Millere303bf42014-08-26 17:12:29 -07003727 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003728 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003729 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003730 }
3731 }
Jim Millere303bf42014-08-26 17:12:29 -07003732 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003733 }
3734
3735 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003736 * Called by a profile owner of a managed profile to set whether caller-Id information from
3737 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003738 *
3739 * <p>The calling device admin must be a profile owner. If it is not, a
3740 * security exception will be thrown.
3741 *
Robin Lee25e26452015-06-02 09:56:29 -07003742 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003743 * @param disabled If true caller-Id information in the managed profile is not displayed.
3744 */
Robin Lee25e26452015-06-02 09:56:29 -07003745 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003746 if (mService != null) {
3747 try {
Robin Lee25e26452015-06-02 09:56:29 -07003748 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003749 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003750 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003751 }
3752 }
3753 }
3754
3755 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003756 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3757 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003758 *
3759 * <p>The calling device admin must be a profile owner. If it is not, a
3760 * security exception will be thrown.
3761 *
Robin Lee25e26452015-06-02 09:56:29 -07003762 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003763 */
Robin Lee25e26452015-06-02 09:56:29 -07003764 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003765 if (mService != null) {
3766 try {
Robin Lee25e26452015-06-02 09:56:29 -07003767 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003768 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003769 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003770 }
3771 }
3772 return false;
3773 }
3774
3775 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003776 * Determine whether or not caller-Id information has been disabled.
3777 *
3778 * @param userHandle The user for whom to check the caller-id permission
3779 * @hide
3780 */
3781 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3782 if (mService != null) {
3783 try {
3784 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3785 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003786 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003787 }
3788 }
3789 return false;
3790 }
3791
3792 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003793 * Called by a profile owner of a managed profile to set whether contacts search from
3794 * the managed profile will be shown in the parent profile, for incoming calls.
3795 *
3796 * <p>The calling device admin must be a profile owner. If it is not, a
3797 * security exception will be thrown.
3798 *
3799 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3800 * @param disabled If true contacts search in the managed profile is not displayed.
3801 */
3802 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3803 boolean disabled) {
3804 if (mService != null) {
3805 try {
3806 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3807 } catch (RemoteException e) {
3808 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3809 }
3810 }
3811 }
3812
3813 /**
3814 * Called by a profile owner of a managed profile to determine whether or not contacts search
3815 * has been disabled.
3816 *
3817 * <p>The calling device admin must be a profile owner. If it is not, a
3818 * security exception will be thrown.
3819 *
3820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3821 */
3822 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3823 if (mService != null) {
3824 try {
3825 return mService.getCrossProfileContactsSearchDisabled(admin);
3826 } catch (RemoteException e) {
3827 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3828 }
3829 }
3830 return false;
3831 }
3832
3833
3834 /**
3835 * Determine whether or not contacts search has been disabled.
3836 *
3837 * @param userHandle The user for whom to check the contacts search permission
3838 * @hide
3839 */
3840 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3841 if (mService != null) {
3842 try {
3843 return mService
3844 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3845 } catch (RemoteException e) {
3846 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3847 }
3848 }
3849 return false;
3850 }
3851
3852 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003853 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00003854 *
Makoto Onuki1040da12015-03-19 11:24:00 -07003855 * @hide
3856 */
3857 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00003858 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003859 if (mService != null) {
3860 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00003861 mService.startManagedQuickContact(actualLookupKey, actualContactId,
3862 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003863 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003864 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003865 }
3866 }
3867 }
3868
3869 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003870 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003871 * @hide
3872 */
3873 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3874 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00003875 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00003876 originalIntent);
3877 }
3878
3879 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003880 * Called by a profile owner of a managed profile to set whether bluetooth
3881 * devices can access enterprise contacts.
3882 * <p>
3883 * The calling device admin must be a profile owner. If it is not, a
3884 * security exception will be thrown.
3885 * <p>
3886 * This API works on managed profile only.
3887 *
Robin Lee25e26452015-06-02 09:56:29 -07003888 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003889 * with.
3890 * @param disabled If true, bluetooth devices cannot access enterprise
3891 * contacts.
3892 */
Robin Lee25e26452015-06-02 09:56:29 -07003893 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003894 if (mService != null) {
3895 try {
Robin Lee25e26452015-06-02 09:56:29 -07003896 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003897 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003898 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003899 }
3900 }
3901 }
3902
3903 /**
3904 * Called by a profile owner of a managed profile to determine whether or
3905 * not Bluetooth devices cannot access enterprise contacts.
3906 * <p>
3907 * The calling device admin must be a profile owner. If it is not, a
3908 * security exception will be thrown.
3909 * <p>
3910 * This API works on managed profile only.
3911 *
Robin Lee25e26452015-06-02 09:56:29 -07003912 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003913 * with.
3914 */
Robin Lee25e26452015-06-02 09:56:29 -07003915 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003916 if (mService != null) {
3917 try {
Robin Lee25e26452015-06-02 09:56:29 -07003918 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003919 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003920 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003921 }
3922 }
3923 return true;
3924 }
3925
3926 /**
3927 * Determine whether or not Bluetooth devices cannot access contacts.
3928 * <p>
3929 * This API works on managed profile UserHandle only.
3930 *
3931 * @param userHandle The user for whom to check the caller-id permission
3932 * @hide
3933 */
3934 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3935 if (mService != null) {
3936 try {
3937 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3938 .getIdentifier());
3939 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003940 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003941 }
3942 }
3943 return true;
3944 }
3945
3946 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003947 * Called by the profile owner of a managed profile so that some intents sent in the managed
3948 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003949 * Only activity intents are supported.
3950 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003951 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003952 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3953 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003954 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3955 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003956 */
Robin Lee25e26452015-06-02 09:56:29 -07003957 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003958 if (mService != null) {
3959 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003960 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003961 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003962 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003963 }
3964 }
3965 }
3966
3967 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003968 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3969 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003970 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003971 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3972 */
Robin Lee25e26452015-06-02 09:56:29 -07003973 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003974 if (mService != null) {
3975 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003976 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003977 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003978 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003979 }
3980 }
3981 }
3982
3983 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003984 * Called by a profile or device owner to set the permitted accessibility services. When
3985 * set by a device owner or profile owner the restriction applies to all profiles of the
3986 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003987 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003988 * By default the user can use any accessiblity service. When zero or more packages have
3989 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003990 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003991 *
3992 * <p> Calling with a null value for the list disables the restriction so that all services
3993 * can be used, calling with an empty list only allows the builtin system's services.
3994 *
3995 * <p> System accesibility services are always available to the user the list can't modify
3996 * this.
3997 *
3998 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3999 * @param packageNames List of accessibility service package names.
4000 *
4001 * @return true if setting the restriction succeeded. It fail if there is
4002 * one or more non-system accessibility services enabled, that are not in the list.
4003 */
Robin Lee25e26452015-06-02 09:56:29 -07004004 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004005 List<String> packageNames) {
4006 if (mService != null) {
4007 try {
4008 return mService.setPermittedAccessibilityServices(admin, packageNames);
4009 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004010 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004011 }
4012 }
4013 return false;
4014 }
4015
4016 /**
4017 * Returns the list of permitted accessibility services set by this device or profile owner.
4018 *
4019 * <p>An empty list means no accessibility services except system services are allowed.
4020 * Null means all accessibility services are allowed.
4021 *
4022 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4023 * @return List of accessiblity service package names.
4024 */
Robin Lee25e26452015-06-02 09:56:29 -07004025 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004026 if (mService != null) {
4027 try {
4028 return mService.getPermittedAccessibilityServices(admin);
4029 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004030 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004031 }
4032 }
4033 return null;
4034 }
4035
4036 /**
4037 * Returns the list of accessibility services permitted by the device or profiles
4038 * owners of this user.
4039 *
4040 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4041 * it will contain the intersection of the permitted lists for any device or profile
4042 * owners that apply to this user. It will also include any system accessibility services.
4043 *
4044 * @param userId which user to check for.
4045 * @return List of accessiblity service package names.
4046 * @hide
4047 */
4048 @SystemApi
4049 public List<String> getPermittedAccessibilityServices(int userId) {
4050 if (mService != null) {
4051 try {
4052 return mService.getPermittedAccessibilityServicesForUser(userId);
4053 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004054 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004055 }
4056 }
4057 return null;
4058 }
4059
4060 /**
4061 * Called by a profile or device owner to set the permitted input methods services. When
4062 * set by a device owner or profile owner the restriction applies to all profiles of the
4063 * user the device owner or profile owner is an admin for.
4064 *
4065 * By default the user can use any input method. When zero or more packages have
4066 * been added, input method that are not in the list and not part of the system
4067 * can not be enabled by the user.
4068 *
4069 * This method will fail if it is called for a admin that is not for the foreground user
4070 * or a profile of the foreground user.
4071 *
4072 * <p> Calling with a null value for the list disables the restriction so that all input methods
4073 * can be used, calling with an empty list disables all but the system's own input methods.
4074 *
4075 * <p> System input methods are always available to the user this method can't modify this.
4076 *
4077 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4078 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004079 * @return true if setting the restriction succeeded. It will fail if there are
4080 * one or more non-system input methods currently enabled that are not in
4081 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004082 */
Robin Lee25e26452015-06-02 09:56:29 -07004083 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004084 if (mService != null) {
4085 try {
4086 return mService.setPermittedInputMethods(admin, packageNames);
4087 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004088 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004089 }
4090 }
4091 return false;
4092 }
4093
4094
4095 /**
4096 * Returns the list of permitted input methods set by this device or profile owner.
4097 *
4098 * <p>An empty list means no input methods except system input methods are allowed.
4099 * Null means all input methods are allowed.
4100 *
4101 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4102 * @return List of input method package names.
4103 */
Robin Lee25e26452015-06-02 09:56:29 -07004104 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004105 if (mService != null) {
4106 try {
4107 return mService.getPermittedInputMethods(admin);
4108 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004109 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004110 }
4111 }
4112 return null;
4113 }
4114
4115 /**
4116 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004117 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004118 *
4119 * <p>Null means all input methods are allowed, if a non-null list is returned
4120 * it will contain the intersection of the permitted lists for any device or profile
4121 * owners that apply to this user. It will also include any system input methods.
4122 *
4123 * @return List of input method package names.
4124 * @hide
4125 */
4126 @SystemApi
4127 public List<String> getPermittedInputMethodsForCurrentUser() {
4128 if (mService != null) {
4129 try {
4130 return mService.getPermittedInputMethodsForCurrentUser();
4131 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004132 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004133 }
4134 }
4135 return null;
4136 }
4137
4138 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004139 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4140 * currently installed it.
4141 *
4142 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4143 *
4144 * @return List of package names to keep cached.
4145 * @hide
4146 */
4147 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4148 if (mService != null) {
4149 try {
4150 return mService.getKeepUninstalledPackages(admin);
4151 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004152 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004153 }
4154 }
4155 return null;
4156 }
4157
4158 /**
4159 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4160 * currently installed it.
4161 *
4162 * <p>Please note that setting this policy does not imply that specified apps will be
4163 * automatically pre-cached.</p>
4164 *
4165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4166 * @param packageNames List of package names to keep cached.
4167 * @hide
4168 */
4169 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4170 @NonNull List<String> packageNames) {
4171 if (mService != null) {
4172 try {
4173 mService.setKeepUninstalledPackages(admin, packageNames);
4174 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004175 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004176 }
4177 }
4178 }
4179
4180 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004181 * Called by a device owner to create a user with the specified name. The UserHandle returned
4182 * by this method should not be persisted as user handles are recycled as users are removed and
4183 * created. If you need to persist an identifier for this user, use
4184 * {@link UserManager#getSerialNumberForUser}.
4185 *
4186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4187 * @param name the user's name
4188 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004189 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4190 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004191 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004192 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04004193 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004194 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004195 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004196 try {
4197 return mService.createUser(admin, name);
4198 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004199 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004200 }
4201 return null;
4202 }
4203
4204 /**
Jason Monk03978a42014-06-10 15:05:30 -04004205 * Called by a device owner to create a user with the specified name. The UserHandle returned
4206 * by this method should not be persisted as user handles are recycled as users are removed and
4207 * created. If you need to persist an identifier for this user, use
4208 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4209 * immediately.
4210 *
4211 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4212 * as registered as an active admin on the new user. The profile owner package will be
4213 * installed on the new user if it already is installed on the device.
4214 *
4215 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4216 * profileOwnerComponent when onEnable is called.
4217 *
4218 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4219 * @param name the user's name
4220 * @param ownerName the human readable name of the organisation associated with this DPM.
4221 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4222 * the user.
4223 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4224 * on the new user.
4225 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004226 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4227 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004228 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004229 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004230 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004231 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004232 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4233 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004234 try {
4235 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4236 adminExtras);
4237 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004238 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004239 }
4240 return null;
4241 }
4242
4243 /**
phweissa92e1212016-01-25 17:14:10 +01004244 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004245 */
4246 public static final int SKIP_SETUP_WIZARD = 0x0001;
4247
4248 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004249 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4250 * ephemeral.
4251 * @hide
4252 */
4253 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4254
4255 /**
phweissa92e1212016-01-25 17:14:10 +01004256 * Called by a device owner to create a user with the specified name and a given component of
4257 * the calling package as profile owner. The UserHandle returned by this method should not be
4258 * persisted as user handles are recycled as users are removed and created. If you need to
4259 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4260 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004261 *
phweissa92e1212016-01-25 17:14:10 +01004262 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4263 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4264 * will be registered as an active admin on the new user. The profile owner package will be
4265 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004266 *
4267 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4268 * started for the first time. Then the extras will be passed to the admin when
4269 * onEnable is called.
4270 *
4271 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4272 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004273 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4274 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4275 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004276 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4277 * user.
phweissa92e1212016-01-25 17:14:10 +01004278 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004279 * @see UserHandle
4280 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4281 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004282 */
4283 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004284 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4285 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004286 try {
phweissa92e1212016-01-25 17:14:10 +01004287 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004288 } catch (RemoteException re) {
4289 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4290 }
4291 return null;
4292 }
4293
4294 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004295 * Called by a device owner to remove a user and all associated data. The primary user can
4296 * not be removed.
4297 *
4298 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4299 * @param userHandle the user to remove.
4300 * @return {@code true} if the user was removed, {@code false} otherwise.
4301 */
Robin Lee25e26452015-06-02 09:56:29 -07004302 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004303 try {
4304 return mService.removeUser(admin, userHandle);
4305 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004306 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004307 return false;
4308 }
4309 }
4310
4311 /**
Jason Monk582d9112014-07-09 19:57:08 -04004312 * Called by a device owner to switch the specified user to the foreground.
4313 *
4314 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4315 * @param userHandle the user to switch to; null will switch to primary.
4316 * @return {@code true} if the switch was successful, {@code false} otherwise.
4317 *
4318 * @see Intent#ACTION_USER_FOREGROUND
4319 */
Robin Lee25e26452015-06-02 09:56:29 -07004320 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004321 try {
4322 return mService.switchUser(admin, userHandle);
4323 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004324 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004325 return false;
4326 }
4327 }
4328
4329 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004330 * Retrieves the application restrictions for a given target application running in the calling
4331 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004332 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004333 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4334 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4335 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004336 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004337 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4338 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004339 * @param packageName The name of the package to fetch restricted settings of.
4340 * @return {@link Bundle} of settings corresponding to what was set last time
4341 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4342 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004343 *
4344 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004345 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004346 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004347 if (mService != null) {
4348 try {
4349 return mService.getApplicationRestrictions(admin, packageName);
4350 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004351 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004352 }
4353 }
4354 return null;
4355 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004356
4357 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004358 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004359 * <p>
4360 * The calling device admin must be a profile or device owner; if it is not,
4361 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004362 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004363 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4364 * with.
4365 * @param key The key of the restriction. See the constants in
4366 * {@link android.os.UserManager} for the list of keys.
4367 */
Robin Lee25e26452015-06-02 09:56:29 -07004368 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004369 if (mService != null) {
4370 try {
4371 mService.setUserRestriction(admin, key, true);
4372 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004373 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004374 }
4375 }
4376 }
4377
4378 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004379 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004380 * <p>
4381 * The calling device admin must be a profile or device owner; if it is not,
4382 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004383 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004384 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4385 * with.
4386 * @param key The key of the restriction. See the constants in
4387 * {@link android.os.UserManager} for the list of keys.
4388 */
Robin Lee25e26452015-06-02 09:56:29 -07004389 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004390 if (mService != null) {
4391 try {
4392 mService.setUserRestriction(admin, key, false);
4393 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004394 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004395 }
4396 }
4397 }
Adam Connors010cfd42014-04-16 12:48:13 +01004398
4399 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004400 * Called by a profile or device owner to get user restrictions set with
4401 * {@link #addUserRestriction(ComponentName, String)}.
4402 * <p>
4403 * The target user may have more restrictions set by the system or other device owner / profile
4404 * owner. To get all the user restrictions currently set, use
4405 * {@link UserManager#getUserRestrictions()}.
4406 *
4407 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004408 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004409 */
4410 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004411 return getUserRestrictions(admin, myUserId());
4412 }
4413
4414 /** @hide per-user version */
4415 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004416 Bundle ret = null;
4417 if (mService != null) {
4418 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004419 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004420 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004421 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004422 }
4423 }
4424 return ret == null ? new Bundle() : ret;
4425 }
4426
4427 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004428 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004429 * is unavailable for use, but the data and actual package file remain.
4430 *
4431 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004432 * @param packageName The name of the package to hide or unhide.
4433 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4434 * unhidden.
4435 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004436 */
Robin Lee25e26452015-06-02 09:56:29 -07004437 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004438 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004439 if (mService != null) {
4440 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004441 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004442 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004443 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004444 }
4445 }
4446 return false;
4447 }
4448
4449 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004450 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004451 *
4452 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004453 * @param packageName The name of the package to retrieve the hidden status of.
4454 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004455 */
Robin Lee25e26452015-06-02 09:56:29 -07004456 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004457 if (mService != null) {
4458 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004459 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004460 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004461 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004462 }
4463 }
4464 return false;
4465 }
4466
4467 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004468 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004469 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004470 *
4471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004472 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004473 */
Robin Lee25e26452015-06-02 09:56:29 -07004474 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004475 if (mService != null) {
4476 try {
4477 mService.enableSystemApp(admin, packageName);
4478 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004479 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004480 }
4481 }
4482 }
4483
4484 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004485 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004486 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004487 *
4488 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4489 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004490 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004491 * @return int The number of activities that matched the intent and were installed.
4492 */
Robin Lee25e26452015-06-02 09:56:29 -07004493 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004494 if (mService != null) {
4495 try {
4496 return mService.enableSystemAppWithIntent(admin, intent);
4497 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004498 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004499 }
4500 }
4501 return 0;
4502 }
4503
4504 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004505 * Called by a device owner or profile owner to disable account management for a specific type
4506 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004507 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004508 * <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 +01004509 * security exception will be thrown.
4510 *
4511 * <p>When account management is disabled for an account type, adding or removing an account
4512 * of that type will not be possible.
4513 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004514 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4515 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4516 * management for a specific type is disabled.
4517 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004518 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4519 * @param accountType For which account management is disabled or enabled.
4520 * @param disabled The boolean indicating that account management will be disabled (true) or
4521 * enabled (false).
4522 */
Robin Lee25e26452015-06-02 09:56:29 -07004523 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004524 boolean disabled) {
4525 if (mService != null) {
4526 try {
4527 mService.setAccountManagementDisabled(admin, accountType, disabled);
4528 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004529 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004530 }
4531 }
4532 }
4533
4534 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004535 * Gets the array of accounts for which account management is disabled by the profile owner.
4536 *
4537 * <p> Account management can be disabled/enabled by calling
4538 * {@link #setAccountManagementDisabled}.
4539 *
4540 * @return a list of account types for which account management has been disabled.
4541 *
4542 * @see #setAccountManagementDisabled
4543 */
4544 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004545 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004546 }
4547
4548 /**
4549 * @see #getAccountTypesWithManagementDisabled()
4550 * @hide
4551 */
4552 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004553 if (mService != null) {
4554 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004555 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004556 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004557 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004558 }
4559 }
4560
4561 return null;
4562 }
justinzhang511e0d82014-03-24 16:09:24 -04004563
4564 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004565 * Sets which packages may enter lock task mode.
4566 *
4567 * <p>Any packages that shares uid with an allowed package will also be allowed
4568 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004569 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004570 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004571 * package list results in locked tasks belonging to those packages to be finished.
4572 *
Jason Monkc5185f22014-06-24 11:12:42 -04004573 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004574 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004575 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004576 *
4577 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004578 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4579 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004580 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004581 */
Robin Lee25e26452015-06-02 09:56:29 -07004582 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004583 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004584 if (mService != null) {
4585 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004586 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004587 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004588 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004589 }
4590 }
4591 }
4592
4593 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004594 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004595 *
4596 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004597 * @hide
4598 */
Robin Lee25e26452015-06-02 09:56:29 -07004599 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004600 if (mService != null) {
4601 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004602 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004603 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004604 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004605 }
4606 }
4607 return null;
4608 }
4609
4610 /**
4611 * This function lets the caller know whether the given component is allowed to start the
4612 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004613 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004614 */
Jason Monkd7b86212014-06-16 13:15:38 -04004615 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004616 if (mService != null) {
4617 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004618 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004619 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004620 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004621 }
4622 }
4623 return false;
4624 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004625
4626 /**
4627 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4628 * 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 -04004629 * <p>The settings that can be updated with this method are:
4630 * <ul>
4631 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4632 * <li>{@link Settings.Global#AUTO_TIME}</li>
4633 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004634 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004635 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004636 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004637 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004638 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004639 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004640 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004641 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004642 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004643 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004644 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004645 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004646 * <ul>
4647 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4648 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4649 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4650 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4651 * <li>{@link Settings.Global#MODE_RINGER}.
4652 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4653 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4654 * <li>{@link Settings.Global#WIFI_ON}.
4655 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4656 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004657 *
4658 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4659 * @param setting The name of the setting to update.
4660 * @param value The value to update the setting to.
4661 */
Robin Lee25e26452015-06-02 09:56:29 -07004662 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004663 if (mService != null) {
4664 try {
4665 mService.setGlobalSetting(admin, setting, value);
4666 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004667 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004668 }
4669 }
4670 }
4671
4672 /**
4673 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4674 * that the value of the setting is in the correct form for the setting type should be performed
4675 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004676 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004677 * <ul>
4678 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004679 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004680 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4681 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004682 * <p>A device owner can additionally update the following settings:
4683 * <ul>
4684 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4685 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004686 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4687 * @param setting The name of the setting to update.
4688 * @param value The value to update the setting to.
4689 */
Robin Lee25e26452015-06-02 09:56:29 -07004690 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004691 if (mService != null) {
4692 try {
4693 mService.setSecureSetting(admin, setting, value);
4694 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004695 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004696 }
4697 }
4698 }
4699
Amith Yamasanif20d6402014-05-24 15:34:37 -07004700 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004701 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004702 * making permission requests of a local or remote administrator of the user.
4703 * <p/>
4704 * Only a profile owner can designate the restrictions provider.
4705 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004706 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004707 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004708 * it removes the restrictions provider previously assigned.
4709 */
Robin Lee25e26452015-06-02 09:56:29 -07004710 public void setRestrictionsProvider(@NonNull ComponentName admin,
4711 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004712 if (mService != null) {
4713 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004714 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004715 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004716 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004717 }
4718 }
4719 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004720
4721 /**
4722 * Called by profile or device owners to set the master volume mute on or off.
4723 *
4724 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4725 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4726 */
Robin Lee25e26452015-06-02 09:56:29 -07004727 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004728 if (mService != null) {
4729 try {
4730 mService.setMasterVolumeMuted(admin, on);
4731 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004732 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004733 }
4734 }
4735 }
4736
4737 /**
4738 * Called by profile or device owners to check whether the master volume mute is on or off.
4739 *
4740 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4741 * @return {@code true} if master volume is muted, {@code false} if it's not.
4742 */
Robin Lee25e26452015-06-02 09:56:29 -07004743 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004744 if (mService != null) {
4745 try {
4746 return mService.isMasterVolumeMuted(admin);
4747 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004748 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004749 }
4750 }
4751 return false;
4752 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004753
4754 /**
4755 * Called by profile or device owners to change whether a user can uninstall
4756 * a package.
4757 *
4758 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4759 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004760 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004761 */
Robin Lee25e26452015-06-02 09:56:29 -07004762 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004763 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004764 if (mService != null) {
4765 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004766 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004767 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004768 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004769 }
4770 }
4771 }
4772
4773 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004774 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004775 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004776 * <p>
4777 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004778 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004779 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004780 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004781 *
Robin Lee25e26452015-06-02 09:56:29 -07004782 * @param admin The name of the admin component whose blocking policy will be checked, or
4783 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004784 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004785 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004786 */
Robin Lee25e26452015-06-02 09:56:29 -07004787 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004788 if (mService != null) {
4789 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004790 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004791 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004792 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004793 }
4794 }
4795 return false;
4796 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004797
4798 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004799 * Called by the profile owner of a managed profile to enable widget providers from a
4800 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004801 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004802 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004803 * a package may have zero or more provider components, where each component
4804 * provides a different widget type.
4805 * <p>
4806 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004807 *
4808 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4809 * @param packageName The package from which widget providers are white-listed.
4810 * @return Whether the package was added.
4811 *
4812 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4813 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4814 */
Robin Lee25e26452015-06-02 09:56:29 -07004815 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004816 if (mService != null) {
4817 try {
4818 return mService.addCrossProfileWidgetProvider(admin, packageName);
4819 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004820 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004821 }
4822 }
4823 return false;
4824 }
4825
4826 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004827 * Called by the profile owner of a managed profile to disable widget providers from a given
4828 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004829 * package should have been added via {@link #addCrossProfileWidgetProvider(
4830 * android.content.ComponentName, String)}.
4831 * <p>
4832 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004833 *
4834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4835 * @param packageName The package from which widget providers are no longer
4836 * white-listed.
4837 * @return Whether the package was removed.
4838 *
4839 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4840 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4841 */
Esteban Talavera62399912016-01-11 15:37:55 +00004842 public boolean removeCrossProfileWidgetProvider(
4843 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004844 if (mService != null) {
4845 try {
4846 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4847 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004848 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004849 }
4850 }
4851 return false;
4852 }
4853
4854 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004855 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004856 * available in the parent profile.
4857 *
4858 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4859 * @return The white-listed package list.
4860 *
4861 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4862 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4863 */
Robin Lee25e26452015-06-02 09:56:29 -07004864 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004865 if (mService != null) {
4866 try {
4867 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4868 if (providers != null) {
4869 return providers;
4870 }
4871 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004872 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004873 }
4874 }
4875 return Collections.emptyList();
4876 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004877
4878 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004879 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004880 *
4881 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4882 * @param icon the bitmap to set as the photo.
4883 */
Robin Lee25e26452015-06-02 09:56:29 -07004884 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004885 try {
4886 mService.setUserIcon(admin, icon);
4887 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004888 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004889 }
4890 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004891
4892 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004893 * Called by device owners to set a local system update policy. When a new policy is set,
4894 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004895 *
Robin Lee25e26452015-06-02 09:56:29 -07004896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4897 * components in the device owner package can set system update policies and the
4898 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004899 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004900 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004901 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004902 */
Robin Lee25e26452015-06-02 09:56:29 -07004903 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004904 if (mService != null) {
4905 try {
Robin Lee25e26452015-06-02 09:56:29 -07004906 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004907 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004908 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004909 }
4910 }
4911 }
4912
4913 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004914 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004915 *
Robin Lee25e26452015-06-02 09:56:29 -07004916 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004917 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004918 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004919 if (mService != null) {
4920 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004921 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004922 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004923 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004924 }
4925 }
4926 return null;
4927 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004928
4929 /**
4930 * Called by a device owner to disable the keyguard altogether.
4931 *
4932 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4933 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4934 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4935 * being disabled.
4936 *
4937 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004938 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004939 *
4940 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004941 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004942 */
Robin Lee25e26452015-06-02 09:56:29 -07004943 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004944 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004945 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004946 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004947 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01004948 return false;
4949 }
4950 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004951
4952 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004953 * Called by device owner to disable the status bar. Disabling the status bar blocks
4954 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004955 * a single use device.
4956 *
4957 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004958 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4959 *
4960 * @return {@code false} if attempting to disable the status bar failed.
4961 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004962 */
Robin Lee25e26452015-06-02 09:56:29 -07004963 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004964 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004965 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004966 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004967 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004968 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004969 }
4970 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004971
4972 /**
4973 * Callable by the system update service to notify device owners about pending updates.
4974 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4975 * permission.
4976 *
4977 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4978 * when the current pending update was first available. -1 if no update is available.
4979 * @hide
4980 */
4981 @SystemApi
4982 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4983 if (mService != null) {
4984 try {
4985 mService.notifyPendingSystemUpdate(updateReceivedTime);
4986 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004987 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01004988 }
4989 }
4990 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004991
4992 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004993 * Called by profile or device owners to set the default response for future runtime permission
4994 * requests by applications. The policy can allow for normal operation which prompts the
4995 * user to grant a permission, or can allow automatic granting or denying of runtime
4996 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004997 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4998 * the permission grant state via {@link #setPermissionGrantState}.
4999 *
5000 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005001 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005002 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005003 * @param admin Which profile or device owner this request is associated with.
5004 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5005 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005006 *
5007 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005008 */
Robin Lee25e26452015-06-02 09:56:29 -07005009 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005010 try {
5011 mService.setPermissionPolicy(admin, policy);
5012 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005013 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005014 }
5015 }
5016
5017 /**
5018 * Returns the current runtime permission policy set by the device or profile owner. The
5019 * default is {@link #PERMISSION_POLICY_PROMPT}.
5020 * @param admin Which profile or device owner this request is associated with.
5021 * @return the current policy for future permission requests.
5022 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005023 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005024 try {
5025 return mService.getPermissionPolicy(admin);
5026 } catch (RemoteException re) {
5027 return PERMISSION_POLICY_PROMPT;
5028 }
5029 }
5030
5031 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005032 * Sets the grant state of a runtime permission for a specific application. The state
5033 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5034 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5035 * is denied and the user cannot manage it through the UI, and {@link
5036 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5037 * user cannot manage it through the UI. This might affect all permissions in a
5038 * group that the runtime permission belongs to. This method can only be called
5039 * by a profile or device owner.
5040 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005041 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5042 * revoke the permission. It retains the previous grant, if any.
5043 *
5044 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005045 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005046 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005047 * @param admin Which profile or device owner this request is associated with.
5048 * @param packageName The application to grant or revoke a permission to.
5049 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005050 * @param grantState The permission grant state which is one of {@link
5051 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5052 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5053 * @return whether the permission was successfully granted or revoked.
5054 *
5055 * @see #PERMISSION_GRANT_STATE_DENIED
5056 * @see #PERMISSION_GRANT_STATE_DEFAULT
5057 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005058 */
Robin Lee25e26452015-06-02 09:56:29 -07005059 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005060 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005061 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005062 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005063 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005064 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005065 return false;
5066 }
5067 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005068
5069 /**
5070 * Returns the current grant state of a runtime permission for a specific application.
5071 *
5072 * @param admin Which profile or device owner this request is associated with.
5073 * @param packageName The application to check the grant state for.
5074 * @param permission The permission to check for.
5075 * @return the current grant state specified by device policy. If the profile or device owner
5076 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5077 * This does not indicate whether or not the permission is currently granted for the package.
5078 *
5079 * <p/>If a grant state was set by the profile or device owner, then the return value will
5080 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5081 * which indicates if the permission is currently denied or granted.
5082 *
5083 * @see #setPermissionGrantState(ComponentName, String, String, int)
5084 * @see PackageManager#checkPermission(String, String)
5085 */
Robin Lee25e26452015-06-02 09:56:29 -07005086 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005087 String permission) {
5088 try {
5089 return mService.getPermissionGrantState(admin, packageName, permission);
5090 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005091 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07005092 return PERMISSION_GRANT_STATE_DEFAULT;
5093 }
5094 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005095
5096 /**
5097 * Returns if provisioning a managed profile or device is possible or not.
5098 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5099 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5100 * Note that even if this method returns true, there is a slight possibility that the
5101 * provisioning will not be allowed when it is actually initiated because some event has
5102 * happened in between.
5103 * @return if provisioning a managed profile or device is possible or not.
5104 * @throws IllegalArgumentException if the supplied action is not valid.
5105 */
5106 public boolean isProvisioningAllowed(String action) {
5107 try {
5108 return mService.isProvisioningAllowed(action);
5109 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005110 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005111 return false;
5112 }
5113 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005114
5115 /**
5116 * @hide
5117 * Return if this user is a managed profile of another user. An admin can become the profile
5118 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5119 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5120 * @param admin Which profile owner this request is associated with.
5121 * @return if this user is a managed profile of another user.
5122 */
5123 public boolean isManagedProfile(@NonNull ComponentName admin) {
5124 try {
5125 return mService.isManagedProfile(admin);
5126 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005127 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005128 return false;
5129 }
5130 }
5131
5132 /**
5133 * @hide
5134 * Return if this user is a system-only user. An admin can manage a device from a system only
5135 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5136 * @param admin Which device owner this request is associated with.
5137 * @return if this user is a system-only user.
5138 */
5139 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5140 try {
5141 return mService.isSystemOnlyUser(admin);
5142 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005143 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005144 return false;
5145 }
5146 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005147
5148 /**
5149 * Called by device owner to get the MAC address of the Wi-Fi device.
5150 *
5151 * @return the MAC address of the Wi-Fi device, or null when the information is not
5152 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5153 *
5154 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5155 */
5156 public String getWifiMacAddress() {
5157 try {
5158 return mService.getWifiMacAddress();
5159 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005160 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005161 return null;
5162 }
5163 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005164
5165 /**
5166 * Called by device owner to reboot the device.
5167 */
5168 public void reboot(@NonNull ComponentName admin) {
5169 try {
5170 mService.reboot(admin);
5171 } catch (RemoteException re) {
5172 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5173 }
5174 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005175
5176 /**
5177 * Called by a device admin to set the short support message. This will
5178 * be displayed to the user in settings screens where funtionality has
5179 * been disabled by the admin.
5180 *
5181 * The message should be limited to a short statement such as
5182 * "This setting is disabled by your administrator. Contact someone@example.com
5183 * for support."
5184 * If the message is longer than 200 characters it may be truncated.
5185 *
5186 * @see #setLongSupportMessage
5187 *
5188 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5189 * @param message Short message to be displayed to the user in settings or null to
5190 * clear the existing message.
5191 */
5192 public void setShortSupportMessage(@NonNull ComponentName admin,
5193 @Nullable String message) {
5194 if (mService != null) {
5195 try {
5196 mService.setShortSupportMessage(admin, message);
5197 } catch (RemoteException e) {
5198 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5199 }
5200 }
5201 }
5202
5203 /**
5204 * Called by a device admin to get the short support message.
5205 *
5206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5207 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5208 * or null if no message has been set.
5209 */
5210 public String getShortSupportMessage(@NonNull ComponentName admin) {
5211 if (mService != null) {
5212 try {
5213 return mService.getShortSupportMessage(admin);
5214 } catch (RemoteException e) {
5215 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5216 }
5217 }
5218 return null;
5219 }
5220
5221 /**
5222 * Called by a device admin to set the long support message. This will
5223 * be displayed to the user in the device administators settings screen.
5224 *
5225 * @see #setShortSupportMessage
5226 *
5227 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5228 * @param message Long message to be displayed to the user in settings or null to
5229 * clear the existing message.
5230 */
5231 public void setLongSupportMessage(@NonNull ComponentName admin,
5232 @Nullable String message) {
5233 if (mService != null) {
5234 try {
5235 mService.setLongSupportMessage(admin, message);
5236 } catch (RemoteException e) {
5237 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5238 }
5239 }
5240 }
5241
5242 /**
5243 * Called by a device admin to get the long support message.
5244 *
5245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5246 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5247 * or null if no message has been set.
5248 */
5249 public String getLongSupportMessage(@NonNull ComponentName admin) {
5250 if (mService != null) {
5251 try {
5252 return mService.getLongSupportMessage(admin);
5253 } catch (RemoteException e) {
5254 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5255 }
5256 }
5257 return null;
5258 }
5259
5260 /**
5261 * Called by the system to get the short support message.
5262 *
5263 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5264 * @param userHandle user id the admin is running as.
5265 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5266 *
5267 * @hide
5268 */
5269 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5270 if (mService != null) {
5271 try {
5272 return mService.getShortSupportMessageForUser(admin, userHandle);
5273 } catch (RemoteException e) {
5274 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5275 }
5276 }
5277 return null;
5278 }
5279
5280
5281 /**
5282 * Called by the system to get the long support message.
5283 *
5284 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5285 * @param userHandle user id the admin is running as.
5286 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5287 *
5288 * @hide
5289 */
5290 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5291 if (mService != null) {
5292 try {
5293 return mService.getLongSupportMessageForUser(admin, userHandle);
5294 } catch (RemoteException e) {
5295 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5296 }
5297 }
5298 return null;
5299 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005300
5301 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005302 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5303 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005304 *
5305 * <p> Note only some methods will work on the parent Manager.
5306 *
5307 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5308 */
5309 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5310 try {
5311 if (!mService.isManagedProfile(admin)) {
5312 throw new SecurityException("The current user does not have a parent profile.");
5313 }
5314 return new DevicePolicyManager(mContext, true);
5315 } catch (RemoteException re) {
5316 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5317 return null;
5318 }
5319 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005320
5321 /**
5322 * Called by a profile owner of a managed profile to set the color used for customization.
5323 * This color is used as background color of the confirm credentials screen for that user.
5324 * The default color is {@link android.graphics.Color#GRAY}.
5325 *
5326 * <p>The confirm credentials screen can be created using
5327 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5328 *
5329 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5330 * @param color The 32bit representation of the color to be used.
5331 */
5332 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5333 try {
5334 mService.setOrganizationColor(admin, color);
5335 } catch (RemoteException re) {
5336 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5337 }
5338 }
5339
5340 /**
5341 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5342 * This color is used as background color of the confirm credentials screen for that user.
5343 *
5344 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5345 * @return The 32bit representation of the color to be used.
5346 */
5347 public int getOrganizationColor(@NonNull ComponentName admin) {
5348 try {
5349 return mService.getOrganizationColor(admin);
5350 } catch (RemoteException re) {
5351 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5352 return 0;
5353 }
5354 }
5355
5356 /**
5357 * @hide
5358 * Retrieve the customization color for a given user.
5359 *
5360 * @param userHandle The user id of the user we're interested in.
5361 * @return The 32bit representation of the color to be used.
5362 */
5363 public int getOrganizationColorForUser(int userHandle) {
5364 try {
5365 return mService.getOrganizationColorForUser(userHandle);
5366 } catch (RemoteException re) {
5367 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5368 return 0;
5369 }
5370 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005371
5372 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005373 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5374 * return {@link #STATE_USER_UNMANAGED}
5375 * @hide
5376 */
5377 @UserProvisioningState
5378 public int getUserProvisioningState() {
5379 if (mService != null) {
5380 try {
5381 return mService.getUserProvisioningState();
5382 } catch (RemoteException e) {
5383 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5384 }
5385 }
5386 return STATE_USER_UNMANAGED;
5387 }
5388
5389 /**
5390 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5391 *
5392 * @param state to store
5393 * @param userHandle for user
5394 * @hide
5395 */
5396 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5397 if (mService != null) {
5398 try {
5399 mService.setUserProvisioningState(state, userHandle);
5400 } catch (RemoteException e) {
5401 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5402 }
5403 }
5404 }
5405
5406 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005407 * @hide
5408 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5409 * affiliated if it is managed by the same entity as the device.
5410 *
5411 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5412 * user/profile is considered affiliated if the following conditions are both met:
5413 * <ul>
5414 * <li>The device owner and the user's/profile's profile owner have called this method,
5415 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5416 * and a profile owner intersect, they must have come from the same source, which means that
5417 * the device owner and profile owner are controlled by the same entity.</li>
5418 * <li>The device owner's and profile owner's package names are the same.</li>
5419 * </ul>
5420 *
5421 * @param admin Which profile or device owner this request is associated with.
5422 * @param ids A set of opaque affiliation ids.
5423 */
5424 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
5425 try {
5426 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
5427 } catch (RemoteException e) {
5428 Log.w(TAG, "Failed talking with device policy service", e);
5429 }
5430 }
5431
5432 /**
5433 * @hide
5434 * Returns whether this user/profile is affiliated with the device. See
5435 * {@link #setAffiliationIds} for the definition of affiliation.
5436 *
5437 * @return whether this user/profile is affiliated with the device.
5438 */
5439 public boolean isAffiliatedUser() {
5440 try {
5441 return mService != null && mService.isAffiliatedUser();
5442 } catch (RemoteException e) {
5443 Log.w(TAG, "Failed talking with device policy service", e);
5444 return false;
5445 }
5446 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005447}