blob: 6ea6b4b26063b74752c7f113313112d3e61ef4af [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 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +000089 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +000090 *
Jessica Hummel9da60392014-05-21 12:32:57 +010091 * <p>A managed profile allows data separation for example for the usage of a
92 * device as a personal and corporate device. The user which provisioning is started from and
93 * the managed profile share a launcher.
94 *
95 * <p>This intent will typically be sent by a mobile device management application (mdm).
96 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
97 * control over the profile
98 *
99 * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}
100 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000101 *
102 * <p> When managed provisioning has completed, an intent of the type
103 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100104 * managed profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100105 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100106 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
107 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000108 *
109 * <p>Input: Nothing.</p>
110 * <p>Output: Nothing</p>
111 */
112 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
113 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000114 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000115
116 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100117 * A String extra holding the package name of the mobile device management application that
118 * will be set as the profile owner or device owner.
119 *
120 * <p>If an application starts provisioning directly via an intent with action
121 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
122 * application that started provisioning. The package will be set as profile owner in that case.
123 *
124 * <p>This package is set as device owner when device owner provisioning is started by an Nfc
125 * message containing an Nfc record with MIME type {@link #PROVISIONING_NFC_MIME_TYPE}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000126 */
127 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100128 = "android.app.extra.deviceAdminPackageName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000129
130 /**
131 * A String extra holding the default name of the profile that is created during managed profile
132 * provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100133 *
Jessica Hummelf72078b2014-03-06 16:13:12 +0000134 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
135 */
136 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100137 = "android.app.extra.defaultManagedProfileName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000138
139 /**
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100140 * A String extra that, holds the email address of the account which a managed profile is
141 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100142 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100143 *
144 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
145 * contains this extra, it is forwarded in the
146 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
147 * device management application that was set as the profile owner during provisioning.
148 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100149 */
150 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
151 = "android.app.extra.ManagedProfileEmailAddress";
152
153 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100154 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
155 * will be set to.
156 *
157 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
158 * provisioning via an Nfc bump.
159 */
160 public static final String EXTRA_PROVISIONING_TIME_ZONE
161 = "android.app.extra.timeZone";
162
163 /**
164 * A Long extra holding the local time {@link android.app.AlarmManager} that the device
165 * will be set to.
166 *
167 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
168 * provisioning via an Nfc bump.
169 */
170 public static final String EXTRA_PROVISIONING_LOCAL_TIME
171 = "android.app.extra.localTime";
172
173 /**
174 * A String extra holding the {@link java.util.Locale} that the device will be set to.
175 * Format: xx_yy, where xx is the language code, and yy the country code.
176 *
177 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
178 * provisioning via an Nfc bump.
179 */
180 public static final String EXTRA_PROVISIONING_LOCALE
181 = "android.app.extra.locale";
182
183 /**
184 * A String extra holding the ssid of the wifi network that should be used during nfc device
185 * owner provisioning for downloading the mobile device management application.
186 *
187 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
188 * provisioning via an Nfc bump.
189 */
190 public static final String EXTRA_PROVISIONING_WIFI_SSID
191 = "android.app.extra.wifiSsid";
192
193 /**
194 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
195 * is hidden or not.
196 *
197 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
198 * provisioning via an Nfc bump.
199 */
200 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
201 = "android.app.extra.wifiHidden";
202
203 /**
204 * A String extra indicating the security type of the wifi network in
205 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
206 *
207 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
208 * provisioning via an Nfc bump.
209 */
210 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
211 = "android.app.extra.wifiSecurityType";
212
213 /**
214 * A String extra holding the password of the wifi network in
215 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
216 *
217 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
218 * provisioning via an Nfc bump.
219 */
220 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
221 = "android.app.extra.wifiPassword";
222
223 /**
224 * A String extra holding the proxy host for the wifi network in
225 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
226 *
227 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
228 * provisioning via an Nfc bump.
229 */
230 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
231 = "android.app.extra.wifiProxyHost";
232
233 /**
234 * An int extra holding the proxy port for the wifi network in
235 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
236 *
237 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
238 * provisioning via an Nfc bump.
239 */
240 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
241 = "android.app.extra.wifiProxyPort";
242
243 /**
244 * A String extra holding the proxy bypass for the wifi network in
245 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
246 *
247 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
248 * provisioning via an Nfc bump.
249 */
250 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
251 = "android.app.extra.wifiProxyBypassHosts";
252
253 /**
254 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
255 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
256 *
257 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
258 * provisioning via an Nfc bump.
259 */
260 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
261 = "android.app.extra.wifiPacUrl";
262
263 /**
264 * A String extra holding a url that specifies the download location of the device admin
265 * package. When not provided it is assumed that the device admin package is already installed.
266 *
267 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
268 * provisioning via an Nfc bump.
269 */
270 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
271 = "android.app.extra.deviceAdminPackageDownloadLocation";
272
273 /**
274 * A String extra holding the SHA-1 checksum of the file at download location specified in
275 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
276 * the file at the download location an error will be shown to the user and the user will be
277 * asked to factory reset the device.
278 *
279 * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner
280 * provisioning via an Nfc bump.
281 */
282 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
283 = "android.app.extra.deviceAdminPackageChecksum";
284
285 /**
286 * This MIME type is used for starting the Device Owner provisioning.
287 *
288 * <p>During device owner provisioning a device admin app is set as the owner of the device.
289 * A device owner has full control over the device. The device owner can not be modified by the
290 * user and the only way of resetting the device is if the device owner app calls a factory
291 * reset.
292 *
293 * <p> A typical use case would be a device that is owned by a company, but used by either an
294 * employee or client.
295 *
296 * <p> The Nfc message should be send to an unprovisioned device.
297 *
298 * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which
299 * contains the following properties:
300 * <ul>
301 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
302 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
303 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
304 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
305 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
306 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
307 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
308 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
309 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
310 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
311 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
312 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
314 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
315 *
316 * <p> When device owner provisioning has completed, an intent of the type
317 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
318 * device owner.
319 *
320 * <p>
321 * If provisioning fails, the device is factory reset.
322 *
323 * <p>Input: Nothing.</p>
324 * <p>Output: Nothing</p>
325 */
326 public static final String PROVISIONING_NFC_MIME_TYPE
327 = "application/com.android.managedprovisioning";
328
329 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800330 * Activity action: ask the user to add a new device administrator to the system.
331 * The desired policy is the ComponentName of the policy in the
332 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
333 * bring the user through adding the device administrator to the system (or
334 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700335 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800336 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
337 * field to provide the user with additional explanation (in addition
338 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800339 *
340 * <p>If your administrator is already active, this will ordinarily return immediately (without
341 * user intervention). However, if your administrator has been updated and is requesting
342 * additional uses-policy flags, the user will be presented with the new list. New policies
343 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800344 */
345 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
346 public static final String ACTION_ADD_DEVICE_ADMIN
347 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700348
Dianne Hackbornd6847842010-01-12 18:14:19 -0800349 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700350 * Activity action: send when any policy admin changes a policy.
351 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700352 *
Jim Miller284b62e2010-06-08 14:27:42 -0700353 * @hide
354 */
355 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
356 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
357
358 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800359 * The ComponentName of the administrator component.
360 *
361 * @see #ACTION_ADD_DEVICE_ADMIN
362 */
363 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700364
Dianne Hackbornd6847842010-01-12 18:14:19 -0800365 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800366 * An optional CharSequence providing additional explanation for why the
367 * admin is being added.
368 *
369 * @see #ACTION_ADD_DEVICE_ADMIN
370 */
371 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700372
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800373 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700374 * Activity action: have the user enter a new password. This activity should
375 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
376 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
377 * enter a new password that meets the current requirements. You can use
378 * {@link #isActivePasswordSufficient()} to determine whether you need to
379 * have the user select a new password in order to meet the current
380 * constraints. Upon being resumed from this activity, you can check the new
381 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800382 */
383 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
384 public static final String ACTION_SET_NEW_PASSWORD
385 = "android.app.action.SET_NEW_PASSWORD";
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000386 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100387 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
388 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000389 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100390 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000391
392 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100393 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
394 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000395 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100396 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700397
Dianne Hackbornd6847842010-01-12 18:14:19 -0800398 /**
399 * Return true if the given administrator component is currently
400 * active (enabled) in the system.
401 */
402 public boolean isAdminActive(ComponentName who) {
403 if (mService != null) {
404 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700405 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800406 } catch (RemoteException e) {
407 Log.w(TAG, "Failed talking with device policy service", e);
408 }
409 }
410 return false;
411 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700412
Dianne Hackbornd6847842010-01-12 18:14:19 -0800413 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800414 * Return a list of all currently active device administrator's component
415 * names. Note that if there are no administrators than null may be
416 * returned.
417 */
418 public List<ComponentName> getActiveAdmins() {
419 if (mService != null) {
420 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700421 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800422 } catch (RemoteException e) {
423 Log.w(TAG, "Failed talking with device policy service", e);
424 }
425 }
426 return null;
427 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700428
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800429 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700430 * Used by package administration code to determine if a package can be stopped
431 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800432 * @hide
433 */
434 public boolean packageHasActiveAdmins(String packageName) {
435 if (mService != null) {
436 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700437 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800438 } catch (RemoteException e) {
439 Log.w(TAG, "Failed talking with device policy service", e);
440 }
441 }
442 return false;
443 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700444
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800445 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800446 * Remove a current administration component. This can only be called
447 * by the application that owns the administration component; if you
448 * try to remove someone else's component, a security exception will be
449 * thrown.
450 */
451 public void removeActiveAdmin(ComponentName who) {
452 if (mService != null) {
453 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700454 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800455 } catch (RemoteException e) {
456 Log.w(TAG, "Failed talking with device policy service", e);
457 }
458 }
459 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700460
Dianne Hackbornd6847842010-01-12 18:14:19 -0800461 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800462 * Returns true if an administrator has been granted a particular device policy. This can
463 * be used to check if the administrator was activated under an earlier set of policies,
464 * but requires additional policies after an upgrade.
465 *
466 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
467 * an active administrator, or an exception will be thrown.
468 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
469 */
470 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
471 if (mService != null) {
472 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700473 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800474 } catch (RemoteException e) {
475 Log.w(TAG, "Failed talking with device policy service", e);
476 }
477 }
478 return false;
479 }
480
481 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800482 * Constant for {@link #setPasswordQuality}: the policy has no requirements
483 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800484 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800485 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800486 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700487
Dianne Hackbornd6847842010-01-12 18:14:19 -0800488 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700489 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
490 * recognition technology. This implies technologies that can recognize the identity of
491 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
492 * Note that quality constants are ordered so that higher values are more restrictive.
493 */
494 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
495
496 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800497 * Constant for {@link #setPasswordQuality}: the policy requires some kind
498 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800499 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800500 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800501 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700502
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800503 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800504 * Constant for {@link #setPasswordQuality}: the user must have entered a
505 * password containing at least numeric characters. Note that quality
506 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800507 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800508 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700509
Dianne Hackbornd6847842010-01-12 18:14:19 -0800510 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800511 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800512 * password containing at least numeric characters with no repeating (4444)
513 * or ordered (1234, 4321, 2468) sequences. Note that quality
514 * constants are ordered so that higher values are more restrictive.
515 */
516 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
517
518 /**
519 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700520 * password containing at least alphabetic (or other symbol) characters.
521 * Note that quality constants are ordered so that higher values are more
522 * restrictive.
523 */
524 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700525
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700526 /**
527 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800528 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700529 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800530 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800531 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700532 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700533
Dianne Hackbornd6847842010-01-12 18:14:19 -0800534 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700535 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700536 * password containing at least a letter, a numerical digit and a special
537 * symbol, by default. With this password quality, passwords can be
538 * restricted to contain various sets of characters, like at least an
539 * uppercase letter, etc. These are specified using various methods,
540 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
541 * that quality constants are ordered so that higher values are more
542 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700543 */
544 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
545
546 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800547 * Called by an application that is administering the device to set the
548 * password restrictions it is imposing. After setting this, the user
549 * will not be able to enter a new password that is not at least as
550 * restrictive as what has been set. Note that the current password
551 * will remain until the user has set a new one, so the change does not
552 * take place immediately. To prompt the user for a new password, use
553 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700554 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800555 * <p>Quality constants are ordered so that higher values are more restrictive;
556 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800557 * the user's preference, and any other considerations) is the one that
558 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700559 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800560 * <p>The calling device admin must have requested
561 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
562 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700563 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800564 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800565 * @param quality The new desired quality. One of
566 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800567 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
568 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
569 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800570 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800571 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800572 if (mService != null) {
573 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700574 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800575 } catch (RemoteException e) {
576 Log.w(TAG, "Failed talking with device policy service", e);
577 }
578 }
579 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700580
Dianne Hackbornd6847842010-01-12 18:14:19 -0800581 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100582 * Retrieve the current minimum password quality for all admins of this user
583 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800584 * @param admin The name of the admin component to check, or null to aggregate
585 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800586 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800587 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700588 return getPasswordQuality(admin, UserHandle.myUserId());
589 }
590
591 /** @hide per-user version */
592 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800593 if (mService != null) {
594 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700595 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800596 } catch (RemoteException e) {
597 Log.w(TAG, "Failed talking with device policy service", e);
598 }
599 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800600 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800601 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700602
Dianne Hackbornd6847842010-01-12 18:14:19 -0800603 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800604 * Called by an application that is administering the device to set the
605 * minimum allowed password length. After setting this, the user
606 * will not be able to enter a new password that is not at least as
607 * restrictive as what has been set. Note that the current password
608 * will remain until the user has set a new one, so the change does not
609 * take place immediately. To prompt the user for a new password, use
610 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
611 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800612 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
613 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
614 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700615 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800616 * <p>The calling device admin must have requested
617 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
618 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700619 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800620 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800621 * @param length The new desired minimum password length. A value of 0
622 * means there is no restriction.
623 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800624 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800625 if (mService != null) {
626 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700627 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800628 } catch (RemoteException e) {
629 Log.w(TAG, "Failed talking with device policy service", e);
630 }
631 }
632 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700633
Dianne Hackbornd6847842010-01-12 18:14:19 -0800634 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100635 * Retrieve the current minimum password length for all admins of this
636 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800637 * @param admin The name of the admin component to check, or null to aggregate
638 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800639 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800640 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700641 return getPasswordMinimumLength(admin, UserHandle.myUserId());
642 }
643
644 /** @hide per-user version */
645 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800646 if (mService != null) {
647 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700648 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800649 } catch (RemoteException e) {
650 Log.w(TAG, "Failed talking with device policy service", e);
651 }
652 }
653 return 0;
654 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700655
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700656 /**
657 * Called by an application that is administering the device to set the
658 * minimum number of upper case letters required in the password. After
659 * setting this, the user will not be able to enter a new password that is
660 * not at least as restrictive as what has been set. Note that the current
661 * password will remain until the user has set a new one, so the change does
662 * not take place immediately. To prompt the user for a new password, use
663 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
664 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700665 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
666 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700667 * <p>
668 * The calling device admin must have requested
669 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
670 * this method; if it has not, a security exception will be thrown.
671 *
672 * @param admin Which {@link DeviceAdminReceiver} this request is associated
673 * with.
674 * @param length The new desired minimum number of upper case letters
675 * required in the password. A value of 0 means there is no
676 * restriction.
677 */
678 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
679 if (mService != null) {
680 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700681 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700682 } catch (RemoteException e) {
683 Log.w(TAG, "Failed talking with device policy service", e);
684 }
685 }
686 }
687
688 /**
689 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100690 * password for all admins of this user and its profiles or a particular one.
691 * This is the same value as set by
692 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700693 * and only applies when the password quality is
694 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700695 *
696 * @param admin The name of the admin component to check, or null to
697 * aggregate all admins.
698 * @return The minimum number of upper case letters required in the
699 * password.
700 */
701 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700702 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
703 }
704
705 /** @hide per-user version */
706 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700707 if (mService != null) {
708 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700709 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700710 } catch (RemoteException e) {
711 Log.w(TAG, "Failed talking with device policy service", e);
712 }
713 }
714 return 0;
715 }
716
717 /**
718 * Called by an application that is administering the device to set the
719 * minimum number of lower case letters required in the password. After
720 * setting this, the user will not be able to enter a new password that is
721 * not at least as restrictive as what has been set. Note that the current
722 * password will remain until the user has set a new one, so the change does
723 * not take place immediately. To prompt the user for a new password, use
724 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
725 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700726 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
727 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700728 * <p>
729 * The calling device admin must have requested
730 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
731 * this method; if it has not, a security exception will be thrown.
732 *
733 * @param admin Which {@link DeviceAdminReceiver} this request is associated
734 * with.
735 * @param length The new desired minimum number of lower case letters
736 * required in the password. A value of 0 means there is no
737 * restriction.
738 */
739 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
740 if (mService != null) {
741 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700742 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700743 } catch (RemoteException e) {
744 Log.w(TAG, "Failed talking with device policy service", e);
745 }
746 }
747 }
748
749 /**
750 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100751 * password for all admins of this user and its profiles or a particular one.
752 * This is the same value as set by
753 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700754 * and only applies when the password quality is
755 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700756 *
757 * @param admin The name of the admin component to check, or null to
758 * aggregate all admins.
759 * @return The minimum number of lower case letters required in the
760 * password.
761 */
762 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700763 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
764 }
765
766 /** @hide per-user version */
767 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700768 if (mService != null) {
769 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700770 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700771 } catch (RemoteException e) {
772 Log.w(TAG, "Failed talking with device policy service", e);
773 }
774 }
775 return 0;
776 }
777
778 /**
779 * Called by an application that is administering the device to set the
780 * minimum number of letters required in the password. After setting this,
781 * the user will not be able to enter a new password that is not at least as
782 * restrictive as what has been set. Note that the current password will
783 * remain until the user has set a new one, so the change does not take
784 * place immediately. To prompt the user for a new password, use
785 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
786 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700787 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
788 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700789 * <p>
790 * The calling device admin must have requested
791 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
792 * this method; if it has not, a security exception will be thrown.
793 *
794 * @param admin Which {@link DeviceAdminReceiver} this request is associated
795 * with.
796 * @param length The new desired minimum number of letters required in the
797 * password. A value of 0 means there is no restriction.
798 */
799 public void setPasswordMinimumLetters(ComponentName admin, int length) {
800 if (mService != null) {
801 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700802 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700803 } catch (RemoteException e) {
804 Log.w(TAG, "Failed talking with device policy service", e);
805 }
806 }
807 }
808
809 /**
810 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700811 * admins or a particular one. This is the same value as
812 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
813 * and only applies when the password quality is
814 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700815 *
816 * @param admin The name of the admin component to check, or null to
817 * aggregate all admins.
818 * @return The minimum number of letters required in the password.
819 */
820 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700821 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
822 }
823
824 /** @hide per-user version */
825 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700826 if (mService != null) {
827 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700828 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700829 } catch (RemoteException e) {
830 Log.w(TAG, "Failed talking with device policy service", e);
831 }
832 }
833 return 0;
834 }
835
836 /**
837 * Called by an application that is administering the device to set the
838 * minimum number of numerical digits required in the password. After
839 * setting this, the user will not be able to enter a new password that is
840 * not at least as restrictive as what has been set. Note that the current
841 * password will remain until the user has set a new one, so the change does
842 * not take place immediately. To prompt the user for a new password, use
843 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
844 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700845 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
846 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700847 * <p>
848 * The calling device admin must have requested
849 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
850 * this method; if it has not, a security exception will be thrown.
851 *
852 * @param admin Which {@link DeviceAdminReceiver} this request is associated
853 * with.
854 * @param length The new desired minimum number of numerical digits required
855 * in the password. A value of 0 means there is no restriction.
856 */
857 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
858 if (mService != null) {
859 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700860 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700861 } catch (RemoteException e) {
862 Log.w(TAG, "Failed talking with device policy service", e);
863 }
864 }
865 }
866
867 /**
868 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100869 * for all admins of this user and its profiles or a particular one.
870 * This is the same value as set by
871 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700872 * and only applies when the password quality is
873 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700874 *
875 * @param admin The name of the admin component to check, or null to
876 * aggregate all admins.
877 * @return The minimum number of numerical digits required in the password.
878 */
879 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700880 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
881 }
882
883 /** @hide per-user version */
884 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700885 if (mService != null) {
886 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700887 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700888 } catch (RemoteException e) {
889 Log.w(TAG, "Failed talking with device policy service", e);
890 }
891 }
892 return 0;
893 }
894
895 /**
896 * Called by an application that is administering the device to set the
897 * minimum number of symbols required in the password. After setting this,
898 * the user will not be able to enter a new password that is not at least as
899 * restrictive as what has been set. Note that the current password will
900 * remain until the user has set a new one, so the change does not take
901 * place immediately. To prompt the user for a new password, use
902 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
903 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700904 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
905 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700906 * <p>
907 * The calling device admin must have requested
908 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
909 * this method; if it has not, a security exception will be thrown.
910 *
911 * @param admin Which {@link DeviceAdminReceiver} this request is associated
912 * with.
913 * @param length The new desired minimum number of symbols required in the
914 * password. A value of 0 means there is no restriction.
915 */
916 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
917 if (mService != null) {
918 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700919 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700920 } catch (RemoteException e) {
921 Log.w(TAG, "Failed talking with device policy service", e);
922 }
923 }
924 }
925
926 /**
927 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700928 * admins or a particular one. This is the same value as
929 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
930 * and only applies when the password quality is
931 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700932 *
933 * @param admin The name of the admin component to check, or null to
934 * aggregate all admins.
935 * @return The minimum number of symbols required in the password.
936 */
937 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700938 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
939 }
940
941 /** @hide per-user version */
942 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700943 if (mService != null) {
944 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700945 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700946 } catch (RemoteException e) {
947 Log.w(TAG, "Failed talking with device policy service", e);
948 }
949 }
950 return 0;
951 }
952
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700953 /**
954 * Called by an application that is administering the device to set the
955 * minimum number of non-letter characters (numerical digits or symbols)
956 * required in the password. After setting this, the user will not be able
957 * to enter a new password that is not at least as restrictive as what has
958 * been set. Note that the current password will remain until the user has
959 * set a new one, so the change does not take place immediately. To prompt
960 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
961 * setting this value. This constraint is only imposed if the administrator
962 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
963 * {@link #setPasswordQuality}. The default value is 0.
964 * <p>
965 * The calling device admin must have requested
966 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
967 * this method; if it has not, a security exception will be thrown.
968 *
969 * @param admin Which {@link DeviceAdminReceiver} this request is associated
970 * with.
971 * @param length The new desired minimum number of letters required in the
972 * password. A value of 0 means there is no restriction.
973 */
974 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
975 if (mService != null) {
976 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700977 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700978 } catch (RemoteException e) {
979 Log.w(TAG, "Failed talking with device policy service", e);
980 }
981 }
982 }
983
984 /**
985 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100986 * password for all admins of this user and its profiles or a particular one.
987 * This is the same value as set by
988 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700989 * and only applies when the password quality is
990 * {@link #PASSWORD_QUALITY_COMPLEX}.
991 *
992 * @param admin The name of the admin component to check, or null to
993 * aggregate all admins.
994 * @return The minimum number of letters required in the password.
995 */
996 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700997 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
998 }
999
1000 /** @hide per-user version */
1001 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001002 if (mService != null) {
1003 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001004 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001005 } catch (RemoteException e) {
1006 Log.w(TAG, "Failed talking with device policy service", e);
1007 }
1008 }
1009 return 0;
1010 }
1011
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001012 /**
1013 * Called by an application that is administering the device to set the length
1014 * of the password history. After setting this, the user will not be able to
1015 * enter a new password that is the same as any password in the history. Note
1016 * that the current password will remain until the user has set a new one, so
1017 * the change does not take place immediately. To prompt the user for a new
1018 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1019 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001020 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1021 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1022 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001023 *
1024 * <p>
1025 * The calling device admin must have requested
1026 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1027 * method; if it has not, a security exception will be thrown.
1028 *
1029 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1030 * with.
1031 * @param length The new desired length of password history. A value of 0
1032 * means there is no restriction.
1033 */
1034 public void setPasswordHistoryLength(ComponentName admin, int length) {
1035 if (mService != null) {
1036 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001037 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001038 } catch (RemoteException e) {
1039 Log.w(TAG, "Failed talking with device policy service", e);
1040 }
1041 }
1042 }
1043
1044 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001045 * Called by a device admin to set the password expiration timeout. Calling this method
1046 * will restart the countdown for password expiration for the given admin, as will changing
1047 * the device password (for all admins).
1048 *
1049 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1050 * For example, to have the password expire 5 days from now, timeout would be
1051 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1052 *
1053 * <p>To disable password expiration, a value of 0 may be used for timeout.
1054 *
Jim Millera4e28d12010-11-08 16:15:47 -08001055 * <p>The calling device admin must have requested
1056 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1057 * method; if it has not, a security exception will be thrown.
1058 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001059 * <p> Note that setting the password will automatically reset the expiration time for all
1060 * active admins. Active admins do not need to explicitly call this method in that case.
1061 *
Jim Millera4e28d12010-11-08 16:15:47 -08001062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1063 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1064 * means there is no restriction (unlimited).
1065 */
1066 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1067 if (mService != null) {
1068 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001069 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001070 } catch (RemoteException e) {
1071 Log.w(TAG, "Failed talking with device policy service", e);
1072 }
1073 }
1074 }
1075
1076 /**
Jim Miller6b857682011-02-16 16:27:41 -08001077 * Get the password expiration timeout for the given admin. The expiration timeout is the
1078 * recurring expiration timeout provided in the call to
1079 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1080 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001081 *
1082 * @param admin The name of the admin component to check, or null to aggregate all admins.
1083 * @return The timeout for the given admin or the minimum of all timeouts
1084 */
1085 public long getPasswordExpirationTimeout(ComponentName admin) {
1086 if (mService != null) {
1087 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001088 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001089 } catch (RemoteException e) {
1090 Log.w(TAG, "Failed talking with device policy service", e);
1091 }
1092 }
1093 return 0;
1094 }
1095
1096 /**
1097 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001098 * all admins of this user and its profiles if admin is null. If the password is
1099 * expired, this will return the time since the password expired as a negative number.
1100 * If admin is null, then a composite of all expiration timeouts is returned
1101 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001102 *
1103 * @param admin The name of the admin component to check, or null to aggregate all admins.
1104 * @return The password expiration time, in ms.
1105 */
1106 public long getPasswordExpiration(ComponentName admin) {
1107 if (mService != null) {
1108 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001109 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001110 } catch (RemoteException e) {
1111 Log.w(TAG, "Failed talking with device policy service", e);
1112 }
1113 }
1114 return 0;
1115 }
1116
1117 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001118 * Retrieve the current password history length for all admins of this
1119 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001120 * @param admin The name of the admin component to check, or null to aggregate
1121 * all admins.
1122 * @return The length of the password history
1123 */
1124 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001125 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1126 }
1127
1128 /** @hide per-user version */
1129 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001130 if (mService != null) {
1131 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001132 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001133 } catch (RemoteException e) {
1134 Log.w(TAG, "Failed talking with device policy service", e);
1135 }
1136 }
1137 return 0;
1138 }
1139
Dianne Hackbornd6847842010-01-12 18:14:19 -08001140 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001141 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001142 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001143 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001144 * @return Returns the maximum length that the user can enter.
1145 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001146 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001147 // Kind-of arbitrary.
1148 return 16;
1149 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001150
Dianne Hackborn254cb442010-01-27 19:23:59 -08001151 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001152 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001153 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001154 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001155 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001156 * <p>The calling device admin must have requested
1157 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1158 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001159 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001160 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001161 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001162 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001163 if (mService != null) {
1164 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001165 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001166 } catch (RemoteException e) {
1167 Log.w(TAG, "Failed talking with device policy service", e);
1168 }
1169 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001170 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001171 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001172
Dianne Hackbornd6847842010-01-12 18:14:19 -08001173 /**
1174 * Retrieve the number of times the user has failed at entering a
1175 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001176 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001177 * <p>The calling device admin must have requested
1178 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1179 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001180 */
1181 public int getCurrentFailedPasswordAttempts() {
1182 if (mService != null) {
1183 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001184 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001185 } catch (RemoteException e) {
1186 Log.w(TAG, "Failed talking with device policy service", e);
1187 }
1188 }
1189 return -1;
1190 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001191
1192 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001193 * Setting this to a value greater than zero enables a built-in policy
1194 * that will perform a device wipe after too many incorrect
1195 * device-unlock passwords have been entered. This built-in policy combines
1196 * watching for failed passwords and wiping the device, and requires
1197 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001198 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001199 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001200 * <p>To implement any other policy (e.g. wiping data for a particular
1201 * application only, erasing or revoking credentials, or reporting the
1202 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001203 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001204 * instead. Do not use this API, because if the maximum count is reached,
1205 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001206 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001207 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001208 * @param num The number of failed password attempts at which point the
1209 * device will wipe its data.
1210 */
1211 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1212 if (mService != null) {
1213 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001214 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001215 } catch (RemoteException e) {
1216 Log.w(TAG, "Failed talking with device policy service", e);
1217 }
1218 }
1219 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001220
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001221 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001222 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001223 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001224 * or a particular one.
1225 * @param admin The name of the admin component to check, or null to aggregate
1226 * all admins.
1227 */
1228 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001229 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1230 }
1231
1232 /** @hide per-user version */
1233 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001234 if (mService != null) {
1235 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001236 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001237 } catch (RemoteException e) {
1238 Log.w(TAG, "Failed talking with device policy service", e);
1239 }
1240 }
1241 return 0;
1242 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001243
Dianne Hackborn254cb442010-01-27 19:23:59 -08001244 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001245 * Flag for {@link #resetPassword}: don't allow other admins to change
1246 * the password again until the user has entered it.
1247 */
1248 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001249
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001250 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001251 * Force a new device unlock password (the password needed to access the
1252 * entire device, not for individual accounts) on the user. This takes
1253 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001254 * The given password must be sufficient for the
1255 * current password quality and length constraints as returned by
1256 * {@link #getPasswordQuality(ComponentName)} and
1257 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1258 * these constraints, then it will be rejected and false returned. Note
1259 * that the password may be a stronger quality (containing alphanumeric
1260 * characters when the requested quality is only numeric), in which case
1261 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001262 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001263 * <p>The calling device admin must have requested
1264 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1265 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001266 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001267 * Can not be called from a managed profile.
1268 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001269 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001270 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001271 * @return Returns true if the password was applied, or false if it is
1272 * not acceptable for the current constraints.
1273 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001274 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001275 if (mService != null) {
1276 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001277 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001278 } catch (RemoteException e) {
1279 Log.w(TAG, "Failed talking with device policy service", e);
1280 }
1281 }
1282 return false;
1283 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001284
Dianne Hackbornd6847842010-01-12 18:14:19 -08001285 /**
1286 * Called by an application that is administering the device to set the
1287 * maximum time for user activity until the device will lock. This limits
1288 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001289 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001290 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001291 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001292 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001293 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001295 * @param timeMs The new desired maximum time to lock in milliseconds.
1296 * A value of 0 means there is no restriction.
1297 */
1298 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1299 if (mService != null) {
1300 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001301 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001302 } catch (RemoteException e) {
1303 Log.w(TAG, "Failed talking with device policy service", e);
1304 }
1305 }
1306 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001307
Dianne Hackbornd6847842010-01-12 18:14:19 -08001308 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001309 * Retrieve the current maximum time to unlock for all admins of this user
1310 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001311 * @param admin The name of the admin component to check, or null to aggregate
1312 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001313 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001314 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001315 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1316 }
1317
1318 /** @hide per-user version */
1319 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001320 if (mService != null) {
1321 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001322 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001323 } catch (RemoteException e) {
1324 Log.w(TAG, "Failed talking with device policy service", e);
1325 }
1326 }
1327 return 0;
1328 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001329
Dianne Hackbornd6847842010-01-12 18:14:19 -08001330 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001331 * Make the device lock immediately, as if the lock screen timeout has
1332 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001333 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001334 * <p>The calling device admin must have requested
1335 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1336 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001337 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001338 public void lockNow() {
1339 if (mService != null) {
1340 try {
1341 mService.lockNow();
1342 } catch (RemoteException e) {
1343 Log.w(TAG, "Failed talking with device policy service", e);
1344 }
1345 }
1346 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001347
Dianne Hackbornd6847842010-01-12 18:14:19 -08001348 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001349 * Flag for {@link #wipeData(int)}: also erase the device's external
1350 * storage.
1351 */
1352 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1353
1354 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001355 * Ask the user data be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001356 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001357 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1358 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001359 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001360 * <p>The calling device admin must have requested
1361 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1362 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001363 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001364 * @param flags Bit mask of additional options: currently 0 and
1365 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001366 */
1367 public void wipeData(int flags) {
1368 if (mService != null) {
1369 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001370 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001371 } catch (RemoteException e) {
1372 Log.w(TAG, "Failed talking with device policy service", e);
1373 }
1374 }
1375 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001376
Dianne Hackbornd6847842010-01-12 18:14:19 -08001377 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001378 * Called by an application that is administering the device to set the
1379 * global proxy and exclusion list.
1380 * <p>
1381 * The calling device admin must have requested
1382 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1383 * this method; if it has not, a security exception will be thrown.
1384 * Only the first device admin can set the proxy. If a second admin attempts
1385 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1386 * proxy will be returned. If successful in setting the proxy, null will
1387 * be returned.
1388 * The method can be called repeatedly by the device admin alrady setting the
1389 * proxy to update the proxy and exclusion list.
1390 *
1391 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1392 * with.
1393 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1394 * Pass Proxy.NO_PROXY to reset the proxy.
1395 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001396 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1397 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001398 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001399 */
1400 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1401 List<String> exclusionList ) {
1402 if (proxySpec == null) {
1403 throw new NullPointerException();
1404 }
1405 if (mService != null) {
1406 try {
1407 String hostSpec;
1408 String exclSpec;
1409 if (proxySpec.equals(Proxy.NO_PROXY)) {
1410 hostSpec = null;
1411 exclSpec = null;
1412 } else {
1413 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1414 throw new IllegalArgumentException();
1415 }
1416 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1417 String hostName = sa.getHostName();
1418 int port = sa.getPort();
1419 StringBuilder hostBuilder = new StringBuilder();
1420 hostSpec = hostBuilder.append(hostName)
1421 .append(":").append(Integer.toString(port)).toString();
1422 if (exclusionList == null) {
1423 exclSpec = "";
1424 } else {
1425 StringBuilder listBuilder = new StringBuilder();
1426 boolean firstDomain = true;
1427 for (String exclDomain : exclusionList) {
1428 if (!firstDomain) {
1429 listBuilder = listBuilder.append(",");
1430 } else {
1431 firstDomain = false;
1432 }
1433 listBuilder = listBuilder.append(exclDomain.trim());
1434 }
1435 exclSpec = listBuilder.toString();
1436 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001437 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1438 != android.net.Proxy.PROXY_VALID)
1439 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001440 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001441 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001442 } catch (RemoteException e) {
1443 Log.w(TAG, "Failed talking with device policy service", e);
1444 }
1445 }
1446 return null;
1447 }
1448
1449 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001450 * Set a network-independent global HTTP proxy. This is not normally what you want
1451 * for typical HTTP proxies - they are generally network dependent. However if you're
1452 * doing something unusual like general internal filtering this may be useful. On
1453 * a private network where the proxy is not accessible, you may break HTTP using this.
1454 *
1455 * <p>This method requires the caller to be the device owner.
1456 *
1457 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1458 * @see ProxyInfo
1459 *
1460 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1461 * with.
1462 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1463 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1464 */
1465 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1466 if (mService != null) {
1467 try {
1468 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1469 } catch (RemoteException e) {
1470 Log.w(TAG, "Failed talking with device policy service", e);
1471 }
1472 }
1473 }
1474
1475 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001476 * Returns the component name setting the global proxy.
1477 * @return ComponentName object of the device admin that set the global proxy, or
1478 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001479 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001480 */
1481 public ComponentName getGlobalProxyAdmin() {
1482 if (mService != null) {
1483 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001484 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001485 } catch (RemoteException e) {
1486 Log.w(TAG, "Failed talking with device policy service", e);
1487 }
1488 }
1489 return null;
1490 }
1491
1492 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001493 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001494 * indicating that encryption is not supported.
1495 */
1496 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1497
1498 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001499 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001500 * indicating that encryption is supported, but is not currently active.
1501 */
1502 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1503
1504 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001505 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001506 * indicating that encryption is not currently active, but is currently
1507 * being activated. This is only reported by devices that support
1508 * encryption of data and only when the storage is currently
1509 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1510 * to become encrypted will never return this value.
1511 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001512 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001513
1514 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001515 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001516 * indicating that encryption is active.
1517 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001518 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001519
1520 /**
1521 * Activity action: begin the process of encrypting data on the device. This activity should
1522 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1523 * After resuming from this activity, use {@link #getStorageEncryption}
1524 * to check encryption status. However, on some devices this activity may never return, as
1525 * it may trigger a reboot and in some cases a complete data wipe of the device.
1526 */
1527 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1528 public static final String ACTION_START_ENCRYPTION
1529 = "android.app.action.START_ENCRYPTION";
1530
1531 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001532 * Widgets are enabled in keyguard
1533 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001534 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001535
1536 /**
Jim Miller50e62182014-04-23 17:25:00 -07001537 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001538 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001539 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1540
1541 /**
1542 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1543 */
1544 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1545
1546 /**
Jim Miller50e62182014-04-23 17:25:00 -07001547 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1548 */
1549 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1550
1551 /**
1552 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1553 */
1554 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1555
1556 /**
1557 * Ignore {@link TrustAgentService} state on secure keyguard screens
1558 * (e.g. PIN/Pattern/Password).
1559 */
1560 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1561
1562 /**
Jim Miller35207742012-11-02 15:33:20 -07001563 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001564 */
1565 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001566
1567 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001568 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001569 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001570 *
1571 * <p>When multiple device administrators attempt to control device
1572 * encryption, the most secure, supported setting will always be
1573 * used. If any device administrator requests device encryption,
1574 * it will be enabled; Conversely, if a device administrator
1575 * attempts to disable device encryption while another
1576 * device administrator has enabled it, the call to disable will
1577 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1578 *
1579 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001580 * written to other storage areas may or may not be encrypted, and this policy does not require
1581 * or control the encryption of any other storage areas.
1582 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1583 * {@code true}, then the directory returned by
1584 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1585 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001586 *
1587 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1588 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1589 * the encryption key may not be fully secured. For maximum security, the administrator should
1590 * also require (and check for) a pattern, PIN, or password.
1591 *
1592 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1593 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001594 * @return the new request status (for all active admins) - will be one of
1595 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1596 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1597 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001598 */
1599 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1600 if (mService != null) {
1601 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001602 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001603 } catch (RemoteException e) {
1604 Log.w(TAG, "Failed talking with device policy service", e);
1605 }
1606 }
1607 return ENCRYPTION_STATUS_UNSUPPORTED;
1608 }
1609
1610 /**
1611 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001612 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001613 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001614 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1615 * this will return the requested encryption setting as an aggregate of all active
1616 * administrators.
1617 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001618 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001619 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001620 if (mService != null) {
1621 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001622 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001623 } catch (RemoteException e) {
1624 Log.w(TAG, "Failed talking with device policy service", e);
1625 }
1626 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001627 return false;
1628 }
1629
1630 /**
1631 * Called by an application that is administering the device to
1632 * determine the current encryption status of the device.
1633 *
1634 * Depending on the returned status code, the caller may proceed in different
1635 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1636 * storage system does not support encryption. If the
1637 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1638 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1639 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1640 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1641 *
1642 * @return current status of encryption. The value will be one of
1643 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1644 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1645 */
1646 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001647 return getStorageEncryptionStatus(UserHandle.myUserId());
1648 }
1649
1650 /** @hide per-user version */
1651 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001652 if (mService != null) {
1653 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001654 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001655 } catch (RemoteException e) {
1656 Log.w(TAG, "Failed talking with device policy service", e);
1657 }
1658 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001659 return ENCRYPTION_STATUS_UNSUPPORTED;
1660 }
1661
1662 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001663 * Installs the given certificate as a User CA.
1664 *
1665 * @return false if the certBuffer cannot be parsed or installation is
1666 * interrupted, otherwise true
Maggie Benthallda51e682013-08-08 22:35:44 -04001667 */
Robin Lee306fe082014-06-19 14:04:24 +00001668 public boolean installCaCert(ComponentName who, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001669 if (mService != null) {
1670 try {
Robin Lee306fe082014-06-19 14:04:24 +00001671 return mService.installCaCert(who, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001672 } catch (RemoteException e) {
1673 Log.w(TAG, "Failed talking with device policy service", e);
1674 }
1675 }
1676 return false;
1677 }
1678
1679 /**
1680 * Uninstalls the given certificate from the list of User CAs, if present.
Maggie Benthallda51e682013-08-08 22:35:44 -04001681 */
Robin Lee306fe082014-06-19 14:04:24 +00001682 public void uninstallCaCert(ComponentName who, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001683 if (mService != null) {
1684 try {
Robin Lee306fe082014-06-19 14:04:24 +00001685 final String alias = getCaCertAlias(certBuffer);
1686 mService.uninstallCaCert(who, alias);
1687 } catch (CertificateException e) {
1688 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001689 } catch (RemoteException e) {
1690 Log.w(TAG, "Failed talking with device policy service", e);
1691 }
1692 }
1693 }
1694
1695 /**
1696 * Returns whether there are any user-installed CA certificates.
Maggie Benthallda51e682013-08-08 22:35:44 -04001697 */
Robin Lee306fe082014-06-19 14:04:24 +00001698 public boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001699 TrustedCertificateStore certStore = new TrustedCertificateStore();
1700 Set<String> aliases = certStore.userAliases();
1701 return aliases != null && !aliases.isEmpty();
1702 }
1703
1704 /**
1705 * Returns whether this certificate has been installed as a User CA.
Maggie Benthallda51e682013-08-08 22:35:44 -04001706 */
1707 public boolean hasCaCertInstalled(byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001708 try {
Robin Lee306fe082014-06-19 14:04:24 +00001709 return getCaCertAlias(certBuffer) != null;
Maggie Benthallda51e682013-08-08 22:35:44 -04001710 } catch (CertificateException ce) {
1711 Log.w(TAG, "Could not parse certificate", ce);
1712 }
1713 return false;
1714 }
1715
1716 /**
Robin Lee306fe082014-06-19 14:04:24 +00001717 * Returns the alias of a given CA certificate in the certificate store, or null if it
1718 * doesn't exist.
1719 */
1720 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1721 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1722 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1723 new ByteArrayInputStream(certBuffer));
1724 return new TrustedCertificateStore().getCertificateAlias(cert);
1725 }
1726
1727 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001728 * Called by an application that is administering the device to disable all cameras
1729 * on the device. After setting this, no applications will be able to access any cameras
1730 * on the device.
1731 *
1732 * <p>The calling device admin must have requested
1733 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1734 * this method; if it has not, a security exception will be thrown.
1735 *
1736 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1737 * @param disabled Whether or not the camera should be disabled.
1738 */
1739 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1740 if (mService != null) {
1741 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001742 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001743 } catch (RemoteException e) {
1744 Log.w(TAG, "Failed talking with device policy service", e);
1745 }
1746 }
1747 }
1748
1749 /**
1750 * Determine whether or not the device's cameras have been disabled either by the current
1751 * admin, if specified, or all admins.
1752 * @param admin The name of the admin component to check, or null to check if any admins
1753 * have disabled the camera
1754 */
1755 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001756 return getCameraDisabled(admin, UserHandle.myUserId());
1757 }
1758
1759 /** @hide per-user version */
1760 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001761 if (mService != null) {
1762 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001763 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001764 } catch (RemoteException e) {
1765 Log.w(TAG, "Failed talking with device policy service", e);
1766 }
1767 }
1768 return false;
1769 }
1770
1771 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001772 * Called by an application that is administering the device to disable keyguard customizations,
1773 * such as widgets. After setting this, keyguard features will be disabled according to the
1774 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001775 *
1776 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001777 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001778 * this method; if it has not, a security exception will be thrown.
1779 *
1780 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001781 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1782 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001783 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1784 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001785 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001786 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001787 if (mService != null) {
1788 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001789 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001790 } catch (RemoteException e) {
1791 Log.w(TAG, "Failed talking with device policy service", e);
1792 }
1793 }
1794 }
1795
1796 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001797 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001798 * admin, if specified, or all admins.
1799 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001800 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001801 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1802 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001803 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001804 public int getKeyguardDisabledFeatures(ComponentName admin) {
1805 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001806 }
1807
1808 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001809 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001810 if (mService != null) {
1811 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001812 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001813 } catch (RemoteException e) {
1814 Log.w(TAG, "Failed talking with device policy service", e);
1815 }
1816 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001817 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001818 }
1819
1820 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001821 * @hide
1822 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001823 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 if (mService != null) {
1825 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001826 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001827 } catch (RemoteException e) {
1828 Log.w(TAG, "Failed talking with device policy service", e);
1829 }
1830 }
1831 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001832
Dianne Hackbornd6847842010-01-12 18:14:19 -08001833 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001834 * @hide
1835 */
1836 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1837 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1838 }
1839
1840 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001841 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001842 * @hide
1843 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001844 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001845 ActivityInfo ai;
1846 try {
1847 ai = mContext.getPackageManager().getReceiverInfo(cn,
1848 PackageManager.GET_META_DATA);
1849 } catch (PackageManager.NameNotFoundException e) {
1850 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1851 return null;
1852 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001853
Dianne Hackbornd6847842010-01-12 18:14:19 -08001854 ResolveInfo ri = new ResolveInfo();
1855 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001856
Dianne Hackbornd6847842010-01-12 18:14:19 -08001857 try {
1858 return new DeviceAdminInfo(mContext, ri);
1859 } catch (XmlPullParserException e) {
1860 Log.w(TAG, "Unable to parse device policy " + cn, e);
1861 return null;
1862 } catch (IOException e) {
1863 Log.w(TAG, "Unable to parse device policy " + cn, e);
1864 return null;
1865 }
1866 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001867
Dianne Hackbornd6847842010-01-12 18:14:19 -08001868 /**
1869 * @hide
1870 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001871 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1872 if (mService != null) {
1873 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001874 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001875 } catch (RemoteException e) {
1876 Log.w(TAG, "Failed talking with device policy service", e);
1877 }
1878 }
1879 }
1880
1881 /**
1882 * @hide
1883 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001884 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001885 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001886 if (mService != null) {
1887 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001888 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001889 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001890 } catch (RemoteException e) {
1891 Log.w(TAG, "Failed talking with device policy service", e);
1892 }
1893 }
1894 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001895
Dianne Hackbornd6847842010-01-12 18:14:19 -08001896 /**
1897 * @hide
1898 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001899 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001900 if (mService != null) {
1901 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001902 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001903 } catch (RemoteException e) {
1904 Log.w(TAG, "Failed talking with device policy service", e);
1905 }
1906 }
1907 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001908
Dianne Hackbornd6847842010-01-12 18:14:19 -08001909 /**
1910 * @hide
1911 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001912 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001913 if (mService != null) {
1914 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001915 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001916 } catch (RemoteException e) {
1917 Log.w(TAG, "Failed talking with device policy service", e);
1918 }
1919 }
1920 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001921
1922 /**
1923 * @hide
1924 * Sets the given package as the device owner. The package must already be installed and there
1925 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1926 * method must be called before the device is provisioned.
1927 * @param packageName the package name of the application to be registered as the device owner.
1928 * @return whether the package was successfully registered as the device owner.
1929 * @throws IllegalArgumentException if the package name is null or invalid
1930 * @throws IllegalStateException if a device owner is already registered or the device has
1931 * already been provisioned.
1932 */
1933 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1934 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001935 return setDeviceOwner(packageName, null);
1936 }
1937
1938 /**
1939 * @hide
1940 * Sets the given package as the device owner. The package must already be installed and there
1941 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1942 * method must be called before the device is provisioned.
1943 * @param packageName the package name of the application to be registered as the device owner.
1944 * @param ownerName the human readable name of the institution that owns this device.
1945 * @return whether the package was successfully registered as the device owner.
1946 * @throws IllegalArgumentException if the package name is null or invalid
1947 * @throws IllegalStateException if a device owner is already registered or the device has
1948 * already been provisioned.
1949 */
1950 public boolean setDeviceOwner(String packageName, String ownerName)
1951 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001952 if (mService != null) {
1953 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001954 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07001955 } catch (RemoteException re) {
1956 Log.w(TAG, "Failed to set device owner");
1957 }
1958 }
1959 return false;
1960 }
1961
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001962
Amith Yamasani71e6c692013-03-24 17:39:28 -07001963 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001964 * Used to determine if a particular package has been registered as a Device Owner app.
1965 * A device owner app is a special device admin that cannot be deactivated by the user, once
1966 * activated as a device admin. It also cannot be uninstalled. To check if a particular
1967 * package is currently registered as the device owner app, pass in the package name from
1968 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
1969 * admin apps that want to check if they are also registered as the device owner app. The
1970 * exact mechanism by which a device admin app is registered as a device owner app is defined by
1971 * the setup process.
1972 * @param packageName the package name of the app, to compare with the registered device owner
1973 * app, if any.
1974 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001975 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001976 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001977 if (mService != null) {
1978 try {
1979 return mService.isDeviceOwner(packageName);
1980 } catch (RemoteException re) {
1981 Log.w(TAG, "Failed to check device owner");
1982 }
1983 }
1984 return false;
1985 }
1986
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001987 /**
1988 * @hide
1989 * Redirect to isDeviceOwnerApp.
1990 */
1991 public boolean isDeviceOwner(String packageName) {
1992 return isDeviceOwnerApp(packageName);
1993 }
1994
Jason Monkb0dced82014-06-06 14:36:20 -04001995 /**
1996 * Clears the current device owner. The caller must be the device owner.
1997 *
1998 * This function should be used cautiously as once it is called it cannot
1999 * be undone. The device owner can only be set as a part of device setup
2000 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002001 *
2002 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002003 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002004 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002005 if (mService != null) {
2006 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002007 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002008 } catch (RemoteException re) {
2009 Log.w(TAG, "Failed to clear device owner");
2010 }
2011 }
2012 }
2013
Amith Yamasani71e6c692013-03-24 17:39:28 -07002014 /** @hide */
2015 public String getDeviceOwner() {
2016 if (mService != null) {
2017 try {
2018 return mService.getDeviceOwner();
2019 } catch (RemoteException re) {
2020 Log.w(TAG, "Failed to get device owner");
2021 }
2022 }
2023 return null;
2024 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002025
2026 /** @hide */
2027 public String getDeviceOwnerName() {
2028 if (mService != null) {
2029 try {
2030 return mService.getDeviceOwnerName();
2031 } catch (RemoteException re) {
2032 Log.w(TAG, "Failed to get device owner");
2033 }
2034 }
2035 return null;
2036 }
Adam Connors776c5552014-01-09 10:42:56 +00002037
2038 /**
2039 * @hide
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302040 * @SystemApi
2041 * Sets the given component as an active admin and registers the package as the profile
2042 * owner for this user. The package must already be installed and there shouldn't be
2043 * an existing profile owner registered for this user. Also, this method must be called
2044 * before the user setup has been completed.
2045 * <p>
2046 * This method can only be called by system apps that hold MANAGE_USERS permission and
2047 * MANAGE_DEVICE_ADMINS permission.
2048 * @param admin The component to register as an active admin and profile owner.
2049 * @param ownerName The user-visible name of the entity that is managing this user.
2050 * @return whether the admin was successfully registered as the profile owner.
2051 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2052 * the user has already been set up.
2053 */
2054 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2055 throws IllegalArgumentException {
2056 if (mService != null) {
2057 try {
2058 final int myUserId = UserHandle.myUserId();
2059 mService.setActiveAdmin(admin, false, myUserId);
2060 return mService.setProfileOwner(admin.getPackageName(), ownerName, myUserId);
2061 } catch (RemoteException re) {
2062 Log.w(TAG, "Failed to set profile owner " + re);
2063 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2064 }
2065 }
2066 return false;
2067 }
2068
2069 /**
2070 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002071 * Sets the given package as the profile owner of the given user profile. The package must
2072 * already be installed and there shouldn't be an existing profile owner registered for this
2073 * user. Also, this method must be called before the user has been used for the first time.
2074 * @param packageName the package name of the application to be registered as profile owner.
2075 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002076 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002077 * @return whether the package was successfully registered as the profile owner.
2078 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2079 * the user has already been set up.
2080 */
Adam Connors661ec472014-02-11 13:59:46 +00002081 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002082 throws IllegalArgumentException {
2083 if (mService != null) {
2084 try {
Adam Connors661ec472014-02-11 13:59:46 +00002085 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002086 } 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 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002095 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2096 * be used. Only the profile owner can call this.
2097 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002098 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002099 *
2100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2101 */
2102 public void setProfileEnabled(ComponentName admin) {
2103 if (mService != null) {
2104 try {
2105 mService.setProfileEnabled(admin);
2106 } catch (RemoteException e) {
2107 Log.w(TAG, "Failed talking with device policy service", e);
2108 }
2109 }
2110 }
2111
2112 /**
Jessica Hummel1333ea12014-06-23 11:20:10 +01002113 * Sets the name of the Managed profile. In the device owner case it sets the name of the user
2114 * which it is called from. Only the profile owner or device owner can call this. If this is
2115 * never called by the profile or device owner, the name will be set to default values.
2116 *
2117 * @see #isProfileOwnerApp
2118 * @see #isDeviceOwnerApp
2119 *
2120 * @param profileName The name of the profile.
2121 */
2122 public void setProfileName(ComponentName who, String profileName) {
2123 if (mService != null) {
2124 try {
2125 mService.setProfileName(who, profileName);
2126 } catch (RemoteException e) {
2127 Log.w(TAG, "Failed talking with device policy service", e);
2128 }
2129 }
2130}
2131
2132 /**
Adam Connors776c5552014-01-09 10:42:56 +00002133 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002134 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00002135 * within the managed profile.
2136 *
2137 * @param packageName The package name of the app to compare with the registered profile owner.
2138 * @return Whether or not the package is registered as the profile owner.
2139 */
2140 public boolean isProfileOwnerApp(String packageName) {
2141 if (mService != null) {
2142 try {
2143 String profileOwnerPackage = mService.getProfileOwner(
2144 Process.myUserHandle().getIdentifier());
2145 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
2146 } catch (RemoteException re) {
2147 Log.w(TAG, "Failed to check profile owner");
2148 }
2149 }
2150 return false;
2151 }
2152
2153 /**
2154 * @hide
2155 * @return the packageName of the owner of the given user profile or null if no profile
2156 * owner has been set for that user.
2157 * @throws IllegalArgumentException if the userId is invalid.
2158 */
2159 public String getProfileOwner() throws IllegalArgumentException {
2160 if (mService != null) {
2161 try {
2162 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
2163 } catch (RemoteException re) {
2164 Log.w(TAG, "Failed to get profile owner");
2165 throw new IllegalArgumentException(
2166 "Requested profile owner for invalid userId", re);
2167 }
2168 }
2169 return null;
2170 }
2171
2172 /**
2173 * @hide
2174 * @return the human readable name of the organisation associated with this DPM or null if
2175 * one is not set.
2176 * @throws IllegalArgumentException if the userId is invalid.
2177 */
2178 public String getProfileOwnerName() throws IllegalArgumentException {
2179 if (mService != null) {
2180 try {
2181 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2182 } catch (RemoteException re) {
2183 Log.w(TAG, "Failed to get profile owner");
2184 throw new IllegalArgumentException(
2185 "Requested profile owner for invalid userId", re);
2186 }
2187 }
2188 return null;
2189 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002190
2191 /**
2192 * Called by a profile owner or device owner to add a default intent handler activity for
2193 * intents that match a certain intent filter. This activity will remain the default intent
2194 * handler even if the set of potential event handlers for the intent filter changes and if
2195 * the intent preferences are reset.
2196 *
2197 * <p>The default disambiguation mechanism takes over if the activity is not installed
2198 * (anymore). When the activity is (re)installed, it is automatically reset as default
2199 * intent handler for the filter.
2200 *
2201 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2202 * security exception will be thrown.
2203 *
2204 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2205 * @param filter The IntentFilter for which a default handler is added.
2206 * @param activity The Activity that is added as default intent handler.
2207 */
2208 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2209 ComponentName activity) {
2210 if (mService != null) {
2211 try {
2212 mService.addPersistentPreferredActivity(admin, filter, activity);
2213 } catch (RemoteException e) {
2214 Log.w(TAG, "Failed talking with device policy service", e);
2215 }
2216 }
2217 }
2218
2219 /**
2220 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002221 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002222 *
2223 * <p>The calling device admin must be a profile owner. If it is not, a security
2224 * exception will be thrown.
2225 *
2226 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2227 * @param packageName The name of the package for which preferences are removed.
2228 */
2229 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2230 String packageName) {
2231 if (mService != null) {
2232 try {
2233 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2234 } catch (RemoteException e) {
2235 Log.w(TAG, "Failed talking with device policy service", e);
2236 }
2237 }
2238 }
Robin Lee66e5d962014-04-09 16:44:21 +01002239
2240 /**
2241 * Called by a profile or device owner to set the application restrictions for a given target
2242 * application running in the managed profile.
2243 *
2244 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
2245 * {@link Boolean}, {@link String}, or {@link String}[]. The recommended format for key strings
2246 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2247 * components such as {@link android.webkit.WebView}.
2248 *
2249 * <p>The application restrictions are only made visible to the target application and the
2250 * profile or device owner.
2251 *
2252 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2253 * exception will be thrown.
2254 *
2255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2256 * @param packageName The name of the package to update restricted settings for.
2257 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2258 * set of active restrictions.
2259 */
2260 public void setApplicationRestrictions(ComponentName admin, String packageName,
2261 Bundle settings) {
2262 if (mService != null) {
2263 try {
2264 mService.setApplicationRestrictions(admin, packageName, settings);
2265 } catch (RemoteException e) {
2266 Log.w(TAG, "Failed talking with device policy service", e);
2267 }
2268 }
2269 }
2270
2271 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002272 * Called by the profile owner so that some intents sent in the managed profile can also be
2273 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002274 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002275 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2276 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002277 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2278 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002279 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002280 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002281 if (mService != null) {
2282 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002283 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002284 } catch (RemoteException e) {
2285 Log.w(TAG, "Failed talking with device policy service", e);
2286 }
2287 }
2288 }
2289
2290 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002291 * Called by a profile owner to remove the cross-profile intent filters from the managed profile
2292 * and from the parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002293 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2294 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002295 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002296 if (mService != null) {
2297 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002298 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002299 } catch (RemoteException e) {
2300 Log.w(TAG, "Failed talking with device policy service", e);
2301 }
2302 }
2303 }
2304
2305 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002306 * Called by a device owner to create a user with the specified name. The UserHandle returned
2307 * by this method should not be persisted as user handles are recycled as users are removed and
2308 * created. If you need to persist an identifier for this user, use
2309 * {@link UserManager#getSerialNumberForUser}.
2310 *
2311 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2312 * @param name the user's name
2313 * @see UserHandle
2314 * @return the UserHandle object for the created user, or null if the user could not be created.
2315 */
2316 public UserHandle createUser(ComponentName admin, String name) {
2317 try {
2318 return mService.createUser(admin, name);
2319 } catch (RemoteException re) {
2320 Log.w(TAG, "Could not create a user", re);
2321 }
2322 return null;
2323 }
2324
2325 /**
Jason Monk03978a42014-06-10 15:05:30 -04002326 * Called by a device owner to create a user with the specified name. The UserHandle returned
2327 * by this method should not be persisted as user handles are recycled as users are removed and
2328 * created. If you need to persist an identifier for this user, use
2329 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2330 * immediately.
2331 *
2332 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2333 * as registered as an active admin on the new user. The profile owner package will be
2334 * installed on the new user if it already is installed on the device.
2335 *
2336 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2337 * profileOwnerComponent when onEnable is called.
2338 *
2339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2340 * @param name the user's name
2341 * @param ownerName the human readable name of the organisation associated with this DPM.
2342 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2343 * the user.
2344 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2345 * on the new user.
2346 * @see UserHandle
2347 * @return the UserHandle object for the created user, or null if the user could not be created.
2348 */
2349 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2350 ComponentName profileOwnerComponent, Bundle adminExtras) {
2351 try {
2352 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2353 adminExtras);
2354 } catch (RemoteException re) {
2355 Log.w(TAG, "Could not create a user", re);
2356 }
2357 return null;
2358 }
2359
2360 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002361 * Called by a device owner to remove a user and all associated data. The primary user can
2362 * not be removed.
2363 *
2364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2365 * @param userHandle the user to remove.
2366 * @return {@code true} if the user was removed, {@code false} otherwise.
2367 */
2368 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2369 try {
2370 return mService.removeUser(admin, userHandle);
2371 } catch (RemoteException re) {
2372 Log.w(TAG, "Could not remove user ", re);
2373 return false;
2374 }
2375 }
2376
2377 /**
Jason Monk582d9112014-07-09 19:57:08 -04002378 * Called by a device owner to switch the specified user to the foreground.
2379 *
2380 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2381 * @param userHandle the user to switch to; null will switch to primary.
2382 * @return {@code true} if the switch was successful, {@code false} otherwise.
2383 *
2384 * @see Intent#ACTION_USER_FOREGROUND
2385 */
2386 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
2387 try {
2388 return mService.switchUser(admin, userHandle);
2389 } catch (RemoteException re) {
2390 Log.w(TAG, "Could not switch user ", re);
2391 return false;
2392 }
2393 }
2394
2395 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002396 * Called by a profile or device owner to get the application restrictions for a given target
2397 * application running in the managed profile.
2398 *
2399 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2400 * exception will be thrown.
2401 *
2402 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2403 * @param packageName The name of the package to fetch restricted settings of.
2404 * @return {@link Bundle} of settings corresponding to what was set last time
2405 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2406 * if no restrictions have been set.
2407 */
2408 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2409 if (mService != null) {
2410 try {
2411 return mService.getApplicationRestrictions(admin, packageName);
2412 } catch (RemoteException e) {
2413 Log.w(TAG, "Failed talking with device policy service", e);
2414 }
2415 }
2416 return null;
2417 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002418
2419 /**
2420 * Called by a profile or device owner to set a user restriction specified
2421 * by the key.
2422 * <p>
2423 * The calling device admin must be a profile or device owner; if it is not,
2424 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002425 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002426 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2427 * with.
2428 * @param key The key of the restriction. See the constants in
2429 * {@link android.os.UserManager} for the list of keys.
2430 */
2431 public void addUserRestriction(ComponentName admin, String key) {
2432 if (mService != null) {
2433 try {
2434 mService.setUserRestriction(admin, key, true);
2435 } catch (RemoteException e) {
2436 Log.w(TAG, "Failed talking with device policy service", e);
2437 }
2438 }
2439 }
2440
2441 /**
2442 * Called by a profile or device owner to clear a user restriction specified
2443 * by the key.
2444 * <p>
2445 * The calling device admin must be a profile or device owner; if it is not,
2446 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002447 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002448 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2449 * with.
2450 * @param key The key of the restriction. See the constants in
2451 * {@link android.os.UserManager} for the list of keys.
2452 */
2453 public void clearUserRestriction(ComponentName admin, String key) {
2454 if (mService != null) {
2455 try {
2456 mService.setUserRestriction(admin, key, false);
2457 } catch (RemoteException e) {
2458 Log.w(TAG, "Failed talking with device policy service", e);
2459 }
2460 }
2461 }
Adam Connors010cfd42014-04-16 12:48:13 +01002462
2463 /**
Julia Reynolds966881e2014-05-14 12:23:08 -04002464 * Called by device or profile owner to block or unblock packages. When a package is blocked it
2465 * is unavailable for use, but the data and actual package file remain.
2466 *
2467 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2468 * @param packageName The name of the package to block or unblock.
2469 * @param blocked {@code true} if the package should be blocked, {@code false} if it should be
2470 * unblocked.
2471 * @return boolean Whether the blocked setting of the package was successfully updated.
2472 */
2473 public boolean setApplicationBlocked(ComponentName admin, String packageName,
2474 boolean blocked) {
2475 if (mService != null) {
2476 try {
2477 return mService.setApplicationBlocked(admin, packageName, blocked);
2478 } catch (RemoteException e) {
2479 Log.w(TAG, "Failed talking with device policy service", e);
2480 }
2481 }
2482 return false;
2483 }
2484
2485 /**
2486 * Called by profile or device owner to block or unblock currently installed packages. This
2487 * should only be called by a profile or device owner running within a managed profile.
2488 *
2489 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2490 * @param intent An intent matching the app(s) to be updated. All apps that resolve for this
2491 * intent will be updated in the current profile.
2492 * @param blocked {@code true} if the packages should be blocked, {@code false} if they should
2493 * be unblocked.
2494 * @return int The number of activities that matched the intent and were updated.
2495 */
2496 public int setApplicationsBlocked(ComponentName admin, Intent intent, boolean blocked) {
2497 if (mService != null) {
2498 try {
2499 return mService.setApplicationsBlocked(admin, intent, blocked);
2500 } catch (RemoteException e) {
2501 Log.w(TAG, "Failed talking with device policy service", e);
2502 }
2503 }
2504 return 0;
2505 }
2506
2507 /**
2508 * Called by device or profile owner to determine if a package is blocked.
2509 *
2510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2511 * @param packageName The name of the package to retrieve the blocked status of.
2512 * @return boolean {@code true} if the package is blocked, {@code false} otherwise.
2513 */
2514 public boolean isApplicationBlocked(ComponentName admin, String packageName) {
2515 if (mService != null) {
2516 try {
2517 return mService.isApplicationBlocked(admin, packageName);
2518 } catch (RemoteException e) {
2519 Log.w(TAG, "Failed talking with device policy service", e);
2520 }
2521 }
2522 return false;
2523 }
2524
2525 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01002526 * Called by a profile owner to disable account management for a specific type of account.
2527 *
2528 * <p>The calling device admin must be a profile owner. If it is not, a
2529 * security exception will be thrown.
2530 *
2531 * <p>When account management is disabled for an account type, adding or removing an account
2532 * of that type will not be possible.
2533 *
2534 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2535 * @param accountType For which account management is disabled or enabled.
2536 * @param disabled The boolean indicating that account management will be disabled (true) or
2537 * enabled (false).
2538 */
2539 public void setAccountManagementDisabled(ComponentName admin, String accountType,
2540 boolean disabled) {
2541 if (mService != null) {
2542 try {
2543 mService.setAccountManagementDisabled(admin, accountType, disabled);
2544 } catch (RemoteException e) {
2545 Log.w(TAG, "Failed talking with device policy service", e);
2546 }
2547 }
2548 }
2549
2550 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002551 * Gets the array of accounts for which account management is disabled by the profile owner.
2552 *
2553 * <p> Account management can be disabled/enabled by calling
2554 * {@link #setAccountManagementDisabled}.
2555 *
2556 * @return a list of account types for which account management has been disabled.
2557 *
2558 * @see #setAccountManagementDisabled
2559 */
2560 public String[] getAccountTypesWithManagementDisabled() {
2561 if (mService != null) {
2562 try {
2563 return mService.getAccountTypesWithManagementDisabled();
2564 } catch (RemoteException e) {
2565 Log.w(TAG, "Failed talking with device policy service", e);
2566 }
2567 }
2568
2569 return null;
2570 }
justinzhang511e0d82014-03-24 16:09:24 -04002571
2572 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002573 * Sets which packages may enter lock task mode.
2574 *
2575 * <p>Any packages that shares uid with an allowed package will also be allowed
2576 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04002577 *
Jason Monkc5185f22014-06-24 11:12:42 -04002578 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04002579 * @param packages The list of packages allowed to enter lock task mode
2580 *
2581 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04002582 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
2583 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04002584 */
Jason Monkd7b86212014-06-16 13:15:38 -04002585 public void setLockTaskPackages(String[] packages) throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04002586 if (mService != null) {
2587 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002588 mService.setLockTaskPackages(packages);
justinzhang511e0d82014-03-24 16:09:24 -04002589 } catch (RemoteException e) {
2590 Log.w(TAG, "Failed talking with device policy service", e);
2591 }
2592 }
2593 }
2594
2595 /**
Jason Monkd7b86212014-06-16 13:15:38 -04002596 * This function returns the list of packages allowed to start the lock task mode.
justinzhang511e0d82014-03-24 16:09:24 -04002597 * @hide
2598 */
Jason Monkd7b86212014-06-16 13:15:38 -04002599 public String[] getLockTaskPackages() {
justinzhang511e0d82014-03-24 16:09:24 -04002600 if (mService != null) {
2601 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002602 return mService.getLockTaskPackages();
justinzhang511e0d82014-03-24 16:09:24 -04002603 } catch (RemoteException e) {
2604 Log.w(TAG, "Failed talking with device policy service", e);
2605 }
2606 }
2607 return null;
2608 }
2609
2610 /**
2611 * This function lets the caller know whether the given component is allowed to start the
2612 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04002613 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04002614 */
Jason Monkd7b86212014-06-16 13:15:38 -04002615 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04002616 if (mService != null) {
2617 try {
Jason Monkd7b86212014-06-16 13:15:38 -04002618 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04002619 } catch (RemoteException e) {
2620 Log.w(TAG, "Failed talking with device policy service", e);
2621 }
2622 }
2623 return false;
2624 }
Julia Reynoldsda551652014-05-14 17:15:16 -04002625
2626 /**
2627 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
2628 * of the setting is in the correct form for the setting type should be performed by the caller.
2629 *
2630 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2631 * @param setting The name of the setting to update.
2632 * @param value The value to update the setting to.
2633 */
2634 public void setGlobalSetting(ComponentName admin, String setting, String value) {
2635 if (mService != null) {
2636 try {
2637 mService.setGlobalSetting(admin, setting, value);
2638 } catch (RemoteException e) {
2639 Log.w(TAG, "Failed talking with device policy service", e);
2640 }
2641 }
2642 }
2643
2644 /**
2645 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
2646 * that the value of the setting is in the correct form for the setting type should be performed
2647 * by the caller.
2648 *
2649 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2650 * @param setting The name of the setting to update.
2651 * @param value The value to update the setting to.
2652 */
2653 public void setSecureSetting(ComponentName admin, String setting, String value) {
2654 if (mService != null) {
2655 try {
2656 mService.setSecureSetting(admin, setting, value);
2657 } catch (RemoteException e) {
2658 Log.w(TAG, "Failed talking with device policy service", e);
2659 }
2660 }
2661 }
2662
Amith Yamasanif20d6402014-05-24 15:34:37 -07002663 /**
2664 * Designates a specific broadcast receiver component as the provider for
2665 * making permission requests of a local or remote administrator of the user.
2666 * <p/>
2667 * Only a profile owner can designate the restrictions provider.
2668 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2669 * @param receiver The component name of a BroadcastReceiver that handles the
2670 * {@link RestrictionsManager#ACTION_REQUEST_PERMISSION} intent. If this param is null,
2671 * it removes the restrictions provider previously assigned.
2672 */
2673 public void setRestrictionsProvider(ComponentName admin, ComponentName receiver) {
2674 if (mService != null) {
2675 try {
2676 mService.setRestrictionsProvider(admin, receiver);
2677 } catch (RemoteException re) {
2678 Log.w(TAG, "Failed to set permission provider on device policy service");
2679 }
2680 }
2681 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04002682
2683 /**
2684 * Called by profile or device owners to set the master volume mute on or off.
2685 *
2686 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2687 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
2688 */
2689 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
2690 if (mService != null) {
2691 try {
2692 mService.setMasterVolumeMuted(admin, on);
2693 } catch (RemoteException re) {
2694 Log.w(TAG, "Failed to setMasterMute on device policy service");
2695 }
2696 }
2697 }
2698
2699 /**
2700 * Called by profile or device owners to check whether the master volume mute is on or off.
2701 *
2702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2703 * @return {@code true} if master volume is muted, {@code false} if it's not.
2704 */
2705 public boolean isMasterVolumeMuted(ComponentName admin) {
2706 if (mService != null) {
2707 try {
2708 return mService.isMasterVolumeMuted(admin);
2709 } catch (RemoteException re) {
2710 Log.w(TAG, "Failed to get isMasterMute on device policy service");
2711 }
2712 }
2713 return false;
2714 }
Kenny Guyc13053b2014-05-29 14:17:17 +01002715
2716 /**
2717 * Called by profile or device owners to change whether a user can uninstall
2718 * a package.
2719 *
2720 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2721 * @param packageName package to change.
2722 * @param blockUninstall true if the user shouldn't be able to uninstall the package.
2723 */
2724 public void setBlockUninstall(ComponentName admin, String packageName, boolean blockUninstall) {
2725 if (mService != null) {
2726 try {
2727 mService.setBlockUninstall(admin, packageName, blockUninstall);
2728 } catch (RemoteException re) {
2729 Log.w(TAG, "Failed to call block uninstall on device policy service");
2730 }
2731 }
2732 }
2733
2734 /**
2735 * Called by profile or device owners to check whether a user has been blocked from
2736 * uninstalling a package.
2737 *
2738 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2739 * @param packageName package to check.
2740 * @return true if the user shouldn't be able to uninstall the package.
2741 */
2742 public boolean getBlockUninstall(ComponentName admin, String packageName) {
2743 if (mService != null) {
2744 try {
2745 return mService.getBlockUninstall(admin, packageName);
2746 } catch (RemoteException re) {
2747 Log.w(TAG, "Failed to call block uninstall on device policy service");
2748 }
2749 }
2750 return false;
2751 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08002752}