blob: 9ed8960a8d97710fc78c9de2c88eb21b87747f65 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Dianne Hackbornd6847842010-01-12 18:14:19 -080019import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050021import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040022import android.app.Activity;
Svetoslav976e8bd2014-07-16 15:12:03 -070023import android.app.admin.IDevicePolicyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.content.ComponentName;
25import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010026import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000027import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080028import android.content.pm.ActivityInfo;
29import android.content.pm.PackageManager;
30import android.content.pm.ResolveInfo;
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;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070041import android.service.restrictions.RestrictionsReceiver;
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;
Jim Miller604e7552014-07-18 19:00:02 -070055import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070056import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080057import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080058
59/**
60 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080061 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080062 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080063 *
64 * <div class="special reference">
65 * <h3>Developer Guides</h3>
66 * <p>For more information about managing policies for device adminstration, read the
67 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
68 * developer guide.</p>
69 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080070 */
71public class DevicePolicyManager {
72 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080073
74 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080075 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070076
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080077 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080078 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080079 mService = IDevicePolicyManager.Stub.asInterface(
80 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
81 }
82
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080083 /** @hide */
84 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080085 DevicePolicyManager me = new DevicePolicyManager(context, handler);
86 return me.mService != null ? me : null;
87 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070088
Dianne Hackbornd6847842010-01-12 18:14:19 -080089 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +000090 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +000091 *
Jessica Hummel9da60392014-05-21 12:32:57 +010092 * <p>A managed profile allows data separation for example for the usage of a
93 * device as a personal and corporate device. The user which provisioning is started from and
94 * the managed profile share a launcher.
95 *
96 * <p>This intent will typically be sent by a mobile device management application (mdm).
97 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
98 * control over the profile
99 *
100 * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}
101 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000102 *
103 * <p> When managed provisioning has completed, an intent of the type
104 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100105 * managed profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100106 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100107 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
108 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000109 *
110 * <p>Input: Nothing.</p>
111 * <p>Output: Nothing</p>
112 */
113 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
114 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000115 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116
117 /**
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100118 * A {@link Parcelable} extra of type {@link PersistableBundle} that allows a mobile device
119 * management application that starts managed profile provisioning to pass data to itself on the
120 * managed profile when provisioning completes. The mobile device management application sends
121 * this extra in an intent with the action {@link #ACTION_PROVISION_MANAGED_PROFILE} and
122 * receives it in {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with
123 * the action {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is
124 * not changed during the managed profile provisioning.
125 */
126 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
127 "android.app.extra.ADMIN_EXTRA_BUNDLE";
128
129 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100130 * A String extra holding the package name of the mobile device management application that
131 * will be set as the profile owner or device owner.
132 *
133 * <p>If an application starts provisioning directly via an intent with action
134 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
135 * application that started provisioning. The package will be set as profile owner in that case.
136 *
137 * <p>This package is set as device owner when device owner provisioning is started by an Nfc
Esteban Talaveraf057f062014-08-20 14:27:45 +0100138 * message containing an Nfc record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000139 */
140 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaverafbb28df2014-08-26 15:38:17 +0100141 = "android.app.extra.deviceAdminPackageName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000142
143 /**
144 * A String extra holding the default name of the profile that is created during managed profile
145 * provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100146 *
Jessica Hummelf72078b2014-03-06 16:13:12 +0000147 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
148 */
149 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100150 = "android.app.extra.DEFAULT_MANAGED_PROFILE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000151
152 /**
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100153 * A String extra that, holds the email address of the account which a managed profile is
154 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100155 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100156 *
157 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
158 * contains this extra, it is forwarded in the
159 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
160 * device management application that was set as the profile owner during provisioning.
161 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100162 */
163 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
Esteban Talaverafbb28df2014-08-26 15:38:17 +0100164 = "android.app.extra.ManagedProfileEmailAddress";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100165
166 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100167 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
168 * will be set to.
169 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100170 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100171 * provisioning via an Nfc bump.
172 */
173 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100174 = "android.app.extra.TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100175
176 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100177 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
178 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100179 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100180 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100181 * provisioning via an Nfc bump.
182 */
183 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100184 = "android.app.extra.LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100185
186 /**
187 * A String extra holding the {@link java.util.Locale} that the device will be set to.
188 * Format: xx_yy, where xx is the language code, and yy the country code.
189 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100190 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100191 * provisioning via an Nfc bump.
192 */
193 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100194 = "android.app.extra.LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100195
196 /**
197 * A String extra holding the ssid of the wifi network that should be used during nfc device
198 * owner provisioning for downloading the mobile device management application.
199 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100200 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100201 * provisioning via an Nfc bump.
202 */
203 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100204 = "android.app.extra.WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100205
206 /**
207 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
208 * is hidden or not.
209 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100210 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100211 * provisioning via an Nfc bump.
212 */
213 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100214 = "android.app.extra.WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100215
216 /**
217 * A String extra indicating the security type of the wifi network in
218 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
219 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100220 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100221 * provisioning via an Nfc bump.
222 */
223 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100224 = "android.app.extra.WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100225
226 /**
227 * A String extra holding the password of the wifi network in
228 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
229 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100230 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100231 * provisioning via an Nfc bump.
232 */
233 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100234 = "android.app.extra.WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100235
236 /**
237 * A String extra holding the proxy host for the wifi network in
238 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
239 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100240 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100241 * provisioning via an Nfc bump.
242 */
243 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100244 = "android.app.extra.WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100245
246 /**
247 * An int extra holding the proxy port for the wifi network in
248 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
249 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100250 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100251 * provisioning via an Nfc bump.
252 */
253 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100254 = "android.app.extra.WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100255
256 /**
257 * A String extra holding the proxy bypass for the wifi network in
258 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
259 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100260 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100261 * provisioning via an Nfc bump.
262 */
263 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100264 = "android.app.extra.WIFI_PROXY_BYPASS_HOSTS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100265
266 /**
267 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
268 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
269 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100270 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100271 * provisioning via an Nfc bump.
272 */
273 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100274 = "android.app.extra.WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100275
276 /**
277 * A String extra holding a url that specifies the download location of the device admin
278 * package. When not provided it is assumed that the device admin package is already installed.
279 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100280 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100281 * provisioning via an Nfc bump.
282 */
283 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100284 = "android.app.extra.DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100285
286 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100287 * A String extra holding a http cookie header which should be used in the http request to the
288 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
289 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100290 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse681bce92014-07-24 16:46:26 +0100291 * provisioning via an Nfc bump.
292 */
293 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100294 = "android.app.extra.DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100295
296 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100297 * A String extra holding the SHA-1 checksum of the file at download location specified in
298 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
299 * the file at the download location an error will be shown to the user and the user will be
300 * asked to factory reset the device.
301 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100302 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100303 * provisioning via an Nfc bump.
304 */
305 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100306 = "android.app.extra.DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100307
308 /**
309 * This MIME type is used for starting the Device Owner provisioning.
310 *
311 * <p>During device owner provisioning a device admin app is set as the owner of the device.
312 * A device owner has full control over the device. The device owner can not be modified by the
313 * user and the only way of resetting the device is if the device owner app calls a factory
314 * reset.
315 *
316 * <p> A typical use case would be a device that is owned by a company, but used by either an
317 * employee or client.
318 *
319 * <p> The Nfc message should be send to an unprovisioned device.
320 *
321 * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which
322 * contains the following properties:
323 * <ul>
324 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
325 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100326 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100327 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
328 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
329 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
330 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
332 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
333 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
334 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
335 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
336 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
337 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
338 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
339 *
340 * <p> When device owner provisioning has completed, an intent of the type
341 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
342 * device owner.
343 *
344 * <p>
345 * If provisioning fails, the device is factory reset.
346 *
347 * <p>Input: Nothing.</p>
348 * <p>Output: Nothing</p>
349 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100350 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100351 = "application/com.android.managedprovisioning";
352
353 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800354 * Activity action: ask the user to add a new device administrator to the system.
355 * The desired policy is the ComponentName of the policy in the
356 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
357 * bring the user through adding the device administrator to the system (or
358 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700359 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800360 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
361 * field to provide the user with additional explanation (in addition
362 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800363 *
364 * <p>If your administrator is already active, this will ordinarily return immediately (without
365 * user intervention). However, if your administrator has been updated and is requesting
366 * additional uses-policy flags, the user will be presented with the new list. New policies
367 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800368 */
369 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
370 public static final String ACTION_ADD_DEVICE_ADMIN
371 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700372
Dianne Hackbornd6847842010-01-12 18:14:19 -0800373 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700374 * @hide
375 * Activity action: ask the user to add a new device administrator as the profile owner
376 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
377 * permission can call this API.
378 *
379 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
380 * field. This will invoke a UI to bring the user through adding the profile owner admin
381 * to remotely control restrictions on the user.
382 *
383 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
384 * result of whether or not the user approved the action. If approved, the result will
385 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
386 * as a profile owner.
387 *
388 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
389 * field to provide the user with additional explanation (in addition
390 * to your component's description) about what is being added.
391 *
392 * <p>If there is already a profile owner active or the caller doesn't have the required
393 * permissions, the operation will return a failure result.
394 */
395 @SystemApi
396 public static final String ACTION_SET_PROFILE_OWNER
397 = "android.app.action.SET_PROFILE_OWNER";
398
399 /**
400 * @hide
401 * Name of the profile owner admin that controls the user.
402 */
403 @SystemApi
404 public static final String EXTRA_PROFILE_OWNER_NAME
405 = "android.app.extra.PROFILE_OWNER_NAME";
406
407 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700408 * Activity action: send when any policy admin changes a policy.
409 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700410 *
Jim Miller284b62e2010-06-08 14:27:42 -0700411 * @hide
412 */
413 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
414 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
415
416 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800417 * The ComponentName of the administrator component.
418 *
419 * @see #ACTION_ADD_DEVICE_ADMIN
420 */
421 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700422
Dianne Hackbornd6847842010-01-12 18:14:19 -0800423 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800424 * An optional CharSequence providing additional explanation for why the
425 * admin is being added.
426 *
427 * @see #ACTION_ADD_DEVICE_ADMIN
428 */
429 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700430
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800431 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700432 * Activity action: have the user enter a new password. This activity should
433 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
434 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
435 * enter a new password that meets the current requirements. You can use
436 * {@link #isActivePasswordSufficient()} to determine whether you need to
437 * have the user select a new password in order to meet the current
438 * constraints. Upon being resumed from this activity, you can check the new
439 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800440 */
441 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
442 public static final String ACTION_SET_NEW_PASSWORD
443 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700444
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000445 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100446 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
447 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000448 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100449 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000450
451 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100452 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
453 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000454 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100455 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700456
Dianne Hackbornd6847842010-01-12 18:14:19 -0800457 /**
458 * Return true if the given administrator component is currently
459 * active (enabled) in the system.
460 */
461 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100462 return isAdminActiveAsUser(who, UserHandle.myUserId());
463 }
464
465 /**
466 * @see #isAdminActive(ComponentName)
467 * @hide
468 */
469 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800470 if (mService != null) {
471 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100472 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800473 } catch (RemoteException e) {
474 Log.w(TAG, "Failed talking with device policy service", e);
475 }
476 }
477 return false;
478 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700479
Dianne Hackbornd6847842010-01-12 18:14:19 -0800480 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800481 * Return a list of all currently active device administrator's component
482 * names. Note that if there are no administrators than null may be
483 * returned.
484 */
485 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100486 return getActiveAdminsAsUser(UserHandle.myUserId());
487 }
488
489 /**
490 * @see #getActiveAdmins()
491 * @hide
492 */
493 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800494 if (mService != null) {
495 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100496 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800497 } catch (RemoteException e) {
498 Log.w(TAG, "Failed talking with device policy service", e);
499 }
500 }
501 return null;
502 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700503
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800504 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700505 * Used by package administration code to determine if a package can be stopped
506 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800507 * @hide
508 */
509 public boolean packageHasActiveAdmins(String packageName) {
510 if (mService != null) {
511 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700512 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800513 } catch (RemoteException e) {
514 Log.w(TAG, "Failed talking with device policy service", e);
515 }
516 }
517 return false;
518 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700519
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800520 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800521 * Remove a current administration component. This can only be called
522 * by the application that owns the administration component; if you
523 * try to remove someone else's component, a security exception will be
524 * thrown.
525 */
526 public void removeActiveAdmin(ComponentName who) {
527 if (mService != null) {
528 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700529 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800530 } catch (RemoteException e) {
531 Log.w(TAG, "Failed talking with device policy service", e);
532 }
533 }
534 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700535
Dianne Hackbornd6847842010-01-12 18:14:19 -0800536 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800537 * Returns true if an administrator has been granted a particular device policy. This can
538 * be used to check if the administrator was activated under an earlier set of policies,
539 * but requires additional policies after an upgrade.
540 *
541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
542 * an active administrator, or an exception will be thrown.
543 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
544 */
545 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
546 if (mService != null) {
547 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700548 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800549 } catch (RemoteException e) {
550 Log.w(TAG, "Failed talking with device policy service", e);
551 }
552 }
553 return false;
554 }
555
556 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800557 * Constant for {@link #setPasswordQuality}: the policy has no requirements
558 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800559 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800560 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800561 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700562
Dianne Hackbornd6847842010-01-12 18:14:19 -0800563 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700564 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
565 * recognition technology. This implies technologies that can recognize the identity of
566 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
567 * Note that quality constants are ordered so that higher values are more restrictive.
568 */
569 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
570
571 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800572 * Constant for {@link #setPasswordQuality}: the policy requires some kind
573 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800574 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800575 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800576 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700577
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800578 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800579 * Constant for {@link #setPasswordQuality}: the user must have entered a
580 * password containing at least numeric characters. Note that quality
581 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800582 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800583 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700584
Dianne Hackbornd6847842010-01-12 18:14:19 -0800585 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800586 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800587 * password containing at least numeric characters with no repeating (4444)
588 * or ordered (1234, 4321, 2468) sequences. Note that quality
589 * constants are ordered so that higher values are more restrictive.
590 */
591 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
592
593 /**
594 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700595 * password containing at least alphabetic (or other symbol) characters.
596 * Note that quality constants are ordered so that higher values are more
597 * restrictive.
598 */
599 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700600
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700601 /**
602 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800603 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700604 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800605 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800606 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700607 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700608
Dianne Hackbornd6847842010-01-12 18:14:19 -0800609 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700610 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700611 * password containing at least a letter, a numerical digit and a special
612 * symbol, by default. With this password quality, passwords can be
613 * restricted to contain various sets of characters, like at least an
614 * uppercase letter, etc. These are specified using various methods,
615 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
616 * that quality constants are ordered so that higher values are more
617 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700618 */
619 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
620
621 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800622 * Called by an application that is administering the device to set the
623 * password restrictions it is imposing. After setting this, the user
624 * will not be able to enter a new password that is not at least as
625 * restrictive as what has been set. Note that the current password
626 * will remain until the user has set a new one, so the change does not
627 * take place immediately. To prompt the user for a new password, use
628 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700629 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800630 * <p>Quality constants are ordered so that higher values are more restrictive;
631 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800632 * the user's preference, and any other considerations) is the one that
633 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700634 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800635 * <p>The calling device admin must have requested
636 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
637 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700638 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800639 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800640 * @param quality The new desired quality. One of
641 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800642 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
643 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
644 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800645 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800646 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800647 if (mService != null) {
648 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700649 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800650 } catch (RemoteException e) {
651 Log.w(TAG, "Failed talking with device policy service", e);
652 }
653 }
654 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700655
Dianne Hackbornd6847842010-01-12 18:14:19 -0800656 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100657 * Retrieve the current minimum password quality for all admins of this user
658 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800659 * @param admin The name of the admin component to check, or null to aggregate
660 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800661 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800662 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700663 return getPasswordQuality(admin, UserHandle.myUserId());
664 }
665
666 /** @hide per-user version */
667 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800668 if (mService != null) {
669 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700670 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800671 } catch (RemoteException e) {
672 Log.w(TAG, "Failed talking with device policy service", e);
673 }
674 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800675 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800676 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700677
Dianne Hackbornd6847842010-01-12 18:14:19 -0800678 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800679 * Called by an application that is administering the device to set the
680 * minimum allowed password length. After setting this, the user
681 * will not be able to enter a new password that is not at least as
682 * restrictive as what has been set. Note that the current password
683 * will remain until the user has set a new one, so the change does not
684 * take place immediately. To prompt the user for a new password, use
685 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
686 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800687 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
688 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
689 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700690 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800691 * <p>The calling device admin must have requested
692 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
693 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700694 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800695 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800696 * @param length The new desired minimum password length. A value of 0
697 * means there is no restriction.
698 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800699 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800700 if (mService != null) {
701 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700702 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800703 } catch (RemoteException e) {
704 Log.w(TAG, "Failed talking with device policy service", e);
705 }
706 }
707 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700708
Dianne Hackbornd6847842010-01-12 18:14:19 -0800709 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100710 * Retrieve the current minimum password length for all admins of this
711 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800712 * @param admin The name of the admin component to check, or null to aggregate
713 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800714 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800715 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700716 return getPasswordMinimumLength(admin, UserHandle.myUserId());
717 }
718
719 /** @hide per-user version */
720 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800721 if (mService != null) {
722 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700723 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800724 } catch (RemoteException e) {
725 Log.w(TAG, "Failed talking with device policy service", e);
726 }
727 }
728 return 0;
729 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700730
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700731 /**
732 * Called by an application that is administering the device to set the
733 * minimum number of upper case letters required in the password. After
734 * setting this, the user will not be able to enter a new password that is
735 * not at least as restrictive as what has been set. Note that the current
736 * password will remain until the user has set a new one, so the change does
737 * not take place immediately. To prompt the user for a new password, use
738 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
739 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700740 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
741 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700742 * <p>
743 * The calling device admin must have requested
744 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
745 * this method; if it has not, a security exception will be thrown.
746 *
747 * @param admin Which {@link DeviceAdminReceiver} this request is associated
748 * with.
749 * @param length The new desired minimum number of upper case letters
750 * required in the password. A value of 0 means there is no
751 * restriction.
752 */
753 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
754 if (mService != null) {
755 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700756 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700757 } catch (RemoteException e) {
758 Log.w(TAG, "Failed talking with device policy service", e);
759 }
760 }
761 }
762
763 /**
764 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100765 * password for all admins of this user and its profiles or a particular one.
766 * This is the same value as set by
767 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700768 * and only applies when the password quality is
769 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700770 *
771 * @param admin The name of the admin component to check, or null to
772 * aggregate all admins.
773 * @return The minimum number of upper case letters required in the
774 * password.
775 */
776 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700777 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
778 }
779
780 /** @hide per-user version */
781 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700782 if (mService != null) {
783 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700784 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700785 } catch (RemoteException e) {
786 Log.w(TAG, "Failed talking with device policy service", e);
787 }
788 }
789 return 0;
790 }
791
792 /**
793 * Called by an application that is administering the device to set the
794 * minimum number of lower case letters required in the password. After
795 * setting this, the user will not be able to enter a new password that is
796 * not at least as restrictive as what has been set. Note that the current
797 * password will remain until the user has set a new one, so the change does
798 * not take place immediately. To prompt the user for a new password, use
799 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
800 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700801 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
802 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700803 * <p>
804 * The calling device admin must have requested
805 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
806 * this method; if it has not, a security exception will be thrown.
807 *
808 * @param admin Which {@link DeviceAdminReceiver} this request is associated
809 * with.
810 * @param length The new desired minimum number of lower case letters
811 * required in the password. A value of 0 means there is no
812 * restriction.
813 */
814 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
815 if (mService != null) {
816 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700817 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700818 } catch (RemoteException e) {
819 Log.w(TAG, "Failed talking with device policy service", e);
820 }
821 }
822 }
823
824 /**
825 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100826 * password for all admins of this user and its profiles or a particular one.
827 * This is the same value as set by
828 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700829 * and only applies when the password quality is
830 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700831 *
832 * @param admin The name of the admin component to check, or null to
833 * aggregate all admins.
834 * @return The minimum number of lower case letters required in the
835 * password.
836 */
837 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700838 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
839 }
840
841 /** @hide per-user version */
842 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700843 if (mService != null) {
844 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700845 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700846 } catch (RemoteException e) {
847 Log.w(TAG, "Failed talking with device policy service", e);
848 }
849 }
850 return 0;
851 }
852
853 /**
854 * Called by an application that is administering the device to set the
855 * minimum number of letters required in the password. After setting this,
856 * the user will not be able to enter a new password that is not at least as
857 * restrictive as what has been set. Note that the current password will
858 * remain until the user has set a new one, so the change does not take
859 * place immediately. To prompt the user for a new password, use
860 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
861 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700862 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
863 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700864 * <p>
865 * The calling device admin must have requested
866 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
867 * this method; if it has not, a security exception will be thrown.
868 *
869 * @param admin Which {@link DeviceAdminReceiver} this request is associated
870 * with.
871 * @param length The new desired minimum number of letters required in the
872 * password. A value of 0 means there is no restriction.
873 */
874 public void setPasswordMinimumLetters(ComponentName admin, int length) {
875 if (mService != null) {
876 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700877 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700878 } catch (RemoteException e) {
879 Log.w(TAG, "Failed talking with device policy service", e);
880 }
881 }
882 }
883
884 /**
885 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700886 * admins or a particular one. This is the same value as
887 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
888 * and only applies when the password quality is
889 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700890 *
891 * @param admin The name of the admin component to check, or null to
892 * aggregate all admins.
893 * @return The minimum number of letters required in the password.
894 */
895 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700896 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
897 }
898
899 /** @hide per-user version */
900 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700901 if (mService != null) {
902 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700903 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700904 } catch (RemoteException e) {
905 Log.w(TAG, "Failed talking with device policy service", e);
906 }
907 }
908 return 0;
909 }
910
911 /**
912 * Called by an application that is administering the device to set the
913 * minimum number of numerical digits required in the password. After
914 * setting this, the user will not be able to enter a new password that is
915 * not at least as restrictive as what has been set. Note that the current
916 * password will remain until the user has set a new one, so the change does
917 * not take place immediately. To prompt the user for a new password, use
918 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
919 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700920 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
921 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700922 * <p>
923 * The calling device admin must have requested
924 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
925 * this method; if it has not, a security exception will be thrown.
926 *
927 * @param admin Which {@link DeviceAdminReceiver} this request is associated
928 * with.
929 * @param length The new desired minimum number of numerical digits required
930 * in the password. A value of 0 means there is no restriction.
931 */
932 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
933 if (mService != null) {
934 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700935 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700936 } catch (RemoteException e) {
937 Log.w(TAG, "Failed talking with device policy service", e);
938 }
939 }
940 }
941
942 /**
943 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100944 * for all admins of this user and its profiles or a particular one.
945 * This is the same value as set by
946 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700947 * and only applies when the password quality is
948 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700949 *
950 * @param admin The name of the admin component to check, or null to
951 * aggregate all admins.
952 * @return The minimum number of numerical digits required in the password.
953 */
954 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700955 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
956 }
957
958 /** @hide per-user version */
959 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700960 if (mService != null) {
961 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700962 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700963 } catch (RemoteException e) {
964 Log.w(TAG, "Failed talking with device policy service", e);
965 }
966 }
967 return 0;
968 }
969
970 /**
971 * Called by an application that is administering the device to set the
972 * minimum number of symbols required in the password. After setting this,
973 * the user will not be able to enter a new password that is not at least as
974 * restrictive as what has been set. Note that the current password will
975 * remain until the user has set a new one, so the change does not take
976 * place immediately. To prompt the user for a new password, use
977 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
978 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700979 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
980 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700981 * <p>
982 * The calling device admin must have requested
983 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
984 * this method; if it has not, a security exception will be thrown.
985 *
986 * @param admin Which {@link DeviceAdminReceiver} this request is associated
987 * with.
988 * @param length The new desired minimum number of symbols required in the
989 * password. A value of 0 means there is no restriction.
990 */
991 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
992 if (mService != null) {
993 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700994 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700995 } catch (RemoteException e) {
996 Log.w(TAG, "Failed talking with device policy service", e);
997 }
998 }
999 }
1000
1001 /**
1002 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001003 * admins or a particular one. This is the same value as
1004 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1005 * and only applies when the password quality is
1006 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001007 *
1008 * @param admin The name of the admin component to check, or null to
1009 * aggregate all admins.
1010 * @return The minimum number of symbols required in the password.
1011 */
1012 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001013 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1014 }
1015
1016 /** @hide per-user version */
1017 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001018 if (mService != null) {
1019 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001020 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001021 } catch (RemoteException e) {
1022 Log.w(TAG, "Failed talking with device policy service", e);
1023 }
1024 }
1025 return 0;
1026 }
1027
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001028 /**
1029 * Called by an application that is administering the device to set the
1030 * minimum number of non-letter characters (numerical digits or symbols)
1031 * required in the password. After setting this, the user will not be able
1032 * to enter a new password that is not at least as restrictive as what has
1033 * been set. Note that the current password will remain until the user has
1034 * set a new one, so the change does not take place immediately. To prompt
1035 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1036 * setting this value. This constraint is only imposed if the administrator
1037 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1038 * {@link #setPasswordQuality}. The default value is 0.
1039 * <p>
1040 * The calling device admin must have requested
1041 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1042 * this method; if it has not, a security exception will be thrown.
1043 *
1044 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1045 * with.
1046 * @param length The new desired minimum number of letters required in the
1047 * password. A value of 0 means there is no restriction.
1048 */
1049 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1050 if (mService != null) {
1051 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001052 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001053 } catch (RemoteException e) {
1054 Log.w(TAG, "Failed talking with device policy service", e);
1055 }
1056 }
1057 }
1058
1059 /**
1060 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001061 * password for all admins of this user and its profiles or a particular one.
1062 * This is the same value as set by
1063 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001064 * and only applies when the password quality is
1065 * {@link #PASSWORD_QUALITY_COMPLEX}.
1066 *
1067 * @param admin The name of the admin component to check, or null to
1068 * aggregate all admins.
1069 * @return The minimum number of letters required in the password.
1070 */
1071 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001072 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1073 }
1074
1075 /** @hide per-user version */
1076 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001077 if (mService != null) {
1078 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001079 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001080 } catch (RemoteException e) {
1081 Log.w(TAG, "Failed talking with device policy service", e);
1082 }
1083 }
1084 return 0;
1085 }
1086
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001087 /**
1088 * Called by an application that is administering the device to set the length
1089 * of the password history. After setting this, the user will not be able to
1090 * enter a new password that is the same as any password in the history. Note
1091 * that the current password will remain until the user has set a new one, so
1092 * the change does not take place immediately. To prompt the user for a new
1093 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1094 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001095 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1096 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1097 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001098 *
1099 * <p>
1100 * The calling device admin must have requested
1101 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1102 * method; if it has not, a security exception will be thrown.
1103 *
1104 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1105 * with.
1106 * @param length The new desired length of password history. A value of 0
1107 * means there is no restriction.
1108 */
1109 public void setPasswordHistoryLength(ComponentName admin, int length) {
1110 if (mService != null) {
1111 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001112 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001113 } catch (RemoteException e) {
1114 Log.w(TAG, "Failed talking with device policy service", e);
1115 }
1116 }
1117 }
1118
1119 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001120 * Called by a device admin to set the password expiration timeout. Calling this method
1121 * will restart the countdown for password expiration for the given admin, as will changing
1122 * the device password (for all admins).
1123 *
1124 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1125 * For example, to have the password expire 5 days from now, timeout would be
1126 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1127 *
1128 * <p>To disable password expiration, a value of 0 may be used for timeout.
1129 *
Jim Millera4e28d12010-11-08 16:15:47 -08001130 * <p>The calling device admin must have requested
1131 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1132 * method; if it has not, a security exception will be thrown.
1133 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001134 * <p> Note that setting the password will automatically reset the expiration time for all
1135 * active admins. Active admins do not need to explicitly call this method in that case.
1136 *
Jim Millera4e28d12010-11-08 16:15:47 -08001137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1138 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1139 * means there is no restriction (unlimited).
1140 */
1141 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1142 if (mService != null) {
1143 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001144 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001145 } catch (RemoteException e) {
1146 Log.w(TAG, "Failed talking with device policy service", e);
1147 }
1148 }
1149 }
1150
1151 /**
Jim Miller6b857682011-02-16 16:27:41 -08001152 * Get the password expiration timeout for the given admin. The expiration timeout is the
1153 * recurring expiration timeout provided in the call to
1154 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1155 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001156 *
1157 * @param admin The name of the admin component to check, or null to aggregate all admins.
1158 * @return The timeout for the given admin or the minimum of all timeouts
1159 */
1160 public long getPasswordExpirationTimeout(ComponentName admin) {
1161 if (mService != null) {
1162 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001163 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001164 } catch (RemoteException e) {
1165 Log.w(TAG, "Failed talking with device policy service", e);
1166 }
1167 }
1168 return 0;
1169 }
1170
1171 /**
1172 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001173 * all admins of this user and its profiles if admin is null. If the password is
1174 * expired, this will return the time since the password expired as a negative number.
1175 * If admin is null, then a composite of all expiration timeouts is returned
1176 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001177 *
1178 * @param admin The name of the admin component to check, or null to aggregate all admins.
1179 * @return The password expiration time, in ms.
1180 */
1181 public long getPasswordExpiration(ComponentName admin) {
1182 if (mService != null) {
1183 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001184 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001185 } catch (RemoteException e) {
1186 Log.w(TAG, "Failed talking with device policy service", e);
1187 }
1188 }
1189 return 0;
1190 }
1191
1192 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001193 * Retrieve the current password history length for all admins of this
1194 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001195 * @param admin The name of the admin component to check, or null to aggregate
1196 * all admins.
1197 * @return The length of the password history
1198 */
1199 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001200 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1201 }
1202
1203 /** @hide per-user version */
1204 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001205 if (mService != null) {
1206 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001207 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001208 } catch (RemoteException e) {
1209 Log.w(TAG, "Failed talking with device policy service", e);
1210 }
1211 }
1212 return 0;
1213 }
1214
Dianne Hackbornd6847842010-01-12 18:14:19 -08001215 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001216 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001217 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001218 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001219 * @return Returns the maximum length that the user can enter.
1220 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001221 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001222 // Kind-of arbitrary.
1223 return 16;
1224 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001225
Dianne Hackborn254cb442010-01-27 19:23:59 -08001226 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001227 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001228 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001229 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001230 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001231 * <p>The calling device admin must have requested
1232 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1233 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001234 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001235 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001236 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001237 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001238 if (mService != null) {
1239 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001240 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001241 } catch (RemoteException e) {
1242 Log.w(TAG, "Failed talking with device policy service", e);
1243 }
1244 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001245 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001246 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001247
Dianne Hackbornd6847842010-01-12 18:14:19 -08001248 /**
1249 * Retrieve the number of times the user has failed at entering a
1250 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001251 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001252 * <p>The calling device admin must have requested
1253 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1254 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 */
1256 public int getCurrentFailedPasswordAttempts() {
1257 if (mService != null) {
1258 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001259 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001260 } catch (RemoteException e) {
1261 Log.w(TAG, "Failed talking with device policy service", e);
1262 }
1263 }
1264 return -1;
1265 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001266
1267 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001268 * Setting this to a value greater than zero enables a built-in policy
1269 * that will perform a device wipe after too many incorrect
1270 * device-unlock passwords have been entered. This built-in policy combines
1271 * watching for failed passwords and wiping the device, and requires
1272 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001273 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001274 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001275 * <p>To implement any other policy (e.g. wiping data for a particular
1276 * application only, erasing or revoking credentials, or reporting the
1277 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001278 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001279 * instead. Do not use this API, because if the maximum count is reached,
1280 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001281 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001283 * @param num The number of failed password attempts at which point the
1284 * device will wipe its data.
1285 */
1286 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1287 if (mService != null) {
1288 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001289 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001290 } catch (RemoteException e) {
1291 Log.w(TAG, "Failed talking with device policy service", e);
1292 }
1293 }
1294 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001295
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001296 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001297 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001298 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001299 * or a particular one.
1300 * @param admin The name of the admin component to check, or null to aggregate
1301 * all admins.
1302 */
1303 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001304 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1305 }
1306
1307 /** @hide per-user version */
1308 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001309 if (mService != null) {
1310 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001311 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001312 } catch (RemoteException e) {
1313 Log.w(TAG, "Failed talking with device policy service", e);
1314 }
1315 }
1316 return 0;
1317 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001318
Dianne Hackborn254cb442010-01-27 19:23:59 -08001319 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001320 * Flag for {@link #resetPassword}: don't allow other admins to change
1321 * the password again until the user has entered it.
1322 */
1323 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001324
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001325 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001326 * Force a new device unlock password (the password needed to access the
1327 * entire device, not for individual accounts) on the user. This takes
1328 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001329 * The given password must be sufficient for the
1330 * current password quality and length constraints as returned by
1331 * {@link #getPasswordQuality(ComponentName)} and
1332 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1333 * these constraints, then it will be rejected and false returned. Note
1334 * that the password may be a stronger quality (containing alphanumeric
1335 * characters when the requested quality is only numeric), in which case
1336 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001337 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001338 * <p>The calling device admin must have requested
1339 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1340 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001341 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001342 * Can not be called from a managed profile.
1343 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001344 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001345 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001346 * @return Returns true if the password was applied, or false if it is
1347 * not acceptable for the current constraints.
1348 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001349 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001350 if (mService != null) {
1351 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001352 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001353 } catch (RemoteException e) {
1354 Log.w(TAG, "Failed talking with device policy service", e);
1355 }
1356 }
1357 return false;
1358 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001359
Dianne Hackbornd6847842010-01-12 18:14:19 -08001360 /**
1361 * Called by an application that is administering the device to set the
1362 * maximum time for user activity until the device will lock. This limits
1363 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001364 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001365 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001366 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001367 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001368 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001369 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001370 * @param timeMs The new desired maximum time to lock in milliseconds.
1371 * A value of 0 means there is no restriction.
1372 */
1373 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1374 if (mService != null) {
1375 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001376 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001377 } catch (RemoteException e) {
1378 Log.w(TAG, "Failed talking with device policy service", e);
1379 }
1380 }
1381 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001382
Dianne Hackbornd6847842010-01-12 18:14:19 -08001383 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001384 * Retrieve the current maximum time to unlock for all admins of this user
1385 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001386 * @param admin The name of the admin component to check, or null to aggregate
1387 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001388 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001389 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001390 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001391 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001392 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1393 }
1394
1395 /** @hide per-user version */
1396 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001397 if (mService != null) {
1398 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001399 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001400 } catch (RemoteException e) {
1401 Log.w(TAG, "Failed talking with device policy service", e);
1402 }
1403 }
1404 return 0;
1405 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001406
Dianne Hackbornd6847842010-01-12 18:14:19 -08001407 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001408 * Make the device lock immediately, as if the lock screen timeout has
1409 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001410 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001411 * <p>The calling device admin must have requested
1412 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1413 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001414 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001415 public void lockNow() {
1416 if (mService != null) {
1417 try {
1418 mService.lockNow();
1419 } catch (RemoteException e) {
1420 Log.w(TAG, "Failed talking with device policy service", e);
1421 }
1422 }
1423 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001424
Dianne Hackbornd6847842010-01-12 18:14:19 -08001425 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001426 * Flag for {@link #wipeData(int)}: also erase the device's external
1427 * storage.
1428 */
1429 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1430
1431 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001432 * Ask the user data be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001433 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001434 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1435 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001436 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001437 * <p>The calling device admin must have requested
1438 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1439 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001440 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001441 * @param flags Bit mask of additional options: currently 0 and
1442 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001443 */
1444 public void wipeData(int flags) {
1445 if (mService != null) {
1446 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001447 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001448 } catch (RemoteException e) {
1449 Log.w(TAG, "Failed talking with device policy service", e);
1450 }
1451 }
1452 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001453
Dianne Hackbornd6847842010-01-12 18:14:19 -08001454 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001455 * Called by an application that is administering the device to set the
1456 * global proxy and exclusion list.
1457 * <p>
1458 * The calling device admin must have requested
1459 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1460 * this method; if it has not, a security exception will be thrown.
1461 * Only the first device admin can set the proxy. If a second admin attempts
1462 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1463 * proxy will be returned. If successful in setting the proxy, null will
1464 * be returned.
1465 * The method can be called repeatedly by the device admin alrady setting the
1466 * proxy to update the proxy and exclusion list.
1467 *
1468 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1469 * with.
1470 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1471 * Pass Proxy.NO_PROXY to reset the proxy.
1472 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001473 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1474 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001475 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001476 */
1477 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1478 List<String> exclusionList ) {
1479 if (proxySpec == null) {
1480 throw new NullPointerException();
1481 }
1482 if (mService != null) {
1483 try {
1484 String hostSpec;
1485 String exclSpec;
1486 if (proxySpec.equals(Proxy.NO_PROXY)) {
1487 hostSpec = null;
1488 exclSpec = null;
1489 } else {
1490 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1491 throw new IllegalArgumentException();
1492 }
1493 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1494 String hostName = sa.getHostName();
1495 int port = sa.getPort();
1496 StringBuilder hostBuilder = new StringBuilder();
1497 hostSpec = hostBuilder.append(hostName)
1498 .append(":").append(Integer.toString(port)).toString();
1499 if (exclusionList == null) {
1500 exclSpec = "";
1501 } else {
1502 StringBuilder listBuilder = new StringBuilder();
1503 boolean firstDomain = true;
1504 for (String exclDomain : exclusionList) {
1505 if (!firstDomain) {
1506 listBuilder = listBuilder.append(",");
1507 } else {
1508 firstDomain = false;
1509 }
1510 listBuilder = listBuilder.append(exclDomain.trim());
1511 }
1512 exclSpec = listBuilder.toString();
1513 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001514 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1515 != android.net.Proxy.PROXY_VALID)
1516 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001517 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001518 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001519 } catch (RemoteException e) {
1520 Log.w(TAG, "Failed talking with device policy service", e);
1521 }
1522 }
1523 return null;
1524 }
1525
1526 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001527 * Set a network-independent global HTTP proxy. This is not normally what you want
1528 * for typical HTTP proxies - they are generally network dependent. However if you're
1529 * doing something unusual like general internal filtering this may be useful. On
1530 * a private network where the proxy is not accessible, you may break HTTP using this.
1531 *
1532 * <p>This method requires the caller to be the device owner.
1533 *
1534 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1535 * @see ProxyInfo
1536 *
1537 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1538 * with.
1539 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1540 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1541 */
1542 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1543 if (mService != null) {
1544 try {
1545 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1546 } catch (RemoteException e) {
1547 Log.w(TAG, "Failed talking with device policy service", e);
1548 }
1549 }
1550 }
1551
1552 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001553 * Returns the component name setting the global proxy.
1554 * @return ComponentName object of the device admin that set the global proxy, or
1555 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001556 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001557 */
1558 public ComponentName getGlobalProxyAdmin() {
1559 if (mService != null) {
1560 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001561 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001562 } catch (RemoteException e) {
1563 Log.w(TAG, "Failed talking with device policy service", e);
1564 }
1565 }
1566 return null;
1567 }
1568
1569 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001570 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001571 * indicating that encryption is not supported.
1572 */
1573 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1574
1575 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001576 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001577 * indicating that encryption is supported, but is not currently active.
1578 */
1579 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1580
1581 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001582 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001583 * indicating that encryption is not currently active, but is currently
1584 * being activated. This is only reported by devices that support
1585 * encryption of data and only when the storage is currently
1586 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1587 * to become encrypted will never return this value.
1588 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001589 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001590
1591 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001592 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001593 * indicating that encryption is active.
1594 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001595 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001596
1597 /**
1598 * Activity action: begin the process of encrypting data on the device. This activity should
1599 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1600 * After resuming from this activity, use {@link #getStorageEncryption}
1601 * to check encryption status. However, on some devices this activity may never return, as
1602 * it may trigger a reboot and in some cases a complete data wipe of the device.
1603 */
1604 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1605 public static final String ACTION_START_ENCRYPTION
1606 = "android.app.action.START_ENCRYPTION";
1607
1608 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001609 * Widgets are enabled in keyguard
1610 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001611 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001612
1613 /**
Jim Miller50e62182014-04-23 17:25:00 -07001614 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001615 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001616 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1617
1618 /**
1619 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1620 */
1621 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1622
1623 /**
Jim Miller50e62182014-04-23 17:25:00 -07001624 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1625 */
1626 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1627
1628 /**
1629 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1630 */
1631 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1632
1633 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001634 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001635 * (e.g. PIN/Pattern/Password).
1636 */
1637 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1638
1639 /**
Jim Miller06e34502014-07-17 14:46:05 -07001640 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1641 */
1642 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1643
1644 /**
Jim Miller35207742012-11-02 15:33:20 -07001645 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001646 */
1647 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001648
1649 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001650 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001651 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001652 *
1653 * <p>When multiple device administrators attempt to control device
1654 * encryption, the most secure, supported setting will always be
1655 * used. If any device administrator requests device encryption,
1656 * it will be enabled; Conversely, if a device administrator
1657 * attempts to disable device encryption while another
1658 * device administrator has enabled it, the call to disable will
1659 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1660 *
1661 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001662 * written to other storage areas may or may not be encrypted, and this policy does not require
1663 * or control the encryption of any other storage areas.
1664 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1665 * {@code true}, then the directory returned by
1666 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1667 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001668 *
1669 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1670 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1671 * the encryption key may not be fully secured. For maximum security, the administrator should
1672 * also require (and check for) a pattern, PIN, or password.
1673 *
1674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1675 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001676 * @return the new request status (for all active admins) - will be one of
1677 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1678 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1679 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001680 */
1681 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1682 if (mService != null) {
1683 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001684 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001685 } catch (RemoteException e) {
1686 Log.w(TAG, "Failed talking with device policy service", e);
1687 }
1688 }
1689 return ENCRYPTION_STATUS_UNSUPPORTED;
1690 }
1691
1692 /**
1693 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001694 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001695 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001696 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1697 * this will return the requested encryption setting as an aggregate of all active
1698 * administrators.
1699 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001700 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001701 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001702 if (mService != null) {
1703 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001704 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001705 } catch (RemoteException e) {
1706 Log.w(TAG, "Failed talking with device policy service", e);
1707 }
1708 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001709 return false;
1710 }
1711
1712 /**
1713 * Called by an application that is administering the device to
1714 * determine the current encryption status of the device.
1715 *
1716 * Depending on the returned status code, the caller may proceed in different
1717 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1718 * storage system does not support encryption. If the
1719 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1720 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1721 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1722 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1723 *
Robin Lee7e678712014-07-24 16:41:31 +01001724 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001725 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1726 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1727 */
1728 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001729 return getStorageEncryptionStatus(UserHandle.myUserId());
1730 }
1731
1732 /** @hide per-user version */
1733 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001734 if (mService != null) {
1735 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001736 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001737 } catch (RemoteException e) {
1738 Log.w(TAG, "Failed talking with device policy service", e);
1739 }
1740 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001741 return ENCRYPTION_STATUS_UNSUPPORTED;
1742 }
1743
1744 /**
Robin Lee7e678712014-07-24 16:41:31 +01001745 * Installs the given certificate as a user CA.
1746 *
1747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1748 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001749 *
1750 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001751 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001752 */
Robin Lee7e678712014-07-24 16:41:31 +01001753 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001754 if (mService != null) {
1755 try {
Robin Lee7e678712014-07-24 16:41:31 +01001756 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001757 } catch (RemoteException e) {
1758 Log.w(TAG, "Failed talking with device policy service", e);
1759 }
1760 }
1761 return false;
1762 }
1763
1764 /**
Robin Lee7e678712014-07-24 16:41:31 +01001765 * Uninstalls the given certificate from trusted user CAs, if present.
1766 *
1767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1768 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001769 */
Robin Lee7e678712014-07-24 16:41:31 +01001770 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001771 if (mService != null) {
1772 try {
Robin Lee306fe082014-06-19 14:04:24 +00001773 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001774 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001775 } catch (CertificateException e) {
1776 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001777 } catch (RemoteException e) {
1778 Log.w(TAG, "Failed talking with device policy service", e);
1779 }
1780 }
1781 }
1782
1783 /**
Robin Lee7e678712014-07-24 16:41:31 +01001784 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1785 * If a user has installed any certificates by other means than device policy these will be
1786 * included too.
1787 *
1788 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001789 */
Robin Lee7e678712014-07-24 16:41:31 +01001790 public List<byte[]> getInstalledCaCerts() {
1791 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1792 List<byte[]> certs = new ArrayList<byte[]>();
1793 for (String alias : certStore.userAliases()) {
1794 try {
1795 certs.add(certStore.getCertificate(alias).getEncoded());
1796 } catch (CertificateException ce) {
1797 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1798 }
1799 }
1800 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001801 }
1802
1803 /**
Robin Lee7e678712014-07-24 16:41:31 +01001804 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1805 * means other than device policy will also be removed, except for system CA certificates.
1806 *
1807 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1808 */
1809 public void uninstallAllUserCaCerts(ComponentName admin) {
1810 if (mService != null) {
1811 for (String alias : new TrustedCertificateStore().userAliases()) {
1812 try {
1813 mService.uninstallCaCert(admin, alias);
1814 } catch (RemoteException re) {
1815 Log.w(TAG, "Failed talking with device policy service", re);
1816 }
1817 }
1818 }
1819 }
1820
1821 /**
1822 * Returns whether this certificate is installed as a trusted CA.
1823 *
1824 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001825 */
1826 public boolean hasCaCertInstalled(byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001827 try {
Robin Lee306fe082014-06-19 14:04:24 +00001828 return getCaCertAlias(certBuffer) != null;
Maggie Benthallda51e682013-08-08 22:35:44 -04001829 } catch (CertificateException ce) {
1830 Log.w(TAG, "Could not parse certificate", ce);
1831 }
1832 return false;
1833 }
1834
1835 /**
Robin Lee306fe082014-06-19 14:04:24 +00001836 * Returns the alias of a given CA certificate in the certificate store, or null if it
1837 * doesn't exist.
1838 */
1839 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1840 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1841 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1842 new ByteArrayInputStream(certBuffer));
1843 return new TrustedCertificateStore().getCertificateAlias(cert);
1844 }
1845
1846 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001847 * Called by an application that is administering the device to disable all cameras
1848 * on the device. After setting this, no applications will be able to access any cameras
1849 * on the device.
1850 *
1851 * <p>The calling device admin must have requested
1852 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1853 * this method; if it has not, a security exception will be thrown.
1854 *
1855 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1856 * @param disabled Whether or not the camera should be disabled.
1857 */
1858 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1859 if (mService != null) {
1860 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001861 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001862 } catch (RemoteException e) {
1863 Log.w(TAG, "Failed talking with device policy service", e);
1864 }
1865 }
1866 }
1867
1868 /**
1869 * Determine whether or not the device's cameras have been disabled either by the current
1870 * admin, if specified, or all admins.
1871 * @param admin The name of the admin component to check, or null to check if any admins
1872 * have disabled the camera
1873 */
1874 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001875 return getCameraDisabled(admin, UserHandle.myUserId());
1876 }
1877
1878 /** @hide per-user version */
1879 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001880 if (mService != null) {
1881 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001882 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001883 } catch (RemoteException e) {
1884 Log.w(TAG, "Failed talking with device policy service", e);
1885 }
1886 }
1887 return false;
1888 }
1889
1890 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01001891 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
1892 * screen capture also prevents the content from being shown on display devices that do not have
1893 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
1894 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001895 *
1896 * <p>The calling device admin must be a device or profile owner. If it is not, a
1897 * security exception will be thrown.
1898 *
1899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001900 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001901 */
1902 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
1903 if (mService != null) {
1904 try {
1905 mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled);
1906 } catch (RemoteException e) {
1907 Log.w(TAG, "Failed talking with device policy service", e);
1908 }
1909 }
1910 }
1911
1912 /**
1913 * Determine whether or not screen capture has been disabled by the current
1914 * admin, if specified, or all admins.
1915 * @param admin The name of the admin component to check, or null to check if any admins
1916 * have disabled screen capture.
1917 */
1918 public boolean getScreenCaptureDisabled(ComponentName admin) {
1919 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
1920 }
1921
1922 /** @hide per-user version */
1923 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
1924 if (mService != null) {
1925 try {
1926 return mService.getScreenCaptureDisabled(admin, userHandle);
1927 } catch (RemoteException e) {
1928 Log.w(TAG, "Failed talking with device policy service", e);
1929 }
1930 }
1931 return false;
1932 }
1933
1934 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001935 * Called by a device owner to set whether auto time is required. If auto time is
1936 * required the user cannot set the date and time, but has to use network date and time.
1937 *
1938 * <p>Note: if auto time is required the user can still manually set the time zone.
1939 *
1940 * <p>The calling device admin must be a device owner. If it is not, a security exception will
1941 * be thrown.
1942 *
1943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1944 * @param required Whether auto time is set required or not.
1945 */
1946 public void setAutoTimeRequired(ComponentName admin, boolean required) {
1947 if (mService != null) {
1948 try {
1949 mService.setAutoTimeRequired(admin, UserHandle.myUserId(), required);
1950 } catch (RemoteException e) {
1951 Log.w(TAG, "Failed talking with device policy service", e);
1952 }
1953 }
1954 }
1955
1956 /**
1957 * @return true if auto time is required.
1958 */
1959 public boolean getAutoTimeRequired() {
1960 if (mService != null) {
1961 try {
1962 return mService.getAutoTimeRequired();
1963 } catch (RemoteException e) {
1964 Log.w(TAG, "Failed talking with device policy service", e);
1965 }
1966 }
1967 return false;
1968 }
1969
1970 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001971 * Called by an application that is administering the device to disable keyguard customizations,
1972 * such as widgets. After setting this, keyguard features will be disabled according to the
1973 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001974 *
1975 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001976 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001977 * this method; if it has not, a security exception will be thrown.
1978 *
1979 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001980 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1981 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001982 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1983 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001984 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001985 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001986 if (mService != null) {
1987 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001988 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001989 } catch (RemoteException e) {
1990 Log.w(TAG, "Failed talking with device policy service", e);
1991 }
1992 }
1993 }
1994
1995 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001996 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001997 * admin, if specified, or all admins.
1998 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001999 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002000 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2001 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002002 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002003 public int getKeyguardDisabledFeatures(ComponentName admin) {
2004 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002005 }
2006
2007 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002008 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002009 if (mService != null) {
2010 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002011 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002012 } catch (RemoteException e) {
2013 Log.w(TAG, "Failed talking with device policy service", e);
2014 }
2015 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002016 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002017 }
2018
2019 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002020 * @hide
2021 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002022 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002023 if (mService != null) {
2024 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002025 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002026 } catch (RemoteException e) {
2027 Log.w(TAG, "Failed talking with device policy service", e);
2028 }
2029 }
2030 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002031
Dianne Hackbornd6847842010-01-12 18:14:19 -08002032 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002033 * @hide
2034 */
2035 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2036 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2037 }
2038
2039 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002040 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002041 * @hide
2042 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002043 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002044 ActivityInfo ai;
2045 try {
2046 ai = mContext.getPackageManager().getReceiverInfo(cn,
2047 PackageManager.GET_META_DATA);
2048 } catch (PackageManager.NameNotFoundException e) {
2049 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2050 return null;
2051 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002052
Dianne Hackbornd6847842010-01-12 18:14:19 -08002053 ResolveInfo ri = new ResolveInfo();
2054 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002055
Dianne Hackbornd6847842010-01-12 18:14:19 -08002056 try {
2057 return new DeviceAdminInfo(mContext, ri);
2058 } catch (XmlPullParserException e) {
2059 Log.w(TAG, "Unable to parse device policy " + cn, e);
2060 return null;
2061 } catch (IOException e) {
2062 Log.w(TAG, "Unable to parse device policy " + cn, e);
2063 return null;
2064 }
2065 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002066
Dianne Hackbornd6847842010-01-12 18:14:19 -08002067 /**
2068 * @hide
2069 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002070 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2071 if (mService != null) {
2072 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002073 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002074 } catch (RemoteException e) {
2075 Log.w(TAG, "Failed talking with device policy service", e);
2076 }
2077 }
2078 }
2079
2080 /**
2081 * @hide
2082 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002083 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002084 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002085 if (mService != null) {
2086 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002087 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002088 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002089 } catch (RemoteException e) {
2090 Log.w(TAG, "Failed talking with device policy service", e);
2091 }
2092 }
2093 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002094
Dianne Hackbornd6847842010-01-12 18:14:19 -08002095 /**
2096 * @hide
2097 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002098 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002099 if (mService != null) {
2100 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002101 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002102 } catch (RemoteException e) {
2103 Log.w(TAG, "Failed talking with device policy service", e);
2104 }
2105 }
2106 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002107
Dianne Hackbornd6847842010-01-12 18:14:19 -08002108 /**
2109 * @hide
2110 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002111 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002112 if (mService != null) {
2113 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002114 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002115 } catch (RemoteException e) {
2116 Log.w(TAG, "Failed talking with device policy service", e);
2117 }
2118 }
2119 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002120
2121 /**
2122 * @hide
2123 * Sets the given package as the device owner. The package must already be installed and there
2124 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2125 * method must be called before the device is provisioned.
2126 * @param packageName the package name of the application to be registered as the device owner.
2127 * @return whether the package was successfully registered as the device owner.
2128 * @throws IllegalArgumentException if the package name is null or invalid
2129 * @throws IllegalStateException if a device owner is already registered or the device has
2130 * already been provisioned.
2131 */
2132 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2133 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002134 return setDeviceOwner(packageName, null);
2135 }
2136
2137 /**
2138 * @hide
2139 * Sets the given package as the device owner. The package must already be installed and there
2140 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2141 * method must be called before the device is provisioned.
2142 * @param packageName the package name of the application to be registered as the device owner.
2143 * @param ownerName the human readable name of the institution that owns this device.
2144 * @return whether the package was successfully registered as the device owner.
2145 * @throws IllegalArgumentException if the package name is null or invalid
2146 * @throws IllegalStateException if a device owner is already registered or the device has
2147 * already been provisioned.
2148 */
2149 public boolean setDeviceOwner(String packageName, String ownerName)
2150 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002151 if (mService != null) {
2152 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002153 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002154 } catch (RemoteException re) {
2155 Log.w(TAG, "Failed to set device owner");
2156 }
2157 }
2158 return false;
2159 }
2160
2161 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002162 * Used to determine if a particular package has been registered as a Device Owner app.
2163 * A device owner app is a special device admin that cannot be deactivated by the user, once
2164 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2165 * package is currently registered as the device owner app, pass in the package name from
2166 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2167 * admin apps that want to check if they are also registered as the device owner app. The
2168 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2169 * the setup process.
2170 * @param packageName the package name of the app, to compare with the registered device owner
2171 * app, if any.
2172 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002173 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002174 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002175 if (mService != null) {
2176 try {
2177 return mService.isDeviceOwner(packageName);
2178 } catch (RemoteException re) {
2179 Log.w(TAG, "Failed to check device owner");
2180 }
2181 }
2182 return false;
2183 }
2184
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002185 /**
2186 * @hide
2187 * Redirect to isDeviceOwnerApp.
2188 */
2189 public boolean isDeviceOwner(String packageName) {
2190 return isDeviceOwnerApp(packageName);
2191 }
2192
Jason Monkb0dced82014-06-06 14:36:20 -04002193 /**
2194 * Clears the current device owner. The caller must be the device owner.
2195 *
2196 * This function should be used cautiously as once it is called it cannot
2197 * be undone. The device owner can only be set as a part of device setup
2198 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002199 *
2200 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002201 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002202 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002203 if (mService != null) {
2204 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002205 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002206 } catch (RemoteException re) {
2207 Log.w(TAG, "Failed to clear device owner");
2208 }
2209 }
2210 }
2211
Amith Yamasani71e6c692013-03-24 17:39:28 -07002212 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002213 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002214 public String getDeviceOwner() {
2215 if (mService != null) {
2216 try {
2217 return mService.getDeviceOwner();
2218 } catch (RemoteException re) {
2219 Log.w(TAG, "Failed to get device owner");
2220 }
2221 }
2222 return null;
2223 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002224
2225 /** @hide */
2226 public String getDeviceOwnerName() {
2227 if (mService != null) {
2228 try {
2229 return mService.getDeviceOwnerName();
2230 } catch (RemoteException re) {
2231 Log.w(TAG, "Failed to get device owner");
2232 }
2233 }
2234 return null;
2235 }
Adam Connors776c5552014-01-09 10:42:56 +00002236
2237 /**
2238 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002239 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302240 * Sets the given component as an active admin and registers the package as the profile
2241 * owner for this user. The package must already be installed and there shouldn't be
2242 * an existing profile owner registered for this user. Also, this method must be called
2243 * before the user setup has been completed.
2244 * <p>
2245 * This method can only be called by system apps that hold MANAGE_USERS permission and
2246 * MANAGE_DEVICE_ADMINS permission.
2247 * @param admin The component to register as an active admin and profile owner.
2248 * @param ownerName The user-visible name of the entity that is managing this user.
2249 * @return whether the admin was successfully registered as the profile owner.
2250 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2251 * the user has already been set up.
2252 */
Justin Morey80440cc2014-07-24 09:16:35 -05002253 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302254 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2255 throws IllegalArgumentException {
2256 if (mService != null) {
2257 try {
2258 final int myUserId = UserHandle.myUserId();
2259 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002260 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302261 } catch (RemoteException re) {
2262 Log.w(TAG, "Failed to set profile owner " + re);
2263 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2264 }
2265 }
2266 return false;
2267 }
2268
2269 /**
2270 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002271 * Clears the active profile owner and removes all user restrictions. The caller must
2272 * be from the same package as the active profile owner for this user, otherwise a
2273 * SecurityException will be thrown.
2274 *
2275 * @param admin The component to remove as the profile owner.
2276 * @return
2277 */
2278 @SystemApi
2279 public void clearProfileOwner(ComponentName admin) {
2280 if (mService != null) {
2281 try {
2282 mService.clearProfileOwner(admin);
2283 } catch (RemoteException re) {
2284 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2285 }
2286 }
2287 }
2288
2289 /**
2290 * @hide
2291 * Checks if the user was already setup.
2292 */
2293 public boolean hasUserSetupCompleted() {
2294 if (mService != null) {
2295 try {
2296 return mService.hasUserSetupCompleted();
2297 } catch (RemoteException re) {
2298 Log.w(TAG, "Failed to check if user setup has completed");
2299 }
2300 }
2301 return true;
2302 }
2303
2304 /**
2305 * @deprecated Use setProfileOwner(ComponentName ...)
2306 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002307 * Sets the given package as the profile owner of the given user profile. The package must
2308 * already be installed and there shouldn't be an existing profile owner registered for this
2309 * user. Also, this method must be called before the user has been used for the first time.
2310 * @param packageName the package name of the application to be registered as profile owner.
2311 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002312 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002313 * @return whether the package was successfully registered as the profile owner.
2314 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2315 * the user has already been set up.
2316 */
Adam Connors661ec472014-02-11 13:59:46 +00002317 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002318 throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002319 if (packageName == null) {
2320 throw new NullPointerException("packageName cannot be null");
2321 }
2322 return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle);
2323 }
2324
2325 /**
2326 * @hide
2327 * Sets the given component as the profile owner of the given user profile. The package must
2328 * already be installed and there shouldn't be an existing profile owner registered for this
2329 * user. Only the system can call this API if the user has already completed setup.
2330 * @param admin the component name to be registered as profile owner.
2331 * @param ownerName the human readable name of the organisation associated with this DPM.
2332 * @param userHandle the userId to set the profile owner for.
2333 * @return whether the component was successfully registered as the profile owner.
2334 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2335 * the user has already been set up.
2336 */
2337 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2338 throws IllegalArgumentException {
2339 if (admin == null) {
2340 throw new NullPointerException("admin cannot be null");
2341 }
Adam Connors776c5552014-01-09 10:42:56 +00002342 if (mService != null) {
2343 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002344 if (ownerName == null) {
2345 ownerName = "";
2346 }
2347 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002348 } catch (RemoteException re) {
2349 Log.w(TAG, "Failed to set profile owner", re);
2350 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2351 }
2352 }
2353 return false;
2354 }
2355
2356 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002357 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2358 * be used. Only the profile owner can call this.
2359 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002360 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002361 *
2362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2363 */
2364 public void setProfileEnabled(ComponentName admin) {
2365 if (mService != null) {
2366 try {
2367 mService.setProfileEnabled(admin);
2368 } catch (RemoteException e) {
2369 Log.w(TAG, "Failed talking with device policy service", e);
2370 }
2371 }
2372 }
2373
2374 /**
Jessica Hummel1333ea12014-06-23 11:20:10 +01002375 * Sets the name of the Managed profile. In the device owner case it sets the name of the user
2376 * which it is called from. Only the profile owner or device owner can call this. If this is
2377 * never called by the profile or device owner, the name will be set to default values.
2378 *
2379 * @see #isProfileOwnerApp
2380 * @see #isDeviceOwnerApp
2381 *
2382 * @param profileName The name of the profile.
2383 */
2384 public void setProfileName(ComponentName who, String profileName) {
2385 if (mService != null) {
2386 try {
2387 mService.setProfileName(who, profileName);
2388 } catch (RemoteException e) {
2389 Log.w(TAG, "Failed talking with device policy service", e);
2390 }
2391 }
2392}
2393
2394 /**
Adam Connors776c5552014-01-09 10:42:56 +00002395 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002396 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00002397 * within the managed profile.
2398 *
2399 * @param packageName The package name of the app to compare with the registered profile owner.
2400 * @return Whether or not the package is registered as the profile owner.
2401 */
2402 public boolean isProfileOwnerApp(String packageName) {
2403 if (mService != null) {
2404 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002405 ComponentName profileOwner = mService.getProfileOwner(
2406 Process.myUserHandle().getIdentifier());
2407 return profileOwner != null
2408 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002409 } catch (RemoteException re) {
2410 Log.w(TAG, "Failed to check profile owner");
2411 }
2412 }
2413 return false;
2414 }
2415
2416 /**
2417 * @hide
2418 * @return the packageName of the owner of the given user profile or null if no profile
2419 * owner has been set for that user.
2420 * @throws IllegalArgumentException if the userId is invalid.
2421 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002422 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002423 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002424 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2425 }
2426
2427 /**
2428 * @see #getProfileOwner()
2429 * @hide
2430 */
2431 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002432 if (mService != null) {
2433 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002434 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002435 } catch (RemoteException re) {
2436 Log.w(TAG, "Failed to get profile owner");
2437 throw new IllegalArgumentException(
2438 "Requested profile owner for invalid userId", re);
2439 }
2440 }
2441 return null;
2442 }
2443
2444 /**
2445 * @hide
2446 * @return the human readable name of the organisation associated with this DPM or null if
2447 * one is not set.
2448 * @throws IllegalArgumentException if the userId is invalid.
2449 */
2450 public String getProfileOwnerName() throws IllegalArgumentException {
2451 if (mService != null) {
2452 try {
2453 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2454 } catch (RemoteException re) {
2455 Log.w(TAG, "Failed to get profile owner");
2456 throw new IllegalArgumentException(
2457 "Requested profile owner for invalid userId", re);
2458 }
2459 }
2460 return null;
2461 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002462
2463 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002464 * @hide
2465 * @param user The user for whom to fetch the profile owner name, if any.
2466 * @return the human readable name of the organisation associated with this profile owner or
2467 * null if one is not set.
2468 * @throws IllegalArgumentException if the userId is invalid.
2469 */
2470 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002471 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002472 if (mService != null) {
2473 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002474 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002475 } catch (RemoteException re) {
2476 Log.w(TAG, "Failed to get profile owner");
2477 throw new IllegalArgumentException(
2478 "Requested profile owner for invalid userId", re);
2479 }
2480 }
2481 return null;
2482 }
2483
2484 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002485 * Called by a profile owner or device owner to add a default intent handler activity for
2486 * intents that match a certain intent filter. This activity will remain the default intent
2487 * handler even if the set of potential event handlers for the intent filter changes and if
2488 * the intent preferences are reset.
2489 *
2490 * <p>The default disambiguation mechanism takes over if the activity is not installed
2491 * (anymore). When the activity is (re)installed, it is automatically reset as default
2492 * intent handler for the filter.
2493 *
2494 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2495 * security exception will be thrown.
2496 *
2497 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2498 * @param filter The IntentFilter for which a default handler is added.
2499 * @param activity The Activity that is added as default intent handler.
2500 */
2501 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2502 ComponentName activity) {
2503 if (mService != null) {
2504 try {
2505 mService.addPersistentPreferredActivity(admin, filter, activity);
2506 } catch (RemoteException e) {
2507 Log.w(TAG, "Failed talking with device policy service", e);
2508 }
2509 }
2510 }
2511
2512 /**
2513 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002514 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002515 *
2516 * <p>The calling device admin must be a profile owner. If it is not, a security
2517 * exception will be thrown.
2518 *
2519 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2520 * @param packageName The name of the package for which preferences are removed.
2521 */
2522 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2523 String packageName) {
2524 if (mService != null) {
2525 try {
2526 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2527 } catch (RemoteException e) {
2528 Log.w(TAG, "Failed talking with device policy service", e);
2529 }
2530 }
2531 }
Robin Lee66e5d962014-04-09 16:44:21 +01002532
2533 /**
2534 * Called by a profile or device owner to set the application restrictions for a given target
2535 * application running in the managed profile.
2536 *
2537 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Amith Yamasanic8c84252014-07-13 17:12:12 -07002538 * boolean, int, String, or String[]. The recommended format for keys
Robin Lee66e5d962014-04-09 16:44:21 +01002539 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2540 * components such as {@link android.webkit.WebView}.
2541 *
2542 * <p>The application restrictions are only made visible to the target application and the
2543 * profile or device owner.
2544 *
2545 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2546 * exception will be thrown.
2547 *
2548 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2549 * @param packageName The name of the package to update restricted settings for.
2550 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2551 * set of active restrictions.
2552 */
2553 public void setApplicationRestrictions(ComponentName admin, String packageName,
2554 Bundle settings) {
2555 if (mService != null) {
2556 try {
2557 mService.setApplicationRestrictions(admin, packageName, settings);
2558 } catch (RemoteException e) {
2559 Log.w(TAG, "Failed talking with device policy service", e);
2560 }
2561 }
2562 }
2563
2564 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002565 * Sets a list of features to enable for a TrustAgent component. This is meant to be
Jim Miller604e7552014-07-18 19:00:02 -07002566 * used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which will disable all
2567 * trust agents but those with features enabled by this function call.
2568 *
2569 * <p>The calling device admin must have requested
2570 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
2571 * this method; if it has not, a security exception will be thrown.
2572 *
2573 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2574 * @param agent Which component to enable features for.
2575 * @param features List of features to enable. Consult specific TrustAgent documentation for
2576 * the feature list.
Jim Millerb1474f42014-08-26 18:42:58 -07002577 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002578 */
2579 public void setTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent,
2580 List<String> features) {
2581 if (mService != null) {
2582 try {
2583 mService.setTrustAgentFeaturesEnabled(admin, agent, features, UserHandle.myUserId());
2584 } catch (RemoteException e) {
2585 Log.w(TAG, "Failed talking with device policy service", e);
2586 }
2587 }
2588 }
2589
2590 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002591 * Gets list of enabled features for the given TrustAgent component. If admin is
Jim Miller604e7552014-07-18 19:00:02 -07002592 * null, this will return the intersection of all features enabled for the given agent by all
2593 * admins.
2594 *
2595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2596 * @param agent Which component to get enabled features for.
2597 * @return List of enabled features.
Jim Millerb1474f42014-08-26 18:42:58 -07002598 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002599 */
2600 public List<String> getTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent) {
2601 if (mService != null) {
2602 try {
2603 return mService.getTrustAgentFeaturesEnabled(admin, agent, UserHandle.myUserId());
2604 } catch (RemoteException e) {
2605 Log.w(TAG, "Failed talking with device policy service", e);
2606 }
2607 }
2608 return new ArrayList<String>(); // empty list
2609 }
2610
2611 /**
Adam Connors210fe212014-07-17 15:41:43 +01002612 * Called by a profile owner to set whether caller-Id information from the managed
2613 * profile will be shown for incoming calls.
2614 *
2615 * <p>The calling device admin must be a profile owner. If it is not, a
2616 * security exception will be thrown.
2617 *
2618 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2619 * @param disabled If true caller-Id information in the managed profile is not displayed.
2620 */
2621 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2622 if (mService != null) {
2623 try {
2624 mService.setCrossProfileCallerIdDisabled(who, disabled);
2625 } catch (RemoteException e) {
2626 Log.w(TAG, "Failed talking with device policy service", e);
2627 }
2628 }
2629 }
2630
2631 /**
2632 * Determine whether or not caller-Id information has been disabled.
2633 *
2634 * <p>The calling device admin must be a profile owner. If it is not, a
2635 * security exception will be thrown.
2636 *
2637 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2638 */
2639 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2640 if (mService != null) {
2641 try {
2642 return mService.getCrossProfileCallerIdDisabled(who);
2643 } catch (RemoteException e) {
2644 Log.w(TAG, "Failed talking with device policy service", e);
2645 }
2646 }
2647 return false;
2648 }
2649
2650 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002651 * Determine whether or not caller-Id information has been disabled.
2652 *
2653 * @param userHandle The user for whom to check the caller-id permission
2654 * @hide
2655 */
2656 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2657 if (mService != null) {
2658 try {
2659 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2660 } catch (RemoteException e) {
2661 Log.w(TAG, "Failed talking with device policy service", e);
2662 }
2663 }
2664 return false;
2665 }
2666
2667 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002668 * Called by the profile owner so that some intents sent in the managed profile can also be
2669 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002671 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2672 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002673 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2674 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002675 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002676 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002677 if (mService != null) {
2678 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002679 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002680 } catch (RemoteException e) {
2681 Log.w(TAG, "Failed talking with device policy service", e);
2682 }
2683 }
2684 }
2685
2686 /**
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002687 * Called by a profile owner to remove the cross-profile intent filters that go from the
2688 * managed profile to the parent, or from the parent to the managed profile.
2689 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002690 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2691 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002692 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002693 if (mService != null) {
2694 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002695 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002696 } catch (RemoteException e) {
2697 Log.w(TAG, "Failed talking with device policy service", e);
2698 }
2699 }
2700 }
2701
2702 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002703 * Called by a profile or device owner to set the permitted accessibility services. When
2704 * set by a device owner or profile owner the restriction applies to all profiles of the
2705 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07002706 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002707 * By default the user can use any accessiblity service. When zero or more packages have
2708 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07002709 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002710 *
2711 * <p> Calling with a null value for the list disables the restriction so that all services
2712 * can be used, calling with an empty list only allows the builtin system's services.
2713 *
2714 * <p> System accesibility services are always available to the user the list can't modify
2715 * this.
2716 *
2717 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2718 * @param packageNames List of accessibility service package names.
2719 *
2720 * @return true if setting the restriction succeeded. It fail if there is
2721 * one or more non-system accessibility services enabled, that are not in the list.
2722 */
2723 public boolean setPermittedAccessibilityServices(ComponentName admin,
2724 List<String> packageNames) {
2725 if (mService != null) {
2726 try {
2727 return mService.setPermittedAccessibilityServices(admin, packageNames);
2728 } catch (RemoteException e) {
2729 Log.w(TAG, "Failed talking with device policy service", e);
2730 }
2731 }
2732 return false;
2733 }
2734
2735 /**
2736 * Returns the list of permitted accessibility services set by this device or profile owner.
2737 *
2738 * <p>An empty list means no accessibility services except system services are allowed.
2739 * Null means all accessibility services are allowed.
2740 *
2741 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2742 * @return List of accessiblity service package names.
2743 */
2744 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2745 if (mService != null) {
2746 try {
2747 return mService.getPermittedAccessibilityServices(admin);
2748 } catch (RemoteException e) {
2749 Log.w(TAG, "Failed talking with device policy service", e);
2750 }
2751 }
2752 return null;
2753 }
2754
2755 /**
2756 * Returns the list of accessibility services permitted by the device or profiles
2757 * owners of this user.
2758 *
2759 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2760 * it will contain the intersection of the permitted lists for any device or profile
2761 * owners that apply to this user. It will also include any system accessibility services.
2762 *
2763 * @param userId which user to check for.
2764 * @return List of accessiblity service package names.
2765 * @hide
2766 */
2767 @SystemApi
2768 public List<String> getPermittedAccessibilityServices(int userId) {
2769 if (mService != null) {
2770 try {
2771 return mService.getPermittedAccessibilityServicesForUser(userId);
2772 } catch (RemoteException e) {
2773 Log.w(TAG, "Failed talking with device policy service", e);
2774 }
2775 }
2776 return null;
2777 }
2778
2779 /**
2780 * Called by a profile or device owner to set the permitted input methods services. When
2781 * set by a device owner or profile owner the restriction applies to all profiles of the
2782 * user the device owner or profile owner is an admin for.
2783 *
2784 * By default the user can use any input method. When zero or more packages have
2785 * been added, input method that are not in the list and not part of the system
2786 * can not be enabled by the user.
2787 *
2788 * This method will fail if it is called for a admin that is not for the foreground user
2789 * or a profile of the foreground user.
2790 *
2791 * <p> Calling with a null value for the list disables the restriction so that all input methods
2792 * can be used, calling with an empty list disables all but the system's own input methods.
2793 *
2794 * <p> System input methods are always available to the user this method can't modify this.
2795 *
2796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2797 * @param packageNames List of input method package names.
2798 * @return true if setting the restriction succeeded. It will fail if there is
2799 * one or more input method enabled, that are not in the list or user if the foreground
2800 * user.
2801 */
2802 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2803 if (mService != null) {
2804 try {
2805 return mService.setPermittedInputMethods(admin, packageNames);
2806 } catch (RemoteException e) {
2807 Log.w(TAG, "Failed talking with device policy service", e);
2808 }
2809 }
2810 return false;
2811 }
2812
2813
2814 /**
2815 * Returns the list of permitted input methods set by this device or profile owner.
2816 *
2817 * <p>An empty list means no input methods except system input methods are allowed.
2818 * Null means all input methods are allowed.
2819 *
2820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2821 * @return List of input method package names.
2822 */
2823 public List<String> getPermittedInputMethods(ComponentName admin) {
2824 if (mService != null) {
2825 try {
2826 return mService.getPermittedInputMethods(admin);
2827 } catch (RemoteException e) {
2828 Log.w(TAG, "Failed talking with device policy service", e);
2829 }
2830 }
2831 return null;
2832 }
2833
2834 /**
2835 * Returns the list of input methods permitted by the device or profiles
2836 * owners of the current user.
2837 *
2838 * <p>Null means all input methods are allowed, if a non-null list is returned
2839 * it will contain the intersection of the permitted lists for any device or profile
2840 * owners that apply to this user. It will also include any system input methods.
2841 *
2842 * @return List of input method package names.
2843 * @hide
2844 */
2845 @SystemApi
2846 public List<String> getPermittedInputMethodsForCurrentUser() {
2847 if (mService != null) {
2848 try {
2849 return mService.getPermittedInputMethodsForCurrentUser();
2850 } catch (RemoteException e) {
2851 Log.w(TAG, "Failed talking with device policy service", e);
2852 }
2853 }
2854 return null;
2855 }
2856
2857 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002858 * Called by a device owner to create a user with the specified name. The UserHandle returned
2859 * by this method should not be persisted as user handles are recycled as users are removed and
2860 * created. If you need to persist an identifier for this user, use
2861 * {@link UserManager#getSerialNumberForUser}.
2862 *
2863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2864 * @param name the user's name
2865 * @see UserHandle
2866 * @return the UserHandle object for the created user, or null if the user could not be created.
2867 */
2868 public UserHandle createUser(ComponentName admin, String name) {
2869 try {
2870 return mService.createUser(admin, name);
2871 } catch (RemoteException re) {
2872 Log.w(TAG, "Could not create a user", re);
2873 }
2874 return null;
2875 }
2876
2877 /**
Jason Monk03978a42014-06-10 15:05:30 -04002878 * Called by a device owner to create a user with the specified name. The UserHandle returned
2879 * by this method should not be persisted as user handles are recycled as users are removed and
2880 * created. If you need to persist an identifier for this user, use
2881 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2882 * immediately.
2883 *
2884 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2885 * as registered as an active admin on the new user. The profile owner package will be
2886 * installed on the new user if it already is installed on the device.
2887 *
2888 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2889 * profileOwnerComponent when onEnable is called.
2890 *
2891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2892 * @param name the user's name
2893 * @param ownerName the human readable name of the organisation associated with this DPM.
2894 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2895 * the user.
2896 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2897 * on the new user.
2898 * @see UserHandle
2899 * @return the UserHandle object for the created user, or null if the user could not be created.
2900 */
2901 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2902 ComponentName profileOwnerComponent, Bundle adminExtras) {
2903 try {
2904 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2905 adminExtras);
2906 } catch (RemoteException re) {
2907 Log.w(TAG, "Could not create a user", re);
2908 }
2909 return null;
2910 }
2911
2912 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002913 * Called by a device owner to remove a user and all associated data. The primary user can
2914 * not be removed.
2915 *
2916 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2917 * @param userHandle the user to remove.
2918 * @return {@code true} if the user was removed, {@code false} otherwise.
2919 */
2920 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2921 try {
2922 return mService.removeUser(admin, userHandle);
2923 } catch (RemoteException re) {
2924 Log.w(TAG, "Could not remove user ", re);
2925 return false;
2926 }
2927 }
2928
2929 /**
Jason Monk582d9112014-07-09 19:57:08 -04002930 * Called by a device owner to switch the specified user to the foreground.
2931 *
2932 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2933 * @param userHandle the user to switch to; null will switch to primary.
2934 * @return {@code true} if the switch was successful, {@code false} otherwise.
2935 *
2936 * @see Intent#ACTION_USER_FOREGROUND
2937 */
2938 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
2939 try {
2940 return mService.switchUser(admin, userHandle);
2941 } catch (RemoteException re) {
2942 Log.w(TAG, "Could not switch user ", re);
2943 return false;
2944 }
2945 }
2946
2947 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002948 * Called by a profile or device owner to get the application restrictions for a given target
2949 * application running in the managed profile.
2950 *
2951 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2952 * exception will be thrown.
2953 *
2954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2955 * @param packageName The name of the package to fetch restricted settings of.
2956 * @return {@link Bundle} of settings corresponding to what was set last time
2957 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2958 * if no restrictions have been set.
2959 */
2960 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2961 if (mService != null) {
2962 try {
2963 return mService.getApplicationRestrictions(admin, packageName);
2964 } catch (RemoteException e) {
2965 Log.w(TAG, "Failed talking with device policy service", e);
2966 }
2967 }
2968 return null;
2969 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002970
2971 /**
2972 * Called by a profile or device owner to set a user restriction specified
2973 * by the key.
2974 * <p>
2975 * The calling device admin must be a profile or device owner; if it is not,
2976 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002977 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002978 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2979 * with.
2980 * @param key The key of the restriction. See the constants in
2981 * {@link android.os.UserManager} for the list of keys.
2982 */
2983 public void addUserRestriction(ComponentName admin, String key) {
2984 if (mService != null) {
2985 try {
2986 mService.setUserRestriction(admin, key, true);
2987 } catch (RemoteException e) {
2988 Log.w(TAG, "Failed talking with device policy service", e);
2989 }
2990 }
2991 }
2992
2993 /**
2994 * Called by a profile or device owner to clear a user restriction specified
2995 * by the key.
2996 * <p>
2997 * The calling device admin must be a profile or device owner; if it is not,
2998 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002999 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003000 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3001 * with.
3002 * @param key The key of the restriction. See the constants in
3003 * {@link android.os.UserManager} for the list of keys.
3004 */
3005 public void clearUserRestriction(ComponentName admin, String key) {
3006 if (mService != null) {
3007 try {
3008 mService.setUserRestriction(admin, key, false);
3009 } catch (RemoteException e) {
3010 Log.w(TAG, "Failed talking with device policy service", e);
3011 }
3012 }
3013 }
Adam Connors010cfd42014-04-16 12:48:13 +01003014
3015 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003016 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003017 * is unavailable for use, but the data and actual package file remain.
3018 *
3019 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003020 * @param packageName The name of the package to hide or unhide.
3021 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3022 * unhidden.
3023 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003024 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003025 public boolean setApplicationHidden(ComponentName admin, String packageName,
3026 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003027 if (mService != null) {
3028 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003029 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003030 } catch (RemoteException e) {
3031 Log.w(TAG, "Failed talking with device policy service", e);
3032 }
3033 }
3034 return false;
3035 }
3036
3037 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003038 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003039 *
3040 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003041 * @param packageName The name of the package to retrieve the hidden status of.
3042 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003043 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003044 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003045 if (mService != null) {
3046 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003047 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003048 } catch (RemoteException e) {
3049 Log.w(TAG, "Failed talking with device policy service", e);
3050 }
3051 }
3052 return false;
3053 }
3054
3055 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003056 * Called by profile or device owner to re-enable a system app that was disabled by default
3057 * when the managed profile was created. This can only be called from a profile or device
3058 * owner running within a managed profile.
3059 *
3060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3061 * @param packageName The package to be re-enabled in the current profile.
3062 */
3063 public void enableSystemApp(ComponentName admin, String packageName) {
3064 if (mService != null) {
3065 try {
3066 mService.enableSystemApp(admin, packageName);
3067 } catch (RemoteException e) {
3068 Log.w(TAG, "Failed to install package: " + packageName);
3069 }
3070 }
3071 }
3072
3073 /**
3074 * Called by profile or device owner to re-enable system apps by intent that were disabled
3075 * by default when the managed profile was created. This can only be called from a profile
3076 * or device owner running within a managed profile.
3077 *
3078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3079 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3080 * intent will be re-enabled in the current profile.
3081 * @return int The number of activities that matched the intent and were installed.
3082 */
3083 public int enableSystemApp(ComponentName admin, Intent intent) {
3084 if (mService != null) {
3085 try {
3086 return mService.enableSystemAppWithIntent(admin, intent);
3087 } catch (RemoteException e) {
3088 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3089 }
3090 }
3091 return 0;
3092 }
3093
3094 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01003095 * Called by a profile owner to disable account management for a specific type of account.
3096 *
3097 * <p>The calling device admin must be a profile owner. If it is not, a
3098 * security exception will be thrown.
3099 *
3100 * <p>When account management is disabled for an account type, adding or removing an account
3101 * of that type will not be possible.
3102 *
3103 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3104 * @param accountType For which account management is disabled or enabled.
3105 * @param disabled The boolean indicating that account management will be disabled (true) or
3106 * enabled (false).
3107 */
3108 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3109 boolean disabled) {
3110 if (mService != null) {
3111 try {
3112 mService.setAccountManagementDisabled(admin, accountType, disabled);
3113 } catch (RemoteException e) {
3114 Log.w(TAG, "Failed talking with device policy service", e);
3115 }
3116 }
3117 }
3118
3119 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003120 * Gets the array of accounts for which account management is disabled by the profile owner.
3121 *
3122 * <p> Account management can be disabled/enabled by calling
3123 * {@link #setAccountManagementDisabled}.
3124 *
3125 * @return a list of account types for which account management has been disabled.
3126 *
3127 * @see #setAccountManagementDisabled
3128 */
3129 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003130 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003131 }
3132
3133 /**
3134 * @see #getAccountTypesWithManagementDisabled()
3135 * @hide
3136 */
3137 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003138 if (mService != null) {
3139 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003140 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003141 } catch (RemoteException e) {
3142 Log.w(TAG, "Failed talking with device policy service", e);
3143 }
3144 }
3145
3146 return null;
3147 }
justinzhang511e0d82014-03-24 16:09:24 -04003148
3149 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003150 * Sets which packages may enter lock task mode.
3151 *
3152 * <p>Any packages that shares uid with an allowed package will also be allowed
3153 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003154 *
Jason Monkc5185f22014-06-24 11:12:42 -04003155 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003156 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003157 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003158 *
3159 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003160 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3161 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003162 */
Jason Monk48aacba2014-08-13 16:29:08 -04003163 public void setLockTaskPackages(ComponentName admin, String[] packages)
3164 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003165 if (mService != null) {
3166 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003167 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003168 } catch (RemoteException e) {
3169 Log.w(TAG, "Failed talking with device policy service", e);
3170 }
3171 }
3172 }
3173
3174 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003175 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003176 *
3177 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003178 * @hide
3179 */
Jason Monk48aacba2014-08-13 16:29:08 -04003180 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003181 if (mService != null) {
3182 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003183 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003184 } catch (RemoteException e) {
3185 Log.w(TAG, "Failed talking with device policy service", e);
3186 }
3187 }
3188 return null;
3189 }
3190
3191 /**
3192 * This function lets the caller know whether the given component is allowed to start the
3193 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003194 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003195 */
Jason Monkd7b86212014-06-16 13:15:38 -04003196 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003197 if (mService != null) {
3198 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003199 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003200 } catch (RemoteException e) {
3201 Log.w(TAG, "Failed talking with device policy service", e);
3202 }
3203 }
3204 return false;
3205 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003206
3207 /**
3208 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3209 * of the setting is in the correct form for the setting type should be performed by the caller.
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003210 * <p>The settings that can be updated with this method are:
3211 * <ul>
3212 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3213 * <li>{@link Settings.Global#AUTO_TIME}</li>
3214 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
3215 * <li>{@link Settings.Global#BLUETOOTH_ON}</li>
3216 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3217 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3218 * <li>{@link Settings.Global#MODE_RINGER}</li>
3219 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3220 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
3221 * <li>{@link Settings.Global#WIFI_ON}</li>
3222 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3223 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003224 *
3225 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3226 * @param setting The name of the setting to update.
3227 * @param value The value to update the setting to.
3228 */
3229 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3230 if (mService != null) {
3231 try {
3232 mService.setGlobalSetting(admin, setting, value);
3233 } catch (RemoteException e) {
3234 Log.w(TAG, "Failed talking with device policy service", e);
3235 }
3236 }
3237 }
3238
3239 /**
3240 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3241 * that the value of the setting is in the correct form for the setting type should be performed
3242 * by the caller.
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003243 * <p>The settings that can be updated with this method are:
3244 * <ul>
3245 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
3246 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3247 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003248 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3249 * @param setting The name of the setting to update.
3250 * @param value The value to update the setting to.
3251 */
3252 public void setSecureSetting(ComponentName admin, String setting, String value) {
3253 if (mService != null) {
3254 try {
3255 mService.setSecureSetting(admin, setting, value);
3256 } catch (RemoteException e) {
3257 Log.w(TAG, "Failed talking with device policy service", e);
3258 }
3259 }
3260 }
3261
Amith Yamasanif20d6402014-05-24 15:34:37 -07003262 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003263 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003264 * making permission requests of a local or remote administrator of the user.
3265 * <p/>
3266 * Only a profile owner can designate the restrictions provider.
3267 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003268 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003269 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003270 * it removes the restrictions provider previously assigned.
3271 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003272 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003273 if (mService != null) {
3274 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003275 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003276 } catch (RemoteException re) {
3277 Log.w(TAG, "Failed to set permission provider on device policy service");
3278 }
3279 }
3280 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003281
3282 /**
3283 * Called by profile or device owners to set the master volume mute on or off.
3284 *
3285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3286 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3287 */
3288 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3289 if (mService != null) {
3290 try {
3291 mService.setMasterVolumeMuted(admin, on);
3292 } catch (RemoteException re) {
3293 Log.w(TAG, "Failed to setMasterMute on device policy service");
3294 }
3295 }
3296 }
3297
3298 /**
3299 * Called by profile or device owners to check whether the master volume mute is on or off.
3300 *
3301 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3302 * @return {@code true} if master volume is muted, {@code false} if it's not.
3303 */
3304 public boolean isMasterVolumeMuted(ComponentName admin) {
3305 if (mService != null) {
3306 try {
3307 return mService.isMasterVolumeMuted(admin);
3308 } catch (RemoteException re) {
3309 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3310 }
3311 }
3312 return false;
3313 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003314
3315 /**
3316 * Called by profile or device owners to change whether a user can uninstall
3317 * a package.
3318 *
3319 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3320 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003321 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003322 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003323 public void setUninstallBlocked(ComponentName admin, String packageName,
3324 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003325 if (mService != null) {
3326 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003327 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003328 } catch (RemoteException re) {
3329 Log.w(TAG, "Failed to call block uninstall on device policy service");
3330 }
3331 }
3332 }
3333
3334 /**
3335 * Called by profile or device owners to check whether a user has been blocked from
3336 * uninstalling a package.
3337 *
3338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3339 * @param packageName package to check.
3340 * @return true if the user shouldn't be able to uninstall the package.
3341 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003342 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003343 if (mService != null) {
3344 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003345 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003346 } catch (RemoteException re) {
3347 Log.w(TAG, "Failed to call block uninstall on device policy service");
3348 }
3349 }
3350 return false;
3351 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003352
3353 /**
3354 * Called by the profile owner to enable widget providers from a given package
3355 * to be available in the parent profile. As a result the user will be able to
3356 * add widgets from the white-listed package running under the profile to a widget
3357 * host which runs under the device owner, for example the home screen. Note that
3358 * a package may have zero or more provider components, where each component
3359 * provides a different widget type.
3360 * <p>
3361 * <strong>Note:</strong> By default no widget provider package is white-listed.
3362 * </p>
3363 *
3364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3365 * @param packageName The package from which widget providers are white-listed.
3366 * @return Whether the package was added.
3367 *
3368 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3369 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3370 */
3371 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3372 if (mService != null) {
3373 try {
3374 return mService.addCrossProfileWidgetProvider(admin, packageName);
3375 } catch (RemoteException re) {
3376 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3377 }
3378 }
3379 return false;
3380 }
3381
3382 /**
3383 * Called by the profile owner to disable widget providers from a given package
3384 * to be available in the parent profile. For this method to take effect the
3385 * package should have been added via {@link #addCrossProfileWidgetProvider(
3386 * android.content.ComponentName, String)}.
3387 * <p>
3388 * <strong>Note:</strong> By default no widget provider package is white-listed.
3389 * </p>
3390 *
3391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3392 * @param packageName The package from which widget providers are no longer
3393 * white-listed.
3394 * @return Whether the package was removed.
3395 *
3396 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3397 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3398 */
3399 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3400 if (mService != null) {
3401 try {
3402 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3403 } catch (RemoteException re) {
3404 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3405 }
3406 }
3407 return false;
3408 }
3409
3410 /**
3411 * Called by the profile owner to query providers from which packages are
3412 * available in the parent profile.
3413 *
3414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3415 * @return The white-listed package list.
3416 *
3417 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3418 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3419 */
3420 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3421 if (mService != null) {
3422 try {
3423 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3424 if (providers != null) {
3425 return providers;
3426 }
3427 } catch (RemoteException re) {
3428 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3429 }
3430 }
3431 return Collections.emptyList();
3432 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003433}