blob: b89c5a61ef1092060c89ba4ed141c08aebb050de [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010034import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070035import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000036import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080037import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080038import android.os.RemoteException;
39import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070040import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040041import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040042import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010043import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070044import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080045import android.util.Log;
46
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070047import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040048import com.android.org.conscrypt.TrustedCertificateStore;
49
Jessica Hummel91da58d2014-04-10 17:39:43 +010050import org.xmlpull.v1.XmlPullParserException;
51
Maggie Benthallda51e682013-08-08 22:35:44 -040052import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080053import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070054import java.net.InetSocketAddress;
55import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010056import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010057import java.security.PrivateKey;
58import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040059import java.security.cert.CertificateException;
60import java.security.cert.CertificateFactory;
61import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010062import java.security.spec.PKCS8EncodedKeySpec;
63import java.security.spec.InvalidKeySpecException;
64import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070065import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070066import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080067import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080068
69/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000070 * Public interface for managing policies enforced on a device. Most clients of this class must be
71 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000072 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000073 * a device administrator may be registered as either a profile or device owner. A given method is
74 * accessible to all device administrators unless the documentation for that method specifies that
75 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080076 *
77 * <div class="special reference">
78 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000079 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080080 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070081 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080083 */
84public class DevicePolicyManager {
85 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080086
87 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080088 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070089
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070090 private DevicePolicyManager(Context context) {
91 this(context, IDevicePolicyManager.Stub.asInterface(
92 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Dianne Hackbornd6847842010-01-12 18:14:19 -080093 }
94
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080095 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070096 @VisibleForTesting
97 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
98 mContext = context;
99 mService = service;
100 }
101
102 /** @hide */
103 public static DevicePolicyManager create(Context context) {
104 DevicePolicyManager me = new DevicePolicyManager(context);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800105 return me.mService != null ? me : null;
106 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700107
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700108 /** @hide test will override it. */
109 @VisibleForTesting
110 protected int myUserId() {
111 return UserHandle.myUserId();
112 }
113
Dianne Hackbornd6847842010-01-12 18:14:19 -0800114 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000115 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100117 * <p>A managed profile allows data separation for example for the usage of a
118 * device as a personal and corporate device. The user which provisioning is started from and
119 * the managed profile share a launcher.
120 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800121 * <p>This intent will typically be sent by a mobile device management application (MDM).
122 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
123 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100124 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000125 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
126 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700127 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000128 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
129 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000131 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
132 * in the provisioning intent. The
133 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
134 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
135 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100136 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100137 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
138 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100139 *
140 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
141 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
142 * the provisioning flow was successful, although this doesn't guarantee the full flow will
143 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
144 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000145 */
146 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
147 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100148 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000149
150 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000151 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000152 * Activity action: Starts the provisioning flow which sets up a managed user.
153 *
154 * <p>This intent will typically be sent by a mobile device management application (MDM).
155 * Provisioning configures the current user as managed user and sets the MDM as the profile
156 * owner who has full control over the user. Provisioning can only happen before user setup has
157 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
158 * allowed.
159 *
160 * This intent should contain the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME},
161 * although specifying only {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is also
162 * supported.
163 *
164 * <p> If provisioning fails, the device returns to its previous state.
165 *
166 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
167 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
168 * the provisioning flow was successful, although this doesn't guarantee the full flow will
169 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
170 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000171 */
172 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
173 public static final String ACTION_PROVISION_MANAGED_USER
174 = "android.app.action.PROVISION_MANAGED_USER";
175
176 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100177 * Activity action: Starts the provisioning flow which sets up a managed device.
178 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
179 *
180 * <p> During device owner provisioning a device admin app is set as the owner of the device.
181 * A device owner has full control over the device. The device owner can not be modified by the
182 * user.
183 *
184 * <p> A typical use case would be a device that is owned by a company, but used by either an
185 * employee or client.
186 *
187 * <p> An intent with this action can be sent only on an unprovisioned device.
188 * It is possible to check if the device is provisioned or not by looking at
189 * {@link android.provider.Settings.Global#DEVICE_PROVISIONED}
190 *
191 * The intent contains the following extras:
192 * <ul>
193 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
194 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
195 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100196 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100197 * </ul>
198 *
199 * <p> When device owner provisioning has completed, an intent of the type
200 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
201 * device owner.
202 *
203 * <p> If provisioning fails, the device is factory reset.
204 *
Alan Treadway4582f812015-07-28 11:49:35 +0100205 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
206 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
207 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
208 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100209 */
210 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
211 public static final String ACTION_PROVISION_MANAGED_DEVICE
212 = "android.app.action.PROVISION_MANAGED_DEVICE";
213
214 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100215 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100216 * allows a mobile device management application or NFC programmer application which starts
217 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100218 * <p>
219 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
220 * sends the intent to pass data to itself on the newly created profile.
221 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
222 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100223 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
224 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
225 * message should contain a stringified {@link java.util.Properties} instance, whose string
226 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
227 * management application after provisioning.
228 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100229 * <p>
230 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700231 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
232 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100233 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100234 */
235 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100236 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100237
238 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100239 * A String extra holding the package name of the mobile device management application that
240 * will be set as the profile owner or device owner.
241 *
242 * <p>If an application starts provisioning directly via an intent with action
243 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
244 * application that started provisioning. The package will be set as profile owner in that case.
245 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000246 * <p>This package is set as device owner when device owner provisioning is started by an NFC
247 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000248 *
249 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700250 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000251
252 * @see DeviceAdminReceiver
253 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100254 * supported, but only if there is only one device admin receiver in the package that requires
255 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000256 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000257 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000258 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100259 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000260
261 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000262 * A ComponentName extra indicating the device admin receiver of the mobile device management
263 * application that will be set as the profile owner or device owner and active admin.
264 *
265 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100266 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
267 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
268 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000269 *
270 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100271 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
272 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400273 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000274 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000275 *
276 * @see DeviceAdminReceiver
277 */
278 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
279 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
280
281 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000282 * An {@link android.accounts.Account} extra holding the account to migrate during managed
283 * profile provisioning. If the account supplied is present in the primary user, it will be
284 * copied, along with its credentials to the managed profile and removed from the primary user.
285 *
286 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
287 */
288
289 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
290 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
291
292 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100293 * A String extra that, holds the email address of the account which a managed profile is
294 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
295 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100296 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100297 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
298 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100299 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
300 * contains this extra, it is forwarded in the
301 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
302 * device management application that was set as the profile owner during provisioning.
303 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100304 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100305 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
306 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100307
308 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000309 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700310 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000311 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100312 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
313 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000314 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000315 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
316 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000317
318 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
320 * will be set to.
321 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000322 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
323 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100324 */
325 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100326 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100327
328 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100329 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
330 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100331 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000332 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
333 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100334 */
335 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100336 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100337
338 /**
339 * A String extra holding the {@link java.util.Locale} that the device will be set to.
340 * Format: xx_yy, where xx is the language code, and yy the country code.
341 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000342 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
343 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100344 */
345 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100346 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100347
348 /**
349 * A String extra holding the ssid of the wifi network that should be used during nfc device
350 * owner provisioning for downloading the mobile device management application.
351 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000352 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
353 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100354 */
355 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100356 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100357
358 /**
359 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
360 * is hidden or not.
361 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000362 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
363 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100364 */
365 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100366 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100367
368 /**
369 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100370 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
371 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100372 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000373 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
374 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100375 */
376 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100377 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100378
379 /**
380 * A String extra holding the password of the wifi network in
381 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
382 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000383 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
384 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100385 */
386 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100387 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100388
389 /**
390 * A String extra holding the proxy host for the wifi network in
391 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
392 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000393 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
394 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100395 */
396 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100397 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100398
399 /**
400 * An int extra holding the proxy port for the wifi network in
401 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
402 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000403 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
404 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100405 */
406 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100407 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100408
409 /**
410 * A String extra holding the proxy bypass for the wifi network in
411 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
412 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000413 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
414 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100415 */
416 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100417 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100418
419 /**
420 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
421 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
422 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000423 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
424 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100425 */
426 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100427 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100428
429 /**
430 * A String extra holding a url that specifies the download location of the device admin
431 * package. When not provided it is assumed that the device admin package is already installed.
432 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000433 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
434 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100435 */
436 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100437 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100438
439 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400440 * An int extra holding a minimum required version code for the device admin package. If the
441 * device admin is already installed on the device, it will only be re-downloaded from
442 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
443 * installed package is less than this version code.
444 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400445 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400446 * provisioning via an NFC bump.
447 */
448 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
449 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
450
451 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100452 * A String extra holding a http cookie header which should be used in the http request to the
453 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
454 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000455 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
456 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100457 */
458 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100459 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100460
461 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100462 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
463 * the file at download location specified in
464 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100465 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100466 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100467 * present. The provided checksum should match the checksum of the file at the download
468 * location. If the checksum doesn't match an error will be shown to the user and the user will
469 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100470 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000471 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
472 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100473 *
474 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
475 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700476 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100477 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100478 */
479 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100480 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100481
482 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100483 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100484 * android package archive at the download location specified in {@link
485 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
486 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100487 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100488 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
489 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
490 *
491 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100492 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100493 * the download location. If the checksum does not match an error will be shown to the user and
494 * the user will be asked to factory reset the device.
495 *
496 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
497 * provisioning via an NFC bump.
498 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100499 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
500 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100501
502 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000503 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
504 * has completed successfully.
505 *
506 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700507 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000508 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800509 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000510 * corresponds to the account requested to be migrated at provisioning time, if any.
511 */
512 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
513 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
514 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
515
516 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400517 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500518 * provisioning.
519 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400520 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100521 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500522 */
523 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
524 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
525
526 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400527 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100528 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400529 * <p>During device owner provisioning a device admin app is set as the owner of the device.
530 * A device owner has full control over the device. The device owner can not be modified by the
531 * user and the only way of resetting the device is if the device owner app calls a factory
532 * reset.
533 *
534 * <p> A typical use case would be a device that is owned by a company, but used by either an
535 * employee or client.
536 *
537 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100538 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000539 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100540 * contains the following properties:
541 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400542 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
543 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100544 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400545 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100546 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
547 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
548 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
549 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
550 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
551 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
552 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
553 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
554 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
555 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100556 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
557 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
558 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100559 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000560 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700561 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400562 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
563 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
564 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400565 */
566 public static final String MIME_TYPE_PROVISIONING_NFC
567 = "application/com.android.managedprovisioning";
568
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100569 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800570 * Activity action: ask the user to add a new device administrator to the system.
571 * The desired policy is the ComponentName of the policy in the
572 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
573 * bring the user through adding the device administrator to the system (or
574 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700575 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800576 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
577 * field to provide the user with additional explanation (in addition
578 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800579 *
580 * <p>If your administrator is already active, this will ordinarily return immediately (without
581 * user intervention). However, if your administrator has been updated and is requesting
582 * additional uses-policy flags, the user will be presented with the new list. New policies
583 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800584 */
585 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
586 public static final String ACTION_ADD_DEVICE_ADMIN
587 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700588
Dianne Hackbornd6847842010-01-12 18:14:19 -0800589 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700590 * @hide
591 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700592 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700593 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700594 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
595 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700596 * to remotely control restrictions on the user.
597 *
Makoto Onuki53de36f2015-11-06 17:08:01 -0800598 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700599 * result of whether or not the user approved the action. If approved, the result will
600 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
601 * as a profile owner.
602 *
603 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
604 * field to provide the user with additional explanation (in addition
605 * to your component's description) about what is being added.
606 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700607 * <p>If there is already a profile owner active or the caller is not a system app, the
608 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700609 */
610 @SystemApi
611 public static final String ACTION_SET_PROFILE_OWNER
612 = "android.app.action.SET_PROFILE_OWNER";
613
614 /**
615 * @hide
616 * Name of the profile owner admin that controls the user.
617 */
618 @SystemApi
619 public static final String EXTRA_PROFILE_OWNER_NAME
620 = "android.app.extra.PROFILE_OWNER_NAME";
621
622 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100623 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700624 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700625 *
Jim Miller284b62e2010-06-08 14:27:42 -0700626 * @hide
627 */
628 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
629 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
630
631 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100632 * Broadcast action: sent when the device owner is set or changed.
633 *
634 * This broadcast is sent only to the primary user.
635 * @see #ACTION_PROVISION_MANAGED_DEVICE
636 */
637 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
638 public static final String ACTION_DEVICE_OWNER_CHANGED
639 = "android.app.action.DEVICE_OWNER_CHANGED";
640
641 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800642 * The ComponentName of the administrator component.
643 *
644 * @see #ACTION_ADD_DEVICE_ADMIN
645 */
646 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700647
Dianne Hackbornd6847842010-01-12 18:14:19 -0800648 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800649 * An optional CharSequence providing additional explanation for why the
650 * admin is being added.
651 *
652 * @see #ACTION_ADD_DEVICE_ADMIN
653 */
654 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700655
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800656 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700657 * Activity action: have the user enter a new password. This activity should
658 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
659 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
660 * enter a new password that meets the current requirements. You can use
661 * {@link #isActivePasswordSufficient()} to determine whether you need to
662 * have the user select a new password in order to meet the current
663 * constraints. Upon being resumed from this activity, you can check the new
664 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800665 */
666 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
667 public static final String ACTION_SET_NEW_PASSWORD
668 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700669
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000670 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000671 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
672 * the parent profile to access intents sent from the managed profile.
673 * That is, when an app in the managed profile calls
674 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
675 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000676 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100677 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000678
679 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000680 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
681 * the managed profile to access intents sent from the parent profile.
682 * That is, when an app in the parent profile calls
683 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
684 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000685 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100686 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700687
Dianne Hackbornd6847842010-01-12 18:14:19 -0800688 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100689 * Broadcast action: notify that a new local system update policy has been set by the device
690 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000691 */
692 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100693 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
694 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000695
Amith Yamasanid49489b2015-04-28 14:00:26 -0700696 /**
697 * Permission policy to prompt user for new permission requests for runtime permissions.
698 * Already granted or denied permissions are not affected by this.
699 */
700 public static final int PERMISSION_POLICY_PROMPT = 0;
701
702 /**
703 * Permission policy to always grant new permission requests for runtime permissions.
704 * Already granted or denied permissions are not affected by this.
705 */
706 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
707
708 /**
709 * Permission policy to always deny new permission requests for runtime permissions.
710 * Already granted or denied permissions are not affected by this.
711 */
712 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
713
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700714 /**
715 * Runtime permission state: The user can manage the permission
716 * through the UI.
717 */
718 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
719
720 /**
721 * Runtime permission state: The permission is granted to the app
722 * and the user cannot manage the permission through the UI.
723 */
724 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
725
726 /**
727 * Runtime permission state: The permission is denied to the app
728 * and the user cannot manage the permission through the UI.
729 */
730 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000731
732 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800733 * Return true if the given administrator component is currently
734 * active (enabled) in the system.
735 */
Robin Lee25e26452015-06-02 09:56:29 -0700736 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700737 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100738 }
739
740 /**
741 * @see #isAdminActive(ComponentName)
742 * @hide
743 */
Robin Lee25e26452015-06-02 09:56:29 -0700744 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800745 if (mService != null) {
746 try {
Robin Lee25e26452015-06-02 09:56:29 -0700747 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800748 } catch (RemoteException e) {
749 Log.w(TAG, "Failed talking with device policy service", e);
750 }
751 }
752 return false;
753 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800754 /**
755 * Return true if the given administrator component is currently being removed
756 * for the user.
757 * @hide
758 */
Robin Lee25e26452015-06-02 09:56:29 -0700759 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800760 if (mService != null) {
761 try {
Robin Lee25e26452015-06-02 09:56:29 -0700762 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800763 } catch (RemoteException e) {
764 Log.w(TAG, "Failed talking with device policy service", e);
765 }
766 }
767 return false;
768 }
769
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700770
Dianne Hackbornd6847842010-01-12 18:14:19 -0800771 /**
Robin Lee25e26452015-06-02 09:56:29 -0700772 * Return a list of all currently active device administrators' component
773 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800774 * returned.
775 */
776 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700777 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100778 }
779
780 /**
781 * @see #getActiveAdmins()
782 * @hide
783 */
784 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800785 if (mService != null) {
786 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100787 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800788 } catch (RemoteException e) {
789 Log.w(TAG, "Failed talking with device policy service", e);
790 }
791 }
792 return null;
793 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700794
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800795 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700796 * Used by package administration code to determine if a package can be stopped
797 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800798 * @hide
799 */
800 public boolean packageHasActiveAdmins(String packageName) {
801 if (mService != null) {
802 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700803 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800804 } catch (RemoteException e) {
805 Log.w(TAG, "Failed talking with device policy service", e);
806 }
807 }
808 return false;
809 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700810
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800811 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800812 * Remove a current administration component. This can only be called
813 * by the application that owns the administration component; if you
814 * try to remove someone else's component, a security exception will be
815 * thrown.
816 */
Robin Lee25e26452015-06-02 09:56:29 -0700817 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800818 if (mService != null) {
819 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700820 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800821 } catch (RemoteException e) {
822 Log.w(TAG, "Failed talking with device policy service", e);
823 }
824 }
825 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700826
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800828 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700829 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800830 * but requires additional policies after an upgrade.
831 *
832 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
833 * an active administrator, or an exception will be thrown.
834 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
835 */
Robin Lee25e26452015-06-02 09:56:29 -0700836 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800837 if (mService != null) {
838 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700839 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800840 } catch (RemoteException e) {
841 Log.w(TAG, "Failed talking with device policy service", e);
842 }
843 }
844 return false;
845 }
846
847 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800848 * Constant for {@link #setPasswordQuality}: the policy has no requirements
849 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800850 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800851 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800852 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700853
Dianne Hackbornd6847842010-01-12 18:14:19 -0800854 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700855 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
856 * recognition technology. This implies technologies that can recognize the identity of
857 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
858 * Note that quality constants are ordered so that higher values are more restrictive.
859 */
860 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
861
862 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800863 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100864 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800865 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800866 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800867 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700868
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800869 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800870 * Constant for {@link #setPasswordQuality}: the user must have entered a
871 * password containing at least numeric characters. Note that quality
872 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800873 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800874 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700875
Dianne Hackbornd6847842010-01-12 18:14:19 -0800876 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800877 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800878 * password containing at least numeric characters with no repeating (4444)
879 * or ordered (1234, 4321, 2468) sequences. Note that quality
880 * constants are ordered so that higher values are more restrictive.
881 */
882 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
883
884 /**
885 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700886 * password containing at least alphabetic (or other symbol) characters.
887 * Note that quality constants are ordered so that higher values are more
888 * restrictive.
889 */
890 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700891
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700892 /**
893 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800894 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700895 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800896 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800897 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700898 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700899
Dianne Hackbornd6847842010-01-12 18:14:19 -0800900 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700901 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700902 * password containing at least a letter, a numerical digit and a special
903 * symbol, by default. With this password quality, passwords can be
904 * restricted to contain various sets of characters, like at least an
905 * uppercase letter, etc. These are specified using various methods,
906 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
907 * that quality constants are ordered so that higher values are more
908 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700909 */
910 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
911
912 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800913 * Called by an application that is administering the device to set the
914 * password restrictions it is imposing. After setting this, the user
915 * will not be able to enter a new password that is not at least as
916 * restrictive as what has been set. Note that the current password
917 * will remain until the user has set a new one, so the change does not
918 * take place immediately. To prompt the user for a new password, use
919 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700920 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800921 * <p>Quality constants are ordered so that higher values are more restrictive;
922 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800923 * the user's preference, and any other considerations) is the one that
924 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700925 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800926 * <p>The calling device admin must have requested
927 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
928 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700929 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800931 * @param quality The new desired quality. One of
932 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800933 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
934 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
935 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800936 */
Robin Lee25e26452015-06-02 09:56:29 -0700937 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800938 if (mService != null) {
939 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800940 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800941 } catch (RemoteException e) {
942 Log.w(TAG, "Failed talking with device policy service", e);
943 }
944 }
945 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700946
Dianne Hackbornd6847842010-01-12 18:14:19 -0800947 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100948 * Retrieve the current minimum password quality for all admins of this user
949 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -0700950 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -0800951 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800952 */
Robin Lee25e26452015-06-02 09:56:29 -0700953 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700954 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700955 }
956
957 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -0700958 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800959 if (mService != null) {
960 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700961 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800962 } catch (RemoteException e) {
963 Log.w(TAG, "Failed talking with device policy service", e);
964 }
965 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800966 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800967 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700968
Dianne Hackbornd6847842010-01-12 18:14:19 -0800969 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800970 * Called by an application that is administering the device to set the
971 * minimum allowed password length. After setting this, the user
972 * will not be able to enter a new password that is not at least as
973 * restrictive as what has been set. Note that the current password
974 * will remain until the user has set a new one, so the change does not
975 * take place immediately. To prompt the user for a new password, use
976 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
977 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800978 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
979 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
980 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700981 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800982 * <p>The calling device admin must have requested
983 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
984 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700985 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800987 * @param length The new desired minimum password length. A value of 0
988 * means there is no restriction.
989 */
Robin Lee25e26452015-06-02 09:56:29 -0700990 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800991 if (mService != null) {
992 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800993 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800994 } catch (RemoteException e) {
995 Log.w(TAG, "Failed talking with device policy service", e);
996 }
997 }
998 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700999
Dianne Hackbornd6847842010-01-12 18:14:19 -08001000 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001001 * Retrieve the current minimum password length for all admins of this
1002 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001003 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001004 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001005 */
Robin Lee25e26452015-06-02 09:56:29 -07001006 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001007 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001008 }
1009
1010 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001011 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001012 if (mService != null) {
1013 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001014 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001015 } catch (RemoteException e) {
1016 Log.w(TAG, "Failed talking with device policy service", e);
1017 }
1018 }
1019 return 0;
1020 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001021
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001022 /**
1023 * Called by an application that is administering the device to set the
1024 * minimum number of upper case letters required in the password. After
1025 * setting this, the user will not be able to enter a new password that is
1026 * not at least as restrictive as what has been set. Note that the current
1027 * password will remain until the user has set a new one, so the change does
1028 * not take place immediately. To prompt the user for a new password, use
1029 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1030 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001031 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1032 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001033 * <p>
1034 * The calling device admin must have requested
1035 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1036 * this method; if it has not, a security exception will be thrown.
1037 *
1038 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1039 * with.
1040 * @param length The new desired minimum number of upper case letters
1041 * required in the password. A value of 0 means there is no
1042 * restriction.
1043 */
Robin Lee25e26452015-06-02 09:56:29 -07001044 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001045 if (mService != null) {
1046 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001047 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001048 } catch (RemoteException e) {
1049 Log.w(TAG, "Failed talking with device policy service", e);
1050 }
1051 }
1052 }
1053
1054 /**
1055 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001056 * password for all admins of this user and its profiles or a particular one.
1057 * This is the same value as set by
1058 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001059 * and only applies when the password quality is
1060 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001061 *
Robin Lee25e26452015-06-02 09:56:29 -07001062 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001063 * aggregate all admins.
1064 * @return The minimum number of upper case letters required in the
1065 * password.
1066 */
Robin Lee25e26452015-06-02 09:56:29 -07001067 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001068 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001069 }
1070
1071 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001072 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001073 if (mService != null) {
1074 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001075 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001076 } catch (RemoteException e) {
1077 Log.w(TAG, "Failed talking with device policy service", e);
1078 }
1079 }
1080 return 0;
1081 }
1082
1083 /**
1084 * Called by an application that is administering the device to set the
1085 * minimum number of lower case letters required in the password. After
1086 * setting this, the user will not be able to enter a new password that is
1087 * not at least as restrictive as what has been set. Note that the current
1088 * password will remain until the user has set a new one, so the change does
1089 * not take place immediately. To prompt the user for a new password, use
1090 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1091 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001092 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1093 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001094 * <p>
1095 * The calling device admin must have requested
1096 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1097 * this method; if it has not, a security exception will be thrown.
1098 *
1099 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1100 * with.
1101 * @param length The new desired minimum number of lower case letters
1102 * required in the password. A value of 0 means there is no
1103 * restriction.
1104 */
Robin Lee25e26452015-06-02 09:56:29 -07001105 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001106 if (mService != null) {
1107 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001108 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001109 } catch (RemoteException e) {
1110 Log.w(TAG, "Failed talking with device policy service", e);
1111 }
1112 }
1113 }
1114
1115 /**
1116 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001117 * password for all admins of this user and its profiles or a particular one.
1118 * This is the same value as set by
1119 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001120 * and only applies when the password quality is
1121 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001122 *
Robin Lee25e26452015-06-02 09:56:29 -07001123 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001124 * aggregate all admins.
1125 * @return The minimum number of lower case letters required in the
1126 * password.
1127 */
Robin Lee25e26452015-06-02 09:56:29 -07001128 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001129 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001130 }
1131
1132 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001133 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001134 if (mService != null) {
1135 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001136 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001137 } catch (RemoteException e) {
1138 Log.w(TAG, "Failed talking with device policy service", e);
1139 }
1140 }
1141 return 0;
1142 }
1143
1144 /**
1145 * Called by an application that is administering the device to set the
1146 * minimum number of letters required in the password. After setting this,
1147 * the user will not be able to enter a new password that is not at least as
1148 * restrictive as what has been set. Note that the current password will
1149 * remain until the user has set a new one, so the change does not take
1150 * place immediately. To prompt the user for a new password, use
1151 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1152 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001153 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1154 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001155 * <p>
1156 * The calling device admin must have requested
1157 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1158 * this method; if it has not, a security exception will be thrown.
1159 *
1160 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1161 * with.
1162 * @param length The new desired minimum number of letters required in the
1163 * password. A value of 0 means there is no restriction.
1164 */
Robin Lee25e26452015-06-02 09:56:29 -07001165 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001166 if (mService != null) {
1167 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001168 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001169 } catch (RemoteException e) {
1170 Log.w(TAG, "Failed talking with device policy service", e);
1171 }
1172 }
1173 }
1174
1175 /**
1176 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001177 * admins or a particular one. This is the same value as
1178 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1179 * and only applies when the password quality is
1180 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001181 *
Robin Lee25e26452015-06-02 09:56:29 -07001182 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001183 * aggregate all admins.
1184 * @return The minimum number of letters required in the password.
1185 */
Robin Lee25e26452015-06-02 09:56:29 -07001186 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001187 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001188 }
1189
1190 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001191 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001192 if (mService != null) {
1193 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001194 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001195 } catch (RemoteException e) {
1196 Log.w(TAG, "Failed talking with device policy service", e);
1197 }
1198 }
1199 return 0;
1200 }
1201
1202 /**
1203 * Called by an application that is administering the device to set the
1204 * minimum number of numerical digits required in the password. After
1205 * setting this, the user will not be able to enter a new password that is
1206 * not at least as restrictive as what has been set. Note that the current
1207 * password will remain until the user has set a new one, so the change does
1208 * not take place immediately. To prompt the user for a new password, use
1209 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1210 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001211 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1212 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001213 * <p>
1214 * The calling device admin must have requested
1215 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1216 * this method; if it has not, a security exception will be thrown.
1217 *
1218 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1219 * with.
1220 * @param length The new desired minimum number of numerical digits required
1221 * in the password. A value of 0 means there is no restriction.
1222 */
Robin Lee25e26452015-06-02 09:56:29 -07001223 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001224 if (mService != null) {
1225 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001226 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001227 } catch (RemoteException e) {
1228 Log.w(TAG, "Failed talking with device policy service", e);
1229 }
1230 }
1231 }
1232
1233 /**
1234 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001235 * for all admins of this user and its profiles or a particular one.
1236 * This is the same value as set by
1237 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001238 * and only applies when the password quality is
1239 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001240 *
Robin Lee25e26452015-06-02 09:56:29 -07001241 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001242 * aggregate all admins.
1243 * @return The minimum number of numerical digits required in the password.
1244 */
Robin Lee25e26452015-06-02 09:56:29 -07001245 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001246 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001247 }
1248
1249 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001250 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001251 if (mService != null) {
1252 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001253 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001254 } catch (RemoteException e) {
1255 Log.w(TAG, "Failed talking with device policy service", e);
1256 }
1257 }
1258 return 0;
1259 }
1260
1261 /**
1262 * Called by an application that is administering the device to set the
1263 * minimum number of symbols required in the password. After setting this,
1264 * the user will not be able to enter a new password that is not at least as
1265 * restrictive as what has been set. Note that the current password will
1266 * remain until the user has set a new one, so the change does not take
1267 * place immediately. To prompt the user for a new password, use
1268 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1269 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001270 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1271 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001272 * <p>
1273 * The calling device admin must have requested
1274 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1275 * this method; if it has not, a security exception will be thrown.
1276 *
1277 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1278 * with.
1279 * @param length The new desired minimum number of symbols required in the
1280 * password. A value of 0 means there is no restriction.
1281 */
Robin Lee25e26452015-06-02 09:56:29 -07001282 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001283 if (mService != null) {
1284 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001285 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001286 } catch (RemoteException e) {
1287 Log.w(TAG, "Failed talking with device policy service", e);
1288 }
1289 }
1290 }
1291
1292 /**
1293 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001294 * admins or a particular one. This is the same value as
1295 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1296 * and only applies when the password quality is
1297 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001298 *
Robin Lee25e26452015-06-02 09:56:29 -07001299 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001300 * aggregate all admins.
1301 * @return The minimum number of symbols required in the password.
1302 */
Robin Lee25e26452015-06-02 09:56:29 -07001303 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001304 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001305 }
1306
1307 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001308 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001309 if (mService != null) {
1310 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001311 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001312 } catch (RemoteException e) {
1313 Log.w(TAG, "Failed talking with device policy service", e);
1314 }
1315 }
1316 return 0;
1317 }
1318
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001319 /**
1320 * Called by an application that is administering the device to set the
1321 * minimum number of non-letter characters (numerical digits or symbols)
1322 * required in the password. After setting this, the user will not be able
1323 * to enter a new password that is not at least as restrictive as what has
1324 * been set. Note that the current password will remain until the user has
1325 * set a new one, so the change does not take place immediately. To prompt
1326 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1327 * setting this value. This constraint is only imposed if the administrator
1328 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1329 * {@link #setPasswordQuality}. The default value is 0.
1330 * <p>
1331 * The calling device admin must have requested
1332 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1333 * this method; if it has not, a security exception will be thrown.
1334 *
1335 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1336 * with.
1337 * @param length The new desired minimum number of letters required in the
1338 * password. A value of 0 means there is no restriction.
1339 */
Robin Lee25e26452015-06-02 09:56:29 -07001340 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001341 if (mService != null) {
1342 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001343 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001344 } catch (RemoteException e) {
1345 Log.w(TAG, "Failed talking with device policy service", e);
1346 }
1347 }
1348 }
1349
1350 /**
1351 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001352 * password for all admins of this user and its profiles or a particular one.
1353 * This is the same value as set by
1354 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001355 * and only applies when the password quality is
1356 * {@link #PASSWORD_QUALITY_COMPLEX}.
1357 *
Robin Lee25e26452015-06-02 09:56:29 -07001358 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001359 * aggregate all admins.
1360 * @return The minimum number of letters required in the password.
1361 */
Robin Lee25e26452015-06-02 09:56:29 -07001362 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001363 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001364 }
1365
1366 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001367 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001368 if (mService != null) {
1369 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001370 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001371 } catch (RemoteException e) {
1372 Log.w(TAG, "Failed talking with device policy service", e);
1373 }
1374 }
1375 return 0;
1376 }
1377
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001378 /**
1379 * Called by an application that is administering the device to set the length
1380 * of the password history. After setting this, the user will not be able to
1381 * enter a new password that is the same as any password in the history. Note
1382 * that the current password will remain until the user has set a new one, so
1383 * the change does not take place immediately. To prompt the user for a new
1384 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1385 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001386 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1387 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1388 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001389 *
1390 * <p>
1391 * The calling device admin must have requested
1392 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1393 * method; if it has not, a security exception will be thrown.
1394 *
1395 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1396 * with.
1397 * @param length The new desired length of password history. A value of 0
1398 * means there is no restriction.
1399 */
Robin Lee25e26452015-06-02 09:56:29 -07001400 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001401 if (mService != null) {
1402 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001403 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001404 } catch (RemoteException e) {
1405 Log.w(TAG, "Failed talking with device policy service", e);
1406 }
1407 }
1408 }
1409
1410 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001411 * Called by a device admin to set the password expiration timeout. Calling this method
1412 * will restart the countdown for password expiration for the given admin, as will changing
1413 * the device password (for all admins).
1414 *
1415 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1416 * For example, to have the password expire 5 days from now, timeout would be
1417 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1418 *
1419 * <p>To disable password expiration, a value of 0 may be used for timeout.
1420 *
Jim Millera4e28d12010-11-08 16:15:47 -08001421 * <p>The calling device admin must have requested
1422 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1423 * method; if it has not, a security exception will be thrown.
1424 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001425 * <p> Note that setting the password will automatically reset the expiration time for all
1426 * active admins. Active admins do not need to explicitly call this method in that case.
1427 *
Jim Millera4e28d12010-11-08 16:15:47 -08001428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1429 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1430 * means there is no restriction (unlimited).
1431 */
Robin Lee25e26452015-06-02 09:56:29 -07001432 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001433 if (mService != null) {
1434 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001435 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001436 } catch (RemoteException e) {
1437 Log.w(TAG, "Failed talking with device policy service", e);
1438 }
1439 }
1440 }
1441
1442 /**
Jim Miller6b857682011-02-16 16:27:41 -08001443 * Get the password expiration timeout for the given admin. The expiration timeout is the
1444 * recurring expiration timeout provided in the call to
1445 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001446 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001447 *
Robin Lee25e26452015-06-02 09:56:29 -07001448 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001449 * @return The timeout for the given admin or the minimum of all timeouts
1450 */
Robin Lee25e26452015-06-02 09:56:29 -07001451 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001452 if (mService != null) {
1453 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001454 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001455 } catch (RemoteException e) {
1456 Log.w(TAG, "Failed talking with device policy service", e);
1457 }
1458 }
1459 return 0;
1460 }
1461
1462 /**
1463 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001464 * all admins of this user and its profiles if admin is null. If the password is
1465 * expired, this will return the time since the password expired as a negative number.
1466 * If admin is null, then a composite of all expiration timeouts is returned
1467 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001468 *
Robin Lee25e26452015-06-02 09:56:29 -07001469 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001470 * @return The password expiration time, in ms.
1471 */
Robin Lee25e26452015-06-02 09:56:29 -07001472 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001473 if (mService != null) {
1474 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001475 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001476 } catch (RemoteException e) {
1477 Log.w(TAG, "Failed talking with device policy service", e);
1478 }
1479 }
1480 return 0;
1481 }
1482
1483 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001484 * Retrieve the current password history length for all admins of this
1485 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001486 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001487 * all admins.
1488 * @return The length of the password history
1489 */
Robin Lee25e26452015-06-02 09:56:29 -07001490 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001491 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001492 }
1493
1494 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001495 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001496 if (mService != null) {
1497 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001498 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001499 } catch (RemoteException e) {
1500 Log.w(TAG, "Failed talking with device policy service", e);
1501 }
1502 }
1503 return 0;
1504 }
1505
Dianne Hackbornd6847842010-01-12 18:14:19 -08001506 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001507 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001508 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001509 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001510 * @return Returns the maximum length that the user can enter.
1511 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001512 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001513 // Kind-of arbitrary.
1514 return 16;
1515 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001516
Dianne Hackborn254cb442010-01-27 19:23:59 -08001517 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001518 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001519 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001520 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001521 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001522 * <p>The calling device admin must have requested
1523 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1524 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001525 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001526 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001527 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001528 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001529 if (mService != null) {
1530 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001531 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001532 } catch (RemoteException e) {
1533 Log.w(TAG, "Failed talking with device policy service", e);
1534 }
1535 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001536 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001537 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001538
Dianne Hackbornd6847842010-01-12 18:14:19 -08001539 /**
1540 * Retrieve the number of times the user has failed at entering a
1541 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001542 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001543 * <p>The calling device admin must have requested
1544 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1545 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001546 */
1547 public int getCurrentFailedPasswordAttempts() {
1548 if (mService != null) {
1549 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001550 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001551 } catch (RemoteException e) {
1552 Log.w(TAG, "Failed talking with device policy service", e);
1553 }
1554 }
1555 return -1;
1556 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001557
1558 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001559 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001560 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001561 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001562 * @hide
1563 */
1564 public boolean getDoNotAskCredentialsOnBoot() {
1565 if (mService != null) {
1566 try {
1567 return mService.getDoNotAskCredentialsOnBoot();
1568 } catch (RemoteException e) {
1569 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1570 }
1571 }
1572 return false;
1573 }
1574
1575 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001576 * Setting this to a value greater than zero enables a built-in policy
1577 * that will perform a device wipe after too many incorrect
1578 * device-unlock passwords have been entered. This built-in policy combines
1579 * watching for failed passwords and wiping the device, and requires
1580 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001581 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001582 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001583 * <p>To implement any other policy (e.g. wiping data for a particular
1584 * application only, erasing or revoking credentials, or reporting the
1585 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001586 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001587 * instead. Do not use this API, because if the maximum count is reached,
1588 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001589 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001590 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001591 * @param num The number of failed password attempts at which point the
1592 * device will wipe its data.
1593 */
Robin Lee25e26452015-06-02 09:56:29 -07001594 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001595 if (mService != null) {
1596 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001597 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001598 } catch (RemoteException e) {
1599 Log.w(TAG, "Failed talking with device policy service", e);
1600 }
1601 }
1602 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001603
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001604 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001605 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001606 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001607 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001608 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001609 * all admins.
1610 */
Robin Lee25e26452015-06-02 09:56:29 -07001611 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001612 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001613 }
1614
1615 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001616 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001617 if (mService != null) {
1618 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001619 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001620 } catch (RemoteException e) {
1621 Log.w(TAG, "Failed talking with device policy service", e);
1622 }
1623 }
1624 return 0;
1625 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001626
Dianne Hackborn254cb442010-01-27 19:23:59 -08001627 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001628 * Returns the profile with the smallest maximum failed passwords for wipe,
1629 * for the given user. So for primary user, it might return the primary or
1630 * a managed profile. For a secondary user, it would be the same as the
1631 * user passed in.
1632 * @hide Used only by Keyguard
1633 */
1634 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1635 if (mService != null) {
1636 try {
1637 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1638 } catch (RemoteException e) {
1639 Log.w(TAG, "Failed talking with device policy service", e);
1640 }
1641 }
1642 return UserHandle.USER_NULL;
1643 }
1644
1645 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001646 * Flag for {@link #resetPassword}: don't allow other admins to change
1647 * the password again until the user has entered it.
1648 */
1649 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001650
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001651 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001652 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1653 * If the flag is set, the device can be booted without asking for user password.
1654 * The absence of this flag does not change the current boot requirements. This flag
1655 * can be set by the device owner only. If the app is not the device owner, the flag
1656 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1657 * device to factory defaults.
1658 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001659 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001660
1661 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001662 * Force a new device unlock password (the password needed to access the
1663 * entire device, not for individual accounts) on the user. This takes
1664 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001665 * The given password must be sufficient for the
1666 * current password quality and length constraints as returned by
1667 * {@link #getPasswordQuality(ComponentName)} and
1668 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1669 * these constraints, then it will be rejected and false returned. Note
1670 * that the password may be a stronger quality (containing alphanumeric
1671 * characters when the requested quality is only numeric), in which case
1672 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001673 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001674 * <p>Calling with a null or empty password will clear any existing PIN,
1675 * pattern or password if the current password constraints allow it.
1676 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001677 * <p>The calling device admin must have requested
1678 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1679 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001680 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001681 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001682 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001683 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001684 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001685 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001686 * @return Returns true if the password was applied, or false if it is
1687 * not acceptable for the current constraints.
1688 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001689 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001690 if (mService != null) {
1691 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001692 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001693 } catch (RemoteException e) {
1694 Log.w(TAG, "Failed talking with device policy service", e);
1695 }
1696 }
1697 return false;
1698 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001699
Dianne Hackbornd6847842010-01-12 18:14:19 -08001700 /**
1701 * Called by an application that is administering the device to set the
1702 * maximum time for user activity until the device will lock. This limits
1703 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001704 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001705 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001706 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001707 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001708 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001709 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001710 * @param timeMs The new desired maximum time to lock in milliseconds.
1711 * A value of 0 means there is no restriction.
1712 */
Robin Lee25e26452015-06-02 09:56:29 -07001713 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001714 if (mService != null) {
1715 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001716 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001717 } catch (RemoteException e) {
1718 Log.w(TAG, "Failed talking with device policy service", e);
1719 }
1720 }
1721 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001722
Dianne Hackbornd6847842010-01-12 18:14:19 -08001723 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001724 * Retrieve the current maximum time to unlock for all admins of this user
1725 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001726 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001727 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001728 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001729 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001730 */
Robin Lee25e26452015-06-02 09:56:29 -07001731 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001732 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001733 }
1734
1735 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001736 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001737 if (mService != null) {
1738 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001739 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001740 } catch (RemoteException e) {
1741 Log.w(TAG, "Failed talking with device policy service", e);
1742 }
1743 }
1744 return 0;
1745 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001746
Dianne Hackbornd6847842010-01-12 18:14:19 -08001747 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001748 * Make the device lock immediately, as if the lock screen timeout has
1749 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001750 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001751 * <p>The calling device admin must have requested
1752 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1753 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001754 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001755 public void lockNow() {
1756 if (mService != null) {
1757 try {
1758 mService.lockNow();
1759 } catch (RemoteException e) {
1760 Log.w(TAG, "Failed talking with device policy service", e);
1761 }
1762 }
1763 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001764
Dianne Hackbornd6847842010-01-12 18:14:19 -08001765 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001766 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001767 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001768 */
1769 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1770
1771 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001772 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1773 * data.
1774 *
Paul Crowley2934b262014-12-02 11:21:13 +00001775 * <p>This flag may only be set by device owner admins; if it is set by
1776 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001777 */
1778 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1779
1780 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001781 * Ask the user data be wiped. Wiping the primary user will cause the
1782 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001783 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001784 * <p>The calling device admin must have requested
1785 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1786 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001787 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001788 * @param flags Bit mask of additional options: currently supported flags
1789 * are {@link #WIPE_EXTERNAL_STORAGE} and
1790 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001791 */
1792 public void wipeData(int flags) {
1793 if (mService != null) {
1794 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001795 mService.wipeData(flags, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001796 } catch (RemoteException e) {
1797 Log.w(TAG, "Failed talking with device policy service", e);
1798 }
1799 }
1800 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001801
Dianne Hackbornd6847842010-01-12 18:14:19 -08001802 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001803 * Called by an application that is administering the device to set the
1804 * global proxy and exclusion list.
1805 * <p>
1806 * The calling device admin must have requested
1807 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1808 * this method; if it has not, a security exception will be thrown.
1809 * Only the first device admin can set the proxy. If a second admin attempts
1810 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001811 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001812 * be returned.
1813 * The method can be called repeatedly by the device admin alrady setting the
1814 * proxy to update the proxy and exclusion list.
1815 *
Robin Lee25e26452015-06-02 09:56:29 -07001816 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001817 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1818 * Pass Proxy.NO_PROXY to reset the proxy.
1819 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001820 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1821 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001822 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001823 */
Robin Lee25e26452015-06-02 09:56:29 -07001824 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001825 List<String> exclusionList ) {
1826 if (proxySpec == null) {
1827 throw new NullPointerException();
1828 }
1829 if (mService != null) {
1830 try {
1831 String hostSpec;
1832 String exclSpec;
1833 if (proxySpec.equals(Proxy.NO_PROXY)) {
1834 hostSpec = null;
1835 exclSpec = null;
1836 } else {
1837 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1838 throw new IllegalArgumentException();
1839 }
1840 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1841 String hostName = sa.getHostName();
1842 int port = sa.getPort();
1843 StringBuilder hostBuilder = new StringBuilder();
1844 hostSpec = hostBuilder.append(hostName)
1845 .append(":").append(Integer.toString(port)).toString();
1846 if (exclusionList == null) {
1847 exclSpec = "";
1848 } else {
1849 StringBuilder listBuilder = new StringBuilder();
1850 boolean firstDomain = true;
1851 for (String exclDomain : exclusionList) {
1852 if (!firstDomain) {
1853 listBuilder = listBuilder.append(",");
1854 } else {
1855 firstDomain = false;
1856 }
1857 listBuilder = listBuilder.append(exclDomain.trim());
1858 }
1859 exclSpec = listBuilder.toString();
1860 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001861 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1862 != android.net.Proxy.PROXY_VALID)
1863 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001864 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001865 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001866 } catch (RemoteException e) {
1867 Log.w(TAG, "Failed talking with device policy service", e);
1868 }
1869 }
1870 return null;
1871 }
1872
1873 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001874 * Set a network-independent global HTTP proxy. This is not normally what you want
1875 * for typical HTTP proxies - they are generally network dependent. However if you're
1876 * doing something unusual like general internal filtering this may be useful. On
1877 * a private network where the proxy is not accessible, you may break HTTP using this.
1878 *
1879 * <p>This method requires the caller to be the device owner.
1880 *
1881 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1882 * @see ProxyInfo
1883 *
1884 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1885 * with.
1886 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1887 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1888 */
Robin Lee25e26452015-06-02 09:56:29 -07001889 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1890 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001891 if (mService != null) {
1892 try {
1893 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1894 } catch (RemoteException e) {
1895 Log.w(TAG, "Failed talking with device policy service", e);
1896 }
1897 }
1898 }
1899
1900 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001901 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001902 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1903 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001904 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001905 */
1906 public ComponentName getGlobalProxyAdmin() {
1907 if (mService != null) {
1908 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001909 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001910 } catch (RemoteException e) {
1911 Log.w(TAG, "Failed talking with device policy service", e);
1912 }
1913 }
1914 return null;
1915 }
1916
1917 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001918 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001919 * indicating that encryption is not supported.
1920 */
1921 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1922
1923 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001924 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001925 * indicating that encryption is supported, but is not currently active.
1926 */
1927 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1928
1929 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001930 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001931 * indicating that encryption is not currently active, but is currently
1932 * being activated. This is only reported by devices that support
1933 * encryption of data and only when the storage is currently
1934 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1935 * to become encrypted will never return this value.
1936 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001937 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001938
1939 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001940 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001941 * indicating that encryption is active.
1942 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001943 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001944
1945 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001946 * Result code for {@link #getStorageEncryptionStatus}:
1947 * indicating that encryption is active, but an encryption key has not
1948 * been set by the user.
1949 */
1950 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1951
1952 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001953 * Activity action: begin the process of encrypting data on the device. This activity should
1954 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1955 * After resuming from this activity, use {@link #getStorageEncryption}
1956 * to check encryption status. However, on some devices this activity may never return, as
1957 * it may trigger a reboot and in some cases a complete data wipe of the device.
1958 */
1959 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1960 public static final String ACTION_START_ENCRYPTION
1961 = "android.app.action.START_ENCRYPTION";
1962
1963 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001964 * Widgets are enabled in keyguard
1965 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001966 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001967
1968 /**
Jim Miller50e62182014-04-23 17:25:00 -07001969 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001970 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001971 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1972
1973 /**
1974 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1975 */
1976 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1977
1978 /**
Jim Miller50e62182014-04-23 17:25:00 -07001979 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1980 */
1981 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1982
1983 /**
1984 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1985 */
1986 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1987
1988 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001989 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001990 * (e.g. PIN/Pattern/Password).
1991 */
1992 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1993
1994 /**
Jim Miller06e34502014-07-17 14:46:05 -07001995 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1996 */
1997 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1998
1999 /**
Jim Miller35207742012-11-02 15:33:20 -07002000 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002001 */
2002 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002003
2004 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002005 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002006 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002007 *
2008 * <p>When multiple device administrators attempt to control device
2009 * encryption, the most secure, supported setting will always be
2010 * used. If any device administrator requests device encryption,
2011 * it will be enabled; Conversely, if a device administrator
2012 * attempts to disable device encryption while another
2013 * device administrator has enabled it, the call to disable will
2014 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2015 *
2016 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002017 * written to other storage areas may or may not be encrypted, and this policy does not require
2018 * or control the encryption of any other storage areas.
2019 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2020 * {@code true}, then the directory returned by
2021 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2022 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002023 *
2024 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2025 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2026 * the encryption key may not be fully secured. For maximum security, the administrator should
2027 * also require (and check for) a pattern, PIN, or password.
2028 *
2029 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2030 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002031 * @return the new request status (for all active admins) - will be one of
2032 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2033 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2034 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002035 */
Robin Lee25e26452015-06-02 09:56:29 -07002036 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002037 if (mService != null) {
2038 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002039 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002040 } catch (RemoteException e) {
2041 Log.w(TAG, "Failed talking with device policy service", e);
2042 }
2043 }
2044 return ENCRYPTION_STATUS_UNSUPPORTED;
2045 }
2046
2047 /**
2048 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002049 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002050 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2052 * this will return the requested encryption setting as an aggregate of all active
2053 * administrators.
2054 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002055 */
Robin Lee25e26452015-06-02 09:56:29 -07002056 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002057 if (mService != null) {
2058 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002059 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002060 } catch (RemoteException e) {
2061 Log.w(TAG, "Failed talking with device policy service", e);
2062 }
2063 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002064 return false;
2065 }
2066
2067 /**
2068 * Called by an application that is administering the device to
2069 * determine the current encryption status of the device.
2070 *
2071 * Depending on the returned status code, the caller may proceed in different
2072 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2073 * storage system does not support encryption. If the
2074 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2075 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002076 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2077 * storage system has enabled encryption but no password is set so further action
2078 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002079 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2080 *
Robin Lee7e678712014-07-24 16:41:31 +01002081 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002082 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002083 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2084 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002085 */
2086 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002087 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002088 }
2089
2090 /** @hide per-user version */
2091 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002092 if (mService != null) {
2093 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002094 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002095 } catch (RemoteException e) {
2096 Log.w(TAG, "Failed talking with device policy service", e);
2097 }
2098 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002099 return ENCRYPTION_STATUS_UNSUPPORTED;
2100 }
2101
2102 /**
Robin Lee7e678712014-07-24 16:41:31 +01002103 * Installs the given certificate as a user CA.
2104 *
Robin Lee25e26452015-06-02 09:56:29 -07002105 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2106 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002107 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002108 *
2109 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002110 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002111 */
Robin Lee25e26452015-06-02 09:56:29 -07002112 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002113 if (mService != null) {
2114 try {
Robin Lee7e678712014-07-24 16:41:31 +01002115 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002116 } catch (RemoteException e) {
2117 Log.w(TAG, "Failed talking with device policy service", e);
2118 }
2119 }
2120 return false;
2121 }
2122
2123 /**
Robin Lee7e678712014-07-24 16:41:31 +01002124 * Uninstalls the given certificate from trusted user CAs, if present.
2125 *
Robin Lee25e26452015-06-02 09:56:29 -07002126 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2127 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002128 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002129 */
Robin Lee25e26452015-06-02 09:56:29 -07002130 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002131 if (mService != null) {
2132 try {
Robin Lee306fe082014-06-19 14:04:24 +00002133 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002134 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002135 } catch (CertificateException e) {
2136 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002137 } catch (RemoteException e) {
2138 Log.w(TAG, "Failed talking with device policy service", e);
2139 }
2140 }
2141 }
2142
2143 /**
Robin Lee7e678712014-07-24 16:41:31 +01002144 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2145 * If a user has installed any certificates by other means than device policy these will be
2146 * included too.
2147 *
Robin Lee25e26452015-06-02 09:56:29 -07002148 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2149 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002150 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002151 */
Robin Lee25e26452015-06-02 09:56:29 -07002152 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002153 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002154 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002155 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002156 mService.enforceCanManageCaCerts(admin);
2157 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2158 for (String alias : certStore.userAliases()) {
2159 try {
2160 certs.add(certStore.getCertificate(alias).getEncoded());
2161 } catch (CertificateException ce) {
2162 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2163 }
2164 }
2165 } catch (RemoteException re) {
2166 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002167 }
2168 }
2169 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002170 }
2171
2172 /**
Robin Lee7e678712014-07-24 16:41:31 +01002173 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2174 * means other than device policy will also be removed, except for system CA certificates.
2175 *
Robin Lee25e26452015-06-02 09:56:29 -07002176 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2177 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002178 */
Robin Lee25e26452015-06-02 09:56:29 -07002179 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002180 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002181 try {
2182 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2183 .toArray(new String[0]));
2184 } catch (RemoteException re) {
2185 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002186 }
2187 }
2188 }
2189
2190 /**
2191 * Returns whether this certificate is installed as a trusted CA.
2192 *
Robin Lee25e26452015-06-02 09:56:29 -07002193 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2194 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002195 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002196 */
Robin Lee25e26452015-06-02 09:56:29 -07002197 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002198 if (mService != null) {
2199 try {
2200 mService.enforceCanManageCaCerts(admin);
2201 return getCaCertAlias(certBuffer) != null;
2202 } catch (RemoteException re) {
2203 Log.w(TAG, "Failed talking with device policy service", re);
2204 } catch (CertificateException ce) {
2205 Log.w(TAG, "Could not parse certificate", ce);
2206 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002207 }
2208 return false;
2209 }
2210
2211 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002212 * Called by a device or profile owner to install a certificate and private key pair. The
2213 * keypair will be visible to all apps within the profile.
2214 *
Robin Lee25e26452015-06-02 09:56:29 -07002215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2216 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002217 * @param privKey The private key to install.
2218 * @param cert The certificate to install.
2219 * @param alias The private key alias under which to install the certificate. If a certificate
2220 * with that alias already exists, it will be overwritten.
2221 * @return {@code true} if the keys were installed, {@code false} otherwise.
2222 */
Robin Lee25e26452015-06-02 09:56:29 -07002223 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002224 String alias) {
2225 try {
2226 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002227 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2228 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002229 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002230 } catch (RemoteException e) {
2231 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002232 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2233 Log.w(TAG, "Failed to obtain private key material", e);
2234 } catch (CertificateException | IOException e) {
2235 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002236 }
2237 return false;
2238 }
2239
2240 /**
Robin Lee25e26452015-06-02 09:56:29 -07002241 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002242 * doesn't exist.
2243 */
2244 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2245 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2246 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2247 new ByteArrayInputStream(certBuffer));
2248 return new TrustedCertificateStore().getCertificateAlias(cert);
2249 }
2250
2251 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002252 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002253 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002254 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002255 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002256 * <p>
2257 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2258 * it is later cleared by calling this method with a null value or uninstallling the certificate
2259 * installer.
2260 *
Robin Lee25e26452015-06-02 09:56:29 -07002261 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002262 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002263 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002264 */
Robin Lee25e26452015-06-02 09:56:29 -07002265 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2266 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002267 if (mService != null) {
2268 try {
Robin Lee25e26452015-06-02 09:56:29 -07002269 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002270 } catch (RemoteException e) {
2271 Log.w(TAG, "Failed talking with device policy service", e);
2272 }
2273 }
2274 }
2275
2276 /**
2277 * Called by a profile owner or device owner to retrieve the certificate installer for the
2278 * current user. null if none is set.
2279 *
Robin Lee25e26452015-06-02 09:56:29 -07002280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2281 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002282 * if none is set.
2283 */
Robin Lee25e26452015-06-02 09:56:29 -07002284 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002285 if (mService != null) {
2286 try {
Robin Lee25e26452015-06-02 09:56:29 -07002287 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002288 } catch (RemoteException e) {
2289 Log.w(TAG, "Failed talking with device policy service", e);
2290 }
2291 }
2292 return null;
2293 }
2294
2295 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002296 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002297 * on the device, for this user. After setting this, no applications running as this user
2298 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002299 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002300 * <p>If the caller is device owner, then the restriction will be applied to all users.
2301 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002302 * <p>The calling device admin must have requested
2303 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2304 * this method; if it has not, a security exception will be thrown.
2305 *
2306 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2307 * @param disabled Whether or not the camera should be disabled.
2308 */
Robin Lee25e26452015-06-02 09:56:29 -07002309 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002310 if (mService != null) {
2311 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002312 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002313 } catch (RemoteException e) {
2314 Log.w(TAG, "Failed talking with device policy service", e);
2315 }
2316 }
2317 }
2318
2319 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002320 * Determine whether or not the device's cameras have been disabled for this user,
2321 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002322 * @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 -07002323 * have disabled the camera
2324 */
Robin Lee25e26452015-06-02 09:56:29 -07002325 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002326 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002327 }
2328
2329 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002330 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002331 if (mService != null) {
2332 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002333 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002334 } catch (RemoteException e) {
2335 Log.w(TAG, "Failed talking with device policy service", e);
2336 }
2337 }
2338 return false;
2339 }
2340
2341 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002342 * Determine whether or not creating a guest user has been disabled for the device
2343 *
2344 * @hide
2345 */
2346 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2347 // Currently guest users can always be created if multi-user is enabled
2348 // TODO introduce a policy for guest user creation
2349 return false;
2350 }
2351
2352 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002353 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2354 * screen capture also prevents the content from being shown on display devices that do not have
2355 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2356 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002357 *
2358 * <p>The calling device admin must be a device or profile owner. If it is not, a
2359 * security exception will be thrown.
2360 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002361 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002362 * blocks assist requests for all activities of the relevant user.
2363 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002365 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002366 */
Robin Lee25e26452015-06-02 09:56:29 -07002367 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002368 if (mService != null) {
2369 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002370 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002371 } catch (RemoteException e) {
2372 Log.w(TAG, "Failed talking with device policy service", e);
2373 }
2374 }
2375 }
2376
2377 /**
2378 * Determine whether or not screen capture has been disabled by the current
2379 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002380 * @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 +01002381 * have disabled screen capture.
2382 */
Robin Lee25e26452015-06-02 09:56:29 -07002383 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002384 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002385 }
2386
2387 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002388 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002389 if (mService != null) {
2390 try {
2391 return mService.getScreenCaptureDisabled(admin, userHandle);
2392 } catch (RemoteException e) {
2393 Log.w(TAG, "Failed talking with device policy service", e);
2394 }
2395 }
2396 return false;
2397 }
2398
2399 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002400 * Called by a device owner to set whether auto time is required. If auto time is
2401 * required the user cannot set the date and time, but has to use network date and time.
2402 *
2403 * <p>Note: if auto time is required the user can still manually set the time zone.
2404 *
2405 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2406 * be thrown.
2407 *
2408 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2409 * @param required Whether auto time is set required or not.
2410 */
Robin Lee25e26452015-06-02 09:56:29 -07002411 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002412 if (mService != null) {
2413 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002414 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002415 } catch (RemoteException e) {
2416 Log.w(TAG, "Failed talking with device policy service", e);
2417 }
2418 }
2419 }
2420
2421 /**
2422 * @return true if auto time is required.
2423 */
2424 public boolean getAutoTimeRequired() {
2425 if (mService != null) {
2426 try {
2427 return mService.getAutoTimeRequired();
2428 } catch (RemoteException e) {
2429 Log.w(TAG, "Failed talking with device policy service", e);
2430 }
2431 }
2432 return false;
2433 }
2434
2435 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002436 * Called by an application that is administering the device to disable keyguard customizations,
2437 * such as widgets. After setting this, keyguard features will be disabled according to the
2438 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002439 *
2440 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002441 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002442 * this method; if it has not, a security exception will be thrown.
2443 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002444 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002445 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002446 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002447 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002448 * <ul>
2449 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2450 * these will affect the profile's parent user.
2451 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2452 * generated by applications in the managed profile.
2453 * </ul>
2454 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2455 * can check which features have been disabled by calling
2456 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002457 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002458 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002459 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2460 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002461 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002462 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2463 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002464 */
Robin Lee25e26452015-06-02 09:56:29 -07002465 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002466 if (mService != null) {
2467 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002468 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002469 } catch (RemoteException e) {
2470 Log.w(TAG, "Failed talking with device policy service", e);
2471 }
2472 }
2473 }
2474
2475 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002476 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002477 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002478 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002479 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002480 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2481 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002482 */
Robin Lee25e26452015-06-02 09:56:29 -07002483 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002484 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002485 }
2486
2487 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002488 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002489 if (mService != null) {
2490 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002491 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002492 } catch (RemoteException e) {
2493 Log.w(TAG, "Failed talking with device policy service", e);
2494 }
2495 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002496 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002497 }
2498
2499 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002500 * @hide
2501 */
Robin Lee25e26452015-06-02 09:56:29 -07002502 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2503 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002504 if (mService != null) {
2505 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002506 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002507 } catch (RemoteException e) {
2508 Log.w(TAG, "Failed talking with device policy service", e);
2509 }
2510 }
2511 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002512
Dianne Hackbornd6847842010-01-12 18:14:19 -08002513 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002514 * @hide
2515 */
Robin Lee25e26452015-06-02 09:56:29 -07002516 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002517 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002518 }
2519
2520 /**
Robin Lee25e26452015-06-02 09:56:29 -07002521 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002522 * @hide
2523 */
Robin Lee25e26452015-06-02 09:56:29 -07002524 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002525 ActivityInfo ai;
2526 try {
2527 ai = mContext.getPackageManager().getReceiverInfo(cn,
2528 PackageManager.GET_META_DATA);
2529 } catch (PackageManager.NameNotFoundException e) {
2530 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2531 return null;
2532 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002533
Dianne Hackbornd6847842010-01-12 18:14:19 -08002534 ResolveInfo ri = new ResolveInfo();
2535 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002536
Dianne Hackbornd6847842010-01-12 18:14:19 -08002537 try {
2538 return new DeviceAdminInfo(mContext, ri);
2539 } catch (XmlPullParserException e) {
2540 Log.w(TAG, "Unable to parse device policy " + cn, e);
2541 return null;
2542 } catch (IOException e) {
2543 Log.w(TAG, "Unable to parse device policy " + cn, e);
2544 return null;
2545 }
2546 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002547
Dianne Hackbornd6847842010-01-12 18:14:19 -08002548 /**
2549 * @hide
2550 */
Robin Lee25e26452015-06-02 09:56:29 -07002551 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002552 if (mService != null) {
2553 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002554 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002555 } catch (RemoteException e) {
2556 Log.w(TAG, "Failed talking with device policy service", e);
2557 }
2558 }
2559 }
2560
2561 /**
2562 * @hide
2563 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002564 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002565 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002566 if (mService != null) {
2567 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002568 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002569 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002570 } catch (RemoteException e) {
2571 Log.w(TAG, "Failed talking with device policy service", e);
2572 }
2573 }
2574 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002575
Dianne Hackbornd6847842010-01-12 18:14:19 -08002576 /**
2577 * @hide
2578 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002579 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002580 if (mService != null) {
2581 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002582 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002583 } catch (RemoteException e) {
2584 Log.w(TAG, "Failed talking with device policy service", e);
2585 }
2586 }
2587 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002588
Dianne Hackbornd6847842010-01-12 18:14:19 -08002589 /**
2590 * @hide
2591 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002592 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002593 if (mService != null) {
2594 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002595 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002596 } catch (RemoteException e) {
2597 Log.w(TAG, "Failed talking with device policy service", e);
2598 }
2599 }
2600 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002601
2602 /**
2603 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002604 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002605 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2606 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002607 * @return whether the package was successfully registered as the device owner.
2608 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002609 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002610 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002611 public boolean setDeviceOwner(ComponentName who) {
2612 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002613 }
2614
2615 /**
2616 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002617 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002618 public boolean setDeviceOwner(ComponentName who, int userId) {
2619 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002620 }
2621
2622 /**
2623 * @hide
2624 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002625 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2626 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002627 }
2628
2629 /**
2630 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002631 * Sets the given package as the device owner. The package must already be installed. There
2632 * must not already be a device owner.
2633 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2634 * this method.
2635 * Calling this after the setup phase of the primary user has completed is allowed only if
2636 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002637 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002638 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002639 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002640 * @return whether the package was successfully registered as the device owner.
2641 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002642 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002643 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002644 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002645 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002646 if (mService != null) {
2647 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002648 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002649 } catch (RemoteException re) {
2650 Log.w(TAG, "Failed to set device owner");
2651 }
2652 }
2653 return false;
2654 }
2655
2656 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002657 * Used to determine if a particular package has been registered as a Device Owner app.
2658 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002659 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002660 * package is currently registered as the device owner app, pass in the package name from
2661 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002662 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002663 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2664 * the setup process.
2665 * @param packageName the package name of the app, to compare with the registered device owner
2666 * app, if any.
Makoto Onukia52562c2015-10-01 16:12:31 -07002667 * @return whether or not the package is registered as the device owner app. Note this method
2668 * does *not* check weather the device owner is actually running on the current user.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002669 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002670 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002671 if (mService != null) {
2672 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002673 return mService.isDeviceOwnerPackage(packageName);
2674 } catch (RemoteException e) {
2675 Log.w(TAG, "Failed talking with device policy service", e);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002676 }
2677 }
2678 return false;
2679 }
2680
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002681 /**
2682 * @hide
2683 * Redirect to isDeviceOwnerApp.
2684 */
2685 public boolean isDeviceOwner(String packageName) {
2686 return isDeviceOwnerApp(packageName);
2687 }
2688
Jason Monkb0dced82014-06-06 14:36:20 -04002689 /**
Makoto Onukia52562c2015-10-01 16:12:31 -07002690 * Check whether a given component is registered as a device owner.
2691 * Note this method does *not* check weather the device owner is actually running on the current
2692 * user.
2693 *
2694 * @hide
2695 */
2696 public boolean isDeviceOwner(ComponentName who) {
2697 return (who != null) && who.equals(getDeviceOwner());
2698 }
2699
2700 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002701 * Clears the current device owner. The caller must be the device owner.
2702 *
2703 * This function should be used cautiously as once it is called it cannot
2704 * be undone. The device owner can only be set as a part of device setup
2705 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002706 *
2707 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002708 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002709 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002710 if (mService != null) {
2711 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002712 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002713 } catch (RemoteException re) {
2714 Log.w(TAG, "Failed to clear device owner");
2715 }
2716 }
2717 }
2718
Makoto Onukia52562c2015-10-01 16:12:31 -07002719 /**
2720 * Returns the device owner package name. Note this method will still return the device owner
2721 * package name even if it's running on a different user.
2722 *
2723 * @hide
2724 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002725 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002726 public String getDeviceOwner() {
Makoto Onukia52562c2015-10-01 16:12:31 -07002727 final ComponentName componentName = getDeviceOwnerComponent();
2728 return componentName == null ? null : componentName.getPackageName();
2729 }
2730
2731 /**
2732 * Returns the device owner name. Note this method will still return the device owner
2733 * name even if it's running on a different user.
2734 *
2735 * @hide
2736 */
2737 public String getDeviceOwnerName() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002738 if (mService != null) {
2739 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002740 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002741 } catch (RemoteException re) {
2742 Log.w(TAG, "Failed to get device owner");
2743 }
2744 }
2745 return null;
2746 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002747
Makoto Onukia52562c2015-10-01 16:12:31 -07002748 /**
2749 * Returns the device owner component name. Note this method will still return the device owner
2750 * component name even if it's running on a different user.
2751 *
2752 * @hide
2753 */
2754 public ComponentName getDeviceOwnerComponent() {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002755 if (mService != null) {
2756 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002757 return mService.getDeviceOwner();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002758 } catch (RemoteException re) {
2759 Log.w(TAG, "Failed to get device owner");
2760 }
2761 }
2762 return null;
2763 }
Adam Connors776c5552014-01-09 10:42:56 +00002764
2765 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002766 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002767 * @deprecated Do not use
2768 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002769 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002770 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002771 @SystemApi
2772 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002773 return null;
2774 }
2775
2776 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002777 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002778 * @deprecated Do not use
2779 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002780 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002781 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002782 @SystemApi
2783 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002784 return null;
2785 }
2786
Julia Reynolds20118f12015-02-11 12:34:08 -05002787 /**
Adam Connors776c5552014-01-09 10:42:56 +00002788 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002789 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302790 * Sets the given component as an active admin and registers the package as the profile
2791 * owner for this user. The package must already be installed and there shouldn't be
2792 * an existing profile owner registered for this user. Also, this method must be called
2793 * before the user setup has been completed.
2794 * <p>
2795 * This method can only be called by system apps that hold MANAGE_USERS permission and
2796 * MANAGE_DEVICE_ADMINS permission.
2797 * @param admin The component to register as an active admin and profile owner.
2798 * @param ownerName The user-visible name of the entity that is managing this user.
2799 * @return whether the admin was successfully registered as the profile owner.
2800 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2801 * the user has already been set up.
2802 */
Justin Morey80440cc2014-07-24 09:16:35 -05002803 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002804 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302805 throws IllegalArgumentException {
2806 if (mService != null) {
2807 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002808 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302809 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002810 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302811 } catch (RemoteException re) {
2812 Log.w(TAG, "Failed to set profile owner " + re);
2813 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2814 }
2815 }
2816 return false;
2817 }
2818
2819 /**
2820 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002821 * Clears the active profile owner and removes all user restrictions. The caller must
2822 * be from the same package as the active profile owner for this user, otherwise a
2823 * SecurityException will be thrown.
2824 *
2825 * @param admin The component to remove as the profile owner.
2826 * @return
2827 */
2828 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002829 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002830 if (mService != null) {
2831 try {
2832 mService.clearProfileOwner(admin);
2833 } catch (RemoteException re) {
2834 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2835 }
2836 }
2837 }
2838
2839 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002840 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002841 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002842 */
2843 public boolean hasUserSetupCompleted() {
2844 if (mService != null) {
2845 try {
2846 return mService.hasUserSetupCompleted();
2847 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002848 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002849 }
2850 }
2851 return true;
2852 }
2853
2854 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002855 * @hide
2856 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002857 * already be installed. There must not already be a profile owner for this user.
2858 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2859 * this method.
2860 * Calling this after the setup phase of the specified user has completed is allowed only if:
2861 * - the caller is SYSTEM_UID.
2862 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002863 * @param admin the component name to be registered as profile owner.
2864 * @param ownerName the human readable name of the organisation associated with this DPM.
2865 * @param userHandle the userId to set the profile owner for.
2866 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002867 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2868 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002869 */
Robin Lee25e26452015-06-02 09:56:29 -07002870 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002871 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002872 if (admin == null) {
2873 throw new NullPointerException("admin cannot be null");
2874 }
Adam Connors776c5552014-01-09 10:42:56 +00002875 if (mService != null) {
2876 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002877 if (ownerName == null) {
2878 ownerName = "";
2879 }
2880 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002881 } catch (RemoteException re) {
2882 Log.w(TAG, "Failed to set profile owner", re);
2883 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2884 }
2885 }
2886 return false;
2887 }
2888
2889 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002890 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2891 * be used. Only the profile owner can call this.
2892 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002893 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002894 *
2895 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2896 */
Robin Lee25e26452015-06-02 09:56:29 -07002897 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002898 if (mService != null) {
2899 try {
2900 mService.setProfileEnabled(admin);
2901 } catch (RemoteException e) {
2902 Log.w(TAG, "Failed talking with device policy service", e);
2903 }
2904 }
2905 }
2906
2907 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002908 * Sets the name of the profile. In the device owner case it sets the name of the user
2909 * 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 +01002910 * never called by the profile or device owner, the name will be set to default values.
2911 *
2912 * @see #isProfileOwnerApp
2913 * @see #isDeviceOwnerApp
2914 *
Robin Lee25e26452015-06-02 09:56:29 -07002915 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01002916 * @param profileName The name of the profile.
2917 */
Robin Lee25e26452015-06-02 09:56:29 -07002918 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01002919 if (mService != null) {
2920 try {
Robin Lee25e26452015-06-02 09:56:29 -07002921 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07002922 } catch (RemoteException e) {
2923 Log.w(TAG, "Failed talking with device policy service", e);
2924 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002925 }
2926 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01002927
2928 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002929 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002930 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002931 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002932 *
2933 * @param packageName The package name of the app to compare with the registered profile owner.
2934 * @return Whether or not the package is registered as the profile owner.
2935 */
2936 public boolean isProfileOwnerApp(String packageName) {
2937 if (mService != null) {
2938 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002939 ComponentName profileOwner = mService.getProfileOwner(
2940 Process.myUserHandle().getIdentifier());
2941 return profileOwner != null
2942 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002943 } catch (RemoteException re) {
2944 Log.w(TAG, "Failed to check profile owner");
2945 }
2946 }
2947 return false;
2948 }
2949
2950 /**
2951 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002952 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00002953 * owner has been set for that user.
2954 * @throws IllegalArgumentException if the userId is invalid.
2955 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002956 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002957 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002958 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2959 }
2960
2961 /**
2962 * @see #getProfileOwner()
2963 * @hide
2964 */
2965 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002966 if (mService != null) {
2967 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002968 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002969 } catch (RemoteException re) {
2970 Log.w(TAG, "Failed to get profile owner");
2971 throw new IllegalArgumentException(
2972 "Requested profile owner for invalid userId", re);
2973 }
2974 }
2975 return null;
2976 }
2977
2978 /**
2979 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002980 * @return the human readable name of the organisation associated with this DPM or {@code null}
2981 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00002982 * @throws IllegalArgumentException if the userId is invalid.
2983 */
2984 public String getProfileOwnerName() throws IllegalArgumentException {
2985 if (mService != null) {
2986 try {
2987 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2988 } catch (RemoteException re) {
2989 Log.w(TAG, "Failed to get profile owner");
2990 throw new IllegalArgumentException(
2991 "Requested profile owner for invalid userId", re);
2992 }
2993 }
2994 return null;
2995 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002996
2997 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002998 * @hide
Makoto Onuki53de36f2015-11-06 17:08:01 -08002999 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003000 * @return the human readable name of the organisation associated with this profile owner or
3001 * null if one is not set.
3002 * @throws IllegalArgumentException if the userId is invalid.
3003 */
3004 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003005 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003006 if (mService != null) {
3007 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003008 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003009 } catch (RemoteException re) {
3010 Log.w(TAG, "Failed to get profile owner");
3011 throw new IllegalArgumentException(
3012 "Requested profile owner for invalid userId", re);
3013 }
3014 }
3015 return null;
3016 }
3017
3018 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003019 * Called by a profile owner or device owner to add a default intent handler activity for
3020 * intents that match a certain intent filter. This activity will remain the default intent
3021 * handler even if the set of potential event handlers for the intent filter changes and if
3022 * the intent preferences are reset.
3023 *
3024 * <p>The default disambiguation mechanism takes over if the activity is not installed
3025 * (anymore). When the activity is (re)installed, it is automatically reset as default
3026 * intent handler for the filter.
3027 *
3028 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3029 * security exception will be thrown.
3030 *
3031 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3032 * @param filter The IntentFilter for which a default handler is added.
3033 * @param activity The Activity that is added as default intent handler.
3034 */
Robin Lee25e26452015-06-02 09:56:29 -07003035 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3036 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003037 if (mService != null) {
3038 try {
3039 mService.addPersistentPreferredActivity(admin, filter, activity);
3040 } catch (RemoteException e) {
3041 Log.w(TAG, "Failed talking with device policy service", e);
3042 }
3043 }
3044 }
3045
3046 /**
3047 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003048 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003049 *
3050 * <p>The calling device admin must be a profile owner. If it is not, a security
3051 * exception will be thrown.
3052 *
3053 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3054 * @param packageName The name of the package for which preferences are removed.
3055 */
Robin Lee25e26452015-06-02 09:56:29 -07003056 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003057 String packageName) {
3058 if (mService != null) {
3059 try {
3060 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3061 } catch (RemoteException e) {
3062 Log.w(TAG, "Failed talking with device policy service", e);
3063 }
3064 }
3065 }
Robin Lee66e5d962014-04-09 16:44:21 +01003066
3067 /**
3068 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003069 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003070 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003071 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3072 * <ul>
3073 * <li>{@code boolean}
3074 * <li>{@code int}
3075 * <li>{@code String} or {@code String[]}
3076 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3077 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003078 *
3079 * <p>The application restrictions are only made visible to the target application and the
3080 * profile or device owner.
3081 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003082 * <p>If the restrictions are not available yet, but may be applied in the near future,
3083 * the admin can notify the target application of that by adding
3084 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3085 *
Robin Lee66e5d962014-04-09 16:44:21 +01003086 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3087 * exception will be thrown.
3088 *
3089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3090 * @param packageName The name of the package to update restricted settings for.
3091 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3092 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003093 *
3094 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003095 */
Robin Lee25e26452015-06-02 09:56:29 -07003096 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003097 Bundle settings) {
3098 if (mService != null) {
3099 try {
3100 mService.setApplicationRestrictions(admin, packageName, settings);
3101 } catch (RemoteException e) {
3102 Log.w(TAG, "Failed talking with device policy service", e);
3103 }
3104 }
3105 }
3106
3107 /**
Jim Millere303bf42014-08-26 17:12:29 -07003108 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3109 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3110 * trust agents but those enabled by this function call. If flag
3111 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003112 *
3113 * <p>The calling device admin must have requested
3114 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003115 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003116 *
3117 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003118 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003119 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003120 * will be strictly disabled according to the state of the
3121 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3122 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3123 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3124 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003125 */
Robin Lee25e26452015-06-02 09:56:29 -07003126 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3127 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003128 if (mService != null) {
3129 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003130 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003131 } catch (RemoteException e) {
3132 Log.w(TAG, "Failed talking with device policy service", e);
3133 }
3134 }
3135 }
3136
3137 /**
Jim Millere303bf42014-08-26 17:12:29 -07003138 * Gets configuration for the given trust agent based on aggregating all calls to
3139 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3140 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003141 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003142 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3143 * this function returns a list of configurations for all admins that declare
3144 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3145 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3146 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3147 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003148 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003149 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003150 */
Robin Lee25e26452015-06-02 09:56:29 -07003151 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3152 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003153 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003154 }
3155
3156 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003157 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3158 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003159 if (mService != null) {
3160 try {
Jim Millere303bf42014-08-26 17:12:29 -07003161 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003162 } catch (RemoteException e) {
3163 Log.w(TAG, "Failed talking with device policy service", e);
3164 }
3165 }
Jim Millere303bf42014-08-26 17:12:29 -07003166 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003167 }
3168
3169 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003170 * Called by a profile owner of a managed profile to set whether caller-Id information from
3171 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003172 *
3173 * <p>The calling device admin must be a profile owner. If it is not, a
3174 * security exception will be thrown.
3175 *
Robin Lee25e26452015-06-02 09:56:29 -07003176 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003177 * @param disabled If true caller-Id information in the managed profile is not displayed.
3178 */
Robin Lee25e26452015-06-02 09:56:29 -07003179 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003180 if (mService != null) {
3181 try {
Robin Lee25e26452015-06-02 09:56:29 -07003182 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003183 } catch (RemoteException e) {
3184 Log.w(TAG, "Failed talking with device policy service", e);
3185 }
3186 }
3187 }
3188
3189 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003190 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3191 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003192 *
3193 * <p>The calling device admin must be a profile owner. If it is not, a
3194 * security exception will be thrown.
3195 *
Robin Lee25e26452015-06-02 09:56:29 -07003196 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003197 */
Robin Lee25e26452015-06-02 09:56:29 -07003198 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003199 if (mService != null) {
3200 try {
Robin Lee25e26452015-06-02 09:56:29 -07003201 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003202 } catch (RemoteException e) {
3203 Log.w(TAG, "Failed talking with device policy service", e);
3204 }
3205 }
3206 return false;
3207 }
3208
3209 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003210 * Determine whether or not caller-Id information has been disabled.
3211 *
3212 * @param userHandle The user for whom to check the caller-id permission
3213 * @hide
3214 */
3215 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3216 if (mService != null) {
3217 try {
3218 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3219 } catch (RemoteException e) {
3220 Log.w(TAG, "Failed talking with device policy service", e);
3221 }
3222 }
3223 return false;
3224 }
3225
3226 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003227 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3228 * @hide
3229 */
3230 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3231 Intent originalIntent) {
3232 if (mService != null) {
3233 try {
3234 mService.startManagedQuickContact(
3235 actualLookupKey, actualContactId, originalIntent);
3236 } catch (RemoteException e) {
3237 Log.w(TAG, "Failed talking with device policy service", e);
3238 }
3239 }
3240 }
3241
3242 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003243 * Called by a profile owner of a managed profile to set whether bluetooth
3244 * devices can access enterprise contacts.
3245 * <p>
3246 * The calling device admin must be a profile owner. If it is not, a
3247 * security exception will be thrown.
3248 * <p>
3249 * This API works on managed profile only.
3250 *
Robin Lee25e26452015-06-02 09:56:29 -07003251 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003252 * with.
3253 * @param disabled If true, bluetooth devices cannot access enterprise
3254 * contacts.
3255 */
Robin Lee25e26452015-06-02 09:56:29 -07003256 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003257 if (mService != null) {
3258 try {
Robin Lee25e26452015-06-02 09:56:29 -07003259 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003260 } catch (RemoteException e) {
3261 Log.w(TAG, "Failed talking with device policy service", e);
3262 }
3263 }
3264 }
3265
3266 /**
3267 * Called by a profile owner of a managed profile to determine whether or
3268 * not Bluetooth devices cannot access enterprise contacts.
3269 * <p>
3270 * The calling device admin must be a profile owner. If it is not, a
3271 * security exception will be thrown.
3272 * <p>
3273 * This API works on managed profile only.
3274 *
Robin Lee25e26452015-06-02 09:56:29 -07003275 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003276 * with.
3277 */
Robin Lee25e26452015-06-02 09:56:29 -07003278 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003279 if (mService != null) {
3280 try {
Robin Lee25e26452015-06-02 09:56:29 -07003281 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003282 } catch (RemoteException e) {
3283 Log.w(TAG, "Failed talking with device policy service", e);
3284 }
3285 }
3286 return true;
3287 }
3288
3289 /**
3290 * Determine whether or not Bluetooth devices cannot access contacts.
3291 * <p>
3292 * This API works on managed profile UserHandle only.
3293 *
3294 * @param userHandle The user for whom to check the caller-id permission
3295 * @hide
3296 */
3297 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3298 if (mService != null) {
3299 try {
3300 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3301 .getIdentifier());
3302 } catch (RemoteException e) {
3303 Log.w(TAG, "Failed talking with device policy service", e);
3304 }
3305 }
3306 return true;
3307 }
3308
3309 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003310 * Called by the profile owner of a managed profile so that some intents sent in the managed
3311 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003312 * Only activity intents are supported.
3313 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003314 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003315 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3316 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003317 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3318 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003319 */
Robin Lee25e26452015-06-02 09:56:29 -07003320 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003321 if (mService != null) {
3322 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003323 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003324 } catch (RemoteException e) {
3325 Log.w(TAG, "Failed talking with device policy service", e);
3326 }
3327 }
3328 }
3329
3330 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003331 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3332 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003333 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003334 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3335 */
Robin Lee25e26452015-06-02 09:56:29 -07003336 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003337 if (mService != null) {
3338 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003339 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003340 } catch (RemoteException e) {
3341 Log.w(TAG, "Failed talking with device policy service", e);
3342 }
3343 }
3344 }
3345
3346 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003347 * Called by a profile or device owner to set the permitted accessibility services. When
3348 * set by a device owner or profile owner the restriction applies to all profiles of the
3349 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003350 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003351 * By default the user can use any accessiblity service. When zero or more packages have
3352 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003353 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003354 *
3355 * <p> Calling with a null value for the list disables the restriction so that all services
3356 * can be used, calling with an empty list only allows the builtin system's services.
3357 *
3358 * <p> System accesibility services are always available to the user the list can't modify
3359 * this.
3360 *
3361 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3362 * @param packageNames List of accessibility service package names.
3363 *
3364 * @return true if setting the restriction succeeded. It fail if there is
3365 * one or more non-system accessibility services enabled, that are not in the list.
3366 */
Robin Lee25e26452015-06-02 09:56:29 -07003367 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003368 List<String> packageNames) {
3369 if (mService != null) {
3370 try {
3371 return mService.setPermittedAccessibilityServices(admin, packageNames);
3372 } catch (RemoteException e) {
3373 Log.w(TAG, "Failed talking with device policy service", e);
3374 }
3375 }
3376 return false;
3377 }
3378
3379 /**
3380 * Returns the list of permitted accessibility services set by this device or profile owner.
3381 *
3382 * <p>An empty list means no accessibility services except system services are allowed.
3383 * Null means all accessibility services are allowed.
3384 *
3385 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3386 * @return List of accessiblity service package names.
3387 */
Robin Lee25e26452015-06-02 09:56:29 -07003388 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003389 if (mService != null) {
3390 try {
3391 return mService.getPermittedAccessibilityServices(admin);
3392 } catch (RemoteException e) {
3393 Log.w(TAG, "Failed talking with device policy service", e);
3394 }
3395 }
3396 return null;
3397 }
3398
3399 /**
3400 * Returns the list of accessibility services permitted by the device or profiles
3401 * owners of this user.
3402 *
3403 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3404 * it will contain the intersection of the permitted lists for any device or profile
3405 * owners that apply to this user. It will also include any system accessibility services.
3406 *
3407 * @param userId which user to check for.
3408 * @return List of accessiblity service package names.
3409 * @hide
3410 */
3411 @SystemApi
3412 public List<String> getPermittedAccessibilityServices(int userId) {
3413 if (mService != null) {
3414 try {
3415 return mService.getPermittedAccessibilityServicesForUser(userId);
3416 } catch (RemoteException e) {
3417 Log.w(TAG, "Failed talking with device policy service", e);
3418 }
3419 }
3420 return null;
3421 }
3422
3423 /**
3424 * Called by a profile or device owner to set the permitted input methods services. When
3425 * set by a device owner or profile owner the restriction applies to all profiles of the
3426 * user the device owner or profile owner is an admin for.
3427 *
3428 * By default the user can use any input method. When zero or more packages have
3429 * been added, input method that are not in the list and not part of the system
3430 * can not be enabled by the user.
3431 *
3432 * This method will fail if it is called for a admin that is not for the foreground user
3433 * or a profile of the foreground user.
3434 *
3435 * <p> Calling with a null value for the list disables the restriction so that all input methods
3436 * can be used, calling with an empty list disables all but the system's own input methods.
3437 *
3438 * <p> System input methods are always available to the user this method can't modify this.
3439 *
3440 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3441 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003442 * @return true if setting the restriction succeeded. It will fail if there are
3443 * one or more non-system input methods currently enabled that are not in
3444 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003445 */
Robin Lee25e26452015-06-02 09:56:29 -07003446 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003447 if (mService != null) {
3448 try {
3449 return mService.setPermittedInputMethods(admin, packageNames);
3450 } catch (RemoteException e) {
3451 Log.w(TAG, "Failed talking with device policy service", e);
3452 }
3453 }
3454 return false;
3455 }
3456
3457
3458 /**
3459 * Returns the list of permitted input methods set by this device or profile owner.
3460 *
3461 * <p>An empty list means no input methods except system input methods are allowed.
3462 * Null means all input methods are allowed.
3463 *
3464 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3465 * @return List of input method package names.
3466 */
Robin Lee25e26452015-06-02 09:56:29 -07003467 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003468 if (mService != null) {
3469 try {
3470 return mService.getPermittedInputMethods(admin);
3471 } catch (RemoteException e) {
3472 Log.w(TAG, "Failed talking with device policy service", e);
3473 }
3474 }
3475 return null;
3476 }
3477
3478 /**
3479 * Returns the list of input methods permitted by the device or profiles
3480 * owners of the current user.
3481 *
3482 * <p>Null means all input methods are allowed, if a non-null list is returned
3483 * it will contain the intersection of the permitted lists for any device or profile
3484 * owners that apply to this user. It will also include any system input methods.
3485 *
3486 * @return List of input method package names.
3487 * @hide
3488 */
3489 @SystemApi
3490 public List<String> getPermittedInputMethodsForCurrentUser() {
3491 if (mService != null) {
3492 try {
3493 return mService.getPermittedInputMethodsForCurrentUser();
3494 } catch (RemoteException e) {
3495 Log.w(TAG, "Failed talking with device policy service", e);
3496 }
3497 }
3498 return null;
3499 }
3500
3501 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003502 * Called by a device owner to create a user with the specified name. The UserHandle returned
3503 * by this method should not be persisted as user handles are recycled as users are removed and
3504 * created. If you need to persist an identifier for this user, use
3505 * {@link UserManager#getSerialNumberForUser}.
3506 *
3507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3508 * @param name the user's name
3509 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003510 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3511 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003512 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003513 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003514 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003515 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003516 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003517 try {
3518 return mService.createUser(admin, name);
3519 } catch (RemoteException re) {
3520 Log.w(TAG, "Could not create a user", re);
3521 }
3522 return null;
3523 }
3524
3525 /**
Jason Monk03978a42014-06-10 15:05:30 -04003526 * Called by a device owner to create a user with the specified name. The UserHandle returned
3527 * by this method should not be persisted as user handles are recycled as users are removed and
3528 * created. If you need to persist an identifier for this user, use
3529 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3530 * immediately.
3531 *
3532 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3533 * as registered as an active admin on the new user. The profile owner package will be
3534 * installed on the new user if it already is installed on the device.
3535 *
3536 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3537 * profileOwnerComponent when onEnable is called.
3538 *
3539 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3540 * @param name the user's name
3541 * @param ownerName the human readable name of the organisation associated with this DPM.
3542 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3543 * the user.
3544 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3545 * on the new user.
3546 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003547 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3548 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003549 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003550 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003551 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003552 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003553 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3554 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003555 try {
3556 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3557 adminExtras);
3558 } catch (RemoteException re) {
3559 Log.w(TAG, "Could not create a user", re);
3560 }
3561 return null;
3562 }
3563
3564 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003565 * Called by a device owner to remove a user and all associated data. The primary user can
3566 * not be removed.
3567 *
3568 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3569 * @param userHandle the user to remove.
3570 * @return {@code true} if the user was removed, {@code false} otherwise.
3571 */
Robin Lee25e26452015-06-02 09:56:29 -07003572 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003573 try {
3574 return mService.removeUser(admin, userHandle);
3575 } catch (RemoteException re) {
3576 Log.w(TAG, "Could not remove user ", re);
3577 return false;
3578 }
3579 }
3580
3581 /**
Jason Monk582d9112014-07-09 19:57:08 -04003582 * Called by a device owner to switch the specified user to the foreground.
3583 *
3584 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3585 * @param userHandle the user to switch to; null will switch to primary.
3586 * @return {@code true} if the switch was successful, {@code false} otherwise.
3587 *
3588 * @see Intent#ACTION_USER_FOREGROUND
3589 */
Robin Lee25e26452015-06-02 09:56:29 -07003590 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003591 try {
3592 return mService.switchUser(admin, userHandle);
3593 } catch (RemoteException re) {
3594 Log.w(TAG, "Could not switch user ", re);
3595 return false;
3596 }
3597 }
3598
3599 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003600 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003601 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003602 *
3603 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3604 * exception will be thrown.
3605 *
3606 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3607 * @param packageName The name of the package to fetch restricted settings of.
3608 * @return {@link Bundle} of settings corresponding to what was set last time
3609 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3610 * if no restrictions have been set.
3611 */
Robin Lee25e26452015-06-02 09:56:29 -07003612 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003613 if (mService != null) {
3614 try {
3615 return mService.getApplicationRestrictions(admin, packageName);
3616 } catch (RemoteException e) {
3617 Log.w(TAG, "Failed talking with device policy service", e);
3618 }
3619 }
3620 return null;
3621 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003622
3623 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003624 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003625 * <p>
3626 * The calling device admin must be a profile or device owner; if it is not,
3627 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003628 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003629 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3630 * with.
3631 * @param key The key of the restriction. See the constants in
3632 * {@link android.os.UserManager} for the list of keys.
3633 */
Robin Lee25e26452015-06-02 09:56:29 -07003634 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003635 if (mService != null) {
3636 try {
3637 mService.setUserRestriction(admin, key, true);
3638 } catch (RemoteException e) {
3639 Log.w(TAG, "Failed talking with device policy service", e);
3640 }
3641 }
3642 }
3643
3644 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003645 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003646 * <p>
3647 * The calling device admin must be a profile or device owner; if it is not,
3648 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003649 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003650 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3651 * with.
3652 * @param key The key of the restriction. See the constants in
3653 * {@link android.os.UserManager} for the list of keys.
3654 */
Robin Lee25e26452015-06-02 09:56:29 -07003655 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003656 if (mService != null) {
3657 try {
3658 mService.setUserRestriction(admin, key, false);
3659 } catch (RemoteException e) {
3660 Log.w(TAG, "Failed talking with device policy service", e);
3661 }
3662 }
3663 }
Adam Connors010cfd42014-04-16 12:48:13 +01003664
3665 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003666 * Called by a profile or device owner to get user restrictions set with
3667 * {@link #addUserRestriction(ComponentName, String)}.
3668 * <p>
3669 * The target user may have more restrictions set by the system or other device owner / profile
3670 * owner. To get all the user restrictions currently set, use
3671 * {@link UserManager#getUserRestrictions()}.
3672 *
3673 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3674 */
3675 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
3676 Bundle ret = null;
3677 if (mService != null) {
3678 try {
3679 ret = mService.getUserRestrictions(admin);
3680 } catch (RemoteException e) {
3681 Log.w(TAG, "Failed talking with device policy service", e);
3682 }
3683 }
3684 return ret == null ? new Bundle() : ret;
3685 }
3686
3687 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003688 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003689 * is unavailable for use, but the data and actual package file remain.
3690 *
3691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003692 * @param packageName The name of the package to hide or unhide.
3693 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3694 * unhidden.
3695 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003696 */
Robin Lee25e26452015-06-02 09:56:29 -07003697 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003698 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003699 if (mService != null) {
3700 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003701 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003702 } catch (RemoteException e) {
3703 Log.w(TAG, "Failed talking with device policy service", e);
3704 }
3705 }
3706 return false;
3707 }
3708
3709 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003710 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003711 *
3712 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003713 * @param packageName The name of the package to retrieve the hidden status of.
3714 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003715 */
Robin Lee25e26452015-06-02 09:56:29 -07003716 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003717 if (mService != null) {
3718 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003719 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003720 } catch (RemoteException e) {
3721 Log.w(TAG, "Failed talking with device policy service", e);
3722 }
3723 }
3724 return false;
3725 }
3726
3727 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003728 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003729 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003730 *
3731 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3732 * @param packageName The package to be re-enabled in the current profile.
3733 */
Robin Lee25e26452015-06-02 09:56:29 -07003734 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003735 if (mService != null) {
3736 try {
3737 mService.enableSystemApp(admin, packageName);
3738 } catch (RemoteException e) {
3739 Log.w(TAG, "Failed to install package: " + packageName);
3740 }
3741 }
3742 }
3743
3744 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003745 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003746 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003747 *
3748 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3749 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3750 * intent will be re-enabled in the current profile.
3751 * @return int The number of activities that matched the intent and were installed.
3752 */
Robin Lee25e26452015-06-02 09:56:29 -07003753 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003754 if (mService != null) {
3755 try {
3756 return mService.enableSystemAppWithIntent(admin, intent);
3757 } catch (RemoteException e) {
3758 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3759 }
3760 }
3761 return 0;
3762 }
3763
3764 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003765 * Called by a device owner or profile owner to disable account management for a specific type
3766 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003767 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003768 * <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 +01003769 * security exception will be thrown.
3770 *
3771 * <p>When account management is disabled for an account type, adding or removing an account
3772 * of that type will not be possible.
3773 *
3774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3775 * @param accountType For which account management is disabled or enabled.
3776 * @param disabled The boolean indicating that account management will be disabled (true) or
3777 * enabled (false).
3778 */
Robin Lee25e26452015-06-02 09:56:29 -07003779 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003780 boolean disabled) {
3781 if (mService != null) {
3782 try {
3783 mService.setAccountManagementDisabled(admin, accountType, disabled);
3784 } catch (RemoteException e) {
3785 Log.w(TAG, "Failed talking with device policy service", e);
3786 }
3787 }
3788 }
3789
3790 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003791 * Gets the array of accounts for which account management is disabled by the profile owner.
3792 *
3793 * <p> Account management can be disabled/enabled by calling
3794 * {@link #setAccountManagementDisabled}.
3795 *
3796 * @return a list of account types for which account management has been disabled.
3797 *
3798 * @see #setAccountManagementDisabled
3799 */
3800 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003801 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003802 }
3803
3804 /**
3805 * @see #getAccountTypesWithManagementDisabled()
3806 * @hide
3807 */
3808 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003809 if (mService != null) {
3810 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003811 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003812 } catch (RemoteException e) {
3813 Log.w(TAG, "Failed talking with device policy service", e);
3814 }
3815 }
3816
3817 return null;
3818 }
justinzhang511e0d82014-03-24 16:09:24 -04003819
3820 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003821 * Sets which packages may enter lock task mode.
3822 *
3823 * <p>Any packages that shares uid with an allowed package will also be allowed
3824 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003825 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003826 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003827 * package list results in locked tasks belonging to those packages to be finished.
3828 *
Jason Monkc5185f22014-06-24 11:12:42 -04003829 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003830 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003831 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003832 *
3833 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003834 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3835 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003836 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003837 */
Robin Lee25e26452015-06-02 09:56:29 -07003838 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003839 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003840 if (mService != null) {
3841 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003842 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003843 } catch (RemoteException e) {
3844 Log.w(TAG, "Failed talking with device policy service", e);
3845 }
3846 }
3847 }
3848
3849 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003850 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003851 *
3852 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003853 * @hide
3854 */
Robin Lee25e26452015-06-02 09:56:29 -07003855 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003856 if (mService != null) {
3857 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003858 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003859 } catch (RemoteException e) {
3860 Log.w(TAG, "Failed talking with device policy service", e);
3861 }
3862 }
3863 return null;
3864 }
3865
3866 /**
3867 * This function lets the caller know whether the given component is allowed to start the
3868 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003869 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003870 */
Jason Monkd7b86212014-06-16 13:15:38 -04003871 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003872 if (mService != null) {
3873 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003874 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003875 } catch (RemoteException e) {
3876 Log.w(TAG, "Failed talking with device policy service", e);
3877 }
3878 }
3879 return false;
3880 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003881
3882 /**
3883 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3884 * 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 -04003885 * <p>The settings that can be updated with this method are:
3886 * <ul>
3887 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3888 * <li>{@link Settings.Global#AUTO_TIME}</li>
3889 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003890 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003891 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003892 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003893 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003894 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003895 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01003896 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003897 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01003898 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003899 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003900 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003901 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01003902 * <ul>
3903 * <li>{@link Settings.Global#BLUETOOTH_ON}.
3904 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
3905 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
3906 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3907 * <li>{@link Settings.Global#MODE_RINGER}.
3908 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
3909 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3910 * <li>{@link Settings.Global#WIFI_ON}.
3911 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
3912 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003913 *
3914 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3915 * @param setting The name of the setting to update.
3916 * @param value The value to update the setting to.
3917 */
Robin Lee25e26452015-06-02 09:56:29 -07003918 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003919 if (mService != null) {
3920 try {
3921 mService.setGlobalSetting(admin, setting, value);
3922 } catch (RemoteException e) {
3923 Log.w(TAG, "Failed talking with device policy service", e);
3924 }
3925 }
3926 }
3927
3928 /**
3929 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3930 * that the value of the setting is in the correct form for the setting type should be performed
3931 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003932 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003933 * <ul>
3934 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003935 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003936 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3937 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003938 * <p>A device owner can additionally update the following settings:
3939 * <ul>
3940 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3941 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003942 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3943 * @param setting The name of the setting to update.
3944 * @param value The value to update the setting to.
3945 */
Robin Lee25e26452015-06-02 09:56:29 -07003946 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04003947 if (mService != null) {
3948 try {
3949 mService.setSecureSetting(admin, setting, value);
3950 } catch (RemoteException e) {
3951 Log.w(TAG, "Failed talking with device policy service", e);
3952 }
3953 }
3954 }
3955
Amith Yamasanif20d6402014-05-24 15:34:37 -07003956 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003957 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003958 * making permission requests of a local or remote administrator of the user.
3959 * <p/>
3960 * Only a profile owner can designate the restrictions provider.
3961 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003962 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003963 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003964 * it removes the restrictions provider previously assigned.
3965 */
Robin Lee25e26452015-06-02 09:56:29 -07003966 public void setRestrictionsProvider(@NonNull ComponentName admin,
3967 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003968 if (mService != null) {
3969 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003970 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003971 } catch (RemoteException re) {
3972 Log.w(TAG, "Failed to set permission provider on device policy service");
3973 }
3974 }
3975 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003976
3977 /**
3978 * Called by profile or device owners to set the master volume mute on or off.
3979 *
3980 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3981 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3982 */
Robin Lee25e26452015-06-02 09:56:29 -07003983 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04003984 if (mService != null) {
3985 try {
3986 mService.setMasterVolumeMuted(admin, on);
3987 } catch (RemoteException re) {
3988 Log.w(TAG, "Failed to setMasterMute on device policy service");
3989 }
3990 }
3991 }
3992
3993 /**
3994 * Called by profile or device owners to check whether the master volume mute is on or off.
3995 *
3996 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3997 * @return {@code true} if master volume is muted, {@code false} if it's not.
3998 */
Robin Lee25e26452015-06-02 09:56:29 -07003999 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004000 if (mService != null) {
4001 try {
4002 return mService.isMasterVolumeMuted(admin);
4003 } catch (RemoteException re) {
4004 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4005 }
4006 }
4007 return false;
4008 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004009
4010 /**
4011 * Called by profile or device owners to change whether a user can uninstall
4012 * a package.
4013 *
4014 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4015 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004016 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004017 */
Robin Lee25e26452015-06-02 09:56:29 -07004018 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004019 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004020 if (mService != null) {
4021 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004022 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004023 } catch (RemoteException re) {
4024 Log.w(TAG, "Failed to call block uninstall on device policy service");
4025 }
4026 }
4027 }
4028
4029 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004030 * Check whether the current user has been blocked by device policy from uninstalling a package.
4031 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004032 * <p>
4033 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004034 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004035 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004036 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004037 *
Robin Lee25e26452015-06-02 09:56:29 -07004038 * @param admin The name of the admin component whose blocking policy will be checked, or
4039 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004040 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004041 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004042 */
Robin Lee25e26452015-06-02 09:56:29 -07004043 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004044 if (mService != null) {
4045 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004046 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004047 } catch (RemoteException re) {
4048 Log.w(TAG, "Failed to call block uninstall on device policy service");
4049 }
4050 }
4051 return false;
4052 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004053
4054 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004055 * Called by the profile owner of a managed profile to enable widget providers from a
4056 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004057 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004058 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004059 * a package may have zero or more provider components, where each component
4060 * provides a different widget type.
4061 * <p>
4062 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004063 *
4064 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4065 * @param packageName The package from which widget providers are white-listed.
4066 * @return Whether the package was added.
4067 *
4068 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4069 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4070 */
Robin Lee25e26452015-06-02 09:56:29 -07004071 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004072 if (mService != null) {
4073 try {
4074 return mService.addCrossProfileWidgetProvider(admin, packageName);
4075 } catch (RemoteException re) {
4076 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4077 }
4078 }
4079 return false;
4080 }
4081
4082 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004083 * Called by the profile owner of a managed profile to disable widget providers from a given
4084 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004085 * package should have been added via {@link #addCrossProfileWidgetProvider(
4086 * android.content.ComponentName, String)}.
4087 * <p>
4088 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004089 *
4090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4091 * @param packageName The package from which widget providers are no longer
4092 * white-listed.
4093 * @return Whether the package was removed.
4094 *
4095 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4096 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4097 */
Robin Lee25e26452015-06-02 09:56:29 -07004098 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004099 if (mService != null) {
4100 try {
4101 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4102 } catch (RemoteException re) {
4103 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4104 }
4105 }
4106 return false;
4107 }
4108
4109 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004110 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004111 * available in the parent profile.
4112 *
4113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4114 * @return The white-listed package list.
4115 *
4116 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4117 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4118 */
Robin Lee25e26452015-06-02 09:56:29 -07004119 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004120 if (mService != null) {
4121 try {
4122 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4123 if (providers != null) {
4124 return providers;
4125 }
4126 } catch (RemoteException re) {
4127 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4128 }
4129 }
4130 return Collections.emptyList();
4131 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004132
4133 /**
4134 * Called by profile or device owners to set the current user's photo.
4135 *
4136 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4137 * @param icon the bitmap to set as the photo.
4138 */
Robin Lee25e26452015-06-02 09:56:29 -07004139 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004140 try {
4141 mService.setUserIcon(admin, icon);
4142 } catch (RemoteException re) {
4143 Log.w(TAG, "Could not set the user icon ", re);
4144 }
4145 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004146
4147 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004148 * Called by device owners to set a local system update policy. When a new policy is set,
4149 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004150 *
Robin Lee25e26452015-06-02 09:56:29 -07004151 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4152 * components in the device owner package can set system update policies and the
4153 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004154 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004155 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004156 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004157 */
Robin Lee25e26452015-06-02 09:56:29 -07004158 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004159 if (mService != null) {
4160 try {
Robin Lee25e26452015-06-02 09:56:29 -07004161 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004162 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004163 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004164 }
4165 }
4166 }
4167
4168 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004169 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004170 *
Robin Lee25e26452015-06-02 09:56:29 -07004171 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004172 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004173 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004174 if (mService != null) {
4175 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004176 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004177 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004178 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004179 }
4180 }
4181 return null;
4182 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004183
4184 /**
4185 * Called by a device owner to disable the keyguard altogether.
4186 *
4187 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4188 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4189 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4190 * being disabled.
4191 *
4192 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004193 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004194 *
4195 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004196 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004197 */
Robin Lee25e26452015-06-02 09:56:29 -07004198 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004199 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004200 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004201 } catch (RemoteException re) {
4202 Log.w(TAG, "Failed talking with device policy service", re);
4203 return false;
4204 }
4205 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004206
4207 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004208 * Called by device owner to disable the status bar. Disabling the status bar blocks
4209 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004210 * a single use device.
4211 *
4212 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004213 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4214 *
4215 * @return {@code false} if attempting to disable the status bar failed.
4216 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004217 */
Robin Lee25e26452015-06-02 09:56:29 -07004218 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004219 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004220 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004221 } catch (RemoteException re) {
4222 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004223 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004224 }
4225 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004226
4227 /**
4228 * Callable by the system update service to notify device owners about pending updates.
4229 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4230 * permission.
4231 *
4232 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4233 * when the current pending update was first available. -1 if no update is available.
4234 * @hide
4235 */
4236 @SystemApi
4237 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4238 if (mService != null) {
4239 try {
4240 mService.notifyPendingSystemUpdate(updateReceivedTime);
4241 } catch (RemoteException re) {
4242 Log.w(TAG, "Could not notify device owner about pending system update", re);
4243 }
4244 }
4245 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004246
4247 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004248 * Called by profile or device owners to set the default response for future runtime permission
4249 * requests by applications. The policy can allow for normal operation which prompts the
4250 * user to grant a permission, or can allow automatic granting or denying of runtime
4251 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004252 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4253 * the permission grant state via {@link #setPermissionGrantState}.
4254 *
4255 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004256 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004257 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004258 * @param admin Which profile or device owner this request is associated with.
4259 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4260 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004261 *
4262 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004263 */
Robin Lee25e26452015-06-02 09:56:29 -07004264 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004265 try {
4266 mService.setPermissionPolicy(admin, policy);
4267 } catch (RemoteException re) {
4268 Log.w(TAG, "Failed talking with device policy service", re);
4269 }
4270 }
4271
4272 /**
4273 * Returns the current runtime permission policy set by the device or profile owner. The
4274 * default is {@link #PERMISSION_POLICY_PROMPT}.
4275 * @param admin Which profile or device owner this request is associated with.
4276 * @return the current policy for future permission requests.
4277 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004278 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004279 try {
4280 return mService.getPermissionPolicy(admin);
4281 } catch (RemoteException re) {
4282 return PERMISSION_POLICY_PROMPT;
4283 }
4284 }
4285
4286 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004287 * Sets the grant state of a runtime permission for a specific application. The state
4288 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4289 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4290 * is denied and the user cannot manage it through the UI, and {@link
4291 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4292 * user cannot manage it through the UI. This might affect all permissions in a
4293 * group that the runtime permission belongs to. This method can only be called
4294 * by a profile or device owner.
4295 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004296 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4297 * revoke the permission. It retains the previous grant, if any.
4298 *
4299 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004300 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004301 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004302 * @param admin Which profile or device owner this request is associated with.
4303 * @param packageName The application to grant or revoke a permission to.
4304 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004305 * @param grantState The permission grant state which is one of {@link
4306 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4307 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4308 * @return whether the permission was successfully granted or revoked.
4309 *
4310 * @see #PERMISSION_GRANT_STATE_DENIED
4311 * @see #PERMISSION_GRANT_STATE_DEFAULT
4312 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004313 */
Robin Lee25e26452015-06-02 09:56:29 -07004314 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004315 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004316 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004317 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004318 } catch (RemoteException re) {
4319 Log.w(TAG, "Failed talking with device policy service", re);
4320 return false;
4321 }
4322 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004323
4324 /**
4325 * Returns the current grant state of a runtime permission for a specific application.
4326 *
4327 * @param admin Which profile or device owner this request is associated with.
4328 * @param packageName The application to check the grant state for.
4329 * @param permission The permission to check for.
4330 * @return the current grant state specified by device policy. If the profile or device owner
4331 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4332 * This does not indicate whether or not the permission is currently granted for the package.
4333 *
4334 * <p/>If a grant state was set by the profile or device owner, then the return value will
4335 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4336 * which indicates if the permission is currently denied or granted.
4337 *
4338 * @see #setPermissionGrantState(ComponentName, String, String, int)
4339 * @see PackageManager#checkPermission(String, String)
4340 */
Robin Lee25e26452015-06-02 09:56:29 -07004341 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004342 String permission) {
4343 try {
4344 return mService.getPermissionGrantState(admin, packageName, permission);
4345 } catch (RemoteException re) {
4346 Log.w(TAG, "Failed talking with device policy service", re);
4347 return PERMISSION_GRANT_STATE_DEFAULT;
4348 }
4349 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004350
4351 /**
4352 * Returns if provisioning a managed profile or device is possible or not.
4353 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4354 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4355 * Note that even if this method returns true, there is a slight possibility that the
4356 * provisioning will not be allowed when it is actually initiated because some event has
4357 * happened in between.
4358 * @return if provisioning a managed profile or device is possible or not.
4359 * @throws IllegalArgumentException if the supplied action is not valid.
4360 */
4361 public boolean isProvisioningAllowed(String action) {
4362 try {
4363 return mService.isProvisioningAllowed(action);
4364 } catch (RemoteException re) {
4365 Log.w(TAG, "Failed talking with device policy service", re);
4366 return false;
4367 }
4368 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004369}