blob: 20a0072e6c335a89f4e487c5ded15e0c9fd934db [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
Dianne Hackbornd6847842010-01-12 18:14:19 -080019import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050021import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040022import android.app.Activity;
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -070023import android.content.AbstractRestrictionsProvider;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.content.ComponentName;
25import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010026import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000027import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080028import android.content.pm.ActivityInfo;
29import android.content.pm.PackageManager;
30import android.content.pm.ResolveInfo;
Amith Yamasanif20d6402014-05-24 15:34:37 -070031import android.content.RestrictionsManager;
Julia Reynolds4a21b252014-06-04 11:11:43 -040032import android.media.AudioService;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010034import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080035import android.os.Handler;
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;
Jim Miller50e62182014-04-23 17:25:00 -070043import android.service.trust.TrustAgentService;
Dianne Hackbornd6847842010-01-12 18:14:19 -080044import android.util.Log;
45
Maggie Benthallda51e682013-08-08 22:35:44 -040046import com.android.org.conscrypt.TrustedCertificateStore;
47
Jessica Hummel91da58d2014-04-10 17:39:43 +010048import org.xmlpull.v1.XmlPullParserException;
49
Maggie Benthallda51e682013-08-08 22:35:44 -040050import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070052import java.net.InetSocketAddress;
53import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040054import java.security.cert.CertificateException;
55import java.security.cert.CertificateFactory;
56import java.security.cert.X509Certificate;
Jim Miller604e7552014-07-18 19:00:02 -070057import java.util.ArrayList;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080058import java.util.List;
Maggie Benthallda51e682013-08-08 22:35:44 -040059import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080060
61/**
62 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080063 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080064 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080065 *
66 * <div class="special reference">
67 * <h3>Developer Guides</h3>
68 * <p>For more information about managing policies for device adminstration, read the
69 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
70 * developer guide.</p>
71 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080072 */
73public class DevicePolicyManager {
74 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080075
76 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080077 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070078
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080079 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080080 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080081 mService = IDevicePolicyManager.Stub.asInterface(
82 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
83 }
84
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080085 /** @hide */
86 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080087 DevicePolicyManager me = new DevicePolicyManager(context, handler);
88 return me.mService != null ? me : null;
89 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070090
Dianne Hackbornd6847842010-01-12 18:14:19 -080091 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +000092 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +000093 *
Jessica Hummel9da60392014-05-21 12:32:57 +010094 * <p>A managed profile allows data separation for example for the usage of a
95 * device as a personal and corporate device. The user which provisioning is started from and
96 * the managed profile share a launcher.
97 *
98 * <p>This intent will typically be sent by a mobile device management application (mdm).
99 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
100 * control over the profile
101 *
102 * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}
103 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000104 *
105 * <p> When managed provisioning has completed, an intent of the type
106 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100107 * managed profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100108 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100109 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
110 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000111 *
112 * <p>Input: Nothing.</p>
113 * <p>Output: Nothing</p>
114 */
115 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
116 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000117 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000118
119 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100120 * A String extra holding the package name of the mobile device management application that
121 * will be set as the profile owner or device owner.
122 *
123 * <p>If an application starts provisioning directly via an intent with action
124 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
125 * application that started provisioning. The package will be set as profile owner in that case.
126 *
127 * <p>This package is set as device owner when device owner provisioning is started by an Nfc
128 * message containing an Nfc record with MIME type {@link #PROVISIONING_NFC_MIME_TYPE}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000129 */
130 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100131 = "android.app.extra.deviceAdminPackageName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000132
133 /**
134 * A String extra holding the default name of the profile that is created during managed profile
135 * provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100136 *
Jessica Hummelf72078b2014-03-06 16:13:12 +0000137 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
138 */
139 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100140 = "android.app.extra.defaultManagedProfileName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000141
142 /**
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100143 * A String extra that, holds the email address of the account which a managed profile is
144 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100145 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100146 *
147 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
148 * contains this extra, it is forwarded in the
149 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
150 * device management application that was set as the profile owner during provisioning.
151 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100152 */
153 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
154 = "android.app.extra.ManagedProfileEmailAddress";
155
156 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100157 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
158 * will be set to.
159 *
160 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
161 * provisioning via an Nfc bump.
162 */
163 public static final String EXTRA_PROVISIONING_TIME_ZONE
164 = "android.app.extra.timeZone";
165
166 /**
167 * A Long extra holding the local time {@link android.app.AlarmManager} that the device
168 * will be set to.
169 *
170 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
171 * provisioning via an Nfc bump.
172 */
173 public static final String EXTRA_PROVISIONING_LOCAL_TIME
174 = "android.app.extra.localTime";
175
176 /**
177 * A String extra holding the {@link java.util.Locale} that the device will be set to.
178 * Format: xx_yy, where xx is the language code, and yy the country code.
179 *
180 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
181 * provisioning via an Nfc bump.
182 */
183 public static final String EXTRA_PROVISIONING_LOCALE
184 = "android.app.extra.locale";
185
186 /**
187 * A String extra holding the ssid of the wifi network that should be used during nfc device
188 * owner provisioning for downloading the mobile device management application.
189 *
190 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
191 * provisioning via an Nfc bump.
192 */
193 public static final String EXTRA_PROVISIONING_WIFI_SSID
194 = "android.app.extra.wifiSsid";
195
196 /**
197 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
198 * is hidden or not.
199 *
200 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
201 * provisioning via an Nfc bump.
202 */
203 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
204 = "android.app.extra.wifiHidden";
205
206 /**
207 * A String extra indicating the security type of the wifi network in
208 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
209 *
210 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
211 * provisioning via an Nfc bump.
212 */
213 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
214 = "android.app.extra.wifiSecurityType";
215
216 /**
217 * A String extra holding the password of the wifi network in
218 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
219 *
220 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
221 * provisioning via an Nfc bump.
222 */
223 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
224 = "android.app.extra.wifiPassword";
225
226 /**
227 * A String extra holding the proxy host for the wifi network in
228 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
229 *
230 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
231 * provisioning via an Nfc bump.
232 */
233 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
234 = "android.app.extra.wifiProxyHost";
235
236 /**
237 * An int extra holding the proxy port for the wifi network in
238 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
239 *
240 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
241 * provisioning via an Nfc bump.
242 */
243 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
244 = "android.app.extra.wifiProxyPort";
245
246 /**
247 * A String extra holding the proxy bypass for the wifi network in
248 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
249 *
250 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
251 * provisioning via an Nfc bump.
252 */
253 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
254 = "android.app.extra.wifiProxyBypassHosts";
255
256 /**
257 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
258 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
259 *
260 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
261 * provisioning via an Nfc bump.
262 */
263 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
264 = "android.app.extra.wifiPacUrl";
265
266 /**
267 * A String extra holding a url that specifies the download location of the device admin
268 * package. When not provided it is assumed that the device admin package is already installed.
269 *
270 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
271 * provisioning via an Nfc bump.
272 */
273 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
274 = "android.app.extra.deviceAdminPackageDownloadLocation";
275
276 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100277 * A String extra holding a http cookie header which should be used in the http request to the
278 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
279 *
280 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
281 * provisioning via an Nfc bump.
282 */
283 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
284 = "android.app.extra.deviceAdminPackageDownloadCookieHeader";
285
286 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100287 * A String extra holding the SHA-1 checksum of the file at download location specified in
288 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
289 * the file at the download location an error will be shown to the user and the user will be
290 * asked to factory reset the device.
291 *
292 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
293 * provisioning via an Nfc bump.
294 */
295 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
296 = "android.app.extra.deviceAdminPackageChecksum";
297
298 /**
299 * This MIME type is used for starting the Device Owner provisioning.
300 *
301 * <p>During device owner provisioning a device admin app is set as the owner of the device.
302 * A device owner has full control over the device. The device owner can not be modified by the
303 * user and the only way of resetting the device is if the device owner app calls a factory
304 * reset.
305 *
306 * <p> A typical use case would be a device that is owned by a company, but used by either an
307 * employee or client.
308 *
309 * <p> The Nfc message should be send to an unprovisioned device.
310 *
311 * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which
312 * contains the following properties:
313 * <ul>
314 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
315 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100316 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100317 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
318 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
319 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
320 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
321 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
322 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
323 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
324 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
325 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
326 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
327 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
328 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
329 *
330 * <p> When device owner provisioning has completed, an intent of the type
331 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
332 * device owner.
333 *
334 * <p>
335 * If provisioning fails, the device is factory reset.
336 *
337 * <p>Input: Nothing.</p>
338 * <p>Output: Nothing</p>
339 */
340 public static final String PROVISIONING_NFC_MIME_TYPE
341 = "application/com.android.managedprovisioning";
342
343 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800344 * Activity action: ask the user to add a new device administrator to the system.
345 * The desired policy is the ComponentName of the policy in the
346 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
347 * bring the user through adding the device administrator to the system (or
348 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700349 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800350 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
351 * field to provide the user with additional explanation (in addition
352 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800353 *
354 * <p>If your administrator is already active, this will ordinarily return immediately (without
355 * user intervention). However, if your administrator has been updated and is requesting
356 * additional uses-policy flags, the user will be presented with the new list. New policies
357 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800358 */
359 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
360 public static final String ACTION_ADD_DEVICE_ADMIN
361 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700362
Dianne Hackbornd6847842010-01-12 18:14:19 -0800363 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700364 * Activity action: send when any policy admin changes a policy.
365 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700366 *
Jim Miller284b62e2010-06-08 14:27:42 -0700367 * @hide
368 */
369 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
370 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
371
372 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800373 * The ComponentName of the administrator component.
374 *
375 * @see #ACTION_ADD_DEVICE_ADMIN
376 */
377 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700378
Dianne Hackbornd6847842010-01-12 18:14:19 -0800379 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800380 * An optional CharSequence providing additional explanation for why the
381 * admin is being added.
382 *
383 * @see #ACTION_ADD_DEVICE_ADMIN
384 */
385 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700386
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800387 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700388 * Activity action: have the user enter a new password. This activity should
389 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
390 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
391 * enter a new password that meets the current requirements. You can use
392 * {@link #isActivePasswordSufficient()} to determine whether you need to
393 * have the user select a new password in order to meet the current
394 * constraints. Upon being resumed from this activity, you can check the new
395 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800396 */
397 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
398 public static final String ACTION_SET_NEW_PASSWORD
399 = "android.app.action.SET_NEW_PASSWORD";
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000400 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100401 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
402 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000403 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100404 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000405
406 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100407 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
408 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000409 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100410 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700411
Dianne Hackbornd6847842010-01-12 18:14:19 -0800412 /**
413 * Return true if the given administrator component is currently
414 * active (enabled) in the system.
415 */
416 public boolean isAdminActive(ComponentName who) {
417 if (mService != null) {
418 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700419 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800420 } catch (RemoteException e) {
421 Log.w(TAG, "Failed talking with device policy service", e);
422 }
423 }
424 return false;
425 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700426
Dianne Hackbornd6847842010-01-12 18:14:19 -0800427 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800428 * Return a list of all currently active device administrator's component
429 * names. Note that if there are no administrators than null may be
430 * returned.
431 */
432 public List<ComponentName> getActiveAdmins() {
433 if (mService != null) {
434 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700435 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800436 } catch (RemoteException e) {
437 Log.w(TAG, "Failed talking with device policy service", e);
438 }
439 }
440 return null;
441 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700442
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800443 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700444 * Used by package administration code to determine if a package can be stopped
445 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800446 * @hide
447 */
448 public boolean packageHasActiveAdmins(String packageName) {
449 if (mService != null) {
450 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700451 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800452 } catch (RemoteException e) {
453 Log.w(TAG, "Failed talking with device policy service", e);
454 }
455 }
456 return false;
457 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700458
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800459 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800460 * Remove a current administration component. This can only be called
461 * by the application that owns the administration component; if you
462 * try to remove someone else's component, a security exception will be
463 * thrown.
464 */
465 public void removeActiveAdmin(ComponentName who) {
466 if (mService != null) {
467 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700468 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800469 } catch (RemoteException e) {
470 Log.w(TAG, "Failed talking with device policy service", e);
471 }
472 }
473 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700474
Dianne Hackbornd6847842010-01-12 18:14:19 -0800475 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800476 * Returns true if an administrator has been granted a particular device policy. This can
477 * be used to check if the administrator was activated under an earlier set of policies,
478 * but requires additional policies after an upgrade.
479 *
480 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
481 * an active administrator, or an exception will be thrown.
482 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
483 */
484 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
485 if (mService != null) {
486 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700487 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800488 } catch (RemoteException e) {
489 Log.w(TAG, "Failed talking with device policy service", e);
490 }
491 }
492 return false;
493 }
494
495 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800496 * Constant for {@link #setPasswordQuality}: the policy has no requirements
497 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800498 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800499 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800500 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700501
Dianne Hackbornd6847842010-01-12 18:14:19 -0800502 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700503 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
504 * recognition technology. This implies technologies that can recognize the identity of
505 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
506 * Note that quality constants are ordered so that higher values are more restrictive.
507 */
508 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
509
510 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800511 * Constant for {@link #setPasswordQuality}: the policy requires some kind
512 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800513 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800514 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800515 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700516
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800517 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800518 * Constant for {@link #setPasswordQuality}: the user must have entered a
519 * password containing at least numeric characters. Note that quality
520 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800521 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800522 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700523
Dianne Hackbornd6847842010-01-12 18:14:19 -0800524 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800525 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800526 * password containing at least numeric characters with no repeating (4444)
527 * or ordered (1234, 4321, 2468) sequences. Note that quality
528 * constants are ordered so that higher values are more restrictive.
529 */
530 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
531
532 /**
533 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700534 * password containing at least alphabetic (or other symbol) characters.
535 * Note that quality constants are ordered so that higher values are more
536 * restrictive.
537 */
538 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700539
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700540 /**
541 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800542 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700543 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800544 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800545 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700546 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700547
Dianne Hackbornd6847842010-01-12 18:14:19 -0800548 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700549 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700550 * password containing at least a letter, a numerical digit and a special
551 * symbol, by default. With this password quality, passwords can be
552 * restricted to contain various sets of characters, like at least an
553 * uppercase letter, etc. These are specified using various methods,
554 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
555 * that quality constants are ordered so that higher values are more
556 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700557 */
558 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
559
560 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800561 * Called by an application that is administering the device to set the
562 * password restrictions it is imposing. After setting this, the user
563 * will not be able to enter a new password that is not at least as
564 * restrictive as what has been set. Note that the current password
565 * will remain until the user has set a new one, so the change does not
566 * take place immediately. To prompt the user for a new password, use
567 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700568 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800569 * <p>Quality constants are ordered so that higher values are more restrictive;
570 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800571 * the user's preference, and any other considerations) is the one that
572 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700573 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800574 * <p>The calling device admin must have requested
575 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
576 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700577 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800578 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800579 * @param quality The new desired quality. One of
580 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800581 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
582 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
583 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800584 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800585 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800586 if (mService != null) {
587 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700588 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800589 } catch (RemoteException e) {
590 Log.w(TAG, "Failed talking with device policy service", e);
591 }
592 }
593 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700594
Dianne Hackbornd6847842010-01-12 18:14:19 -0800595 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100596 * Retrieve the current minimum password quality for all admins of this user
597 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800598 * @param admin The name of the admin component to check, or null to aggregate
599 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800600 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800601 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700602 return getPasswordQuality(admin, UserHandle.myUserId());
603 }
604
605 /** @hide per-user version */
606 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800607 if (mService != null) {
608 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700609 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800610 } catch (RemoteException e) {
611 Log.w(TAG, "Failed talking with device policy service", e);
612 }
613 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800614 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800615 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700616
Dianne Hackbornd6847842010-01-12 18:14:19 -0800617 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800618 * Called by an application that is administering the device to set the
619 * minimum allowed password length. After setting this, the user
620 * will not be able to enter a new password that is not at least as
621 * restrictive as what has been set. Note that the current password
622 * will remain until the user has set a new one, so the change does not
623 * take place immediately. To prompt the user for a new password, use
624 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
625 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800626 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
627 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
628 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700629 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800630 * <p>The calling device admin must have requested
631 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
632 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700633 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800635 * @param length The new desired minimum password length. A value of 0
636 * means there is no restriction.
637 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800638 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800639 if (mService != null) {
640 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700641 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800642 } catch (RemoteException e) {
643 Log.w(TAG, "Failed talking with device policy service", e);
644 }
645 }
646 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700647
Dianne Hackbornd6847842010-01-12 18:14:19 -0800648 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100649 * Retrieve the current minimum password length for all admins of this
650 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800651 * @param admin The name of the admin component to check, or null to aggregate
652 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800653 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800654 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700655 return getPasswordMinimumLength(admin, UserHandle.myUserId());
656 }
657
658 /** @hide per-user version */
659 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800660 if (mService != null) {
661 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700662 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800663 } catch (RemoteException e) {
664 Log.w(TAG, "Failed talking with device policy service", e);
665 }
666 }
667 return 0;
668 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700669
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700670 /**
671 * Called by an application that is administering the device to set the
672 * minimum number of upper case letters required in the password. After
673 * setting this, the user will not be able to enter a new password that is
674 * not at least as restrictive as what has been set. Note that the current
675 * password will remain until the user has set a new one, so the change does
676 * not take place immediately. To prompt the user for a new password, use
677 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
678 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700679 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
680 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700681 * <p>
682 * The calling device admin must have requested
683 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
684 * this method; if it has not, a security exception will be thrown.
685 *
686 * @param admin Which {@link DeviceAdminReceiver} this request is associated
687 * with.
688 * @param length The new desired minimum number of upper case letters
689 * required in the password. A value of 0 means there is no
690 * restriction.
691 */
692 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
693 if (mService != null) {
694 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700695 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700696 } catch (RemoteException e) {
697 Log.w(TAG, "Failed talking with device policy service", e);
698 }
699 }
700 }
701
702 /**
703 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100704 * password for all admins of this user and its profiles or a particular one.
705 * This is the same value as set by
706 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700707 * and only applies when the password quality is
708 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700709 *
710 * @param admin The name of the admin component to check, or null to
711 * aggregate all admins.
712 * @return The minimum number of upper case letters required in the
713 * password.
714 */
715 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700716 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
717 }
718
719 /** @hide per-user version */
720 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700721 if (mService != null) {
722 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700723 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700724 } catch (RemoteException e) {
725 Log.w(TAG, "Failed talking with device policy service", e);
726 }
727 }
728 return 0;
729 }
730
731 /**
732 * Called by an application that is administering the device to set the
733 * minimum number of lower case letters required in the password. After
734 * setting this, the user will not be able to enter a new password that is
735 * not at least as restrictive as what has been set. Note that the current
736 * password will remain until the user has set a new one, so the change does
737 * not take place immediately. To prompt the user for a new password, use
738 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
739 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700740 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
741 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700742 * <p>
743 * The calling device admin must have requested
744 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
745 * this method; if it has not, a security exception will be thrown.
746 *
747 * @param admin Which {@link DeviceAdminReceiver} this request is associated
748 * with.
749 * @param length The new desired minimum number of lower case letters
750 * required in the password. A value of 0 means there is no
751 * restriction.
752 */
753 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
754 if (mService != null) {
755 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700756 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700757 } catch (RemoteException e) {
758 Log.w(TAG, "Failed talking with device policy service", e);
759 }
760 }
761 }
762
763 /**
764 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100765 * password for all admins of this user and its profiles or a particular one.
766 * This is the same value as set by
767 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700768 * and only applies when the password quality is
769 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700770 *
771 * @param admin The name of the admin component to check, or null to
772 * aggregate all admins.
773 * @return The minimum number of lower case letters required in the
774 * password.
775 */
776 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700777 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
778 }
779
780 /** @hide per-user version */
781 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700782 if (mService != null) {
783 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700784 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700785 } catch (RemoteException e) {
786 Log.w(TAG, "Failed talking with device policy service", e);
787 }
788 }
789 return 0;
790 }
791
792 /**
793 * Called by an application that is administering the device to set the
794 * minimum number of letters required in the password. After setting this,
795 * the user will not be able to enter a new password that is not at least as
796 * restrictive as what has been set. Note that the current password will
797 * remain until the user has set a new one, so the change does not take
798 * place immediately. To prompt the user for a new password, use
799 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
800 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700801 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
802 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700803 * <p>
804 * The calling device admin must have requested
805 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
806 * this method; if it has not, a security exception will be thrown.
807 *
808 * @param admin Which {@link DeviceAdminReceiver} this request is associated
809 * with.
810 * @param length The new desired minimum number of letters required in the
811 * password. A value of 0 means there is no restriction.
812 */
813 public void setPasswordMinimumLetters(ComponentName admin, int length) {
814 if (mService != null) {
815 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700816 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700817 } catch (RemoteException e) {
818 Log.w(TAG, "Failed talking with device policy service", e);
819 }
820 }
821 }
822
823 /**
824 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700825 * admins or a particular one. This is the same value as
826 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
827 * and only applies when the password quality is
828 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700829 *
830 * @param admin The name of the admin component to check, or null to
831 * aggregate all admins.
832 * @return The minimum number of letters required in the password.
833 */
834 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700835 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
836 }
837
838 /** @hide per-user version */
839 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700840 if (mService != null) {
841 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700842 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700843 } catch (RemoteException e) {
844 Log.w(TAG, "Failed talking with device policy service", e);
845 }
846 }
847 return 0;
848 }
849
850 /**
851 * Called by an application that is administering the device to set the
852 * minimum number of numerical digits required in the password. After
853 * setting this, the user will not be able to enter a new password that is
854 * not at least as restrictive as what has been set. Note that the current
855 * password will remain until the user has set a new one, so the change does
856 * not take place immediately. To prompt the user for a new password, use
857 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
858 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700859 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
860 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700861 * <p>
862 * The calling device admin must have requested
863 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
864 * this method; if it has not, a security exception will be thrown.
865 *
866 * @param admin Which {@link DeviceAdminReceiver} this request is associated
867 * with.
868 * @param length The new desired minimum number of numerical digits required
869 * in the password. A value of 0 means there is no restriction.
870 */
871 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
872 if (mService != null) {
873 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700874 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700875 } catch (RemoteException e) {
876 Log.w(TAG, "Failed talking with device policy service", e);
877 }
878 }
879 }
880
881 /**
882 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100883 * for all admins of this user and its profiles or a particular one.
884 * This is the same value as set by
885 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700886 * and only applies when the password quality is
887 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700888 *
889 * @param admin The name of the admin component to check, or null to
890 * aggregate all admins.
891 * @return The minimum number of numerical digits required in the password.
892 */
893 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700894 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
895 }
896
897 /** @hide per-user version */
898 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700899 if (mService != null) {
900 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700901 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700902 } catch (RemoteException e) {
903 Log.w(TAG, "Failed talking with device policy service", e);
904 }
905 }
906 return 0;
907 }
908
909 /**
910 * Called by an application that is administering the device to set the
911 * minimum number of symbols required in the password. After setting this,
912 * the user will not be able to enter a new password that is not at least as
913 * restrictive as what has been set. Note that the current password will
914 * remain until the user has set a new one, so the change does not take
915 * place immediately. To prompt the user for a new password, use
916 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
917 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700918 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
919 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700920 * <p>
921 * The calling device admin must have requested
922 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
923 * this method; if it has not, a security exception will be thrown.
924 *
925 * @param admin Which {@link DeviceAdminReceiver} this request is associated
926 * with.
927 * @param length The new desired minimum number of symbols required in the
928 * password. A value of 0 means there is no restriction.
929 */
930 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
931 if (mService != null) {
932 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700933 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700934 } catch (RemoteException e) {
935 Log.w(TAG, "Failed talking with device policy service", e);
936 }
937 }
938 }
939
940 /**
941 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700942 * admins or a particular one. This is the same value as
943 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
944 * and only applies when the password quality is
945 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700946 *
947 * @param admin The name of the admin component to check, or null to
948 * aggregate all admins.
949 * @return The minimum number of symbols required in the password.
950 */
951 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700952 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
953 }
954
955 /** @hide per-user version */
956 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700957 if (mService != null) {
958 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700959 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700960 } catch (RemoteException e) {
961 Log.w(TAG, "Failed talking with device policy service", e);
962 }
963 }
964 return 0;
965 }
966
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700967 /**
968 * Called by an application that is administering the device to set the
969 * minimum number of non-letter characters (numerical digits or symbols)
970 * required in the password. After setting this, the user will not be able
971 * to enter a new password that is not at least as restrictive as what has
972 * been set. Note that the current password will remain until the user has
973 * set a new one, so the change does not take place immediately. To prompt
974 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
975 * setting this value. This constraint is only imposed if the administrator
976 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
977 * {@link #setPasswordQuality}. The default value is 0.
978 * <p>
979 * The calling device admin must have requested
980 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
981 * this method; if it has not, a security exception will be thrown.
982 *
983 * @param admin Which {@link DeviceAdminReceiver} this request is associated
984 * with.
985 * @param length The new desired minimum number of letters required in the
986 * password. A value of 0 means there is no restriction.
987 */
988 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
989 if (mService != null) {
990 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700991 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700992 } catch (RemoteException e) {
993 Log.w(TAG, "Failed talking with device policy service", e);
994 }
995 }
996 }
997
998 /**
999 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001000 * password for all admins of this user and its profiles or a particular one.
1001 * This is the same value as set by
1002 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001003 * and only applies when the password quality is
1004 * {@link #PASSWORD_QUALITY_COMPLEX}.
1005 *
1006 * @param admin The name of the admin component to check, or null to
1007 * aggregate all admins.
1008 * @return The minimum number of letters required in the password.
1009 */
1010 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001011 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1012 }
1013
1014 /** @hide per-user version */
1015 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001016 if (mService != null) {
1017 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001018 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001019 } catch (RemoteException e) {
1020 Log.w(TAG, "Failed talking with device policy service", e);
1021 }
1022 }
1023 return 0;
1024 }
1025
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001026 /**
1027 * Called by an application that is administering the device to set the length
1028 * of the password history. After setting this, the user will not be able to
1029 * enter a new password that is the same as any password in the history. Note
1030 * that the current password will remain until the user has set a new one, so
1031 * the change does not take place immediately. To prompt the user for a new
1032 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1033 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001034 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1035 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1036 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001037 *
1038 * <p>
1039 * The calling device admin must have requested
1040 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1041 * method; if it has not, a security exception will be thrown.
1042 *
1043 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1044 * with.
1045 * @param length The new desired length of password history. A value of 0
1046 * means there is no restriction.
1047 */
1048 public void setPasswordHistoryLength(ComponentName admin, int length) {
1049 if (mService != null) {
1050 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001051 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001052 } catch (RemoteException e) {
1053 Log.w(TAG, "Failed talking with device policy service", e);
1054 }
1055 }
1056 }
1057
1058 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001059 * Called by a device admin to set the password expiration timeout. Calling this method
1060 * will restart the countdown for password expiration for the given admin, as will changing
1061 * the device password (for all admins).
1062 *
1063 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1064 * For example, to have the password expire 5 days from now, timeout would be
1065 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1066 *
1067 * <p>To disable password expiration, a value of 0 may be used for timeout.
1068 *
Jim Millera4e28d12010-11-08 16:15:47 -08001069 * <p>The calling device admin must have requested
1070 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1071 * method; if it has not, a security exception will be thrown.
1072 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001073 * <p> Note that setting the password will automatically reset the expiration time for all
1074 * active admins. Active admins do not need to explicitly call this method in that case.
1075 *
Jim Millera4e28d12010-11-08 16:15:47 -08001076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1077 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1078 * means there is no restriction (unlimited).
1079 */
1080 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1081 if (mService != null) {
1082 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001083 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001084 } catch (RemoteException e) {
1085 Log.w(TAG, "Failed talking with device policy service", e);
1086 }
1087 }
1088 }
1089
1090 /**
Jim Miller6b857682011-02-16 16:27:41 -08001091 * Get the password expiration timeout for the given admin. The expiration timeout is the
1092 * recurring expiration timeout provided in the call to
1093 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1094 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001095 *
1096 * @param admin The name of the admin component to check, or null to aggregate all admins.
1097 * @return The timeout for the given admin or the minimum of all timeouts
1098 */
1099 public long getPasswordExpirationTimeout(ComponentName admin) {
1100 if (mService != null) {
1101 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001102 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001103 } catch (RemoteException e) {
1104 Log.w(TAG, "Failed talking with device policy service", e);
1105 }
1106 }
1107 return 0;
1108 }
1109
1110 /**
1111 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001112 * all admins of this user and its profiles if admin is null. If the password is
1113 * expired, this will return the time since the password expired as a negative number.
1114 * If admin is null, then a composite of all expiration timeouts is returned
1115 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001116 *
1117 * @param admin The name of the admin component to check, or null to aggregate all admins.
1118 * @return The password expiration time, in ms.
1119 */
1120 public long getPasswordExpiration(ComponentName admin) {
1121 if (mService != null) {
1122 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001123 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001124 } catch (RemoteException e) {
1125 Log.w(TAG, "Failed talking with device policy service", e);
1126 }
1127 }
1128 return 0;
1129 }
1130
1131 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001132 * Retrieve the current password history length for all admins of this
1133 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001134 * @param admin The name of the admin component to check, or null to aggregate
1135 * all admins.
1136 * @return The length of the password history
1137 */
1138 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001139 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1140 }
1141
1142 /** @hide per-user version */
1143 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001144 if (mService != null) {
1145 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001146 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001147 } catch (RemoteException e) {
1148 Log.w(TAG, "Failed talking with device policy service", e);
1149 }
1150 }
1151 return 0;
1152 }
1153
Dianne Hackbornd6847842010-01-12 18:14:19 -08001154 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001155 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001156 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001157 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001158 * @return Returns the maximum length that the user can enter.
1159 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001160 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001161 // Kind-of arbitrary.
1162 return 16;
1163 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001164
Dianne Hackborn254cb442010-01-27 19:23:59 -08001165 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001166 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001167 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001168 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001169 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001170 * <p>The calling device admin must have requested
1171 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1172 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001173 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001174 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001175 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001176 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001177 if (mService != null) {
1178 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001179 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001180 } catch (RemoteException e) {
1181 Log.w(TAG, "Failed talking with device policy service", e);
1182 }
1183 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001184 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001185 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001186
Dianne Hackbornd6847842010-01-12 18:14:19 -08001187 /**
1188 * Retrieve the number of times the user has failed at entering a
1189 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001190 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001191 * <p>The calling device admin must have requested
1192 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1193 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001194 */
1195 public int getCurrentFailedPasswordAttempts() {
1196 if (mService != null) {
1197 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001198 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001199 } catch (RemoteException e) {
1200 Log.w(TAG, "Failed talking with device policy service", e);
1201 }
1202 }
1203 return -1;
1204 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001205
1206 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001207 * Setting this to a value greater than zero enables a built-in policy
1208 * that will perform a device wipe after too many incorrect
1209 * device-unlock passwords have been entered. This built-in policy combines
1210 * watching for failed passwords and wiping the device, and requires
1211 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001212 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001213 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001214 * <p>To implement any other policy (e.g. wiping data for a particular
1215 * application only, erasing or revoking credentials, or reporting the
1216 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001217 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001218 * instead. Do not use this API, because if the maximum count is reached,
1219 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001220 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001221 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001222 * @param num The number of failed password attempts at which point the
1223 * device will wipe its data.
1224 */
1225 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1226 if (mService != null) {
1227 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001228 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001229 } catch (RemoteException e) {
1230 Log.w(TAG, "Failed talking with device policy service", e);
1231 }
1232 }
1233 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001234
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001235 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001236 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001237 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001238 * or a particular one.
1239 * @param admin The name of the admin component to check, or null to aggregate
1240 * all admins.
1241 */
1242 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001243 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1244 }
1245
1246 /** @hide per-user version */
1247 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001248 if (mService != null) {
1249 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001250 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001251 } catch (RemoteException e) {
1252 Log.w(TAG, "Failed talking with device policy service", e);
1253 }
1254 }
1255 return 0;
1256 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001257
Dianne Hackborn254cb442010-01-27 19:23:59 -08001258 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001259 * Flag for {@link #resetPassword}: don't allow other admins to change
1260 * the password again until the user has entered it.
1261 */
1262 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001263
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001264 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001265 * Force a new device unlock password (the password needed to access the
1266 * entire device, not for individual accounts) on the user. This takes
1267 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001268 * The given password must be sufficient for the
1269 * current password quality and length constraints as returned by
1270 * {@link #getPasswordQuality(ComponentName)} and
1271 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1272 * these constraints, then it will be rejected and false returned. Note
1273 * that the password may be a stronger quality (containing alphanumeric
1274 * characters when the requested quality is only numeric), in which case
1275 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001276 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001277 * <p>The calling device admin must have requested
1278 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1279 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001280 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001281 * Can not be called from a managed profile.
1282 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001283 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001284 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001285 * @return Returns true if the password was applied, or false if it is
1286 * not acceptable for the current constraints.
1287 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001288 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001289 if (mService != null) {
1290 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001291 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001292 } catch (RemoteException e) {
1293 Log.w(TAG, "Failed talking with device policy service", e);
1294 }
1295 }
1296 return false;
1297 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001298
Dianne Hackbornd6847842010-01-12 18:14:19 -08001299 /**
1300 * Called by an application that is administering the device to set the
1301 * maximum time for user activity until the device will lock. This limits
1302 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001303 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001304 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001305 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001306 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001307 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001308 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001309 * @param timeMs The new desired maximum time to lock in milliseconds.
1310 * A value of 0 means there is no restriction.
1311 */
1312 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1313 if (mService != null) {
1314 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001315 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001316 } catch (RemoteException e) {
1317 Log.w(TAG, "Failed talking with device policy service", e);
1318 }
1319 }
1320 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001321
Dianne Hackbornd6847842010-01-12 18:14:19 -08001322 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001323 * Retrieve the current maximum time to unlock for all admins of this user
1324 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001325 * @param admin The name of the admin component to check, or null to aggregate
1326 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001327 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001328 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001329 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1330 }
1331
1332 /** @hide per-user version */
1333 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001334 if (mService != null) {
1335 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001336 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001337 } catch (RemoteException e) {
1338 Log.w(TAG, "Failed talking with device policy service", e);
1339 }
1340 }
1341 return 0;
1342 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001343
Dianne Hackbornd6847842010-01-12 18:14:19 -08001344 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001345 * Make the device lock immediately, as if the lock screen timeout has
1346 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001347 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001348 * <p>The calling device admin must have requested
1349 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1350 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001351 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001352 public void lockNow() {
1353 if (mService != null) {
1354 try {
1355 mService.lockNow();
1356 } catch (RemoteException e) {
1357 Log.w(TAG, "Failed talking with device policy service", e);
1358 }
1359 }
1360 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001361
Dianne Hackbornd6847842010-01-12 18:14:19 -08001362 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001363 * Flag for {@link #wipeData(int)}: also erase the device's external
1364 * storage.
1365 */
1366 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1367
1368 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001369 * Ask the user data be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001370 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001371 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1372 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001373 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001374 * <p>The calling device admin must have requested
1375 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1376 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001377 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001378 * @param flags Bit mask of additional options: currently 0 and
1379 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001380 */
1381 public void wipeData(int flags) {
1382 if (mService != null) {
1383 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001384 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001385 } catch (RemoteException e) {
1386 Log.w(TAG, "Failed talking with device policy service", e);
1387 }
1388 }
1389 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001390
Dianne Hackbornd6847842010-01-12 18:14:19 -08001391 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001392 * Called by an application that is administering the device to set the
1393 * global proxy and exclusion list.
1394 * <p>
1395 * The calling device admin must have requested
1396 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1397 * this method; if it has not, a security exception will be thrown.
1398 * Only the first device admin can set the proxy. If a second admin attempts
1399 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1400 * proxy will be returned. If successful in setting the proxy, null will
1401 * be returned.
1402 * The method can be called repeatedly by the device admin alrady setting the
1403 * proxy to update the proxy and exclusion list.
1404 *
1405 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1406 * with.
1407 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1408 * Pass Proxy.NO_PROXY to reset the proxy.
1409 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001410 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1411 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001412 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001413 */
1414 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1415 List<String> exclusionList ) {
1416 if (proxySpec == null) {
1417 throw new NullPointerException();
1418 }
1419 if (mService != null) {
1420 try {
1421 String hostSpec;
1422 String exclSpec;
1423 if (proxySpec.equals(Proxy.NO_PROXY)) {
1424 hostSpec = null;
1425 exclSpec = null;
1426 } else {
1427 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1428 throw new IllegalArgumentException();
1429 }
1430 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1431 String hostName = sa.getHostName();
1432 int port = sa.getPort();
1433 StringBuilder hostBuilder = new StringBuilder();
1434 hostSpec = hostBuilder.append(hostName)
1435 .append(":").append(Integer.toString(port)).toString();
1436 if (exclusionList == null) {
1437 exclSpec = "";
1438 } else {
1439 StringBuilder listBuilder = new StringBuilder();
1440 boolean firstDomain = true;
1441 for (String exclDomain : exclusionList) {
1442 if (!firstDomain) {
1443 listBuilder = listBuilder.append(",");
1444 } else {
1445 firstDomain = false;
1446 }
1447 listBuilder = listBuilder.append(exclDomain.trim());
1448 }
1449 exclSpec = listBuilder.toString();
1450 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001451 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1452 != android.net.Proxy.PROXY_VALID)
1453 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001454 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001455 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001456 } catch (RemoteException e) {
1457 Log.w(TAG, "Failed talking with device policy service", e);
1458 }
1459 }
1460 return null;
1461 }
1462
1463 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001464 * Set a network-independent global HTTP proxy. This is not normally what you want
1465 * for typical HTTP proxies - they are generally network dependent. However if you're
1466 * doing something unusual like general internal filtering this may be useful. On
1467 * a private network where the proxy is not accessible, you may break HTTP using this.
1468 *
1469 * <p>This method requires the caller to be the device owner.
1470 *
1471 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1472 * @see ProxyInfo
1473 *
1474 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1475 * with.
1476 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1477 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1478 */
1479 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1480 if (mService != null) {
1481 try {
1482 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1483 } catch (RemoteException e) {
1484 Log.w(TAG, "Failed talking with device policy service", e);
1485 }
1486 }
1487 }
1488
1489 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001490 * Returns the component name setting the global proxy.
1491 * @return ComponentName object of the device admin that set the global proxy, or
1492 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001493 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001494 */
1495 public ComponentName getGlobalProxyAdmin() {
1496 if (mService != null) {
1497 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001498 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001499 } catch (RemoteException e) {
1500 Log.w(TAG, "Failed talking with device policy service", e);
1501 }
1502 }
1503 return null;
1504 }
1505
1506 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001507 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001508 * indicating that encryption is not supported.
1509 */
1510 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1511
1512 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001513 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001514 * indicating that encryption is supported, but is not currently active.
1515 */
1516 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1517
1518 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001519 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001520 * indicating that encryption is not currently active, but is currently
1521 * being activated. This is only reported by devices that support
1522 * encryption of data and only when the storage is currently
1523 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1524 * to become encrypted will never return this value.
1525 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001526 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001527
1528 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001529 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001530 * indicating that encryption is active.
1531 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001532 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001533
1534 /**
1535 * Activity action: begin the process of encrypting data on the device. This activity should
1536 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1537 * After resuming from this activity, use {@link #getStorageEncryption}
1538 * to check encryption status. However, on some devices this activity may never return, as
1539 * it may trigger a reboot and in some cases a complete data wipe of the device.
1540 */
1541 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1542 public static final String ACTION_START_ENCRYPTION
1543 = "android.app.action.START_ENCRYPTION";
1544
1545 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001546 * Widgets are enabled in keyguard
1547 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001548 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001549
1550 /**
Jim Miller50e62182014-04-23 17:25:00 -07001551 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001552 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001553 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1554
1555 /**
1556 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1557 */
1558 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1559
1560 /**
Jim Miller50e62182014-04-23 17:25:00 -07001561 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1562 */
1563 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1564
1565 /**
1566 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1567 */
1568 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1569
1570 /**
1571 * Ignore {@link TrustAgentService} state on secure keyguard screens
1572 * (e.g. PIN/Pattern/Password).
1573 */
1574 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1575
1576 /**
Jim Miller06e34502014-07-17 14:46:05 -07001577 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1578 */
1579 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1580
1581 /**
Jim Miller35207742012-11-02 15:33:20 -07001582 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001583 */
1584 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001585
1586 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001587 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001588 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001589 *
1590 * <p>When multiple device administrators attempt to control device
1591 * encryption, the most secure, supported setting will always be
1592 * used. If any device administrator requests device encryption,
1593 * it will be enabled; Conversely, if a device administrator
1594 * attempts to disable device encryption while another
1595 * device administrator has enabled it, the call to disable will
1596 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1597 *
1598 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001599 * written to other storage areas may or may not be encrypted, and this policy does not require
1600 * or control the encryption of any other storage areas.
1601 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1602 * {@code true}, then the directory returned by
1603 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1604 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001605 *
1606 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1607 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1608 * the encryption key may not be fully secured. For maximum security, the administrator should
1609 * also require (and check for) a pattern, PIN, or password.
1610 *
1611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1612 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001613 * @return the new request status (for all active admins) - will be one of
1614 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1615 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1616 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001617 */
1618 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1619 if (mService != null) {
1620 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001621 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001622 } catch (RemoteException e) {
1623 Log.w(TAG, "Failed talking with device policy service", e);
1624 }
1625 }
1626 return ENCRYPTION_STATUS_UNSUPPORTED;
1627 }
1628
1629 /**
1630 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001631 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001632 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1634 * this will return the requested encryption setting as an aggregate of all active
1635 * administrators.
1636 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001637 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001638 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001639 if (mService != null) {
1640 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001641 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001642 } catch (RemoteException e) {
1643 Log.w(TAG, "Failed talking with device policy service", e);
1644 }
1645 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001646 return false;
1647 }
1648
1649 /**
1650 * Called by an application that is administering the device to
1651 * determine the current encryption status of the device.
1652 *
1653 * Depending on the returned status code, the caller may proceed in different
1654 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1655 * storage system does not support encryption. If the
1656 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1657 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1658 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1659 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1660 *
1661 * @return current status of encryption. The value will be one of
1662 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1663 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1664 */
1665 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001666 return getStorageEncryptionStatus(UserHandle.myUserId());
1667 }
1668
1669 /** @hide per-user version */
1670 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001671 if (mService != null) {
1672 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001673 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001674 } catch (RemoteException e) {
1675 Log.w(TAG, "Failed talking with device policy service", e);
1676 }
1677 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001678 return ENCRYPTION_STATUS_UNSUPPORTED;
1679 }
1680
1681 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001682 * Installs the given certificate as a User CA.
1683 *
1684 * @return false if the certBuffer cannot be parsed or installation is
1685 * interrupted, otherwise true
Maggie Benthallda51e682013-08-08 22:35:44 -04001686 */
Robin Lee306fe082014-06-19 14:04:24 +00001687 public boolean installCaCert(ComponentName who, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001688 if (mService != null) {
1689 try {
Robin Lee306fe082014-06-19 14:04:24 +00001690 return mService.installCaCert(who, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001691 } catch (RemoteException e) {
1692 Log.w(TAG, "Failed talking with device policy service", e);
1693 }
1694 }
1695 return false;
1696 }
1697
1698 /**
1699 * Uninstalls the given certificate from the list of User CAs, if present.
Maggie Benthallda51e682013-08-08 22:35:44 -04001700 */
Robin Lee306fe082014-06-19 14:04:24 +00001701 public void uninstallCaCert(ComponentName who, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001702 if (mService != null) {
1703 try {
Robin Lee306fe082014-06-19 14:04:24 +00001704 final String alias = getCaCertAlias(certBuffer);
1705 mService.uninstallCaCert(who, alias);
1706 } catch (CertificateException e) {
1707 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001708 } catch (RemoteException e) {
1709 Log.w(TAG, "Failed talking with device policy service", e);
1710 }
1711 }
1712 }
1713
1714 /**
1715 * Returns whether there are any user-installed CA certificates.
Maggie Benthallda51e682013-08-08 22:35:44 -04001716 */
Robin Lee306fe082014-06-19 14:04:24 +00001717 public boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001718 TrustedCertificateStore certStore = new TrustedCertificateStore();
1719 Set<String> aliases = certStore.userAliases();
1720 return aliases != null && !aliases.isEmpty();
1721 }
1722
1723 /**
1724 * Returns whether this certificate has been installed as a User CA.
Maggie Benthallda51e682013-08-08 22:35:44 -04001725 */
1726 public boolean hasCaCertInstalled(byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001727 try {
Robin Lee306fe082014-06-19 14:04:24 +00001728 return getCaCertAlias(certBuffer) != null;
Maggie Benthallda51e682013-08-08 22:35:44 -04001729 } catch (CertificateException ce) {
1730 Log.w(TAG, "Could not parse certificate", ce);
1731 }
1732 return false;
1733 }
1734
1735 /**
Robin Lee306fe082014-06-19 14:04:24 +00001736 * Returns the alias of a given CA certificate in the certificate store, or null if it
1737 * doesn't exist.
1738 */
1739 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1740 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1741 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1742 new ByteArrayInputStream(certBuffer));
1743 return new TrustedCertificateStore().getCertificateAlias(cert);
1744 }
1745
1746 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001747 * Called by an application that is administering the device to disable all cameras
1748 * on the device. After setting this, no applications will be able to access any cameras
1749 * on the device.
1750 *
1751 * <p>The calling device admin must have requested
1752 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1753 * this method; if it has not, a security exception will be thrown.
1754 *
1755 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1756 * @param disabled Whether or not the camera should be disabled.
1757 */
1758 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1759 if (mService != null) {
1760 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001761 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001762 } catch (RemoteException e) {
1763 Log.w(TAG, "Failed talking with device policy service", e);
1764 }
1765 }
1766 }
1767
1768 /**
1769 * Determine whether or not the device's cameras have been disabled either by the current
1770 * admin, if specified, or all admins.
1771 * @param admin The name of the admin component to check, or null to check if any admins
1772 * have disabled the camera
1773 */
1774 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001775 return getCameraDisabled(admin, UserHandle.myUserId());
1776 }
1777
1778 /** @hide per-user version */
1779 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001780 if (mService != null) {
1781 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001782 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001783 } catch (RemoteException e) {
1784 Log.w(TAG, "Failed talking with device policy service", e);
1785 }
1786 }
1787 return false;
1788 }
1789
1790 /**
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001791 * Called by a device/profile owner to set whether the screen capture is disabled.
1792 *
1793 * <p>The calling device admin must be a device or profile owner. If it is not, a
1794 * security exception will be thrown.
1795 *
1796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1797 */
1798 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
1799 if (mService != null) {
1800 try {
1801 mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled);
1802 } catch (RemoteException e) {
1803 Log.w(TAG, "Failed talking with device policy service", e);
1804 }
1805 }
1806 }
1807
1808 /**
1809 * Determine whether or not screen capture has been disabled by the current
1810 * admin, if specified, or all admins.
1811 * @param admin The name of the admin component to check, or null to check if any admins
1812 * have disabled screen capture.
1813 */
1814 public boolean getScreenCaptureDisabled(ComponentName admin) {
1815 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
1816 }
1817
1818 /** @hide per-user version */
1819 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
1820 if (mService != null) {
1821 try {
1822 return mService.getScreenCaptureDisabled(admin, userHandle);
1823 } catch (RemoteException e) {
1824 Log.w(TAG, "Failed talking with device policy service", e);
1825 }
1826 }
1827 return false;
1828 }
1829
1830 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001831 * Called by an application that is administering the device to disable keyguard customizations,
1832 * such as widgets. After setting this, keyguard features will be disabled according to the
1833 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001834 *
1835 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001836 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001837 * this method; if it has not, a security exception will be thrown.
1838 *
1839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001840 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1841 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001842 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1843 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001844 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001845 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001846 if (mService != null) {
1847 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001848 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001849 } catch (RemoteException e) {
1850 Log.w(TAG, "Failed talking with device policy service", e);
1851 }
1852 }
1853 }
1854
1855 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001856 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001857 * admin, if specified, or all admins.
1858 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001859 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001860 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1861 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001862 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001863 public int getKeyguardDisabledFeatures(ComponentName admin) {
1864 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001865 }
1866
1867 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001868 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001869 if (mService != null) {
1870 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001871 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001872 } catch (RemoteException e) {
1873 Log.w(TAG, "Failed talking with device policy service", e);
1874 }
1875 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001876 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001877 }
1878
1879 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001880 * @hide
1881 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001882 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001883 if (mService != null) {
1884 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001885 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001886 } catch (RemoteException e) {
1887 Log.w(TAG, "Failed talking with device policy service", e);
1888 }
1889 }
1890 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001891
Dianne Hackbornd6847842010-01-12 18:14:19 -08001892 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001893 * @hide
1894 */
1895 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1896 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1897 }
1898
1899 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001900 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001901 * @hide
1902 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001903 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001904 ActivityInfo ai;
1905 try {
1906 ai = mContext.getPackageManager().getReceiverInfo(cn,
1907 PackageManager.GET_META_DATA);
1908 } catch (PackageManager.NameNotFoundException e) {
1909 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1910 return null;
1911 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001912
Dianne Hackbornd6847842010-01-12 18:14:19 -08001913 ResolveInfo ri = new ResolveInfo();
1914 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001915
Dianne Hackbornd6847842010-01-12 18:14:19 -08001916 try {
1917 return new DeviceAdminInfo(mContext, ri);
1918 } catch (XmlPullParserException e) {
1919 Log.w(TAG, "Unable to parse device policy " + cn, e);
1920 return null;
1921 } catch (IOException e) {
1922 Log.w(TAG, "Unable to parse device policy " + cn, e);
1923 return null;
1924 }
1925 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001926
Dianne Hackbornd6847842010-01-12 18:14:19 -08001927 /**
1928 * @hide
1929 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001930 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1931 if (mService != null) {
1932 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001933 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001934 } catch (RemoteException e) {
1935 Log.w(TAG, "Failed talking with device policy service", e);
1936 }
1937 }
1938 }
1939
1940 /**
1941 * @hide
1942 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001943 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001944 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001945 if (mService != null) {
1946 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001947 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001948 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001949 } catch (RemoteException e) {
1950 Log.w(TAG, "Failed talking with device policy service", e);
1951 }
1952 }
1953 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001954
Dianne Hackbornd6847842010-01-12 18:14:19 -08001955 /**
1956 * @hide
1957 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001958 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001959 if (mService != null) {
1960 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001961 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001962 } catch (RemoteException e) {
1963 Log.w(TAG, "Failed talking with device policy service", e);
1964 }
1965 }
1966 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001967
Dianne Hackbornd6847842010-01-12 18:14:19 -08001968 /**
1969 * @hide
1970 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001971 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001972 if (mService != null) {
1973 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001974 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001975 } catch (RemoteException e) {
1976 Log.w(TAG, "Failed talking with device policy service", e);
1977 }
1978 }
1979 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001980
1981 /**
1982 * @hide
1983 * Sets the given package as the device owner. The package must already be installed and there
1984 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1985 * method must be called before the device is provisioned.
1986 * @param packageName the package name of the application to be registered as the device owner.
1987 * @return whether the package was successfully registered as the device owner.
1988 * @throws IllegalArgumentException if the package name is null or invalid
1989 * @throws IllegalStateException if a device owner is already registered or the device has
1990 * already been provisioned.
1991 */
1992 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1993 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001994 return setDeviceOwner(packageName, null);
1995 }
1996
1997 /**
1998 * @hide
1999 * Sets the given package as the device owner. The package must already be installed and there
2000 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2001 * method must be called before the device is provisioned.
2002 * @param packageName the package name of the application to be registered as the device owner.
2003 * @param ownerName the human readable name of the institution that owns this device.
2004 * @return whether the package was successfully registered as the device owner.
2005 * @throws IllegalArgumentException if the package name is null or invalid
2006 * @throws IllegalStateException if a device owner is already registered or the device has
2007 * already been provisioned.
2008 */
2009 public boolean setDeviceOwner(String packageName, String ownerName)
2010 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002011 if (mService != null) {
2012 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002013 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002014 } catch (RemoteException re) {
2015 Log.w(TAG, "Failed to set device owner");
2016 }
2017 }
2018 return false;
2019 }
2020
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002021
Amith Yamasani71e6c692013-03-24 17:39:28 -07002022 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002023 * Used to determine if a particular package has been registered as a Device Owner app.
2024 * A device owner app is a special device admin that cannot be deactivated by the user, once
2025 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2026 * package is currently registered as the device owner app, pass in the package name from
2027 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2028 * admin apps that want to check if they are also registered as the device owner app. The
2029 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2030 * the setup process.
2031 * @param packageName the package name of the app, to compare with the registered device owner
2032 * app, if any.
2033 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002034 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002035 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002036 if (mService != null) {
2037 try {
2038 return mService.isDeviceOwner(packageName);
2039 } catch (RemoteException re) {
2040 Log.w(TAG, "Failed to check device owner");
2041 }
2042 }
2043 return false;
2044 }
2045
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002046 /**
2047 * @hide
2048 * Redirect to isDeviceOwnerApp.
2049 */
2050 public boolean isDeviceOwner(String packageName) {
2051 return isDeviceOwnerApp(packageName);
2052 }
2053
Jason Monkb0dced82014-06-06 14:36:20 -04002054 /**
2055 * Clears the current device owner. The caller must be the device owner.
2056 *
2057 * This function should be used cautiously as once it is called it cannot
2058 * be undone. The device owner can only be set as a part of device setup
2059 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002060 *
2061 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002062 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002063 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002064 if (mService != null) {
2065 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002066 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002067 } catch (RemoteException re) {
2068 Log.w(TAG, "Failed to clear device owner");
2069 }
2070 }
2071 }
2072
Amith Yamasani71e6c692013-03-24 17:39:28 -07002073 /** @hide */
2074 public String getDeviceOwner() {
2075 if (mService != null) {
2076 try {
2077 return mService.getDeviceOwner();
2078 } catch (RemoteException re) {
2079 Log.w(TAG, "Failed to get device owner");
2080 }
2081 }
2082 return null;
2083 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002084
2085 /** @hide */
2086 public String getDeviceOwnerName() {
2087 if (mService != null) {
2088 try {
2089 return mService.getDeviceOwnerName();
2090 } catch (RemoteException re) {
2091 Log.w(TAG, "Failed to get device owner");
2092 }
2093 }
2094 return null;
2095 }
Adam Connors776c5552014-01-09 10:42:56 +00002096
2097 /**
2098 * @hide
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302099 * Sets the given component as an active admin and registers the package as the profile
2100 * owner for this user. The package must already be installed and there shouldn't be
2101 * an existing profile owner registered for this user. Also, this method must be called
2102 * before the user setup has been completed.
2103 * <p>
2104 * This method can only be called by system apps that hold MANAGE_USERS permission and
2105 * MANAGE_DEVICE_ADMINS permission.
2106 * @param admin The component to register as an active admin and profile owner.
2107 * @param ownerName The user-visible name of the entity that is managing this user.
2108 * @return whether the admin was successfully registered as the profile owner.
2109 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2110 * the user has already been set up.
2111 */
Justin Morey80440cc2014-07-24 09:16:35 -05002112 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302113 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2114 throws IllegalArgumentException {
2115 if (mService != null) {
2116 try {
2117 final int myUserId = UserHandle.myUserId();
2118 mService.setActiveAdmin(admin, false, myUserId);
2119 return mService.setProfileOwner(admin.getPackageName(), ownerName, myUserId);
2120 } catch (RemoteException re) {
2121 Log.w(TAG, "Failed to set profile owner " + re);
2122 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2123 }
2124 }
2125 return false;
2126 }
2127
2128 /**
2129 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002130 * Sets the given package as the profile owner of the given user profile. The package must
2131 * already be installed and there shouldn't be an existing profile owner registered for this
2132 * user. Also, this method must be called before the user has been used for the first time.
2133 * @param packageName the package name of the application to be registered as profile owner.
2134 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002135 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002136 * @return whether the package was successfully registered as the profile owner.
2137 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2138 * the user has already been set up.
2139 */
Adam Connors661ec472014-02-11 13:59:46 +00002140 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002141 throws IllegalArgumentException {
2142 if (mService != null) {
2143 try {
Adam Connors661ec472014-02-11 13:59:46 +00002144 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002145 } catch (RemoteException re) {
2146 Log.w(TAG, "Failed to set profile owner", re);
2147 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2148 }
2149 }
2150 return false;
2151 }
2152
2153 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002154 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2155 * be used. Only the profile owner can call this.
2156 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002157 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002158 *
2159 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2160 */
2161 public void setProfileEnabled(ComponentName admin) {
2162 if (mService != null) {
2163 try {
2164 mService.setProfileEnabled(admin);
2165 } catch (RemoteException e) {
2166 Log.w(TAG, "Failed talking with device policy service", e);
2167 }
2168 }
2169 }
2170
2171 /**
Jessica Hummel1333ea12014-06-23 11:20:10 +01002172 * Sets the name of the Managed profile. In the device owner case it sets the name of the user
2173 * which it is called from. Only the profile owner or device owner can call this. If this is
2174 * never called by the profile or device owner, the name will be set to default values.
2175 *
2176 * @see #isProfileOwnerApp
2177 * @see #isDeviceOwnerApp
2178 *
2179 * @param profileName The name of the profile.
2180 */
2181 public void setProfileName(ComponentName who, String profileName) {
2182 if (mService != null) {
2183 try {
2184 mService.setProfileName(who, profileName);
2185 } catch (RemoteException e) {
2186 Log.w(TAG, "Failed talking with device policy service", e);
2187 }
2188 }
2189}
2190
2191 /**
Adam Connors776c5552014-01-09 10:42:56 +00002192 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002193 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00002194 * within the managed profile.
2195 *
2196 * @param packageName The package name of the app to compare with the registered profile owner.
2197 * @return Whether or not the package is registered as the profile owner.
2198 */
2199 public boolean isProfileOwnerApp(String packageName) {
2200 if (mService != null) {
2201 try {
2202 String profileOwnerPackage = mService.getProfileOwner(
2203 Process.myUserHandle().getIdentifier());
2204 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
2205 } catch (RemoteException re) {
2206 Log.w(TAG, "Failed to check profile owner");
2207 }
2208 }
2209 return false;
2210 }
2211
2212 /**
2213 * @hide
2214 * @return the packageName of the owner of the given user profile or null if no profile
2215 * owner has been set for that user.
2216 * @throws IllegalArgumentException if the userId is invalid.
2217 */
2218 public String getProfileOwner() throws IllegalArgumentException {
2219 if (mService != null) {
2220 try {
2221 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
2222 } catch (RemoteException re) {
2223 Log.w(TAG, "Failed to get profile owner");
2224 throw new IllegalArgumentException(
2225 "Requested profile owner for invalid userId", re);
2226 }
2227 }
2228 return null;
2229 }
2230
2231 /**
2232 * @hide
2233 * @return the human readable name of the organisation associated with this DPM or null if
2234 * one is not set.
2235 * @throws IllegalArgumentException if the userId is invalid.
2236 */
2237 public String getProfileOwnerName() throws IllegalArgumentException {
2238 if (mService != null) {
2239 try {
2240 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2241 } catch (RemoteException re) {
2242 Log.w(TAG, "Failed to get profile owner");
2243 throw new IllegalArgumentException(
2244 "Requested profile owner for invalid userId", re);
2245 }
2246 }
2247 return null;
2248 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002249
2250 /**
2251 * Called by a profile owner or device owner to add a default intent handler activity for
2252 * intents that match a certain intent filter. This activity will remain the default intent
2253 * handler even if the set of potential event handlers for the intent filter changes and if
2254 * the intent preferences are reset.
2255 *
2256 * <p>The default disambiguation mechanism takes over if the activity is not installed
2257 * (anymore). When the activity is (re)installed, it is automatically reset as default
2258 * intent handler for the filter.
2259 *
2260 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2261 * security exception will be thrown.
2262 *
2263 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2264 * @param filter The IntentFilter for which a default handler is added.
2265 * @param activity The Activity that is added as default intent handler.
2266 */
2267 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2268 ComponentName activity) {
2269 if (mService != null) {
2270 try {
2271 mService.addPersistentPreferredActivity(admin, filter, activity);
2272 } catch (RemoteException e) {
2273 Log.w(TAG, "Failed talking with device policy service", e);
2274 }
2275 }
2276 }
2277
2278 /**
2279 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002280 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002281 *
2282 * <p>The calling device admin must be a profile owner. If it is not, a security
2283 * exception will be thrown.
2284 *
2285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2286 * @param packageName The name of the package for which preferences are removed.
2287 */
2288 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2289 String packageName) {
2290 if (mService != null) {
2291 try {
2292 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2293 } catch (RemoteException e) {
2294 Log.w(TAG, "Failed talking with device policy service", e);
2295 }
2296 }
2297 }
Robin Lee66e5d962014-04-09 16:44:21 +01002298
2299 /**
2300 * Called by a profile or device owner to set the application restrictions for a given target
2301 * application running in the managed profile.
2302 *
2303 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Amith Yamasanic8c84252014-07-13 17:12:12 -07002304 * boolean, int, String, or String[]. The recommended format for keys
Robin Lee66e5d962014-04-09 16:44:21 +01002305 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2306 * components such as {@link android.webkit.WebView}.
2307 *
2308 * <p>The application restrictions are only made visible to the target application and the
2309 * profile or device owner.
2310 *
2311 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2312 * exception will be thrown.
2313 *
2314 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2315 * @param packageName The name of the package to update restricted settings for.
2316 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2317 * set of active restrictions.
2318 */
2319 public void setApplicationRestrictions(ComponentName admin, String packageName,
2320 Bundle settings) {
2321 if (mService != null) {
2322 try {
2323 mService.setApplicationRestrictions(admin, packageName, settings);
2324 } catch (RemoteException e) {
2325 Log.w(TAG, "Failed talking with device policy service", e);
2326 }
2327 }
2328 }
2329
2330 /**
Jim Miller604e7552014-07-18 19:00:02 -07002331 * Sets a list of features to enable for a TrustAgentService component. This is meant to be
2332 * used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which will disable all
2333 * trust agents but those with features enabled by this function call.
2334 *
2335 * <p>The calling device admin must have requested
2336 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
2337 * this method; if it has not, a security exception will be thrown.
2338 *
2339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2340 * @param agent Which component to enable features for.
2341 * @param features List of features to enable. Consult specific TrustAgent documentation for
2342 * the feature list.
2343 */
2344 public void setTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent,
2345 List<String> features) {
2346 if (mService != null) {
2347 try {
2348 mService.setTrustAgentFeaturesEnabled(admin, agent, features, UserHandle.myUserId());
2349 } catch (RemoteException e) {
2350 Log.w(TAG, "Failed talking with device policy service", e);
2351 }
2352 }
2353 }
2354
2355 /**
2356 * Gets list of enabled features for the given {@link TrustAgentService} agent. If admin is
2357 * null, this will return the intersection of all features enabled for the given agent by all
2358 * admins.
2359 *
2360 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2361 * @param agent Which component to get enabled features for.
2362 * @return List of enabled features.
2363 */
2364 public List<String> getTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent) {
2365 if (mService != null) {
2366 try {
2367 return mService.getTrustAgentFeaturesEnabled(admin, agent, UserHandle.myUserId());
2368 } catch (RemoteException e) {
2369 Log.w(TAG, "Failed talking with device policy service", e);
2370 }
2371 }
2372 return new ArrayList<String>(); // empty list
2373 }
2374
2375 /**
Adam Connors210fe212014-07-17 15:41:43 +01002376 * Called by a profile owner to set whether caller-Id information from the managed
2377 * profile will be shown for incoming calls.
2378 *
2379 * <p>The calling device admin must be a profile owner. If it is not, a
2380 * security exception will be thrown.
2381 *
2382 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2383 * @param disabled If true caller-Id information in the managed profile is not displayed.
2384 */
2385 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2386 if (mService != null) {
2387 try {
2388 mService.setCrossProfileCallerIdDisabled(who, disabled);
2389 } catch (RemoteException e) {
2390 Log.w(TAG, "Failed talking with device policy service", e);
2391 }
2392 }
2393 }
2394
2395 /**
2396 * Determine whether or not caller-Id information has been disabled.
2397 *
2398 * <p>The calling device admin must be a profile owner. If it is not, a
2399 * security exception will be thrown.
2400 *
2401 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2402 */
2403 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2404 if (mService != null) {
2405 try {
2406 return mService.getCrossProfileCallerIdDisabled(who);
2407 } catch (RemoteException e) {
2408 Log.w(TAG, "Failed talking with device policy service", e);
2409 }
2410 }
2411 return false;
2412 }
2413
2414 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002415 * Determine whether or not caller-Id information has been disabled.
2416 *
2417 * @param userHandle The user for whom to check the caller-id permission
2418 * @hide
2419 */
2420 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2421 if (mService != null) {
2422 try {
2423 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2424 } catch (RemoteException e) {
2425 Log.w(TAG, "Failed talking with device policy service", e);
2426 }
2427 }
2428 return false;
2429 }
2430
2431 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002432 * Called by the profile owner so that some intents sent in the managed profile can also be
2433 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002434 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002435 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2436 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002437 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2438 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002439 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002440 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002441 if (mService != null) {
2442 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002443 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002444 } catch (RemoteException e) {
2445 Log.w(TAG, "Failed talking with device policy service", e);
2446 }
2447 }
2448 }
2449
2450 /**
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002451 * Called by a profile owner to remove the cross-profile intent filters that go from the
2452 * managed profile to the parent, or from the parent to the managed profile.
2453 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2455 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002456 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002457 if (mService != null) {
2458 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002459 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002460 } catch (RemoteException e) {
2461 Log.w(TAG, "Failed talking with device policy service", e);
2462 }
2463 }
2464 }
2465
2466 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002467 * Called by a device owner to create a user with the specified name. The UserHandle returned
2468 * by this method should not be persisted as user handles are recycled as users are removed and
2469 * created. If you need to persist an identifier for this user, use
2470 * {@link UserManager#getSerialNumberForUser}.
2471 *
2472 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2473 * @param name the user's name
2474 * @see UserHandle
2475 * @return the UserHandle object for the created user, or null if the user could not be created.
2476 */
2477 public UserHandle createUser(ComponentName admin, String name) {
2478 try {
2479 return mService.createUser(admin, name);
2480 } catch (RemoteException re) {
2481 Log.w(TAG, "Could not create a user", re);
2482 }
2483 return null;
2484 }
2485
2486 /**
Jason Monk03978a42014-06-10 15:05:30 -04002487 * Called by a device owner to create a user with the specified name. The UserHandle returned
2488 * by this method should not be persisted as user handles are recycled as users are removed and
2489 * created. If you need to persist an identifier for this user, use
2490 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2491 * immediately.
2492 *
2493 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2494 * as registered as an active admin on the new user. The profile owner package will be
2495 * installed on the new user if it already is installed on the device.
2496 *
2497 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2498 * profileOwnerComponent when onEnable is called.
2499 *
2500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2501 * @param name the user's name
2502 * @param ownerName the human readable name of the organisation associated with this DPM.
2503 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2504 * the user.
2505 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2506 * on the new user.
2507 * @see UserHandle
2508 * @return the UserHandle object for the created user, or null if the user could not be created.
2509 */
2510 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2511 ComponentName profileOwnerComponent, Bundle adminExtras) {
2512 try {
2513 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2514 adminExtras);
2515 } catch (RemoteException re) {
2516 Log.w(TAG, "Could not create a user", re);
2517 }
2518 return null;
2519 }
2520
2521 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002522 * Called by a device owner to remove a user and all associated data. The primary user can
2523 * not be removed.
2524 *
2525 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2526 * @param userHandle the user to remove.
2527 * @return {@code true} if the user was removed, {@code false} otherwise.
2528 */
2529 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2530 try {
2531 return mService.removeUser(admin, userHandle);
2532 } catch (RemoteException re) {
2533 Log.w(TAG, "Could not remove user ", re);
2534 return false;
2535 }
2536 }
2537
2538 /**
Jason Monk582d9112014-07-09 19:57:08 -04002539 * Called by a device owner to switch the specified user to the foreground.
2540 *
2541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2542 * @param userHandle the user to switch to; null will switch to primary.
2543 * @return {@code true} if the switch was successful, {@code false} otherwise.
2544 *
2545 * @see Intent#ACTION_USER_FOREGROUND
2546 */
2547 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
2548 try {
2549 return mService.switchUser(admin, userHandle);
2550 } catch (RemoteException re) {
2551 Log.w(TAG, "Could not switch user ", re);
2552 return false;
2553 }
2554 }
2555
2556 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002557 * Called by a profile or device owner to get the application restrictions for a given target
2558 * application running in the managed profile.
2559 *
2560 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2561 * exception will be thrown.
2562 *
2563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2564 * @param packageName The name of the package to fetch restricted settings of.
2565 * @return {@link Bundle} of settings corresponding to what was set last time
2566 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2567 * if no restrictions have been set.
2568 */
2569 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2570 if (mService != null) {
2571 try {
2572 return mService.getApplicationRestrictions(admin, packageName);
2573 } catch (RemoteException e) {
2574 Log.w(TAG, "Failed talking with device policy service", e);
2575 }
2576 }
2577 return null;
2578 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002579
2580 /**
2581 * Called by a profile or device owner to set a user restriction specified
2582 * by the key.
2583 * <p>
2584 * The calling device admin must be a profile or device owner; if it is not,
2585 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002586 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002587 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2588 * with.
2589 * @param key The key of the restriction. See the constants in
2590 * {@link android.os.UserManager} for the list of keys.
2591 */
2592 public void addUserRestriction(ComponentName admin, String key) {
2593 if (mService != null) {
2594 try {
2595 mService.setUserRestriction(admin, key, true);
2596 } catch (RemoteException e) {
2597 Log.w(TAG, "Failed talking with device policy service", e);
2598 }
2599 }
2600 }
2601
2602 /**
2603 * Called by a profile or device owner to clear a user restriction specified
2604 * by the key.
2605 * <p>
2606 * The calling device admin must be a profile or device owner; if it is not,
2607 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002608 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002609 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2610 * with.
2611 * @param key The key of the restriction. See the constants in
2612 * {@link android.os.UserManager} for the list of keys.
2613 */
2614 public void clearUserRestriction(ComponentName admin, String key) {
2615 if (mService != null) {
2616 try {
2617 mService.setUserRestriction(admin, key, false);
2618 } catch (RemoteException e) {
2619 Log.w(TAG, "Failed talking with device policy service", e);
2620 }
2621 }
2622 }
Adam Connors010cfd42014-04-16 12:48:13 +01002623
2624 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002625 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04002626 * is unavailable for use, but the data and actual package file remain.
2627 *
2628 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002629 * @param packageName The name of the package to hide or unhide.
2630 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
2631 * unhidden.
2632 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04002633 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002634 public boolean setApplicationHidden(ComponentName admin, String packageName,
2635 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04002636 if (mService != null) {
2637 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002638 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04002639 } catch (RemoteException e) {
2640 Log.w(TAG, "Failed talking with device policy service", e);
2641 }
2642 }
2643 return false;
2644 }
2645
2646 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002647 * Called by profile or device owner to hide or unhide currently installed packages. This
Julia Reynolds966881e2014-05-14 12:23:08 -04002648 * should only be called by a profile or device owner running within a managed profile.
2649 *
2650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2651 * @param intent An intent matching the app(s) to be updated. All apps that resolve for this
2652 * intent will be updated in the current profile.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002653 * @param hidden {@code true} if the packages should be hidden, {@code false} if they should
2654 * be unhidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04002655 * @return int The number of activities that matched the intent and were updated.
2656 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002657 public int setApplicationsHidden(ComponentName admin, Intent intent, boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04002658 if (mService != null) {
2659 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002660 return mService.setApplicationsHidden(admin, intent, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04002661 } catch (RemoteException e) {
2662 Log.w(TAG, "Failed talking with device policy service", e);
2663 }
2664 }
2665 return 0;
2666 }
2667
2668 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002669 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04002670 *
2671 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002672 * @param packageName The name of the package to retrieve the hidden status of.
2673 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04002674 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002675 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04002676 if (mService != null) {
2677 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002678 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04002679 } catch (RemoteException e) {
2680 Log.w(TAG, "Failed talking with device policy service", e);
2681 }
2682 }
2683 return false;
2684 }
2685
2686 /**
Adam Connors655be2a2014-07-14 09:01:25 +00002687 * Called by profile or device owner to re-enable a system app that was disabled by default
2688 * when the managed profile was created. This can only be called from a profile or device
2689 * owner running within a managed profile.
2690 *
2691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2692 * @param packageName The package to be re-enabled in the current profile.
2693 */
2694 public void enableSystemApp(ComponentName admin, String packageName) {
2695 if (mService != null) {
2696 try {
2697 mService.enableSystemApp(admin, packageName);
2698 } catch (RemoteException e) {
2699 Log.w(TAG, "Failed to install package: " + packageName);
2700 }
2701 }
2702 }
2703
2704 /**
2705 * Called by profile or device owner to re-enable system apps by intent that were disabled
2706 * by default when the managed profile was created. This can only be called from a profile
2707 * or device owner running within a managed profile.
2708 *
2709 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2710 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
2711 * intent will be re-enabled in the current profile.
2712 * @return int The number of activities that matched the intent and were installed.
2713 */
2714 public int enableSystemApp(ComponentName admin, Intent intent) {
2715 if (mService != null) {
2716 try {
2717 return mService.enableSystemAppWithIntent(admin, intent);
2718 } catch (RemoteException e) {
2719 Log.w(TAG, "Failed to install packages matching filter: " + intent);
2720 }
2721 }
2722 return 0;
2723 }
2724
2725 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01002726 * Called by a profile owner to disable account management for a specific type of account.
2727 *
2728 * <p>The calling device admin must be a profile owner. If it is not, a
2729 * security exception will be thrown.
2730 *
2731 * <p>When account management is disabled for an account type, adding or removing an account
2732 * of that type will not be possible.
2733 *
2734 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2735 * @param accountType For which account management is disabled or enabled.
2736 * @param disabled The boolean indicating that account management will be disabled (true) or
2737 * enabled (false).
2738 */
2739 public void setAccountManagementDisabled(ComponentName admin, String accountType,
2740 boolean disabled) {
2741 if (mService != null) {
2742 try {
2743 mService.setAccountManagementDisabled(admin, accountType, disabled);
2744 } catch (RemoteException e) {
2745 Log.w(TAG, "Failed talking with device policy service", e);
2746 }
2747 }
2748 }
2749
2750 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002751 * Gets the array of accounts for which account management is disabled by the profile owner.
2752 *
2753 * <p> Account management can be disabled/enabled by calling
2754 * {@link #setAccountManagementDisabled}.
2755 *
2756 * @return a list of account types for which account management has been disabled.
2757 *
2758 * @see #setAccountManagementDisabled
2759 */
2760 public String[] getAccountTypesWithManagementDisabled() {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01002761 return getAccountTypesWithManagementDisabledAsUser(UserHandle.getCallingUserId());
2762 }
2763
2764 /**
2765 * @see #getAccountTypesWithManagementDisabled()
2766 * @hide
2767 */
2768 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002769 if (mService != null) {
2770 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01002771 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002772 } catch (RemoteException e) {
2773 Log.w(TAG, "Failed talking with device policy service", e);
2774 }
2775 }
2776
2777 return null;
2778 }
justinzhang511e0d82014-03-24 16:09:24 -04002779
2780 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002781 * Sets which packages may enter lock task mode.
2782 *
2783 * <p>Any packages that shares uid with an allowed package will also be allowed
2784 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04002785 *
Jason Monkc5185f22014-06-24 11:12:42 -04002786 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04002787 * @param packages The list of packages allowed to enter lock task mode
2788 *
2789 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04002790 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
2791 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04002792 */
Jason Monkd7b86212014-06-16 13:15:38 -04002793 public void setLockTaskPackages(String[] packages) throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04002794 if (mService != null) {
2795 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002796 mService.setLockTaskPackages(packages);
justinzhang511e0d82014-03-24 16:09:24 -04002797 } catch (RemoteException e) {
2798 Log.w(TAG, "Failed talking with device policy service", e);
2799 }
2800 }
2801 }
2802
2803 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002804 * This function returns the list of packages allowed to start the lock task mode.
justinzhang511e0d82014-03-24 16:09:24 -04002805 * @hide
2806 */
Jason Monkd7b86212014-06-16 13:15:38 -04002807 public String[] getLockTaskPackages() {
justinzhang511e0d82014-03-24 16:09:24 -04002808 if (mService != null) {
2809 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002810 return mService.getLockTaskPackages();
justinzhang511e0d82014-03-24 16:09:24 -04002811 } catch (RemoteException e) {
2812 Log.w(TAG, "Failed talking with device policy service", e);
2813 }
2814 }
2815 return null;
2816 }
2817
2818 /**
2819 * This function lets the caller know whether the given component is allowed to start the
2820 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04002821 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04002822 */
Jason Monkd7b86212014-06-16 13:15:38 -04002823 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04002824 if (mService != null) {
2825 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002826 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04002827 } catch (RemoteException e) {
2828 Log.w(TAG, "Failed talking with device policy service", e);
2829 }
2830 }
2831 return false;
2832 }
Julia Reynoldsda551652014-05-14 17:15:16 -04002833
2834 /**
2835 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
2836 * of the setting is in the correct form for the setting type should be performed by the caller.
2837 *
2838 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2839 * @param setting The name of the setting to update.
2840 * @param value The value to update the setting to.
2841 */
2842 public void setGlobalSetting(ComponentName admin, String setting, String value) {
2843 if (mService != null) {
2844 try {
2845 mService.setGlobalSetting(admin, setting, value);
2846 } catch (RemoteException e) {
2847 Log.w(TAG, "Failed talking with device policy service", e);
2848 }
2849 }
2850 }
2851
2852 /**
2853 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
2854 * that the value of the setting is in the correct form for the setting type should be performed
2855 * by the caller.
2856 *
2857 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2858 * @param setting The name of the setting to update.
2859 * @param value The value to update the setting to.
2860 */
2861 public void setSecureSetting(ComponentName admin, String setting, String value) {
2862 if (mService != null) {
2863 try {
2864 mService.setSecureSetting(admin, setting, value);
2865 } catch (RemoteException e) {
2866 Log.w(TAG, "Failed talking with device policy service", e);
2867 }
2868 }
2869 }
2870
Amith Yamasanif20d6402014-05-24 15:34:37 -07002871 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07002872 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07002873 * making permission requests of a local or remote administrator of the user.
2874 * <p/>
2875 * Only a profile owner can designate the restrictions provider.
2876 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07002877 * @param provider The component name of the service that implements
2878 * {@link AbstractRestrictionsProvider}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07002879 * it removes the restrictions provider previously assigned.
2880 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07002881 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07002882 if (mService != null) {
2883 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07002884 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07002885 } catch (RemoteException re) {
2886 Log.w(TAG, "Failed to set permission provider on device policy service");
2887 }
2888 }
2889 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04002890
2891 /**
2892 * Called by profile or device owners to set the master volume mute on or off.
2893 *
2894 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2895 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
2896 */
2897 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
2898 if (mService != null) {
2899 try {
2900 mService.setMasterVolumeMuted(admin, on);
2901 } catch (RemoteException re) {
2902 Log.w(TAG, "Failed to setMasterMute on device policy service");
2903 }
2904 }
2905 }
2906
2907 /**
2908 * Called by profile or device owners to check whether the master volume mute is on or off.
2909 *
2910 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2911 * @return {@code true} if master volume is muted, {@code false} if it's not.
2912 */
2913 public boolean isMasterVolumeMuted(ComponentName admin) {
2914 if (mService != null) {
2915 try {
2916 return mService.isMasterVolumeMuted(admin);
2917 } catch (RemoteException re) {
2918 Log.w(TAG, "Failed to get isMasterMute on device policy service");
2919 }
2920 }
2921 return false;
2922 }
Kenny Guyc13053b2014-05-29 14:17:17 +01002923
2924 /**
2925 * Called by profile or device owners to change whether a user can uninstall
2926 * a package.
2927 *
2928 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2929 * @param packageName package to change.
2930 * @param blockUninstall true if the user shouldn't be able to uninstall the package.
2931 */
2932 public void setBlockUninstall(ComponentName admin, String packageName, boolean blockUninstall) {
2933 if (mService != null) {
2934 try {
2935 mService.setBlockUninstall(admin, packageName, blockUninstall);
2936 } catch (RemoteException re) {
2937 Log.w(TAG, "Failed to call block uninstall on device policy service");
2938 }
2939 }
2940 }
2941
2942 /**
2943 * Called by profile or device owners to check whether a user has been blocked from
2944 * uninstalling a package.
2945 *
2946 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2947 * @param packageName package to check.
2948 * @return true if the user shouldn't be able to uninstall the package.
2949 */
2950 public boolean getBlockUninstall(ComponentName admin, String packageName) {
2951 if (mService != null) {
2952 try {
2953 return mService.getBlockUninstall(admin, packageName);
2954 } catch (RemoteException re) {
2955 Log.w(TAG, "Failed to call block uninstall on device policy service");
2956 }
2957 }
2958 return false;
2959 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08002960}