blob: df51ff5fed7bd38fe4bc84ad9dcfddd87b3af505 [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;
Jason Monkd7b86212014-06-16 13:15:38 -040021import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080022import android.content.ComponentName;
23import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010024import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000025import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080026import android.content.pm.ActivityInfo;
27import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Amith Yamasanif20d6402014-05-24 15:34:37 -070029import android.content.RestrictionsManager;
Julia Reynolds4a21b252014-06-04 11:11:43 -040030import android.media.AudioService;
Jason Monk03bc9912014-05-13 09:44:57 -040031import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010032import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.os.Handler;
Adam Connors776c5552014-01-09 10:42:56 +000034import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080035import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080036import android.os.RemoteException;
37import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070038import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040039import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040040import android.provider.Settings;
Jim Miller50e62182014-04-23 17:25:00 -070041import android.service.trust.TrustAgentService;
Dianne Hackbornd6847842010-01-12 18:14:19 -080042import android.util.Log;
43
Maggie Benthallda51e682013-08-08 22:35:44 -040044import com.android.org.conscrypt.TrustedCertificateStore;
45
Jessica Hummel91da58d2014-04-10 17:39:43 +010046import org.xmlpull.v1.XmlPullParserException;
47
Maggie Benthallda51e682013-08-08 22:35:44 -040048import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080049import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070050import java.net.InetSocketAddress;
51import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040052import java.security.cert.CertificateException;
53import java.security.cert.CertificateFactory;
54import java.security.cert.X509Certificate;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080055import java.util.List;
Maggie Benthallda51e682013-08-08 22:35:44 -040056import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080057
58/**
59 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080060 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080061 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080062 *
63 * <div class="special reference">
64 * <h3>Developer Guides</h3>
65 * <p>For more information about managing policies for device adminstration, read the
66 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
67 * developer guide.</p>
68 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080069 */
70public class DevicePolicyManager {
71 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080072
73 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080074 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070075
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080076 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080077 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080078 mService = IDevicePolicyManager.Stub.asInterface(
79 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
80 }
81
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080082 /** @hide */
83 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080084 DevicePolicyManager me = new DevicePolicyManager(context, handler);
85 return me.mService != null ? me : null;
86 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070087
Dianne Hackbornd6847842010-01-12 18:14:19 -080088 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +010089 * Activity action: Used to indicate that the receiving activity is being started as part of the
90 * managed profile provisioning flow. This intent is typically sent to a mobile device
91 * management application (mdm) after the first part of the provisioning process is complete in
92 * the expectation that this app will (after optionally showing it's own UI) ultimately call
93 * {@link #ACTION_PROVISION_MANAGED_PROFILE} to complete the creation of the managed profile.
94 *
95 * <p> The intent may contain the extras {@link #EXTRA_PROVISIONING_TOKEN} and
96 * {@link #EXTRA_PROVISIONING_EMAIL_ADDRESS}.
97 */
98 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
99 public static final String ACTION_SEND_PROVISIONING_VALUES
100 = "android.app.action.ACTION_SEND_PROVISIONING_VALUES";
101
102 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000103 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000104 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100105 * <p>A managed profile allows data separation for example for the usage of a
106 * device as a personal and corporate device. The user which provisioning is started from and
107 * the managed profile share a launcher.
108 *
109 * <p>This intent will typically be sent by a mobile device management application (mdm).
110 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
111 * control over the profile
112 *
113 * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}
114 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000115 *
116 * <p> When managed provisioning has completed, an intent of the type
117 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100118 * managed profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100119 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100120 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
121 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000122 *
123 * <p>Input: Nothing.</p>
124 * <p>Output: Nothing</p>
125 */
126 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
127 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000128 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000129
130 /**
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100131 * A broadcast intent with this action can be sent to ManagedProvisionning to specify that the
132 * user has already consented to the creation of the managed profile.
133 * The intent must contain the extras
134 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} and
135 * {@link #EXTRA_PROVISIONING_TOKEN}
136 * @hide
137 */
138 public static final String ACTION_PROVISIONING_USER_HAS_CONSENTED
Nicolas Prevotfb8a98d2014-06-10 17:59:27 +0100139 = "android.app.action.ACTION_PROVISIONING_USER_HAS_CONSENTED";
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100140
141 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100142 * A String extra holding the package name of the mobile device management application that
143 * will be set as the profile owner or device owner.
144 *
145 * <p>If an application starts provisioning directly via an intent with action
146 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
147 * application that started provisioning. The package will be set as profile owner in that case.
148 *
149 * <p>This package is set as device owner when device owner provisioning is started by an Nfc
150 * message containing an Nfc record with MIME type {@link #PROVISIONING_NFC_MIME_TYPE}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000151 */
152 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100153 = "android.app.extra.deviceAdminPackageName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000154
155 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100156 * An int extra used to identify that during the current setup process the user has already
157 * consented to setting up a managed profile. This is typically received by
158 * a mobile device management application when it is started with
159 * {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
160 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. The
161 * token indicates that steps asking for user consent can be skipped as the user has previously
162 * consented.
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100163 */
164 public static final String EXTRA_PROVISIONING_TOKEN
165 = "android.app.extra.token";
166
167 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000168 * A String extra holding the default name of the profile that is created during managed profile
169 * provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100170 *
Jessica Hummelf72078b2014-03-06 16:13:12 +0000171 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
172 */
173 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100174 = "android.app.extra.defaultManagedProfileName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000175
176 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100177 * A String extra holding the email address of the profile that is created during managed
178 * profile provisioning. This is typically received by a mobile management application when it
179 * is started with {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
180 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. It
181 * is eventually passed on in an intent
182 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
183 */
184 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
185 = "android.app.extra.ManagedProfileEmailAddress";
186
187 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100188 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
189 * will be set to.
190 *
191 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
192 * provisioning via an Nfc bump.
193 */
194 public static final String EXTRA_PROVISIONING_TIME_ZONE
195 = "android.app.extra.timeZone";
196
197 /**
198 * A Long extra holding the local time {@link android.app.AlarmManager} that the device
199 * will be set to.
200 *
201 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
202 * provisioning via an Nfc bump.
203 */
204 public static final String EXTRA_PROVISIONING_LOCAL_TIME
205 = "android.app.extra.localTime";
206
207 /**
208 * A String extra holding the {@link java.util.Locale} that the device will be set to.
209 * Format: xx_yy, where xx is the language code, and yy the country code.
210 *
211 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
212 * provisioning via an Nfc bump.
213 */
214 public static final String EXTRA_PROVISIONING_LOCALE
215 = "android.app.extra.locale";
216
217 /**
218 * A String extra holding the ssid of the wifi network that should be used during nfc device
219 * owner provisioning for downloading the mobile device management application.
220 *
221 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
222 * provisioning via an Nfc bump.
223 */
224 public static final String EXTRA_PROVISIONING_WIFI_SSID
225 = "android.app.extra.wifiSsid";
226
227 /**
228 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
229 * is hidden or not.
230 *
231 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
232 * provisioning via an Nfc bump.
233 */
234 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
235 = "android.app.extra.wifiHidden";
236
237 /**
238 * A String extra indicating the security type of the wifi network in
239 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
240 *
241 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
242 * provisioning via an Nfc bump.
243 */
244 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
245 = "android.app.extra.wifiSecurityType";
246
247 /**
248 * A String extra holding the password of the wifi network in
249 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
250 *
251 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
252 * provisioning via an Nfc bump.
253 */
254 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
255 = "android.app.extra.wifiPassword";
256
257 /**
258 * A String extra holding the proxy host for the wifi network in
259 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
260 *
261 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
262 * provisioning via an Nfc bump.
263 */
264 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
265 = "android.app.extra.wifiProxyHost";
266
267 /**
268 * An int extra holding the proxy port for the wifi network in
269 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
270 *
271 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
272 * provisioning via an Nfc bump.
273 */
274 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
275 = "android.app.extra.wifiProxyPort";
276
277 /**
278 * A String extra holding the proxy bypass for the wifi network in
279 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
280 *
281 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
282 * provisioning via an Nfc bump.
283 */
284 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
285 = "android.app.extra.wifiProxyBypassHosts";
286
287 /**
288 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
289 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
290 *
291 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
292 * provisioning via an Nfc bump.
293 */
294 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
295 = "android.app.extra.wifiPacUrl";
296
297 /**
298 * A String extra holding a url that specifies the download location of the device admin
299 * package. When not provided it is assumed that the device admin package is already installed.
300 *
301 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
302 * provisioning via an Nfc bump.
303 */
304 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
305 = "android.app.extra.deviceAdminPackageDownloadLocation";
306
307 /**
308 * A String extra holding the SHA-1 checksum of the file at download location specified in
309 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
310 * the file at the download location an error will be shown to the user and the user will be
311 * asked to factory reset the device.
312 *
313 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
314 * provisioning via an Nfc bump.
315 */
316 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
317 = "android.app.extra.deviceAdminPackageChecksum";
318
319 /**
320 * This MIME type is used for starting the Device Owner provisioning.
321 *
322 * <p>During device owner provisioning a device admin app is set as the owner of the device.
323 * A device owner has full control over the device. The device owner can not be modified by the
324 * user and the only way of resetting the device is if the device owner app calls a factory
325 * reset.
326 *
327 * <p> A typical use case would be a device that is owned by a company, but used by either an
328 * employee or client.
329 *
330 * <p> The Nfc message should be send to an unprovisioned device.
331 *
332 * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which
333 * contains the following properties:
334 * <ul>
335 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
336 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
337 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
338 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
339 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
340 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
341 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
342 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
343 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
344 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
345 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
346 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
347 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
348 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
349 *
350 * <p> When device owner provisioning has completed, an intent of the type
351 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
352 * device owner.
353 *
354 * <p>
355 * If provisioning fails, the device is factory reset.
356 *
357 * <p>Input: Nothing.</p>
358 * <p>Output: Nothing</p>
359 */
360 public static final String PROVISIONING_NFC_MIME_TYPE
361 = "application/com.android.managedprovisioning";
362
363 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800364 * Activity action: ask the user to add a new device administrator to the system.
365 * The desired policy is the ComponentName of the policy in the
366 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
367 * bring the user through adding the device administrator to the system (or
368 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700369 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800370 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
371 * field to provide the user with additional explanation (in addition
372 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800373 *
374 * <p>If your administrator is already active, this will ordinarily return immediately (without
375 * user intervention). However, if your administrator has been updated and is requesting
376 * additional uses-policy flags, the user will be presented with the new list. New policies
377 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800378 */
379 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
380 public static final String ACTION_ADD_DEVICE_ADMIN
381 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700382
Dianne Hackbornd6847842010-01-12 18:14:19 -0800383 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700384 * Activity action: send when any policy admin changes a policy.
385 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700386 *
Jim Miller284b62e2010-06-08 14:27:42 -0700387 * @hide
388 */
389 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
390 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
391
392 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800393 * The ComponentName of the administrator component.
394 *
395 * @see #ACTION_ADD_DEVICE_ADMIN
396 */
397 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700398
Dianne Hackbornd6847842010-01-12 18:14:19 -0800399 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800400 * An optional CharSequence providing additional explanation for why the
401 * admin is being added.
402 *
403 * @see #ACTION_ADD_DEVICE_ADMIN
404 */
405 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700406
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800407 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700408 * Activity action: have the user enter a new password. This activity should
409 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
410 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
411 * enter a new password that meets the current requirements. You can use
412 * {@link #isActivePasswordSufficient()} to determine whether you need to
413 * have the user select a new password in order to meet the current
414 * constraints. Upon being resumed from this activity, you can check the new
415 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800416 */
417 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
418 public static final String ACTION_SET_NEW_PASSWORD
419 = "android.app.action.SET_NEW_PASSWORD";
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000420 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100421 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
422 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000423 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100424 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000425
426 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100427 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
428 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000429 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100430 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700431
Dianne Hackbornd6847842010-01-12 18:14:19 -0800432 /**
433 * Return true if the given administrator component is currently
434 * active (enabled) in the system.
435 */
436 public boolean isAdminActive(ComponentName who) {
437 if (mService != null) {
438 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700439 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800440 } catch (RemoteException e) {
441 Log.w(TAG, "Failed talking with device policy service", e);
442 }
443 }
444 return false;
445 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700446
Dianne Hackbornd6847842010-01-12 18:14:19 -0800447 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800448 * Return a list of all currently active device administrator's component
449 * names. Note that if there are no administrators than null may be
450 * returned.
451 */
452 public List<ComponentName> getActiveAdmins() {
453 if (mService != null) {
454 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700455 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800456 } catch (RemoteException e) {
457 Log.w(TAG, "Failed talking with device policy service", e);
458 }
459 }
460 return null;
461 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700462
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800463 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700464 * Used by package administration code to determine if a package can be stopped
465 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800466 * @hide
467 */
468 public boolean packageHasActiveAdmins(String packageName) {
469 if (mService != null) {
470 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700471 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800472 } catch (RemoteException e) {
473 Log.w(TAG, "Failed talking with device policy service", e);
474 }
475 }
476 return false;
477 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700478
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800479 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800480 * Remove a current administration component. This can only be called
481 * by the application that owns the administration component; if you
482 * try to remove someone else's component, a security exception will be
483 * thrown.
484 */
485 public void removeActiveAdmin(ComponentName who) {
486 if (mService != null) {
487 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700488 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800489 } catch (RemoteException e) {
490 Log.w(TAG, "Failed talking with device policy service", e);
491 }
492 }
493 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700494
Dianne Hackbornd6847842010-01-12 18:14:19 -0800495 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800496 * Returns true if an administrator has been granted a particular device policy. This can
497 * be used to check if the administrator was activated under an earlier set of policies,
498 * but requires additional policies after an upgrade.
499 *
500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
501 * an active administrator, or an exception will be thrown.
502 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
503 */
504 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
505 if (mService != null) {
506 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700507 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800508 } catch (RemoteException e) {
509 Log.w(TAG, "Failed talking with device policy service", e);
510 }
511 }
512 return false;
513 }
514
515 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800516 * Constant for {@link #setPasswordQuality}: the policy has no requirements
517 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800518 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800519 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800520 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700521
Dianne Hackbornd6847842010-01-12 18:14:19 -0800522 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700523 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
524 * recognition technology. This implies technologies that can recognize the identity of
525 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
526 * Note that quality constants are ordered so that higher values are more restrictive.
527 */
528 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
529
530 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800531 * Constant for {@link #setPasswordQuality}: the policy requires some kind
532 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800533 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800534 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800535 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700536
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800537 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800538 * Constant for {@link #setPasswordQuality}: the user must have entered a
539 * password containing at least numeric characters. Note that quality
540 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800541 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800542 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700543
Dianne Hackbornd6847842010-01-12 18:14:19 -0800544 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800545 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700546 * password containing at least alphabetic (or other symbol) characters.
547 * Note that quality constants are ordered so that higher values are more
548 * restrictive.
549 */
550 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700551
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700552 /**
553 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800554 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700555 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800556 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800557 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700558 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700559
Dianne Hackbornd6847842010-01-12 18:14:19 -0800560 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700561 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700562 * password containing at least a letter, a numerical digit and a special
563 * symbol, by default. With this password quality, passwords can be
564 * restricted to contain various sets of characters, like at least an
565 * uppercase letter, etc. These are specified using various methods,
566 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
567 * that quality constants are ordered so that higher values are more
568 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700569 */
570 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
571
572 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800573 * Called by an application that is administering the device to set the
574 * password restrictions it is imposing. After setting this, the user
575 * will not be able to enter a new password that is not at least as
576 * restrictive as what has been set. Note that the current password
577 * will remain until the user has set a new one, so the change does not
578 * take place immediately. To prompt the user for a new password, use
579 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700580 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800581 * <p>Quality constants are ordered so that higher values are more restrictive;
582 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800583 * the user's preference, and any other considerations) is the one that
584 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700585 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800586 * <p>The calling device admin must have requested
587 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
588 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700589 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800590 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800591 * @param quality The new desired quality. One of
592 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700593 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700594 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800595 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800596 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800597 if (mService != null) {
598 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700599 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800600 } catch (RemoteException e) {
601 Log.w(TAG, "Failed talking with device policy service", e);
602 }
603 }
604 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700605
Dianne Hackbornd6847842010-01-12 18:14:19 -0800606 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100607 * Retrieve the current minimum password quality for all admins of this user
608 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800609 * @param admin The name of the admin component to check, or null to aggregate
610 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800611 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800612 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700613 return getPasswordQuality(admin, UserHandle.myUserId());
614 }
615
616 /** @hide per-user version */
617 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800618 if (mService != null) {
619 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700620 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800621 } catch (RemoteException e) {
622 Log.w(TAG, "Failed talking with device policy service", e);
623 }
624 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800625 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800626 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700627
Dianne Hackbornd6847842010-01-12 18:14:19 -0800628 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800629 * Called by an application that is administering the device to set the
630 * minimum allowed password length. After setting this, the user
631 * will not be able to enter a new password that is not at least as
632 * restrictive as what has been set. Note that the current password
633 * will remain until the user has set a new one, so the change does not
634 * take place immediately. To prompt the user for a new password, use
635 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
636 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700637 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
638 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800639 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700640 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800641 * <p>The calling device admin must have requested
642 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
643 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700644 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800645 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800646 * @param length The new desired minimum password length. A value of 0
647 * means there is no restriction.
648 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800649 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800650 if (mService != null) {
651 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700652 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800653 } catch (RemoteException e) {
654 Log.w(TAG, "Failed talking with device policy service", e);
655 }
656 }
657 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700658
Dianne Hackbornd6847842010-01-12 18:14:19 -0800659 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100660 * Retrieve the current minimum password length for all admins of this
661 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800662 * @param admin The name of the admin component to check, or null to aggregate
663 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800664 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800665 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700666 return getPasswordMinimumLength(admin, UserHandle.myUserId());
667 }
668
669 /** @hide per-user version */
670 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800671 if (mService != null) {
672 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700673 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800674 } catch (RemoteException e) {
675 Log.w(TAG, "Failed talking with device policy service", e);
676 }
677 }
678 return 0;
679 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700680
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700681 /**
682 * Called by an application that is administering the device to set the
683 * minimum number of upper case letters required in the password. After
684 * setting this, the user will not be able to enter a new password that is
685 * not at least as restrictive as what has been set. Note that the current
686 * password will remain until the user has set a new one, so the change does
687 * not take place immediately. To prompt the user for a new password, use
688 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
689 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700690 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
691 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700692 * <p>
693 * The calling device admin must have requested
694 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
695 * this method; if it has not, a security exception will be thrown.
696 *
697 * @param admin Which {@link DeviceAdminReceiver} this request is associated
698 * with.
699 * @param length The new desired minimum number of upper case letters
700 * required in the password. A value of 0 means there is no
701 * restriction.
702 */
703 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
704 if (mService != null) {
705 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700706 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700707 } catch (RemoteException e) {
708 Log.w(TAG, "Failed talking with device policy service", e);
709 }
710 }
711 }
712
713 /**
714 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100715 * password for all admins of this user and its profiles or a particular one.
716 * This is the same value as set by
717 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700718 * and only applies when the password quality is
719 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700720 *
721 * @param admin The name of the admin component to check, or null to
722 * aggregate all admins.
723 * @return The minimum number of upper case letters required in the
724 * password.
725 */
726 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700727 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
728 }
729
730 /** @hide per-user version */
731 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700732 if (mService != null) {
733 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700734 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700735 } catch (RemoteException e) {
736 Log.w(TAG, "Failed talking with device policy service", e);
737 }
738 }
739 return 0;
740 }
741
742 /**
743 * Called by an application that is administering the device to set the
744 * minimum number of lower case letters required in the password. After
745 * setting this, the user will not be able to enter a new password that is
746 * not at least as restrictive as what has been set. Note that the current
747 * password will remain until the user has set a new one, so the change does
748 * not take place immediately. To prompt the user for a new password, use
749 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
750 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700751 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
752 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700753 * <p>
754 * The calling device admin must have requested
755 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
756 * this method; if it has not, a security exception will be thrown.
757 *
758 * @param admin Which {@link DeviceAdminReceiver} this request is associated
759 * with.
760 * @param length The new desired minimum number of lower case letters
761 * required in the password. A value of 0 means there is no
762 * restriction.
763 */
764 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
765 if (mService != null) {
766 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700767 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700768 } catch (RemoteException e) {
769 Log.w(TAG, "Failed talking with device policy service", e);
770 }
771 }
772 }
773
774 /**
775 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100776 * password for all admins of this user and its profiles or a particular one.
777 * This is the same value as set by
778 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700779 * and only applies when the password quality is
780 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700781 *
782 * @param admin The name of the admin component to check, or null to
783 * aggregate all admins.
784 * @return The minimum number of lower case letters required in the
785 * password.
786 */
787 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700788 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
789 }
790
791 /** @hide per-user version */
792 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700793 if (mService != null) {
794 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700795 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700796 } catch (RemoteException e) {
797 Log.w(TAG, "Failed talking with device policy service", e);
798 }
799 }
800 return 0;
801 }
802
803 /**
804 * Called by an application that is administering the device to set the
805 * minimum number of letters required in the password. After setting this,
806 * the user will not be able to enter a new password that is not at least as
807 * restrictive as what has been set. Note that the current password will
808 * remain until the user has set a new one, so the change does not take
809 * place immediately. To prompt the user for a new password, use
810 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
811 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700812 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
813 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700814 * <p>
815 * The calling device admin must have requested
816 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
817 * this method; if it has not, a security exception will be thrown.
818 *
819 * @param admin Which {@link DeviceAdminReceiver} this request is associated
820 * with.
821 * @param length The new desired minimum number of letters required in the
822 * password. A value of 0 means there is no restriction.
823 */
824 public void setPasswordMinimumLetters(ComponentName admin, int length) {
825 if (mService != null) {
826 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700827 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700828 } catch (RemoteException e) {
829 Log.w(TAG, "Failed talking with device policy service", e);
830 }
831 }
832 }
833
834 /**
835 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700836 * admins or a particular one. This is the same value as
837 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
838 * and only applies when the password quality is
839 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700840 *
841 * @param admin The name of the admin component to check, or null to
842 * aggregate all admins.
843 * @return The minimum number of letters required in the password.
844 */
845 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700846 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
847 }
848
849 /** @hide per-user version */
850 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700851 if (mService != null) {
852 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700853 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700854 } catch (RemoteException e) {
855 Log.w(TAG, "Failed talking with device policy service", e);
856 }
857 }
858 return 0;
859 }
860
861 /**
862 * Called by an application that is administering the device to set the
863 * minimum number of numerical digits required in the password. After
864 * setting this, the user will not be able to enter a new password that is
865 * not at least as restrictive as what has been set. Note that the current
866 * password will remain until the user has set a new one, so the change does
867 * not take place immediately. To prompt the user for a new password, use
868 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
869 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700870 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
871 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700872 * <p>
873 * The calling device admin must have requested
874 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
875 * this method; if it has not, a security exception will be thrown.
876 *
877 * @param admin Which {@link DeviceAdminReceiver} this request is associated
878 * with.
879 * @param length The new desired minimum number of numerical digits required
880 * in the password. A value of 0 means there is no restriction.
881 */
882 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
883 if (mService != null) {
884 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700885 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700886 } catch (RemoteException e) {
887 Log.w(TAG, "Failed talking with device policy service", e);
888 }
889 }
890 }
891
892 /**
893 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100894 * for all admins of this user and its profiles or a particular one.
895 * This is the same value as set by
896 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700897 * and only applies when the password quality is
898 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700899 *
900 * @param admin The name of the admin component to check, or null to
901 * aggregate all admins.
902 * @return The minimum number of numerical digits required in the password.
903 */
904 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700905 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
906 }
907
908 /** @hide per-user version */
909 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700910 if (mService != null) {
911 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700912 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700913 } catch (RemoteException e) {
914 Log.w(TAG, "Failed talking with device policy service", e);
915 }
916 }
917 return 0;
918 }
919
920 /**
921 * Called by an application that is administering the device to set the
922 * minimum number of symbols required in the password. After setting this,
923 * the user will not be able to enter a new password that is not at least as
924 * restrictive as what has been set. Note that the current password will
925 * remain until the user has set a new one, so the change does not take
926 * place immediately. To prompt the user for a new password, use
927 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
928 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700929 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
930 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700931 * <p>
932 * The calling device admin must have requested
933 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
934 * this method; if it has not, a security exception will be thrown.
935 *
936 * @param admin Which {@link DeviceAdminReceiver} this request is associated
937 * with.
938 * @param length The new desired minimum number of symbols required in the
939 * password. A value of 0 means there is no restriction.
940 */
941 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
942 if (mService != null) {
943 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700944 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700945 } catch (RemoteException e) {
946 Log.w(TAG, "Failed talking with device policy service", e);
947 }
948 }
949 }
950
951 /**
952 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700953 * admins or a particular one. This is the same value as
954 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
955 * and only applies when the password quality is
956 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700957 *
958 * @param admin The name of the admin component to check, or null to
959 * aggregate all admins.
960 * @return The minimum number of symbols required in the password.
961 */
962 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700963 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
964 }
965
966 /** @hide per-user version */
967 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700968 if (mService != null) {
969 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700970 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700971 } catch (RemoteException e) {
972 Log.w(TAG, "Failed talking with device policy service", e);
973 }
974 }
975 return 0;
976 }
977
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700978 /**
979 * Called by an application that is administering the device to set the
980 * minimum number of non-letter characters (numerical digits or symbols)
981 * required in the password. After setting this, the user will not be able
982 * to enter a new password that is not at least as restrictive as what has
983 * been set. Note that the current password will remain until the user has
984 * set a new one, so the change does not take place immediately. To prompt
985 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
986 * setting this value. This constraint is only imposed if the administrator
987 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
988 * {@link #setPasswordQuality}. The default value is 0.
989 * <p>
990 * The calling device admin must have requested
991 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
992 * this method; if it has not, a security exception will be thrown.
993 *
994 * @param admin Which {@link DeviceAdminReceiver} this request is associated
995 * with.
996 * @param length The new desired minimum number of letters required in the
997 * password. A value of 0 means there is no restriction.
998 */
999 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1000 if (mService != null) {
1001 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001002 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001003 } catch (RemoteException e) {
1004 Log.w(TAG, "Failed talking with device policy service", e);
1005 }
1006 }
1007 }
1008
1009 /**
1010 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001011 * password for all admins of this user and its profiles or a particular one.
1012 * This is the same value as set by
1013 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001014 * and only applies when the password quality is
1015 * {@link #PASSWORD_QUALITY_COMPLEX}.
1016 *
1017 * @param admin The name of the admin component to check, or null to
1018 * aggregate all admins.
1019 * @return The minimum number of letters required in the password.
1020 */
1021 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001022 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1023 }
1024
1025 /** @hide per-user version */
1026 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001027 if (mService != null) {
1028 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001029 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001030 } catch (RemoteException e) {
1031 Log.w(TAG, "Failed talking with device policy service", e);
1032 }
1033 }
1034 return 0;
1035 }
1036
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001037 /**
1038 * Called by an application that is administering the device to set the length
1039 * of the password history. After setting this, the user will not be able to
1040 * enter a new password that is the same as any password in the history. Note
1041 * that the current password will remain until the user has set a new one, so
1042 * the change does not take place immediately. To prompt the user for a new
1043 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1044 * This constraint is only imposed if the administrator has also requested
1045 * either {@link #PASSWORD_QUALITY_NUMERIC},
1046 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
1047 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
1048 *
1049 * <p>
1050 * The calling device admin must have requested
1051 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1052 * method; if it has not, a security exception will be thrown.
1053 *
1054 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1055 * with.
1056 * @param length The new desired length of password history. A value of 0
1057 * means there is no restriction.
1058 */
1059 public void setPasswordHistoryLength(ComponentName admin, int length) {
1060 if (mService != null) {
1061 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001062 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001063 } catch (RemoteException e) {
1064 Log.w(TAG, "Failed talking with device policy service", e);
1065 }
1066 }
1067 }
1068
1069 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001070 * Called by a device admin to set the password expiration timeout. Calling this method
1071 * will restart the countdown for password expiration for the given admin, as will changing
1072 * the device password (for all admins).
1073 *
1074 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1075 * For example, to have the password expire 5 days from now, timeout would be
1076 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1077 *
1078 * <p>To disable password expiration, a value of 0 may be used for timeout.
1079 *
Jim Millera4e28d12010-11-08 16:15:47 -08001080 * <p>The calling device admin must have requested
1081 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1082 * method; if it has not, a security exception will be thrown.
1083 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001084 * <p> Note that setting the password will automatically reset the expiration time for all
1085 * active admins. Active admins do not need to explicitly call this method in that case.
1086 *
Jim Millera4e28d12010-11-08 16:15:47 -08001087 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1088 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1089 * means there is no restriction (unlimited).
1090 */
1091 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1092 if (mService != null) {
1093 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001094 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001095 } catch (RemoteException e) {
1096 Log.w(TAG, "Failed talking with device policy service", e);
1097 }
1098 }
1099 }
1100
1101 /**
Jim Miller6b857682011-02-16 16:27:41 -08001102 * Get the password expiration timeout for the given admin. The expiration timeout is the
1103 * recurring expiration timeout provided in the call to
1104 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1105 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001106 *
1107 * @param admin The name of the admin component to check, or null to aggregate all admins.
1108 * @return The timeout for the given admin or the minimum of all timeouts
1109 */
1110 public long getPasswordExpirationTimeout(ComponentName admin) {
1111 if (mService != null) {
1112 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001113 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001114 } catch (RemoteException e) {
1115 Log.w(TAG, "Failed talking with device policy service", e);
1116 }
1117 }
1118 return 0;
1119 }
1120
1121 /**
1122 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001123 * all admins of this user and its profiles if admin is null. If the password is
1124 * expired, this will return the time since the password expired as a negative number.
1125 * If admin is null, then a composite of all expiration timeouts is returned
1126 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001127 *
1128 * @param admin The name of the admin component to check, or null to aggregate all admins.
1129 * @return The password expiration time, in ms.
1130 */
1131 public long getPasswordExpiration(ComponentName admin) {
1132 if (mService != null) {
1133 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001134 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001135 } catch (RemoteException e) {
1136 Log.w(TAG, "Failed talking with device policy service", e);
1137 }
1138 }
1139 return 0;
1140 }
1141
1142 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001143 * Retrieve the current password history length for all admins of this
1144 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001145 * @param admin The name of the admin component to check, or null to aggregate
1146 * all admins.
1147 * @return The length of the password history
1148 */
1149 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001150 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1151 }
1152
1153 /** @hide per-user version */
1154 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001155 if (mService != null) {
1156 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001157 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001158 } catch (RemoteException e) {
1159 Log.w(TAG, "Failed talking with device policy service", e);
1160 }
1161 }
1162 return 0;
1163 }
1164
Dianne Hackbornd6847842010-01-12 18:14:19 -08001165 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001166 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001167 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001168 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001169 * @return Returns the maximum length that the user can enter.
1170 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001171 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001172 // Kind-of arbitrary.
1173 return 16;
1174 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001175
Dianne Hackborn254cb442010-01-27 19:23:59 -08001176 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001177 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001178 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001179 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001180 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001181 * <p>The calling device admin must have requested
1182 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1183 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001184 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001185 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001186 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001187 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001188 if (mService != null) {
1189 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001190 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001191 } catch (RemoteException e) {
1192 Log.w(TAG, "Failed talking with device policy service", e);
1193 }
1194 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001195 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001196 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001197
Dianne Hackbornd6847842010-01-12 18:14:19 -08001198 /**
1199 * Retrieve the number of times the user has failed at entering a
1200 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001201 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001202 * <p>The calling device admin must have requested
1203 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1204 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001205 */
1206 public int getCurrentFailedPasswordAttempts() {
1207 if (mService != null) {
1208 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001209 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001210 } catch (RemoteException e) {
1211 Log.w(TAG, "Failed talking with device policy service", e);
1212 }
1213 }
1214 return -1;
1215 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001216
1217 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001218 * Setting this to a value greater than zero enables a built-in policy
1219 * that will perform a device wipe after too many incorrect
1220 * device-unlock passwords have been entered. This built-in policy combines
1221 * watching for failed passwords and wiping the device, and requires
1222 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001223 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001224 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001225 * <p>To implement any other policy (e.g. wiping data for a particular
1226 * application only, erasing or revoking credentials, or reporting the
1227 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001228 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001229 * instead. Do not use this API, because if the maximum count is reached,
1230 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001231 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001232 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001233 * @param num The number of failed password attempts at which point the
1234 * device will wipe its data.
1235 */
1236 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1237 if (mService != null) {
1238 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001239 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001240 } catch (RemoteException e) {
1241 Log.w(TAG, "Failed talking with device policy service", e);
1242 }
1243 }
1244 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001245
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001246 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001247 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001248 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001249 * or a particular one.
1250 * @param admin The name of the admin component to check, or null to aggregate
1251 * all admins.
1252 */
1253 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001254 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1255 }
1256
1257 /** @hide per-user version */
1258 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001259 if (mService != null) {
1260 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001261 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001262 } catch (RemoteException e) {
1263 Log.w(TAG, "Failed talking with device policy service", e);
1264 }
1265 }
1266 return 0;
1267 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001268
Dianne Hackborn254cb442010-01-27 19:23:59 -08001269 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001270 * Flag for {@link #resetPassword}: don't allow other admins to change
1271 * the password again until the user has entered it.
1272 */
1273 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001274
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001275 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001276 * Force a new device unlock password (the password needed to access the
1277 * entire device, not for individual accounts) on the user. This takes
1278 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001279 * The given password must be sufficient for the
1280 * current password quality and length constraints as returned by
1281 * {@link #getPasswordQuality(ComponentName)} and
1282 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1283 * these constraints, then it will be rejected and false returned. Note
1284 * that the password may be a stronger quality (containing alphanumeric
1285 * characters when the requested quality is only numeric), in which case
1286 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001287 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001288 * <p>The calling device admin must have requested
1289 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1290 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001291 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001292 * Can not be called from a managed profile.
1293 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001294 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001295 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001296 * @return Returns true if the password was applied, or false if it is
1297 * not acceptable for the current constraints.
1298 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001299 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001300 if (mService != null) {
1301 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001302 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001303 } catch (RemoteException e) {
1304 Log.w(TAG, "Failed talking with device policy service", e);
1305 }
1306 }
1307 return false;
1308 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001309
Dianne Hackbornd6847842010-01-12 18:14:19 -08001310 /**
1311 * Called by an application that is administering the device to set the
1312 * maximum time for user activity until the device will lock. This limits
1313 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001314 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001315 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001316 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001317 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001318 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001319 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001320 * @param timeMs The new desired maximum time to lock in milliseconds.
1321 * A value of 0 means there is no restriction.
1322 */
1323 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1324 if (mService != null) {
1325 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001326 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001327 } catch (RemoteException e) {
1328 Log.w(TAG, "Failed talking with device policy service", e);
1329 }
1330 }
1331 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001332
Dianne Hackbornd6847842010-01-12 18:14:19 -08001333 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001334 * Retrieve the current maximum time to unlock for all admins of this user
1335 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001336 * @param admin The name of the admin component to check, or null to aggregate
1337 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001338 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001339 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001340 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1341 }
1342
1343 /** @hide per-user version */
1344 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001345 if (mService != null) {
1346 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001347 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001348 } catch (RemoteException e) {
1349 Log.w(TAG, "Failed talking with device policy service", e);
1350 }
1351 }
1352 return 0;
1353 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001354
Dianne Hackbornd6847842010-01-12 18:14:19 -08001355 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001356 * Make the device lock immediately, as if the lock screen timeout has
1357 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001358 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001359 * <p>The calling device admin must have requested
1360 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1361 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001362 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001363 public void lockNow() {
1364 if (mService != null) {
1365 try {
1366 mService.lockNow();
1367 } catch (RemoteException e) {
1368 Log.w(TAG, "Failed talking with device policy service", e);
1369 }
1370 }
1371 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001372
Dianne Hackbornd6847842010-01-12 18:14:19 -08001373 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001374 * Flag for {@link #wipeData(int)}: also erase the device's external
1375 * storage.
1376 */
1377 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1378
1379 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001380 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001381 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001382 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1383 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001384 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001385 * <p>The calling device admin must have requested
1386 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1387 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001388 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001389 * @param flags Bit mask of additional options: currently 0 and
1390 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001391 */
1392 public void wipeData(int flags) {
1393 if (mService != null) {
1394 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001395 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001396 } catch (RemoteException e) {
1397 Log.w(TAG, "Failed talking with device policy service", e);
1398 }
1399 }
1400 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001401
Dianne Hackbornd6847842010-01-12 18:14:19 -08001402 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001403 * Called by an application that is administering the device to set the
1404 * global proxy and exclusion list.
1405 * <p>
1406 * The calling device admin must have requested
1407 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1408 * this method; if it has not, a security exception will be thrown.
1409 * Only the first device admin can set the proxy. If a second admin attempts
1410 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1411 * proxy will be returned. If successful in setting the proxy, null will
1412 * be returned.
1413 * The method can be called repeatedly by the device admin alrady setting the
1414 * proxy to update the proxy and exclusion list.
1415 *
1416 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1417 * with.
1418 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1419 * Pass Proxy.NO_PROXY to reset the proxy.
1420 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001421 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1422 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001423 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001424 */
1425 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1426 List<String> exclusionList ) {
1427 if (proxySpec == null) {
1428 throw new NullPointerException();
1429 }
1430 if (mService != null) {
1431 try {
1432 String hostSpec;
1433 String exclSpec;
1434 if (proxySpec.equals(Proxy.NO_PROXY)) {
1435 hostSpec = null;
1436 exclSpec = null;
1437 } else {
1438 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1439 throw new IllegalArgumentException();
1440 }
1441 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1442 String hostName = sa.getHostName();
1443 int port = sa.getPort();
1444 StringBuilder hostBuilder = new StringBuilder();
1445 hostSpec = hostBuilder.append(hostName)
1446 .append(":").append(Integer.toString(port)).toString();
1447 if (exclusionList == null) {
1448 exclSpec = "";
1449 } else {
1450 StringBuilder listBuilder = new StringBuilder();
1451 boolean firstDomain = true;
1452 for (String exclDomain : exclusionList) {
1453 if (!firstDomain) {
1454 listBuilder = listBuilder.append(",");
1455 } else {
1456 firstDomain = false;
1457 }
1458 listBuilder = listBuilder.append(exclDomain.trim());
1459 }
1460 exclSpec = listBuilder.toString();
1461 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001462 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1463 != android.net.Proxy.PROXY_VALID)
1464 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001465 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001466 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001467 } catch (RemoteException e) {
1468 Log.w(TAG, "Failed talking with device policy service", e);
1469 }
1470 }
1471 return null;
1472 }
1473
1474 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001475 * Set a network-independent global HTTP proxy. This is not normally what you want
1476 * for typical HTTP proxies - they are generally network dependent. However if you're
1477 * doing something unusual like general internal filtering this may be useful. On
1478 * a private network where the proxy is not accessible, you may break HTTP using this.
1479 *
1480 * <p>This method requires the caller to be the device owner.
1481 *
1482 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1483 * @see ProxyInfo
1484 *
1485 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1486 * with.
1487 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1488 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1489 */
1490 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1491 if (mService != null) {
1492 try {
1493 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1494 } catch (RemoteException e) {
1495 Log.w(TAG, "Failed talking with device policy service", e);
1496 }
1497 }
1498 }
1499
1500 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001501 * Returns the component name setting the global proxy.
1502 * @return ComponentName object of the device admin that set the global proxy, or
1503 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001504 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001505 */
1506 public ComponentName getGlobalProxyAdmin() {
1507 if (mService != null) {
1508 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001509 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001510 } catch (RemoteException e) {
1511 Log.w(TAG, "Failed talking with device policy service", e);
1512 }
1513 }
1514 return null;
1515 }
1516
1517 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001518 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001519 * indicating that encryption is not supported.
1520 */
1521 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1522
1523 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001524 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001525 * indicating that encryption is supported, but is not currently active.
1526 */
1527 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1528
1529 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001530 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001531 * indicating that encryption is not currently active, but is currently
1532 * being activated. This is only reported by devices that support
1533 * encryption of data and only when the storage is currently
1534 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1535 * to become encrypted will never return this value.
1536 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001537 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001538
1539 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001540 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001541 * indicating that encryption is active.
1542 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001543 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001544
1545 /**
1546 * Activity action: begin the process of encrypting data on the device. This activity should
1547 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1548 * After resuming from this activity, use {@link #getStorageEncryption}
1549 * to check encryption status. However, on some devices this activity may never return, as
1550 * it may trigger a reboot and in some cases a complete data wipe of the device.
1551 */
1552 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1553 public static final String ACTION_START_ENCRYPTION
1554 = "android.app.action.START_ENCRYPTION";
1555
1556 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001557 * Widgets are enabled in keyguard
1558 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001559 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001560
1561 /**
Jim Miller50e62182014-04-23 17:25:00 -07001562 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001563 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001564 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1565
1566 /**
1567 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1568 */
1569 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1570
1571 /**
Jim Miller50e62182014-04-23 17:25:00 -07001572 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1573 */
1574 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1575
1576 /**
1577 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1578 */
1579 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1580
1581 /**
1582 * Ignore {@link TrustAgentService} state on secure keyguard screens
1583 * (e.g. PIN/Pattern/Password).
1584 */
1585 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1586
1587 /**
Jim Miller35207742012-11-02 15:33:20 -07001588 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001589 */
1590 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001591
1592 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001593 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001594 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001595 *
1596 * <p>When multiple device administrators attempt to control device
1597 * encryption, the most secure, supported setting will always be
1598 * used. If any device administrator requests device encryption,
1599 * it will be enabled; Conversely, if a device administrator
1600 * attempts to disable device encryption while another
1601 * device administrator has enabled it, the call to disable will
1602 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1603 *
1604 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001605 * written to other storage areas may or may not be encrypted, and this policy does not require
1606 * or control the encryption of any other storage areas.
1607 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1608 * {@code true}, then the directory returned by
1609 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1610 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001611 *
1612 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1613 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1614 * the encryption key may not be fully secured. For maximum security, the administrator should
1615 * also require (and check for) a pattern, PIN, or password.
1616 *
1617 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1618 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001619 * @return the new request status (for all active admins) - will be one of
1620 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1621 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1622 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001623 */
1624 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1625 if (mService != null) {
1626 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001627 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001628 } catch (RemoteException e) {
1629 Log.w(TAG, "Failed talking with device policy service", e);
1630 }
1631 }
1632 return ENCRYPTION_STATUS_UNSUPPORTED;
1633 }
1634
1635 /**
1636 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001637 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001638 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001639 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1640 * this will return the requested encryption setting as an aggregate of all active
1641 * administrators.
1642 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001643 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001644 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001645 if (mService != null) {
1646 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001647 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001648 } catch (RemoteException e) {
1649 Log.w(TAG, "Failed talking with device policy service", e);
1650 }
1651 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001652 return false;
1653 }
1654
1655 /**
1656 * Called by an application that is administering the device to
1657 * determine the current encryption status of the device.
1658 *
1659 * Depending on the returned status code, the caller may proceed in different
1660 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1661 * storage system does not support encryption. If the
1662 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1663 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1664 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1665 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1666 *
1667 * @return current status of encryption. The value will be one of
1668 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1669 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1670 */
1671 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001672 return getStorageEncryptionStatus(UserHandle.myUserId());
1673 }
1674
1675 /** @hide per-user version */
1676 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001677 if (mService != null) {
1678 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001679 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001680 } catch (RemoteException e) {
1681 Log.w(TAG, "Failed talking with device policy service", e);
1682 }
1683 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001684 return ENCRYPTION_STATUS_UNSUPPORTED;
1685 }
1686
1687 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001688 * Installs the given certificate as a User CA.
1689 *
1690 * @return false if the certBuffer cannot be parsed or installation is
1691 * interrupted, otherwise true
Maggie Benthallda51e682013-08-08 22:35:44 -04001692 */
Robin Lee306fe082014-06-19 14:04:24 +00001693 public boolean installCaCert(ComponentName who, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001694 if (mService != null) {
1695 try {
Robin Lee306fe082014-06-19 14:04:24 +00001696 return mService.installCaCert(who, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001697 } catch (RemoteException e) {
1698 Log.w(TAG, "Failed talking with device policy service", e);
1699 }
1700 }
1701 return false;
1702 }
1703
1704 /**
1705 * Uninstalls the given certificate from the list of User CAs, if present.
Maggie Benthallda51e682013-08-08 22:35:44 -04001706 */
Robin Lee306fe082014-06-19 14:04:24 +00001707 public void uninstallCaCert(ComponentName who, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001708 if (mService != null) {
1709 try {
Robin Lee306fe082014-06-19 14:04:24 +00001710 final String alias = getCaCertAlias(certBuffer);
1711 mService.uninstallCaCert(who, alias);
1712 } catch (CertificateException e) {
1713 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001714 } catch (RemoteException e) {
1715 Log.w(TAG, "Failed talking with device policy service", e);
1716 }
1717 }
1718 }
1719
1720 /**
1721 * Returns whether there are any user-installed CA certificates.
Maggie Benthallda51e682013-08-08 22:35:44 -04001722 */
Robin Lee306fe082014-06-19 14:04:24 +00001723 public boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001724 TrustedCertificateStore certStore = new TrustedCertificateStore();
1725 Set<String> aliases = certStore.userAliases();
1726 return aliases != null && !aliases.isEmpty();
1727 }
1728
1729 /**
1730 * Returns whether this certificate has been installed as a User CA.
Maggie Benthallda51e682013-08-08 22:35:44 -04001731 */
1732 public boolean hasCaCertInstalled(byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001733 try {
Robin Lee306fe082014-06-19 14:04:24 +00001734 return getCaCertAlias(certBuffer) != null;
Maggie Benthallda51e682013-08-08 22:35:44 -04001735 } catch (CertificateException ce) {
1736 Log.w(TAG, "Could not parse certificate", ce);
1737 }
1738 return false;
1739 }
1740
1741 /**
Robin Lee306fe082014-06-19 14:04:24 +00001742 * Returns the alias of a given CA certificate in the certificate store, or null if it
1743 * doesn't exist.
1744 */
1745 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1746 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1747 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1748 new ByteArrayInputStream(certBuffer));
1749 return new TrustedCertificateStore().getCertificateAlias(cert);
1750 }
1751
1752 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001753 * Called by an application that is administering the device to disable all cameras
1754 * on the device. After setting this, no applications will be able to access any cameras
1755 * on the device.
1756 *
1757 * <p>The calling device admin must have requested
1758 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1759 * this method; if it has not, a security exception will be thrown.
1760 *
1761 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1762 * @param disabled Whether or not the camera should be disabled.
1763 */
1764 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1765 if (mService != null) {
1766 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001767 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001768 } catch (RemoteException e) {
1769 Log.w(TAG, "Failed talking with device policy service", e);
1770 }
1771 }
1772 }
1773
1774 /**
1775 * Determine whether or not the device's cameras have been disabled either by the current
1776 * admin, if specified, or all admins.
1777 * @param admin The name of the admin component to check, or null to check if any admins
1778 * have disabled the camera
1779 */
1780 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001781 return getCameraDisabled(admin, UserHandle.myUserId());
1782 }
1783
1784 /** @hide per-user version */
1785 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001786 if (mService != null) {
1787 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001788 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001789 } catch (RemoteException e) {
1790 Log.w(TAG, "Failed talking with device policy service", e);
1791 }
1792 }
1793 return false;
1794 }
1795
1796 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001797 * Called by an application that is administering the device to disable keyguard customizations,
1798 * such as widgets. After setting this, keyguard features will be disabled according to the
1799 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001800 *
1801 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001802 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001803 * this method; if it has not, a security exception will be thrown.
1804 *
1805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001806 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1807 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001808 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1809 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001810 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001811 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001812 if (mService != null) {
1813 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001814 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001815 } catch (RemoteException e) {
1816 Log.w(TAG, "Failed talking with device policy service", e);
1817 }
1818 }
1819 }
1820
1821 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001822 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001823 * admin, if specified, or all admins.
1824 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001825 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001826 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1827 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001828 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001829 public int getKeyguardDisabledFeatures(ComponentName admin) {
1830 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001831 }
1832
1833 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001834 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001835 if (mService != null) {
1836 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001837 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001838 } catch (RemoteException e) {
1839 Log.w(TAG, "Failed talking with device policy service", e);
1840 }
1841 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001842 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001843 }
1844
1845 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001846 * @hide
1847 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001848 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001849 if (mService != null) {
1850 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001851 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001852 } catch (RemoteException e) {
1853 Log.w(TAG, "Failed talking with device policy service", e);
1854 }
1855 }
1856 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001857
Dianne Hackbornd6847842010-01-12 18:14:19 -08001858 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001859 * @hide
1860 */
1861 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1862 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1863 }
1864
1865 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001866 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001867 * @hide
1868 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001869 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001870 ActivityInfo ai;
1871 try {
1872 ai = mContext.getPackageManager().getReceiverInfo(cn,
1873 PackageManager.GET_META_DATA);
1874 } catch (PackageManager.NameNotFoundException e) {
1875 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1876 return null;
1877 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001878
Dianne Hackbornd6847842010-01-12 18:14:19 -08001879 ResolveInfo ri = new ResolveInfo();
1880 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001881
Dianne Hackbornd6847842010-01-12 18:14:19 -08001882 try {
1883 return new DeviceAdminInfo(mContext, ri);
1884 } catch (XmlPullParserException e) {
1885 Log.w(TAG, "Unable to parse device policy " + cn, e);
1886 return null;
1887 } catch (IOException e) {
1888 Log.w(TAG, "Unable to parse device policy " + cn, e);
1889 return null;
1890 }
1891 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001892
Dianne Hackbornd6847842010-01-12 18:14:19 -08001893 /**
1894 * @hide
1895 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001896 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1897 if (mService != null) {
1898 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001899 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001900 } catch (RemoteException e) {
1901 Log.w(TAG, "Failed talking with device policy service", e);
1902 }
1903 }
1904 }
1905
1906 /**
1907 * @hide
1908 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001909 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001910 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001911 if (mService != null) {
1912 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001913 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001914 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001915 } catch (RemoteException e) {
1916 Log.w(TAG, "Failed talking with device policy service", e);
1917 }
1918 }
1919 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001920
Dianne Hackbornd6847842010-01-12 18:14:19 -08001921 /**
1922 * @hide
1923 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001924 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001925 if (mService != null) {
1926 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001927 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001928 } catch (RemoteException e) {
1929 Log.w(TAG, "Failed talking with device policy service", e);
1930 }
1931 }
1932 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001933
Dianne Hackbornd6847842010-01-12 18:14:19 -08001934 /**
1935 * @hide
1936 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001937 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001938 if (mService != null) {
1939 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001940 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001941 } catch (RemoteException e) {
1942 Log.w(TAG, "Failed talking with device policy service", e);
1943 }
1944 }
1945 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001946
1947 /**
1948 * @hide
1949 * Sets the given package as the device owner. The package must already be installed and there
1950 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1951 * method must be called before the device is provisioned.
1952 * @param packageName the package name of the application to be registered as the device owner.
1953 * @return whether the package was successfully registered as the device owner.
1954 * @throws IllegalArgumentException if the package name is null or invalid
1955 * @throws IllegalStateException if a device owner is already registered or the device has
1956 * already been provisioned.
1957 */
1958 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1959 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001960 return setDeviceOwner(packageName, null);
1961 }
1962
1963 /**
1964 * @hide
1965 * Sets the given package as the device owner. The package must already be installed and there
1966 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1967 * method must be called before the device is provisioned.
1968 * @param packageName the package name of the application to be registered as the device owner.
1969 * @param ownerName the human readable name of the institution that owns this device.
1970 * @return whether the package was successfully registered as the device owner.
1971 * @throws IllegalArgumentException if the package name is null or invalid
1972 * @throws IllegalStateException if a device owner is already registered or the device has
1973 * already been provisioned.
1974 */
1975 public boolean setDeviceOwner(String packageName, String ownerName)
1976 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001977 if (mService != null) {
1978 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001979 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07001980 } catch (RemoteException re) {
1981 Log.w(TAG, "Failed to set device owner");
1982 }
1983 }
1984 return false;
1985 }
1986
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001987
Amith Yamasani71e6c692013-03-24 17:39:28 -07001988 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001989 * Used to determine if a particular package has been registered as a Device Owner app.
1990 * A device owner app is a special device admin that cannot be deactivated by the user, once
1991 * activated as a device admin. It also cannot be uninstalled. To check if a particular
1992 * package is currently registered as the device owner app, pass in the package name from
1993 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
1994 * admin apps that want to check if they are also registered as the device owner app. The
1995 * exact mechanism by which a device admin app is registered as a device owner app is defined by
1996 * the setup process.
1997 * @param packageName the package name of the app, to compare with the registered device owner
1998 * app, if any.
1999 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002000 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002001 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002002 if (mService != null) {
2003 try {
2004 return mService.isDeviceOwner(packageName);
2005 } catch (RemoteException re) {
2006 Log.w(TAG, "Failed to check device owner");
2007 }
2008 }
2009 return false;
2010 }
2011
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002012 /**
2013 * @hide
2014 * Redirect to isDeviceOwnerApp.
2015 */
2016 public boolean isDeviceOwner(String packageName) {
2017 return isDeviceOwnerApp(packageName);
2018 }
2019
Jason Monkb0dced82014-06-06 14:36:20 -04002020 /**
2021 * Clears the current device owner. The caller must be the device owner.
2022 *
2023 * This function should be used cautiously as once it is called it cannot
2024 * be undone. The device owner can only be set as a part of device setup
2025 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002026 *
2027 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002028 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002029 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002030 if (mService != null) {
2031 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002032 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002033 } catch (RemoteException re) {
2034 Log.w(TAG, "Failed to clear device owner");
2035 }
2036 }
2037 }
2038
Amith Yamasani71e6c692013-03-24 17:39:28 -07002039 /** @hide */
2040 public String getDeviceOwner() {
2041 if (mService != null) {
2042 try {
2043 return mService.getDeviceOwner();
2044 } catch (RemoteException re) {
2045 Log.w(TAG, "Failed to get device owner");
2046 }
2047 }
2048 return null;
2049 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002050
2051 /** @hide */
2052 public String getDeviceOwnerName() {
2053 if (mService != null) {
2054 try {
2055 return mService.getDeviceOwnerName();
2056 } catch (RemoteException re) {
2057 Log.w(TAG, "Failed to get device owner");
2058 }
2059 }
2060 return null;
2061 }
Adam Connors776c5552014-01-09 10:42:56 +00002062
2063 /**
2064 * @hide
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302065 * @SystemApi
2066 * Sets the given component as an active admin and registers the package as the profile
2067 * owner for this user. The package must already be installed and there shouldn't be
2068 * an existing profile owner registered for this user. Also, this method must be called
2069 * before the user setup has been completed.
2070 * <p>
2071 * This method can only be called by system apps that hold MANAGE_USERS permission and
2072 * MANAGE_DEVICE_ADMINS permission.
2073 * @param admin The component to register as an active admin and profile owner.
2074 * @param ownerName The user-visible name of the entity that is managing this user.
2075 * @return whether the admin was successfully registered as the profile owner.
2076 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2077 * the user has already been set up.
2078 */
2079 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2080 throws IllegalArgumentException {
2081 if (mService != null) {
2082 try {
2083 final int myUserId = UserHandle.myUserId();
2084 mService.setActiveAdmin(admin, false, myUserId);
2085 return mService.setProfileOwner(admin.getPackageName(), ownerName, myUserId);
2086 } catch (RemoteException re) {
2087 Log.w(TAG, "Failed to set profile owner " + re);
2088 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2089 }
2090 }
2091 return false;
2092 }
2093
2094 /**
2095 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002096 * Sets the given package as the profile owner of the given user profile. The package must
2097 * already be installed and there shouldn't be an existing profile owner registered for this
2098 * user. Also, this method must be called before the user has been used for the first time.
2099 * @param packageName the package name of the application to be registered as profile owner.
2100 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002101 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002102 * @return whether the package was successfully registered as the profile owner.
2103 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2104 * the user has already been set up.
2105 */
Adam Connors661ec472014-02-11 13:59:46 +00002106 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002107 throws IllegalArgumentException {
2108 if (mService != null) {
2109 try {
Adam Connors661ec472014-02-11 13:59:46 +00002110 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002111 } catch (RemoteException re) {
2112 Log.w(TAG, "Failed to set profile owner", re);
2113 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2114 }
2115 }
2116 return false;
2117 }
2118
2119 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002120 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2121 * be used. Only the profile owner can call this.
2122 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002123 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002124 *
2125 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2126 */
2127 public void setProfileEnabled(ComponentName admin) {
2128 if (mService != null) {
2129 try {
2130 mService.setProfileEnabled(admin);
2131 } catch (RemoteException e) {
2132 Log.w(TAG, "Failed talking with device policy service", e);
2133 }
2134 }
2135 }
2136
2137 /**
Jessica Hummel1333ea12014-06-23 11:20:10 +01002138 * Sets the name of the Managed profile. In the device owner case it sets the name of the user
2139 * which it is called from. Only the profile owner or device owner can call this. If this is
2140 * never called by the profile or device owner, the name will be set to default values.
2141 *
2142 * @see #isProfileOwnerApp
2143 * @see #isDeviceOwnerApp
2144 *
2145 * @param profileName The name of the profile.
2146 */
2147 public void setProfileName(ComponentName who, String profileName) {
2148 if (mService != null) {
2149 try {
2150 mService.setProfileName(who, profileName);
2151 } catch (RemoteException e) {
2152 Log.w(TAG, "Failed talking with device policy service", e);
2153 }
2154 }
2155}
2156
2157 /**
Adam Connors776c5552014-01-09 10:42:56 +00002158 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002159 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00002160 * within the managed profile.
2161 *
2162 * @param packageName The package name of the app to compare with the registered profile owner.
2163 * @return Whether or not the package is registered as the profile owner.
2164 */
2165 public boolean isProfileOwnerApp(String packageName) {
2166 if (mService != null) {
2167 try {
2168 String profileOwnerPackage = mService.getProfileOwner(
2169 Process.myUserHandle().getIdentifier());
2170 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
2171 } catch (RemoteException re) {
2172 Log.w(TAG, "Failed to check profile owner");
2173 }
2174 }
2175 return false;
2176 }
2177
2178 /**
2179 * @hide
2180 * @return the packageName of the owner of the given user profile or null if no profile
2181 * owner has been set for that user.
2182 * @throws IllegalArgumentException if the userId is invalid.
2183 */
2184 public String getProfileOwner() throws IllegalArgumentException {
2185 if (mService != null) {
2186 try {
2187 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
2188 } catch (RemoteException re) {
2189 Log.w(TAG, "Failed to get profile owner");
2190 throw new IllegalArgumentException(
2191 "Requested profile owner for invalid userId", re);
2192 }
2193 }
2194 return null;
2195 }
2196
2197 /**
2198 * @hide
2199 * @return the human readable name of the organisation associated with this DPM or null if
2200 * one is not set.
2201 * @throws IllegalArgumentException if the userId is invalid.
2202 */
2203 public String getProfileOwnerName() throws IllegalArgumentException {
2204 if (mService != null) {
2205 try {
2206 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2207 } catch (RemoteException re) {
2208 Log.w(TAG, "Failed to get profile owner");
2209 throw new IllegalArgumentException(
2210 "Requested profile owner for invalid userId", re);
2211 }
2212 }
2213 return null;
2214 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002215
2216 /**
2217 * Called by a profile owner or device owner to add a default intent handler activity for
2218 * intents that match a certain intent filter. This activity will remain the default intent
2219 * handler even if the set of potential event handlers for the intent filter changes and if
2220 * the intent preferences are reset.
2221 *
2222 * <p>The default disambiguation mechanism takes over if the activity is not installed
2223 * (anymore). When the activity is (re)installed, it is automatically reset as default
2224 * intent handler for the filter.
2225 *
2226 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2227 * security exception will be thrown.
2228 *
2229 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2230 * @param filter The IntentFilter for which a default handler is added.
2231 * @param activity The Activity that is added as default intent handler.
2232 */
2233 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2234 ComponentName activity) {
2235 if (mService != null) {
2236 try {
2237 mService.addPersistentPreferredActivity(admin, filter, activity);
2238 } catch (RemoteException e) {
2239 Log.w(TAG, "Failed talking with device policy service", e);
2240 }
2241 }
2242 }
2243
2244 /**
2245 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002246 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002247 *
2248 * <p>The calling device admin must be a profile owner. If it is not, a security
2249 * exception will be thrown.
2250 *
2251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2252 * @param packageName The name of the package for which preferences are removed.
2253 */
2254 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2255 String packageName) {
2256 if (mService != null) {
2257 try {
2258 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2259 } catch (RemoteException e) {
2260 Log.w(TAG, "Failed talking with device policy service", e);
2261 }
2262 }
2263 }
Robin Lee66e5d962014-04-09 16:44:21 +01002264
2265 /**
2266 * Called by a profile or device owner to set the application restrictions for a given target
2267 * application running in the managed profile.
2268 *
2269 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
2270 * {@link Boolean}, {@link String}, or {@link String}[]. The recommended format for key strings
2271 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2272 * components such as {@link android.webkit.WebView}.
2273 *
2274 * <p>The application restrictions are only made visible to the target application and the
2275 * profile or device owner.
2276 *
2277 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2278 * exception will be thrown.
2279 *
2280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2281 * @param packageName The name of the package to update restricted settings for.
2282 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2283 * set of active restrictions.
2284 */
2285 public void setApplicationRestrictions(ComponentName admin, String packageName,
2286 Bundle settings) {
2287 if (mService != null) {
2288 try {
2289 mService.setApplicationRestrictions(admin, packageName, settings);
2290 } catch (RemoteException e) {
2291 Log.w(TAG, "Failed talking with device policy service", e);
2292 }
2293 }
2294 }
2295
2296 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002297 * Called by the profile owner so that some intents sent in the managed profile can also be
2298 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002300 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2301 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002302 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2303 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002304 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002305 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002306 if (mService != null) {
2307 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002308 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002309 } catch (RemoteException e) {
2310 Log.w(TAG, "Failed talking with device policy service", e);
2311 }
2312 }
2313 }
2314
2315 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002316 * Called by a profile owner to remove the cross-profile intent filters from the managed profile
2317 * and from the parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002318 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2319 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002320 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002321 if (mService != null) {
2322 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002323 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002324 } catch (RemoteException e) {
2325 Log.w(TAG, "Failed talking with device policy service", e);
2326 }
2327 }
2328 }
2329
2330 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002331 * Called by a device owner to create a user with the specified name. The UserHandle returned
2332 * by this method should not be persisted as user handles are recycled as users are removed and
2333 * created. If you need to persist an identifier for this user, use
2334 * {@link UserManager#getSerialNumberForUser}.
2335 *
2336 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2337 * @param name the user's name
2338 * @see UserHandle
2339 * @return the UserHandle object for the created user, or null if the user could not be created.
2340 */
2341 public UserHandle createUser(ComponentName admin, String name) {
2342 try {
2343 return mService.createUser(admin, name);
2344 } catch (RemoteException re) {
2345 Log.w(TAG, "Could not create a user", re);
2346 }
2347 return null;
2348 }
2349
2350 /**
Jason Monk03978a42014-06-10 15:05:30 -04002351 * Called by a device owner to create a user with the specified name. The UserHandle returned
2352 * by this method should not be persisted as user handles are recycled as users are removed and
2353 * created. If you need to persist an identifier for this user, use
2354 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2355 * immediately.
2356 *
2357 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2358 * as registered as an active admin on the new user. The profile owner package will be
2359 * installed on the new user if it already is installed on the device.
2360 *
2361 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2362 * profileOwnerComponent when onEnable is called.
2363 *
2364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2365 * @param name the user's name
2366 * @param ownerName the human readable name of the organisation associated with this DPM.
2367 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2368 * the user.
2369 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2370 * on the new user.
2371 * @see UserHandle
2372 * @return the UserHandle object for the created user, or null if the user could not be created.
2373 */
2374 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2375 ComponentName profileOwnerComponent, Bundle adminExtras) {
2376 try {
2377 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2378 adminExtras);
2379 } catch (RemoteException re) {
2380 Log.w(TAG, "Could not create a user", re);
2381 }
2382 return null;
2383 }
2384
2385 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002386 * Called by a device owner to remove a user and all associated data. The primary user can
2387 * not be removed.
2388 *
2389 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2390 * @param userHandle the user to remove.
2391 * @return {@code true} if the user was removed, {@code false} otherwise.
2392 */
2393 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2394 try {
2395 return mService.removeUser(admin, userHandle);
2396 } catch (RemoteException re) {
2397 Log.w(TAG, "Could not remove user ", re);
2398 return false;
2399 }
2400 }
2401
2402 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002403 * Called by a profile or device owner to get the application restrictions for a given target
2404 * application running in the managed profile.
2405 *
2406 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2407 * exception will be thrown.
2408 *
2409 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2410 * @param packageName The name of the package to fetch restricted settings of.
2411 * @return {@link Bundle} of settings corresponding to what was set last time
2412 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2413 * if no restrictions have been set.
2414 */
2415 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2416 if (mService != null) {
2417 try {
2418 return mService.getApplicationRestrictions(admin, packageName);
2419 } catch (RemoteException e) {
2420 Log.w(TAG, "Failed talking with device policy service", e);
2421 }
2422 }
2423 return null;
2424 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002425
2426 /**
2427 * Called by a profile or device owner to set a user restriction specified
2428 * by the key.
2429 * <p>
2430 * The calling device admin must be a profile or device owner; if it is not,
2431 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002432 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002433 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2434 * with.
2435 * @param key The key of the restriction. See the constants in
2436 * {@link android.os.UserManager} for the list of keys.
2437 */
2438 public void addUserRestriction(ComponentName admin, String key) {
2439 if (mService != null) {
2440 try {
2441 mService.setUserRestriction(admin, key, true);
2442 } catch (RemoteException e) {
2443 Log.w(TAG, "Failed talking with device policy service", e);
2444 }
2445 }
2446 }
2447
2448 /**
2449 * Called by a profile or device owner to clear a user restriction specified
2450 * by the key.
2451 * <p>
2452 * The calling device admin must be a profile or device owner; if it is not,
2453 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002454 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002455 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2456 * with.
2457 * @param key The key of the restriction. See the constants in
2458 * {@link android.os.UserManager} for the list of keys.
2459 */
2460 public void clearUserRestriction(ComponentName admin, String key) {
2461 if (mService != null) {
2462 try {
2463 mService.setUserRestriction(admin, key, false);
2464 } catch (RemoteException e) {
2465 Log.w(TAG, "Failed talking with device policy service", e);
2466 }
2467 }
2468 }
Adam Connors010cfd42014-04-16 12:48:13 +01002469
2470 /**
Julia Reynolds966881e2014-05-14 12:23:08 -04002471 * Called by device or profile owner to block or unblock packages. When a package is blocked it
2472 * is unavailable for use, but the data and actual package file remain.
2473 *
2474 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2475 * @param packageName The name of the package to block or unblock.
2476 * @param blocked {@code true} if the package should be blocked, {@code false} if it should be
2477 * unblocked.
2478 * @return boolean Whether the blocked setting of the package was successfully updated.
2479 */
2480 public boolean setApplicationBlocked(ComponentName admin, String packageName,
2481 boolean blocked) {
2482 if (mService != null) {
2483 try {
2484 return mService.setApplicationBlocked(admin, packageName, blocked);
2485 } catch (RemoteException e) {
2486 Log.w(TAG, "Failed talking with device policy service", e);
2487 }
2488 }
2489 return false;
2490 }
2491
2492 /**
2493 * Called by profile or device owner to block or unblock currently installed packages. This
2494 * should only be called by a profile or device owner running within a managed profile.
2495 *
2496 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2497 * @param intent An intent matching the app(s) to be updated. All apps that resolve for this
2498 * intent will be updated in the current profile.
2499 * @param blocked {@code true} if the packages should be blocked, {@code false} if they should
2500 * be unblocked.
2501 * @return int The number of activities that matched the intent and were updated.
2502 */
2503 public int setApplicationsBlocked(ComponentName admin, Intent intent, boolean blocked) {
2504 if (mService != null) {
2505 try {
2506 return mService.setApplicationsBlocked(admin, intent, blocked);
2507 } catch (RemoteException e) {
2508 Log.w(TAG, "Failed talking with device policy service", e);
2509 }
2510 }
2511 return 0;
2512 }
2513
2514 /**
2515 * Called by device or profile owner to determine if a package is blocked.
2516 *
2517 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2518 * @param packageName The name of the package to retrieve the blocked status of.
2519 * @return boolean {@code true} if the package is blocked, {@code false} otherwise.
2520 */
2521 public boolean isApplicationBlocked(ComponentName admin, String packageName) {
2522 if (mService != null) {
2523 try {
2524 return mService.isApplicationBlocked(admin, packageName);
2525 } catch (RemoteException e) {
2526 Log.w(TAG, "Failed talking with device policy service", e);
2527 }
2528 }
2529 return false;
2530 }
2531
2532 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01002533 * Called by a profile owner to disable account management for a specific type of account.
2534 *
2535 * <p>The calling device admin must be a profile owner. If it is not, a
2536 * security exception will be thrown.
2537 *
2538 * <p>When account management is disabled for an account type, adding or removing an account
2539 * of that type will not be possible.
2540 *
2541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2542 * @param accountType For which account management is disabled or enabled.
2543 * @param disabled The boolean indicating that account management will be disabled (true) or
2544 * enabled (false).
2545 */
2546 public void setAccountManagementDisabled(ComponentName admin, String accountType,
2547 boolean disabled) {
2548 if (mService != null) {
2549 try {
2550 mService.setAccountManagementDisabled(admin, accountType, disabled);
2551 } catch (RemoteException e) {
2552 Log.w(TAG, "Failed talking with device policy service", e);
2553 }
2554 }
2555 }
2556
2557 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002558 * Gets the array of accounts for which account management is disabled by the profile owner.
2559 *
2560 * <p> Account management can be disabled/enabled by calling
2561 * {@link #setAccountManagementDisabled}.
2562 *
2563 * @return a list of account types for which account management has been disabled.
2564 *
2565 * @see #setAccountManagementDisabled
2566 */
2567 public String[] getAccountTypesWithManagementDisabled() {
2568 if (mService != null) {
2569 try {
2570 return mService.getAccountTypesWithManagementDisabled();
2571 } catch (RemoteException e) {
2572 Log.w(TAG, "Failed talking with device policy service", e);
2573 }
2574 }
2575
2576 return null;
2577 }
justinzhang511e0d82014-03-24 16:09:24 -04002578
2579 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002580 * Sets which packages may enter lock task mode.
2581 *
2582 * <p>Any packages that shares uid with an allowed package will also be allowed
2583 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04002584 *
Jason Monkc5185f22014-06-24 11:12:42 -04002585 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04002586 * @param packages The list of packages allowed to enter lock task mode
2587 *
2588 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04002589 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
2590 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04002591 */
Jason Monkd7b86212014-06-16 13:15:38 -04002592 public void setLockTaskPackages(String[] packages) throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04002593 if (mService != null) {
2594 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002595 mService.setLockTaskPackages(packages);
justinzhang511e0d82014-03-24 16:09:24 -04002596 } catch (RemoteException e) {
2597 Log.w(TAG, "Failed talking with device policy service", e);
2598 }
2599 }
2600 }
2601
2602 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002603 * This function returns the list of packages allowed to start the lock task mode.
justinzhang511e0d82014-03-24 16:09:24 -04002604 * @hide
2605 */
Jason Monkd7b86212014-06-16 13:15:38 -04002606 public String[] getLockTaskPackages() {
justinzhang511e0d82014-03-24 16:09:24 -04002607 if (mService != null) {
2608 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002609 return mService.getLockTaskPackages();
justinzhang511e0d82014-03-24 16:09:24 -04002610 } catch (RemoteException e) {
2611 Log.w(TAG, "Failed talking with device policy service", e);
2612 }
2613 }
2614 return null;
2615 }
2616
2617 /**
2618 * This function lets the caller know whether the given component is allowed to start the
2619 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04002620 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04002621 */
Jason Monkd7b86212014-06-16 13:15:38 -04002622 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04002623 if (mService != null) {
2624 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002625 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04002626 } catch (RemoteException e) {
2627 Log.w(TAG, "Failed talking with device policy service", e);
2628 }
2629 }
2630 return false;
2631 }
Julia Reynoldsda551652014-05-14 17:15:16 -04002632
2633 /**
2634 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
2635 * of the setting is in the correct form for the setting type should be performed by the caller.
2636 *
2637 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2638 * @param setting The name of the setting to update.
2639 * @param value The value to update the setting to.
2640 */
2641 public void setGlobalSetting(ComponentName admin, String setting, String value) {
2642 if (mService != null) {
2643 try {
2644 mService.setGlobalSetting(admin, setting, value);
2645 } catch (RemoteException e) {
2646 Log.w(TAG, "Failed talking with device policy service", e);
2647 }
2648 }
2649 }
2650
2651 /**
2652 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
2653 * that the value of the setting is in the correct form for the setting type should be performed
2654 * by the caller.
2655 *
2656 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2657 * @param setting The name of the setting to update.
2658 * @param value The value to update the setting to.
2659 */
2660 public void setSecureSetting(ComponentName admin, String setting, String value) {
2661 if (mService != null) {
2662 try {
2663 mService.setSecureSetting(admin, setting, value);
2664 } catch (RemoteException e) {
2665 Log.w(TAG, "Failed talking with device policy service", e);
2666 }
2667 }
2668 }
2669
Amith Yamasanif20d6402014-05-24 15:34:37 -07002670 /**
2671 * Designates a specific broadcast receiver component as the provider for
2672 * making permission requests of a local or remote administrator of the user.
2673 * <p/>
2674 * Only a profile owner can designate the restrictions provider.
2675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2676 * @param receiver The component name of a BroadcastReceiver that handles the
2677 * {@link RestrictionsManager#ACTION_REQUEST_PERMISSION} intent. If this param is null,
2678 * it removes the restrictions provider previously assigned.
2679 */
2680 public void setRestrictionsProvider(ComponentName admin, ComponentName receiver) {
2681 if (mService != null) {
2682 try {
2683 mService.setRestrictionsProvider(admin, receiver);
2684 } catch (RemoteException re) {
2685 Log.w(TAG, "Failed to set permission provider on device policy service");
2686 }
2687 }
2688 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04002689
2690 /**
2691 * Called by profile or device owners to set the master volume mute on or off.
2692 *
2693 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2694 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
2695 */
2696 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
2697 if (mService != null) {
2698 try {
2699 mService.setMasterVolumeMuted(admin, on);
2700 } catch (RemoteException re) {
2701 Log.w(TAG, "Failed to setMasterMute on device policy service");
2702 }
2703 }
2704 }
2705
2706 /**
2707 * Called by profile or device owners to check whether the master volume mute is on or off.
2708 *
2709 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2710 * @return {@code true} if master volume is muted, {@code false} if it's not.
2711 */
2712 public boolean isMasterVolumeMuted(ComponentName admin) {
2713 if (mService != null) {
2714 try {
2715 return mService.isMasterVolumeMuted(admin);
2716 } catch (RemoteException re) {
2717 Log.w(TAG, "Failed to get isMasterMute on device policy service");
2718 }
2719 }
2720 return false;
2721 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08002722}