blob: 41bbb87e55e9fc4ca3beea9c00103ead8bfd8641 [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 Alewijnse1cc4ecc2014-06-23 19:56:52 +0100118 * A String extra holding the package name of the mobile device management application that
119 * will be set as the profile owner or device owner.
120 *
121 * <p>If an application starts provisioning directly via an intent with action
122 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
123 * application that started provisioning. The package will be set as profile owner in that case.
124 *
125 * <p>This package is set as device owner when device owner provisioning is started by an Nfc
Esteban Talaveraf057f062014-08-20 14:27:45 +0100126 * message containing an Nfc record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127 */
128 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100129 = "android.app.extra.DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130
131 /**
132 * A String extra holding the default name of the profile that is created during managed profile
133 * provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100134 *
Jessica Hummelf72078b2014-03-06 16:13:12 +0000135 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
136 */
137 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100138 = "android.app.extra.DEFAULT_MANAGED_PROFILE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000139
140 /**
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100141 * A String extra that, holds the email address of the account which a managed profile is
142 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100143 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Jessica Hummeledb7ae72014-06-26 12:55:38 +0100144 *
145 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
146 * contains this extra, it is forwarded in the
147 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
148 * device management application that was set as the profile owner during provisioning.
149 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100150 */
151 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100152 = "android.app.extra.MANAGED_PROFILE_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100153
154 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100155 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
156 * will be set to.
157 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100158 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100159 * provisioning via an Nfc bump.
160 */
161 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100162 = "android.app.extra.TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100163
164 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100165 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
166 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100167 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100168 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100169 * provisioning via an Nfc bump.
170 */
171 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100172 = "android.app.extra.LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100173
174 /**
175 * A String extra holding the {@link java.util.Locale} that the device will be set to.
176 * Format: xx_yy, where xx is the language code, and yy the country code.
177 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100178 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100179 * provisioning via an Nfc bump.
180 */
181 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100182 = "android.app.extra.LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100183
184 /**
185 * A String extra holding the ssid of the wifi network that should be used during nfc device
186 * owner provisioning for downloading the mobile device management application.
187 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100188 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100189 * provisioning via an Nfc bump.
190 */
191 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100192 = "android.app.extra.WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100193
194 /**
195 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
196 * is hidden or not.
197 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100198 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100199 * provisioning via an Nfc bump.
200 */
201 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100202 = "android.app.extra.WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100203
204 /**
205 * A String extra indicating the security type of the wifi network in
206 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
207 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100208 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100209 * provisioning via an Nfc bump.
210 */
211 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100212 = "android.app.extra.WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100213
214 /**
215 * A String extra holding the password of the wifi network in
216 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
217 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100218 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100219 * provisioning via an Nfc bump.
220 */
221 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100222 = "android.app.extra.WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100223
224 /**
225 * A String extra holding the proxy host for the wifi network in
226 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
227 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100228 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100229 * provisioning via an Nfc bump.
230 */
231 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100232 = "android.app.extra.WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100233
234 /**
235 * An int extra holding the proxy port for the wifi network in
236 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
237 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100238 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100239 * provisioning via an Nfc bump.
240 */
241 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100242 = "android.app.extra.WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100243
244 /**
245 * A String extra holding the proxy bypass for the wifi network in
246 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
247 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100248 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100249 * provisioning via an Nfc bump.
250 */
251 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100252 = "android.app.extra.WIFI_PROXY_BYPASS_HOSTS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100253
254 /**
255 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
256 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
257 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100258 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100259 * provisioning via an Nfc bump.
260 */
261 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100262 = "android.app.extra.WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100263
264 /**
265 * A String extra holding a url that specifies the download location of the device admin
266 * package. When not provided it is assumed that the device admin package is already installed.
267 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100268 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100269 * provisioning via an Nfc bump.
270 */
271 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100272 = "android.app.extra.DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100273
274 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100275 * A String extra holding a http cookie header which should be used in the http request to the
276 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
277 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100278 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse681bce92014-07-24 16:46:26 +0100279 * provisioning via an Nfc bump.
280 */
281 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100282 = "android.app.extra.DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100283
284 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100285 * A String extra holding the SHA-1 checksum of the file at download location specified in
286 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
287 * the file at the download location an error will be shown to the user and the user will be
288 * asked to factory reset the device.
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 Alewijnse1cc4ecc2014-06-23 19:56:52 +0100291 * provisioning via an Nfc bump.
292 */
293 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100294 = "android.app.extra.DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100295
296 /**
297 * This MIME type is used for starting the Device Owner provisioning.
298 *
299 * <p>During device owner provisioning a device admin app is set as the owner of the device.
300 * A device owner has full control over the device. The device owner can not be modified by the
301 * user and the only way of resetting the device is if the device owner app calls a factory
302 * reset.
303 *
304 * <p> A typical use case would be a device that is owned by a company, but used by either an
305 * employee or client.
306 *
307 * <p> The Nfc message should be send to an unprovisioned device.
308 *
309 * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which
310 * contains the following properties:
311 * <ul>
312 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
313 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100314 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100315 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
316 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
317 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
318 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
319 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
320 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
321 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
322 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
323 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
324 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
325 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
326 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
327 *
328 * <p> When device owner provisioning has completed, an intent of the type
329 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
330 * device owner.
331 *
332 * <p>
333 * If provisioning fails, the device is factory reset.
334 *
335 * <p>Input: Nothing.</p>
336 * <p>Output: Nothing</p>
337 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100338 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100339 = "application/com.android.managedprovisioning";
340
341 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800342 * Activity action: ask the user to add a new device administrator to the system.
343 * The desired policy is the ComponentName of the policy in the
344 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
345 * bring the user through adding the device administrator to the system (or
346 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700347 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800348 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
349 * field to provide the user with additional explanation (in addition
350 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800351 *
352 * <p>If your administrator is already active, this will ordinarily return immediately (without
353 * user intervention). However, if your administrator has been updated and is requesting
354 * additional uses-policy flags, the user will be presented with the new list. New policies
355 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800356 */
357 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
358 public static final String ACTION_ADD_DEVICE_ADMIN
359 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700360
Dianne Hackbornd6847842010-01-12 18:14:19 -0800361 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700362 * @hide
363 * Activity action: ask the user to add a new device administrator as the profile owner
364 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
365 * permission can call this API.
366 *
367 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
368 * field. This will invoke a UI to bring the user through adding the profile owner admin
369 * to remotely control restrictions on the user.
370 *
371 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
372 * result of whether or not the user approved the action. If approved, the result will
373 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
374 * as a profile owner.
375 *
376 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
377 * field to provide the user with additional explanation (in addition
378 * to your component's description) about what is being added.
379 *
380 * <p>If there is already a profile owner active or the caller doesn't have the required
381 * permissions, the operation will return a failure result.
382 */
383 @SystemApi
384 public static final String ACTION_SET_PROFILE_OWNER
385 = "android.app.action.SET_PROFILE_OWNER";
386
387 /**
388 * @hide
389 * Name of the profile owner admin that controls the user.
390 */
391 @SystemApi
392 public static final String EXTRA_PROFILE_OWNER_NAME
393 = "android.app.extra.PROFILE_OWNER_NAME";
394
395 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700396 * Activity action: send when any policy admin changes a policy.
397 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700398 *
Jim Miller284b62e2010-06-08 14:27:42 -0700399 * @hide
400 */
401 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
402 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
403
404 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800405 * The ComponentName of the administrator component.
406 *
407 * @see #ACTION_ADD_DEVICE_ADMIN
408 */
409 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700410
Dianne Hackbornd6847842010-01-12 18:14:19 -0800411 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800412 * An optional CharSequence providing additional explanation for why the
413 * admin is being added.
414 *
415 * @see #ACTION_ADD_DEVICE_ADMIN
416 */
417 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700418
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800419 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700420 * Activity action: have the user enter a new password. This activity should
421 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
422 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
423 * enter a new password that meets the current requirements. You can use
424 * {@link #isActivePasswordSufficient()} to determine whether you need to
425 * have the user select a new password in order to meet the current
426 * constraints. Upon being resumed from this activity, you can check the new
427 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800428 */
429 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
430 public static final String ACTION_SET_NEW_PASSWORD
431 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700432
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000433 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100434 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
435 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000436 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100437 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000438
439 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100440 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
441 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000442 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100443 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700444
Dianne Hackbornd6847842010-01-12 18:14:19 -0800445 /**
446 * Return true if the given administrator component is currently
447 * active (enabled) in the system.
448 */
449 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100450 return isAdminActiveAsUser(who, UserHandle.myUserId());
451 }
452
453 /**
454 * @see #isAdminActive(ComponentName)
455 * @hide
456 */
457 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800458 if (mService != null) {
459 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100460 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800461 } catch (RemoteException e) {
462 Log.w(TAG, "Failed talking with device policy service", e);
463 }
464 }
465 return false;
466 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700467
Dianne Hackbornd6847842010-01-12 18:14:19 -0800468 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800469 * Return a list of all currently active device administrator's component
470 * names. Note that if there are no administrators than null may be
471 * returned.
472 */
473 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100474 return getActiveAdminsAsUser(UserHandle.myUserId());
475 }
476
477 /**
478 * @see #getActiveAdmins()
479 * @hide
480 */
481 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800482 if (mService != null) {
483 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100484 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800485 } catch (RemoteException e) {
486 Log.w(TAG, "Failed talking with device policy service", e);
487 }
488 }
489 return null;
490 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700491
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800492 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700493 * Used by package administration code to determine if a package can be stopped
494 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800495 * @hide
496 */
497 public boolean packageHasActiveAdmins(String packageName) {
498 if (mService != null) {
499 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700500 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800501 } catch (RemoteException e) {
502 Log.w(TAG, "Failed talking with device policy service", e);
503 }
504 }
505 return false;
506 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700507
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800508 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800509 * Remove a current administration component. This can only be called
510 * by the application that owns the administration component; if you
511 * try to remove someone else's component, a security exception will be
512 * thrown.
513 */
514 public void removeActiveAdmin(ComponentName who) {
515 if (mService != null) {
516 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700517 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800518 } catch (RemoteException e) {
519 Log.w(TAG, "Failed talking with device policy service", e);
520 }
521 }
522 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700523
Dianne Hackbornd6847842010-01-12 18:14:19 -0800524 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800525 * Returns true if an administrator has been granted a particular device policy. This can
526 * be used to check if the administrator was activated under an earlier set of policies,
527 * but requires additional policies after an upgrade.
528 *
529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
530 * an active administrator, or an exception will be thrown.
531 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
532 */
533 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
534 if (mService != null) {
535 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700536 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800537 } catch (RemoteException e) {
538 Log.w(TAG, "Failed talking with device policy service", e);
539 }
540 }
541 return false;
542 }
543
544 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800545 * Constant for {@link #setPasswordQuality}: the policy has no requirements
546 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800547 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800548 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800549 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700550
Dianne Hackbornd6847842010-01-12 18:14:19 -0800551 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700552 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
553 * recognition technology. This implies technologies that can recognize the identity of
554 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
555 * Note that quality constants are ordered so that higher values are more restrictive.
556 */
557 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
558
559 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800560 * Constant for {@link #setPasswordQuality}: the policy requires some kind
561 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800562 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800563 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800564 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700565
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800566 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800567 * Constant for {@link #setPasswordQuality}: the user must have entered a
568 * password containing at least numeric characters. Note that quality
569 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800570 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800571 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700572
Dianne Hackbornd6847842010-01-12 18:14:19 -0800573 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800574 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800575 * password containing at least numeric characters with no repeating (4444)
576 * or ordered (1234, 4321, 2468) sequences. Note that quality
577 * constants are ordered so that higher values are more restrictive.
578 */
579 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
580
581 /**
582 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700583 * password containing at least alphabetic (or other symbol) characters.
584 * Note that quality constants are ordered so that higher values are more
585 * restrictive.
586 */
587 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700588
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700589 /**
590 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800591 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700592 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800593 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800594 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700595 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700596
Dianne Hackbornd6847842010-01-12 18:14:19 -0800597 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700598 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700599 * password containing at least a letter, a numerical digit and a special
600 * symbol, by default. With this password quality, passwords can be
601 * restricted to contain various sets of characters, like at least an
602 * uppercase letter, etc. These are specified using various methods,
603 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
604 * that quality constants are ordered so that higher values are more
605 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700606 */
607 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
608
609 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800610 * Called by an application that is administering the device to set the
611 * password restrictions it is imposing. After setting this, the user
612 * will not be able to enter a new password that is not at least as
613 * restrictive as what has been set. Note that the current password
614 * will remain until the user has set a new one, so the change does not
615 * take place immediately. To prompt the user for a new password, use
616 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700617 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800618 * <p>Quality constants are ordered so that higher values are more restrictive;
619 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800620 * the user's preference, and any other considerations) is the one that
621 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700622 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800623 * <p>The calling device admin must have requested
624 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
625 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700626 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800627 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800628 * @param quality The new desired quality. One of
629 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800630 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
631 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
632 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800633 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800634 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800635 if (mService != null) {
636 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700637 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800638 } catch (RemoteException e) {
639 Log.w(TAG, "Failed talking with device policy service", e);
640 }
641 }
642 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700643
Dianne Hackbornd6847842010-01-12 18:14:19 -0800644 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100645 * Retrieve the current minimum password quality for all admins of this user
646 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800647 * @param admin The name of the admin component to check, or null to aggregate
648 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800649 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800650 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700651 return getPasswordQuality(admin, UserHandle.myUserId());
652 }
653
654 /** @hide per-user version */
655 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800656 if (mService != null) {
657 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700658 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800659 } catch (RemoteException e) {
660 Log.w(TAG, "Failed talking with device policy service", e);
661 }
662 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800663 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800664 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700665
Dianne Hackbornd6847842010-01-12 18:14:19 -0800666 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800667 * Called by an application that is administering the device to set the
668 * minimum allowed password length. After setting this, the user
669 * will not be able to enter a new password that is not at least as
670 * restrictive as what has been set. Note that the current password
671 * will remain until the user has set a new one, so the change does not
672 * take place immediately. To prompt the user for a new password, use
673 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
674 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800675 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
676 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
677 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700678 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800679 * <p>The calling device admin must have requested
680 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
681 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700682 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800684 * @param length The new desired minimum password length. A value of 0
685 * means there is no restriction.
686 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800687 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800688 if (mService != null) {
689 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700690 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800691 } catch (RemoteException e) {
692 Log.w(TAG, "Failed talking with device policy service", e);
693 }
694 }
695 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700696
Dianne Hackbornd6847842010-01-12 18:14:19 -0800697 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100698 * Retrieve the current minimum password length for all admins of this
699 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800700 * @param admin The name of the admin component to check, or null to aggregate
701 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800702 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800703 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700704 return getPasswordMinimumLength(admin, UserHandle.myUserId());
705 }
706
707 /** @hide per-user version */
708 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800709 if (mService != null) {
710 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700711 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800712 } catch (RemoteException e) {
713 Log.w(TAG, "Failed talking with device policy service", e);
714 }
715 }
716 return 0;
717 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700718
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700719 /**
720 * Called by an application that is administering the device to set the
721 * minimum number of upper case letters required in the password. After
722 * setting this, the user will not be able to enter a new password that is
723 * not at least as restrictive as what has been set. Note that the current
724 * password will remain until the user has set a new one, so the change does
725 * not take place immediately. To prompt the user for a new password, use
726 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
727 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700728 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
729 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700730 * <p>
731 * The calling device admin must have requested
732 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
733 * this method; if it has not, a security exception will be thrown.
734 *
735 * @param admin Which {@link DeviceAdminReceiver} this request is associated
736 * with.
737 * @param length The new desired minimum number of upper case letters
738 * required in the password. A value of 0 means there is no
739 * restriction.
740 */
741 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
742 if (mService != null) {
743 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700744 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700745 } catch (RemoteException e) {
746 Log.w(TAG, "Failed talking with device policy service", e);
747 }
748 }
749 }
750
751 /**
752 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100753 * password for all admins of this user and its profiles or a particular one.
754 * This is the same value as set by
755 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700756 * and only applies when the password quality is
757 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700758 *
759 * @param admin The name of the admin component to check, or null to
760 * aggregate all admins.
761 * @return The minimum number of upper case letters required in the
762 * password.
763 */
764 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700765 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
766 }
767
768 /** @hide per-user version */
769 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700770 if (mService != null) {
771 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700772 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700773 } catch (RemoteException e) {
774 Log.w(TAG, "Failed talking with device policy service", e);
775 }
776 }
777 return 0;
778 }
779
780 /**
781 * Called by an application that is administering the device to set the
782 * minimum number of lower case letters required in the password. After
783 * setting this, the user will not be able to enter a new password that is
784 * not at least as restrictive as what has been set. Note that the current
785 * password will remain until the user has set a new one, so the change does
786 * not take place immediately. To prompt the user for a new password, use
787 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
788 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700789 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
790 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700791 * <p>
792 * The calling device admin must have requested
793 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
794 * this method; if it has not, a security exception will be thrown.
795 *
796 * @param admin Which {@link DeviceAdminReceiver} this request is associated
797 * with.
798 * @param length The new desired minimum number of lower case letters
799 * required in the password. A value of 0 means there is no
800 * restriction.
801 */
802 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
803 if (mService != null) {
804 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700805 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700806 } catch (RemoteException e) {
807 Log.w(TAG, "Failed talking with device policy service", e);
808 }
809 }
810 }
811
812 /**
813 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100814 * password for all admins of this user and its profiles or a particular one.
815 * This is the same value as set by
816 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700817 * and only applies when the password quality is
818 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700819 *
820 * @param admin The name of the admin component to check, or null to
821 * aggregate all admins.
822 * @return The minimum number of lower case letters required in the
823 * password.
824 */
825 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700826 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
827 }
828
829 /** @hide per-user version */
830 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700831 if (mService != null) {
832 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700833 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700834 } catch (RemoteException e) {
835 Log.w(TAG, "Failed talking with device policy service", e);
836 }
837 }
838 return 0;
839 }
840
841 /**
842 * Called by an application that is administering the device to set the
843 * minimum number of letters required in the password. After setting this,
844 * the user will not be able to enter a new password that is not at least as
845 * restrictive as what has been set. Note that the current password will
846 * remain until the user has set a new one, so the change does not take
847 * place immediately. To prompt the user for a new password, use
848 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
849 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700850 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
851 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700852 * <p>
853 * The calling device admin must have requested
854 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
855 * this method; if it has not, a security exception will be thrown.
856 *
857 * @param admin Which {@link DeviceAdminReceiver} this request is associated
858 * with.
859 * @param length The new desired minimum number of letters required in the
860 * password. A value of 0 means there is no restriction.
861 */
862 public void setPasswordMinimumLetters(ComponentName admin, int length) {
863 if (mService != null) {
864 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700865 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700866 } catch (RemoteException e) {
867 Log.w(TAG, "Failed talking with device policy service", e);
868 }
869 }
870 }
871
872 /**
873 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700874 * admins or a particular one. This is the same value as
875 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
876 * and only applies when the password quality is
877 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700878 *
879 * @param admin The name of the admin component to check, or null to
880 * aggregate all admins.
881 * @return The minimum number of letters required in the password.
882 */
883 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700884 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
885 }
886
887 /** @hide per-user version */
888 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700889 if (mService != null) {
890 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700891 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700892 } catch (RemoteException e) {
893 Log.w(TAG, "Failed talking with device policy service", e);
894 }
895 }
896 return 0;
897 }
898
899 /**
900 * Called by an application that is administering the device to set the
901 * minimum number of numerical digits required in the password. After
902 * setting this, the user will not be able to enter a new password that is
903 * not at least as restrictive as what has been set. Note that the current
904 * password will remain until the user has set a new one, so the change does
905 * not take place immediately. To prompt the user for a new password, use
906 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
907 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700908 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
909 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700910 * <p>
911 * The calling device admin must have requested
912 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
913 * this method; if it has not, a security exception will be thrown.
914 *
915 * @param admin Which {@link DeviceAdminReceiver} this request is associated
916 * with.
917 * @param length The new desired minimum number of numerical digits required
918 * in the password. A value of 0 means there is no restriction.
919 */
920 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
921 if (mService != null) {
922 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700923 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700924 } catch (RemoteException e) {
925 Log.w(TAG, "Failed talking with device policy service", e);
926 }
927 }
928 }
929
930 /**
931 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100932 * for all admins of this user and its profiles or a particular one.
933 * This is the same value as set by
934 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700935 * and only applies when the password quality is
936 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700937 *
938 * @param admin The name of the admin component to check, or null to
939 * aggregate all admins.
940 * @return The minimum number of numerical digits required in the password.
941 */
942 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700943 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
944 }
945
946 /** @hide per-user version */
947 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700948 if (mService != null) {
949 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700950 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700951 } catch (RemoteException e) {
952 Log.w(TAG, "Failed talking with device policy service", e);
953 }
954 }
955 return 0;
956 }
957
958 /**
959 * Called by an application that is administering the device to set the
960 * minimum number of symbols required in the password. After setting this,
961 * the user will not be able to enter a new password that is not at least as
962 * restrictive as what has been set. Note that the current password will
963 * remain until the user has set a new one, so the change does not take
964 * place immediately. To prompt the user for a new password, use
965 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
966 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700967 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
968 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700969 * <p>
970 * The calling device admin must have requested
971 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
972 * this method; if it has not, a security exception will be thrown.
973 *
974 * @param admin Which {@link DeviceAdminReceiver} this request is associated
975 * with.
976 * @param length The new desired minimum number of symbols required in the
977 * password. A value of 0 means there is no restriction.
978 */
979 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
980 if (mService != null) {
981 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700982 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700983 } catch (RemoteException e) {
984 Log.w(TAG, "Failed talking with device policy service", e);
985 }
986 }
987 }
988
989 /**
990 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700991 * admins or a particular one. This is the same value as
992 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
993 * and only applies when the password quality is
994 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700995 *
996 * @param admin The name of the admin component to check, or null to
997 * aggregate all admins.
998 * @return The minimum number of symbols required in the password.
999 */
1000 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001001 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1002 }
1003
1004 /** @hide per-user version */
1005 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001006 if (mService != null) {
1007 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001008 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001009 } catch (RemoteException e) {
1010 Log.w(TAG, "Failed talking with device policy service", e);
1011 }
1012 }
1013 return 0;
1014 }
1015
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001016 /**
1017 * Called by an application that is administering the device to set the
1018 * minimum number of non-letter characters (numerical digits or symbols)
1019 * required in the password. After setting this, the user will not be able
1020 * to enter a new password that is not at least as restrictive as what has
1021 * been set. Note that the current password will remain until the user has
1022 * set a new one, so the change does not take place immediately. To prompt
1023 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1024 * setting this value. This constraint is only imposed if the administrator
1025 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1026 * {@link #setPasswordQuality}. The default value is 0.
1027 * <p>
1028 * The calling device admin must have requested
1029 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1030 * this method; if it has not, a security exception will be thrown.
1031 *
1032 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1033 * with.
1034 * @param length The new desired minimum number of letters required in the
1035 * password. A value of 0 means there is no restriction.
1036 */
1037 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1038 if (mService != null) {
1039 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001040 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001041 } catch (RemoteException e) {
1042 Log.w(TAG, "Failed talking with device policy service", e);
1043 }
1044 }
1045 }
1046
1047 /**
1048 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001049 * password for all admins of this user and its profiles or a particular one.
1050 * This is the same value as set by
1051 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001052 * and only applies when the password quality is
1053 * {@link #PASSWORD_QUALITY_COMPLEX}.
1054 *
1055 * @param admin The name of the admin component to check, or null to
1056 * aggregate all admins.
1057 * @return The minimum number of letters required in the password.
1058 */
1059 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001060 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1061 }
1062
1063 /** @hide per-user version */
1064 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001065 if (mService != null) {
1066 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001067 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001068 } catch (RemoteException e) {
1069 Log.w(TAG, "Failed talking with device policy service", e);
1070 }
1071 }
1072 return 0;
1073 }
1074
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001075 /**
1076 * Called by an application that is administering the device to set the length
1077 * of the password history. After setting this, the user will not be able to
1078 * enter a new password that is the same as any password in the history. Note
1079 * that the current password will remain until the user has set a new one, so
1080 * the change does not take place immediately. To prompt the user for a new
1081 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1082 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001083 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1084 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1085 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001086 *
1087 * <p>
1088 * The calling device admin must have requested
1089 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1090 * method; if it has not, a security exception will be thrown.
1091 *
1092 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1093 * with.
1094 * @param length The new desired length of password history. A value of 0
1095 * means there is no restriction.
1096 */
1097 public void setPasswordHistoryLength(ComponentName admin, int length) {
1098 if (mService != null) {
1099 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001100 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001101 } catch (RemoteException e) {
1102 Log.w(TAG, "Failed talking with device policy service", e);
1103 }
1104 }
1105 }
1106
1107 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001108 * Called by a device admin to set the password expiration timeout. Calling this method
1109 * will restart the countdown for password expiration for the given admin, as will changing
1110 * the device password (for all admins).
1111 *
1112 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1113 * For example, to have the password expire 5 days from now, timeout would be
1114 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1115 *
1116 * <p>To disable password expiration, a value of 0 may be used for timeout.
1117 *
Jim Millera4e28d12010-11-08 16:15:47 -08001118 * <p>The calling device admin must have requested
1119 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1120 * method; if it has not, a security exception will be thrown.
1121 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001122 * <p> Note that setting the password will automatically reset the expiration time for all
1123 * active admins. Active admins do not need to explicitly call this method in that case.
1124 *
Jim Millera4e28d12010-11-08 16:15:47 -08001125 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1126 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1127 * means there is no restriction (unlimited).
1128 */
1129 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1130 if (mService != null) {
1131 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001132 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001133 } catch (RemoteException e) {
1134 Log.w(TAG, "Failed talking with device policy service", e);
1135 }
1136 }
1137 }
1138
1139 /**
Jim Miller6b857682011-02-16 16:27:41 -08001140 * Get the password expiration timeout for the given admin. The expiration timeout is the
1141 * recurring expiration timeout provided in the call to
1142 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1143 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001144 *
1145 * @param admin The name of the admin component to check, or null to aggregate all admins.
1146 * @return The timeout for the given admin or the minimum of all timeouts
1147 */
1148 public long getPasswordExpirationTimeout(ComponentName admin) {
1149 if (mService != null) {
1150 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001151 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001152 } catch (RemoteException e) {
1153 Log.w(TAG, "Failed talking with device policy service", e);
1154 }
1155 }
1156 return 0;
1157 }
1158
1159 /**
1160 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001161 * all admins of this user and its profiles if admin is null. If the password is
1162 * expired, this will return the time since the password expired as a negative number.
1163 * If admin is null, then a composite of all expiration timeouts is returned
1164 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001165 *
1166 * @param admin The name of the admin component to check, or null to aggregate all admins.
1167 * @return The password expiration time, in ms.
1168 */
1169 public long getPasswordExpiration(ComponentName admin) {
1170 if (mService != null) {
1171 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001172 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001173 } catch (RemoteException e) {
1174 Log.w(TAG, "Failed talking with device policy service", e);
1175 }
1176 }
1177 return 0;
1178 }
1179
1180 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001181 * Retrieve the current password history length for all admins of this
1182 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001183 * @param admin The name of the admin component to check, or null to aggregate
1184 * all admins.
1185 * @return The length of the password history
1186 */
1187 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001188 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1189 }
1190
1191 /** @hide per-user version */
1192 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001193 if (mService != null) {
1194 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001195 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001196 } catch (RemoteException e) {
1197 Log.w(TAG, "Failed talking with device policy service", e);
1198 }
1199 }
1200 return 0;
1201 }
1202
Dianne Hackbornd6847842010-01-12 18:14:19 -08001203 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001204 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001205 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001206 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001207 * @return Returns the maximum length that the user can enter.
1208 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001209 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001210 // Kind-of arbitrary.
1211 return 16;
1212 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001213
Dianne Hackborn254cb442010-01-27 19:23:59 -08001214 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001215 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001216 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001217 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001218 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001219 * <p>The calling device admin must have requested
1220 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1221 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001222 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001223 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001224 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001225 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001226 if (mService != null) {
1227 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001228 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001229 } catch (RemoteException e) {
1230 Log.w(TAG, "Failed talking with device policy service", e);
1231 }
1232 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001233 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001234 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001235
Dianne Hackbornd6847842010-01-12 18:14:19 -08001236 /**
1237 * Retrieve the number of times the user has failed at entering a
1238 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001239 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001240 * <p>The calling device admin must have requested
1241 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1242 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001243 */
1244 public int getCurrentFailedPasswordAttempts() {
1245 if (mService != null) {
1246 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001247 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001248 } catch (RemoteException e) {
1249 Log.w(TAG, "Failed talking with device policy service", e);
1250 }
1251 }
1252 return -1;
1253 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001254
1255 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001256 * Setting this to a value greater than zero enables a built-in policy
1257 * that will perform a device wipe after too many incorrect
1258 * device-unlock passwords have been entered. This built-in policy combines
1259 * watching for failed passwords and wiping the device, and requires
1260 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001261 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001262 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001263 * <p>To implement any other policy (e.g. wiping data for a particular
1264 * application only, erasing or revoking credentials, or reporting the
1265 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001266 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001267 * instead. Do not use this API, because if the maximum count is reached,
1268 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001269 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001270 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001271 * @param num The number of failed password attempts at which point the
1272 * device will wipe its data.
1273 */
1274 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1275 if (mService != null) {
1276 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001277 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001278 } catch (RemoteException e) {
1279 Log.w(TAG, "Failed talking with device policy service", e);
1280 }
1281 }
1282 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001283
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001284 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001285 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001286 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001287 * or a particular one.
1288 * @param admin The name of the admin component to check, or null to aggregate
1289 * all admins.
1290 */
1291 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001292 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1293 }
1294
1295 /** @hide per-user version */
1296 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001297 if (mService != null) {
1298 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001299 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001300 } catch (RemoteException e) {
1301 Log.w(TAG, "Failed talking with device policy service", e);
1302 }
1303 }
1304 return 0;
1305 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001306
Dianne Hackborn254cb442010-01-27 19:23:59 -08001307 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001308 * Flag for {@link #resetPassword}: don't allow other admins to change
1309 * the password again until the user has entered it.
1310 */
1311 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001312
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001313 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001314 * Force a new device unlock password (the password needed to access the
1315 * entire device, not for individual accounts) on the user. This takes
1316 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001317 * The given password must be sufficient for the
1318 * current password quality and length constraints as returned by
1319 * {@link #getPasswordQuality(ComponentName)} and
1320 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1321 * these constraints, then it will be rejected and false returned. Note
1322 * that the password may be a stronger quality (containing alphanumeric
1323 * characters when the requested quality is only numeric), in which case
1324 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001325 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001326 * <p>The calling device admin must have requested
1327 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1328 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001329 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001330 * Can not be called from a managed profile.
1331 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001332 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001333 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001334 * @return Returns true if the password was applied, or false if it is
1335 * not acceptable for the current constraints.
1336 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001337 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001338 if (mService != null) {
1339 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001340 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001341 } catch (RemoteException e) {
1342 Log.w(TAG, "Failed talking with device policy service", e);
1343 }
1344 }
1345 return false;
1346 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001347
Dianne Hackbornd6847842010-01-12 18:14:19 -08001348 /**
1349 * Called by an application that is administering the device to set the
1350 * maximum time for user activity until the device will lock. This limits
1351 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001352 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001353 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001354 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001355 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001356 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001357 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001358 * @param timeMs The new desired maximum time to lock in milliseconds.
1359 * A value of 0 means there is no restriction.
1360 */
1361 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1362 if (mService != null) {
1363 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001364 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001365 } catch (RemoteException e) {
1366 Log.w(TAG, "Failed talking with device policy service", e);
1367 }
1368 }
1369 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001370
Dianne Hackbornd6847842010-01-12 18:14:19 -08001371 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001372 * Retrieve the current maximum time to unlock for all admins of this user
1373 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001374 * @param admin The name of the admin component to check, or null to aggregate
1375 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001376 * @return time in milliseconds for the given admin or the minimum value (strictest) of
1377 * all admins if admin is null.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001378 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001379 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001380 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1381 }
1382
1383 /** @hide per-user version */
1384 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001385 if (mService != null) {
1386 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001387 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001388 } catch (RemoteException e) {
1389 Log.w(TAG, "Failed talking with device policy service", e);
1390 }
1391 }
1392 return 0;
1393 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001394
Dianne Hackbornd6847842010-01-12 18:14:19 -08001395 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001396 * Make the device lock immediately, as if the lock screen timeout has
1397 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001398 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001399 * <p>The calling device admin must have requested
1400 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1401 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001402 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001403 public void lockNow() {
1404 if (mService != null) {
1405 try {
1406 mService.lockNow();
1407 } catch (RemoteException e) {
1408 Log.w(TAG, "Failed talking with device policy service", e);
1409 }
1410 }
1411 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001412
Dianne Hackbornd6847842010-01-12 18:14:19 -08001413 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001414 * Flag for {@link #wipeData(int)}: also erase the device's external
1415 * storage.
1416 */
1417 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1418
1419 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001420 * Ask the user data be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001421 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001422 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1423 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001424 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001425 * <p>The calling device admin must have requested
1426 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1427 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001428 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001429 * @param flags Bit mask of additional options: currently 0 and
1430 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001431 */
1432 public void wipeData(int flags) {
1433 if (mService != null) {
1434 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001435 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001436 } catch (RemoteException e) {
1437 Log.w(TAG, "Failed talking with device policy service", e);
1438 }
1439 }
1440 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001441
Dianne Hackbornd6847842010-01-12 18:14:19 -08001442 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001443 * Called by an application that is administering the device to set the
1444 * global proxy and exclusion list.
1445 * <p>
1446 * The calling device admin must have requested
1447 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1448 * this method; if it has not, a security exception will be thrown.
1449 * Only the first device admin can set the proxy. If a second admin attempts
1450 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1451 * proxy will be returned. If successful in setting the proxy, null will
1452 * be returned.
1453 * The method can be called repeatedly by the device admin alrady setting the
1454 * proxy to update the proxy and exclusion list.
1455 *
1456 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1457 * with.
1458 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1459 * Pass Proxy.NO_PROXY to reset the proxy.
1460 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001461 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1462 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001463 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001464 */
1465 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1466 List<String> exclusionList ) {
1467 if (proxySpec == null) {
1468 throw new NullPointerException();
1469 }
1470 if (mService != null) {
1471 try {
1472 String hostSpec;
1473 String exclSpec;
1474 if (proxySpec.equals(Proxy.NO_PROXY)) {
1475 hostSpec = null;
1476 exclSpec = null;
1477 } else {
1478 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1479 throw new IllegalArgumentException();
1480 }
1481 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1482 String hostName = sa.getHostName();
1483 int port = sa.getPort();
1484 StringBuilder hostBuilder = new StringBuilder();
1485 hostSpec = hostBuilder.append(hostName)
1486 .append(":").append(Integer.toString(port)).toString();
1487 if (exclusionList == null) {
1488 exclSpec = "";
1489 } else {
1490 StringBuilder listBuilder = new StringBuilder();
1491 boolean firstDomain = true;
1492 for (String exclDomain : exclusionList) {
1493 if (!firstDomain) {
1494 listBuilder = listBuilder.append(",");
1495 } else {
1496 firstDomain = false;
1497 }
1498 listBuilder = listBuilder.append(exclDomain.trim());
1499 }
1500 exclSpec = listBuilder.toString();
1501 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001502 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1503 != android.net.Proxy.PROXY_VALID)
1504 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001505 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001506 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001507 } catch (RemoteException e) {
1508 Log.w(TAG, "Failed talking with device policy service", e);
1509 }
1510 }
1511 return null;
1512 }
1513
1514 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001515 * Set a network-independent global HTTP proxy. This is not normally what you want
1516 * for typical HTTP proxies - they are generally network dependent. However if you're
1517 * doing something unusual like general internal filtering this may be useful. On
1518 * a private network where the proxy is not accessible, you may break HTTP using this.
1519 *
1520 * <p>This method requires the caller to be the device owner.
1521 *
1522 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1523 * @see ProxyInfo
1524 *
1525 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1526 * with.
1527 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1528 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1529 */
1530 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1531 if (mService != null) {
1532 try {
1533 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1534 } catch (RemoteException e) {
1535 Log.w(TAG, "Failed talking with device policy service", e);
1536 }
1537 }
1538 }
1539
1540 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001541 * Returns the component name setting the global proxy.
1542 * @return ComponentName object of the device admin that set the global proxy, or
1543 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001544 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001545 */
1546 public ComponentName getGlobalProxyAdmin() {
1547 if (mService != null) {
1548 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001549 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001550 } catch (RemoteException e) {
1551 Log.w(TAG, "Failed talking with device policy service", e);
1552 }
1553 }
1554 return null;
1555 }
1556
1557 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001558 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001559 * indicating that encryption is not supported.
1560 */
1561 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1562
1563 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001564 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001565 * indicating that encryption is supported, but is not currently active.
1566 */
1567 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
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 currently active, but is currently
1572 * being activated. This is only reported by devices that support
1573 * encryption of data and only when the storage is currently
1574 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1575 * to become encrypted will never return this value.
1576 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001577 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001578
1579 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001580 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001581 * indicating that encryption is active.
1582 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001583 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001584
1585 /**
1586 * Activity action: begin the process of encrypting data on the device. This activity should
1587 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1588 * After resuming from this activity, use {@link #getStorageEncryption}
1589 * to check encryption status. However, on some devices this activity may never return, as
1590 * it may trigger a reboot and in some cases a complete data wipe of the device.
1591 */
1592 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1593 public static final String ACTION_START_ENCRYPTION
1594 = "android.app.action.START_ENCRYPTION";
1595
1596 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001597 * Widgets are enabled in keyguard
1598 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001599 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001600
1601 /**
Jim Miller50e62182014-04-23 17:25:00 -07001602 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001603 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001604 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1605
1606 /**
1607 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1608 */
1609 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1610
1611 /**
Jim Miller50e62182014-04-23 17:25:00 -07001612 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1613 */
1614 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1615
1616 /**
1617 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1618 */
1619 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1620
1621 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001622 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001623 * (e.g. PIN/Pattern/Password).
1624 */
1625 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1626
1627 /**
Jim Miller06e34502014-07-17 14:46:05 -07001628 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1629 */
1630 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1631
1632 /**
Jim Miller35207742012-11-02 15:33:20 -07001633 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001634 */
1635 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001636
1637 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001638 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001639 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001640 *
1641 * <p>When multiple device administrators attempt to control device
1642 * encryption, the most secure, supported setting will always be
1643 * used. If any device administrator requests device encryption,
1644 * it will be enabled; Conversely, if a device administrator
1645 * attempts to disable device encryption while another
1646 * device administrator has enabled it, the call to disable will
1647 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1648 *
1649 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001650 * written to other storage areas may or may not be encrypted, and this policy does not require
1651 * or control the encryption of any other storage areas.
1652 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1653 * {@code true}, then the directory returned by
1654 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1655 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001656 *
1657 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1658 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1659 * the encryption key may not be fully secured. For maximum security, the administrator should
1660 * also require (and check for) a pattern, PIN, or password.
1661 *
1662 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1663 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001664 * @return the new request status (for all active admins) - will be one of
1665 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1666 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1667 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001668 */
1669 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1670 if (mService != null) {
1671 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001672 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001673 } catch (RemoteException e) {
1674 Log.w(TAG, "Failed talking with device policy service", e);
1675 }
1676 }
1677 return ENCRYPTION_STATUS_UNSUPPORTED;
1678 }
1679
1680 /**
1681 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001682 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001683 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1685 * this will return the requested encryption setting as an aggregate of all active
1686 * administrators.
1687 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001688 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001689 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001690 if (mService != null) {
1691 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001692 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001693 } catch (RemoteException e) {
1694 Log.w(TAG, "Failed talking with device policy service", e);
1695 }
1696 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001697 return false;
1698 }
1699
1700 /**
1701 * Called by an application that is administering the device to
1702 * determine the current encryption status of the device.
1703 *
1704 * Depending on the returned status code, the caller may proceed in different
1705 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1706 * storage system does not support encryption. If the
1707 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1708 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1709 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1710 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1711 *
Robin Lee7e678712014-07-24 16:41:31 +01001712 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001713 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1714 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1715 */
1716 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001717 return getStorageEncryptionStatus(UserHandle.myUserId());
1718 }
1719
1720 /** @hide per-user version */
1721 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001722 if (mService != null) {
1723 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001724 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001725 } catch (RemoteException e) {
1726 Log.w(TAG, "Failed talking with device policy service", e);
1727 }
1728 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001729 return ENCRYPTION_STATUS_UNSUPPORTED;
1730 }
1731
1732 /**
Robin Lee7e678712014-07-24 16:41:31 +01001733 * Installs the given certificate as a user CA.
1734 *
1735 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1736 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001737 *
1738 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001739 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001740 */
Robin Lee7e678712014-07-24 16:41:31 +01001741 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001742 if (mService != null) {
1743 try {
Robin Lee7e678712014-07-24 16:41:31 +01001744 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001745 } catch (RemoteException e) {
1746 Log.w(TAG, "Failed talking with device policy service", e);
1747 }
1748 }
1749 return false;
1750 }
1751
1752 /**
Robin Lee7e678712014-07-24 16:41:31 +01001753 * Uninstalls the given certificate from trusted user CAs, if present.
1754 *
1755 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1756 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001757 */
Robin Lee7e678712014-07-24 16:41:31 +01001758 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001759 if (mService != null) {
1760 try {
Robin Lee306fe082014-06-19 14:04:24 +00001761 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001762 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001763 } catch (CertificateException e) {
1764 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001765 } catch (RemoteException e) {
1766 Log.w(TAG, "Failed talking with device policy service", e);
1767 }
1768 }
1769 }
1770
1771 /**
Robin Lee7e678712014-07-24 16:41:31 +01001772 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1773 * If a user has installed any certificates by other means than device policy these will be
1774 * included too.
1775 *
1776 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001777 */
Robin Lee7e678712014-07-24 16:41:31 +01001778 public List<byte[]> getInstalledCaCerts() {
1779 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1780 List<byte[]> certs = new ArrayList<byte[]>();
1781 for (String alias : certStore.userAliases()) {
1782 try {
1783 certs.add(certStore.getCertificate(alias).getEncoded());
1784 } catch (CertificateException ce) {
1785 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1786 }
1787 }
1788 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001789 }
1790
1791 /**
Robin Lee7e678712014-07-24 16:41:31 +01001792 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1793 * means other than device policy will also be removed, except for system CA certificates.
1794 *
1795 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1796 */
1797 public void uninstallAllUserCaCerts(ComponentName admin) {
1798 if (mService != null) {
1799 for (String alias : new TrustedCertificateStore().userAliases()) {
1800 try {
1801 mService.uninstallCaCert(admin, alias);
1802 } catch (RemoteException re) {
1803 Log.w(TAG, "Failed talking with device policy service", re);
1804 }
1805 }
1806 }
1807 }
1808
1809 /**
1810 * Returns whether this certificate is installed as a trusted CA.
1811 *
1812 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001813 */
1814 public boolean hasCaCertInstalled(byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001815 try {
Robin Lee306fe082014-06-19 14:04:24 +00001816 return getCaCertAlias(certBuffer) != null;
Maggie Benthallda51e682013-08-08 22:35:44 -04001817 } catch (CertificateException ce) {
1818 Log.w(TAG, "Could not parse certificate", ce);
1819 }
1820 return false;
1821 }
1822
1823 /**
Robin Lee306fe082014-06-19 14:04:24 +00001824 * Returns the alias of a given CA certificate in the certificate store, or null if it
1825 * doesn't exist.
1826 */
1827 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1828 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1829 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1830 new ByteArrayInputStream(certBuffer));
1831 return new TrustedCertificateStore().getCertificateAlias(cert);
1832 }
1833
1834 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001835 * Called by an application that is administering the device to disable all cameras
1836 * on the device. After setting this, no applications will be able to access any cameras
1837 * on the device.
1838 *
1839 * <p>The calling device admin must have requested
1840 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1841 * this method; if it has not, a security exception will be thrown.
1842 *
1843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1844 * @param disabled Whether or not the camera should be disabled.
1845 */
1846 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1847 if (mService != null) {
1848 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001849 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001850 } catch (RemoteException e) {
1851 Log.w(TAG, "Failed talking with device policy service", e);
1852 }
1853 }
1854 }
1855
1856 /**
1857 * Determine whether or not the device's cameras have been disabled either by the current
1858 * admin, if specified, or all admins.
1859 * @param admin The name of the admin component to check, or null to check if any admins
1860 * have disabled the camera
1861 */
1862 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001863 return getCameraDisabled(admin, UserHandle.myUserId());
1864 }
1865
1866 /** @hide per-user version */
1867 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001868 if (mService != null) {
1869 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001870 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001871 } catch (RemoteException e) {
1872 Log.w(TAG, "Failed talking with device policy service", e);
1873 }
1874 }
1875 return false;
1876 }
1877
1878 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01001879 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
1880 * screen capture also prevents the content from being shown on display devices that do not have
1881 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
1882 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001883 *
1884 * <p>The calling device admin must be a device or profile owner. If it is not, a
1885 * security exception will be thrown.
1886 *
1887 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Esteban Talavera1aee98f2014-08-21 14:03:55 +01001888 * @param disabled Whether or not screen capture should be disabled.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001889 */
1890 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
1891 if (mService != null) {
1892 try {
1893 mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled);
1894 } catch (RemoteException e) {
1895 Log.w(TAG, "Failed talking with device policy service", e);
1896 }
1897 }
1898 }
1899
1900 /**
1901 * Determine whether or not screen capture has been disabled by the current
1902 * admin, if specified, or all admins.
1903 * @param admin The name of the admin component to check, or null to check if any admins
1904 * have disabled screen capture.
1905 */
1906 public boolean getScreenCaptureDisabled(ComponentName admin) {
1907 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
1908 }
1909
1910 /** @hide per-user version */
1911 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
1912 if (mService != null) {
1913 try {
1914 return mService.getScreenCaptureDisabled(admin, userHandle);
1915 } catch (RemoteException e) {
1916 Log.w(TAG, "Failed talking with device policy service", e);
1917 }
1918 }
1919 return false;
1920 }
1921
1922 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001923 * Called by an application that is administering the device to disable keyguard customizations,
1924 * such as widgets. After setting this, keyguard features will be disabled according to the
1925 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001926 *
1927 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001928 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001929 * this method; if it has not, a security exception will be thrown.
1930 *
1931 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001932 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1933 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001934 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1935 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001936 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001937 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001938 if (mService != null) {
1939 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001940 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001941 } catch (RemoteException e) {
1942 Log.w(TAG, "Failed talking with device policy service", e);
1943 }
1944 }
1945 }
1946
1947 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001948 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001949 * admin, if specified, or all admins.
1950 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001951 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001952 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1953 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001954 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001955 public int getKeyguardDisabledFeatures(ComponentName admin) {
1956 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001957 }
1958
1959 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001960 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001961 if (mService != null) {
1962 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001963 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001964 } catch (RemoteException e) {
1965 Log.w(TAG, "Failed talking with device policy service", e);
1966 }
1967 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001968 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001969 }
1970
1971 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001972 * @hide
1973 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001974 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001975 if (mService != null) {
1976 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001977 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001978 } catch (RemoteException e) {
1979 Log.w(TAG, "Failed talking with device policy service", e);
1980 }
1981 }
1982 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001983
Dianne Hackbornd6847842010-01-12 18:14:19 -08001984 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001985 * @hide
1986 */
1987 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1988 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1989 }
1990
1991 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001992 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001993 * @hide
1994 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001995 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001996 ActivityInfo ai;
1997 try {
1998 ai = mContext.getPackageManager().getReceiverInfo(cn,
1999 PackageManager.GET_META_DATA);
2000 } catch (PackageManager.NameNotFoundException e) {
2001 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2002 return null;
2003 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002004
Dianne Hackbornd6847842010-01-12 18:14:19 -08002005 ResolveInfo ri = new ResolveInfo();
2006 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002007
Dianne Hackbornd6847842010-01-12 18:14:19 -08002008 try {
2009 return new DeviceAdminInfo(mContext, ri);
2010 } catch (XmlPullParserException e) {
2011 Log.w(TAG, "Unable to parse device policy " + cn, e);
2012 return null;
2013 } catch (IOException e) {
2014 Log.w(TAG, "Unable to parse device policy " + cn, e);
2015 return null;
2016 }
2017 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002018
Dianne Hackbornd6847842010-01-12 18:14:19 -08002019 /**
2020 * @hide
2021 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002022 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2023 if (mService != null) {
2024 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002025 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002026 } catch (RemoteException e) {
2027 Log.w(TAG, "Failed talking with device policy service", e);
2028 }
2029 }
2030 }
2031
2032 /**
2033 * @hide
2034 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002035 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002036 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002037 if (mService != null) {
2038 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002039 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002040 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002041 } catch (RemoteException e) {
2042 Log.w(TAG, "Failed talking with device policy service", e);
2043 }
2044 }
2045 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002046
Dianne Hackbornd6847842010-01-12 18:14:19 -08002047 /**
2048 * @hide
2049 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002050 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002051 if (mService != null) {
2052 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002053 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002054 } catch (RemoteException e) {
2055 Log.w(TAG, "Failed talking with device policy service", e);
2056 }
2057 }
2058 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002059
Dianne Hackbornd6847842010-01-12 18:14:19 -08002060 /**
2061 * @hide
2062 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002063 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002064 if (mService != null) {
2065 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002066 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002067 } catch (RemoteException e) {
2068 Log.w(TAG, "Failed talking with device policy service", e);
2069 }
2070 }
2071 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002072
2073 /**
2074 * @hide
2075 * Sets the given package as the device owner. The package must already be installed and there
2076 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2077 * method must be called before the device is provisioned.
2078 * @param packageName the package name of the application to be registered as the device owner.
2079 * @return whether the package was successfully registered as the device owner.
2080 * @throws IllegalArgumentException if the package name is null or invalid
2081 * @throws IllegalStateException if a device owner is already registered or the device has
2082 * already been provisioned.
2083 */
2084 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2085 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002086 return setDeviceOwner(packageName, null);
2087 }
2088
2089 /**
2090 * @hide
2091 * Sets the given package as the device owner. The package must already be installed and there
2092 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2093 * method must be called before the device is provisioned.
2094 * @param packageName the package name of the application to be registered as the device owner.
2095 * @param ownerName the human readable name of the institution that owns this device.
2096 * @return whether the package was successfully registered as the device owner.
2097 * @throws IllegalArgumentException if the package name is null or invalid
2098 * @throws IllegalStateException if a device owner is already registered or the device has
2099 * already been provisioned.
2100 */
2101 public boolean setDeviceOwner(String packageName, String ownerName)
2102 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002103 if (mService != null) {
2104 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002105 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002106 } catch (RemoteException re) {
2107 Log.w(TAG, "Failed to set device owner");
2108 }
2109 }
2110 return false;
2111 }
2112
2113 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002114 * Used to determine if a particular package has been registered as a Device Owner app.
2115 * A device owner app is a special device admin that cannot be deactivated by the user, once
2116 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2117 * package is currently registered as the device owner app, pass in the package name from
2118 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2119 * admin apps that want to check if they are also registered as the device owner app. The
2120 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2121 * the setup process.
2122 * @param packageName the package name of the app, to compare with the registered device owner
2123 * app, if any.
2124 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002125 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002126 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002127 if (mService != null) {
2128 try {
2129 return mService.isDeviceOwner(packageName);
2130 } catch (RemoteException re) {
2131 Log.w(TAG, "Failed to check device owner");
2132 }
2133 }
2134 return false;
2135 }
2136
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002137 /**
2138 * @hide
2139 * Redirect to isDeviceOwnerApp.
2140 */
2141 public boolean isDeviceOwner(String packageName) {
2142 return isDeviceOwnerApp(packageName);
2143 }
2144
Jason Monkb0dced82014-06-06 14:36:20 -04002145 /**
2146 * Clears the current device owner. The caller must be the device owner.
2147 *
2148 * This function should be used cautiously as once it is called it cannot
2149 * be undone. The device owner can only be set as a part of device setup
2150 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002151 *
2152 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002153 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002154 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002155 if (mService != null) {
2156 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002157 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002158 } catch (RemoteException re) {
2159 Log.w(TAG, "Failed to clear device owner");
2160 }
2161 }
2162 }
2163
Amith Yamasani71e6c692013-03-24 17:39:28 -07002164 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002165 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002166 public String getDeviceOwner() {
2167 if (mService != null) {
2168 try {
2169 return mService.getDeviceOwner();
2170 } catch (RemoteException re) {
2171 Log.w(TAG, "Failed to get device owner");
2172 }
2173 }
2174 return null;
2175 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002176
2177 /** @hide */
2178 public String getDeviceOwnerName() {
2179 if (mService != null) {
2180 try {
2181 return mService.getDeviceOwnerName();
2182 } catch (RemoteException re) {
2183 Log.w(TAG, "Failed to get device owner");
2184 }
2185 }
2186 return null;
2187 }
Adam Connors776c5552014-01-09 10:42:56 +00002188
2189 /**
2190 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002191 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302192 * Sets the given component as an active admin and registers the package as the profile
2193 * owner for this user. The package must already be installed and there shouldn't be
2194 * an existing profile owner registered for this user. Also, this method must be called
2195 * before the user setup has been completed.
2196 * <p>
2197 * This method can only be called by system apps that hold MANAGE_USERS permission and
2198 * MANAGE_DEVICE_ADMINS permission.
2199 * @param admin The component to register as an active admin and profile owner.
2200 * @param ownerName The user-visible name of the entity that is managing this user.
2201 * @return whether the admin was successfully registered as the profile owner.
2202 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2203 * the user has already been set up.
2204 */
Justin Morey80440cc2014-07-24 09:16:35 -05002205 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302206 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2207 throws IllegalArgumentException {
2208 if (mService != null) {
2209 try {
2210 final int myUserId = UserHandle.myUserId();
2211 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002212 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302213 } catch (RemoteException re) {
2214 Log.w(TAG, "Failed to set profile owner " + re);
2215 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2216 }
2217 }
2218 return false;
2219 }
2220
2221 /**
2222 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002223 * Clears the active profile owner and removes all user restrictions. The caller must
2224 * be from the same package as the active profile owner for this user, otherwise a
2225 * SecurityException will be thrown.
2226 *
2227 * @param admin The component to remove as the profile owner.
2228 * @return
2229 */
2230 @SystemApi
2231 public void clearProfileOwner(ComponentName admin) {
2232 if (mService != null) {
2233 try {
2234 mService.clearProfileOwner(admin);
2235 } catch (RemoteException re) {
2236 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2237 }
2238 }
2239 }
2240
2241 /**
2242 * @hide
2243 * Checks if the user was already setup.
2244 */
2245 public boolean hasUserSetupCompleted() {
2246 if (mService != null) {
2247 try {
2248 return mService.hasUserSetupCompleted();
2249 } catch (RemoteException re) {
2250 Log.w(TAG, "Failed to check if user setup has completed");
2251 }
2252 }
2253 return true;
2254 }
2255
2256 /**
2257 * @deprecated Use setProfileOwner(ComponentName ...)
2258 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002259 * Sets the given package as the profile owner of the given user profile. The package must
2260 * already be installed and there shouldn't be an existing profile owner registered for this
2261 * user. Also, this method must be called before the user has been used for the first time.
2262 * @param packageName the package name of the application to be registered as profile owner.
2263 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002264 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002265 * @return whether the package was successfully registered as the profile owner.
2266 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2267 * the user has already been set up.
2268 */
Adam Connors661ec472014-02-11 13:59:46 +00002269 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002270 throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002271 if (packageName == null) {
2272 throw new NullPointerException("packageName cannot be null");
2273 }
2274 return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle);
2275 }
2276
2277 /**
2278 * @hide
2279 * Sets the given component as the profile owner of the given user profile. The package must
2280 * already be installed and there shouldn't be an existing profile owner registered for this
2281 * user. Only the system can call this API if the user has already completed setup.
2282 * @param admin the component name to be registered as profile owner.
2283 * @param ownerName the human readable name of the organisation associated with this DPM.
2284 * @param userHandle the userId to set the profile owner for.
2285 * @return whether the component was successfully registered as the profile owner.
2286 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2287 * the user has already been set up.
2288 */
2289 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2290 throws IllegalArgumentException {
2291 if (admin == null) {
2292 throw new NullPointerException("admin cannot be null");
2293 }
Adam Connors776c5552014-01-09 10:42:56 +00002294 if (mService != null) {
2295 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002296 if (ownerName == null) {
2297 ownerName = "";
2298 }
2299 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002300 } catch (RemoteException re) {
2301 Log.w(TAG, "Failed to set profile owner", re);
2302 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2303 }
2304 }
2305 return false;
2306 }
2307
2308 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002309 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2310 * be used. Only the profile owner can call this.
2311 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002312 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002313 *
2314 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2315 */
2316 public void setProfileEnabled(ComponentName admin) {
2317 if (mService != null) {
2318 try {
2319 mService.setProfileEnabled(admin);
2320 } catch (RemoteException e) {
2321 Log.w(TAG, "Failed talking with device policy service", e);
2322 }
2323 }
2324 }
2325
2326 /**
Jessica Hummel1333ea12014-06-23 11:20:10 +01002327 * Sets the name of the Managed profile. In the device owner case it sets the name of the user
2328 * which it is called from. Only the profile owner or device owner can call this. If this is
2329 * never called by the profile or device owner, the name will be set to default values.
2330 *
2331 * @see #isProfileOwnerApp
2332 * @see #isDeviceOwnerApp
2333 *
2334 * @param profileName The name of the profile.
2335 */
2336 public void setProfileName(ComponentName who, String profileName) {
2337 if (mService != null) {
2338 try {
2339 mService.setProfileName(who, profileName);
2340 } catch (RemoteException e) {
2341 Log.w(TAG, "Failed talking with device policy service", e);
2342 }
2343 }
2344}
2345
2346 /**
Adam Connors776c5552014-01-09 10:42:56 +00002347 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002348 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00002349 * within the managed profile.
2350 *
2351 * @param packageName The package name of the app to compare with the registered profile owner.
2352 * @return Whether or not the package is registered as the profile owner.
2353 */
2354 public boolean isProfileOwnerApp(String packageName) {
2355 if (mService != null) {
2356 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002357 ComponentName profileOwner = mService.getProfileOwner(
2358 Process.myUserHandle().getIdentifier());
2359 return profileOwner != null
2360 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002361 } catch (RemoteException re) {
2362 Log.w(TAG, "Failed to check profile owner");
2363 }
2364 }
2365 return false;
2366 }
2367
2368 /**
2369 * @hide
2370 * @return the packageName of the owner of the given user profile or null if no profile
2371 * owner has been set for that user.
2372 * @throws IllegalArgumentException if the userId is invalid.
2373 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002374 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002375 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002376 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2377 }
2378
2379 /**
2380 * @see #getProfileOwner()
2381 * @hide
2382 */
2383 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002384 if (mService != null) {
2385 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002386 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002387 } catch (RemoteException re) {
2388 Log.w(TAG, "Failed to get profile owner");
2389 throw new IllegalArgumentException(
2390 "Requested profile owner for invalid userId", re);
2391 }
2392 }
2393 return null;
2394 }
2395
2396 /**
2397 * @hide
2398 * @return the human readable name of the organisation associated with this DPM or null if
2399 * one is not set.
2400 * @throws IllegalArgumentException if the userId is invalid.
2401 */
2402 public String getProfileOwnerName() throws IllegalArgumentException {
2403 if (mService != null) {
2404 try {
2405 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2406 } catch (RemoteException re) {
2407 Log.w(TAG, "Failed to get profile owner");
2408 throw new IllegalArgumentException(
2409 "Requested profile owner for invalid userId", re);
2410 }
2411 }
2412 return null;
2413 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002414
2415 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002416 * @hide
2417 * @param user The user for whom to fetch the profile owner name, if any.
2418 * @return the human readable name of the organisation associated with this profile owner or
2419 * null if one is not set.
2420 * @throws IllegalArgumentException if the userId is invalid.
2421 */
2422 @SystemApi
2423 public String getProfileOwnerNameAsUser(UserHandle user) throws IllegalArgumentException {
2424 if (mService != null) {
2425 try {
2426 return mService.getProfileOwnerName(user.getIdentifier());
2427 } catch (RemoteException re) {
2428 Log.w(TAG, "Failed to get profile owner");
2429 throw new IllegalArgumentException(
2430 "Requested profile owner for invalid userId", re);
2431 }
2432 }
2433 return null;
2434 }
2435
2436 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002437 * Called by a profile owner or device owner to add a default intent handler activity for
2438 * intents that match a certain intent filter. This activity will remain the default intent
2439 * handler even if the set of potential event handlers for the intent filter changes and if
2440 * the intent preferences are reset.
2441 *
2442 * <p>The default disambiguation mechanism takes over if the activity is not installed
2443 * (anymore). When the activity is (re)installed, it is automatically reset as default
2444 * intent handler for the filter.
2445 *
2446 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2447 * security exception will be thrown.
2448 *
2449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2450 * @param filter The IntentFilter for which a default handler is added.
2451 * @param activity The Activity that is added as default intent handler.
2452 */
2453 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2454 ComponentName activity) {
2455 if (mService != null) {
2456 try {
2457 mService.addPersistentPreferredActivity(admin, filter, activity);
2458 } catch (RemoteException e) {
2459 Log.w(TAG, "Failed talking with device policy service", e);
2460 }
2461 }
2462 }
2463
2464 /**
2465 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002466 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002467 *
2468 * <p>The calling device admin must be a profile owner. If it is not, a security
2469 * exception will be thrown.
2470 *
2471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2472 * @param packageName The name of the package for which preferences are removed.
2473 */
2474 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2475 String packageName) {
2476 if (mService != null) {
2477 try {
2478 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2479 } catch (RemoteException e) {
2480 Log.w(TAG, "Failed talking with device policy service", e);
2481 }
2482 }
2483 }
Robin Lee66e5d962014-04-09 16:44:21 +01002484
2485 /**
2486 * Called by a profile or device owner to set the application restrictions for a given target
2487 * application running in the managed profile.
2488 *
2489 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Amith Yamasanic8c84252014-07-13 17:12:12 -07002490 * boolean, int, String, or String[]. The recommended format for keys
Robin Lee66e5d962014-04-09 16:44:21 +01002491 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2492 * components such as {@link android.webkit.WebView}.
2493 *
2494 * <p>The application restrictions are only made visible to the target application and the
2495 * profile or device owner.
2496 *
2497 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2498 * exception will be thrown.
2499 *
2500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2501 * @param packageName The name of the package to update restricted settings for.
2502 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2503 * set of active restrictions.
2504 */
2505 public void setApplicationRestrictions(ComponentName admin, String packageName,
2506 Bundle settings) {
2507 if (mService != null) {
2508 try {
2509 mService.setApplicationRestrictions(admin, packageName, settings);
2510 } catch (RemoteException e) {
2511 Log.w(TAG, "Failed talking with device policy service", e);
2512 }
2513 }
2514 }
2515
2516 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002517 * Sets a list of features to enable for a TrustAgent component. This is meant to be
Jim Miller604e7552014-07-18 19:00:02 -07002518 * used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which will disable all
2519 * trust agents but those with features enabled by this function call.
2520 *
2521 * <p>The calling device admin must have requested
2522 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
2523 * this method; if it has not, a security exception will be thrown.
2524 *
2525 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2526 * @param agent Which component to enable features for.
2527 * @param features List of features to enable. Consult specific TrustAgent documentation for
2528 * the feature list.
2529 */
2530 public void setTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent,
2531 List<String> features) {
2532 if (mService != null) {
2533 try {
2534 mService.setTrustAgentFeaturesEnabled(admin, agent, features, UserHandle.myUserId());
2535 } catch (RemoteException e) {
2536 Log.w(TAG, "Failed talking with device policy service", e);
2537 }
2538 }
2539 }
2540
2541 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002542 * Gets list of enabled features for the given TrustAgent component. If admin is
Jim Miller604e7552014-07-18 19:00:02 -07002543 * null, this will return the intersection of all features enabled for the given agent by all
2544 * admins.
2545 *
2546 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2547 * @param agent Which component to get enabled features for.
2548 * @return List of enabled features.
2549 */
2550 public List<String> getTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent) {
2551 if (mService != null) {
2552 try {
2553 return mService.getTrustAgentFeaturesEnabled(admin, agent, UserHandle.myUserId());
2554 } catch (RemoteException e) {
2555 Log.w(TAG, "Failed talking with device policy service", e);
2556 }
2557 }
2558 return new ArrayList<String>(); // empty list
2559 }
2560
2561 /**
Adam Connors210fe212014-07-17 15:41:43 +01002562 * Called by a profile owner to set whether caller-Id information from the managed
2563 * profile will be shown for incoming calls.
2564 *
2565 * <p>The calling device admin must be a profile owner. If it is not, a
2566 * security exception will be thrown.
2567 *
2568 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2569 * @param disabled If true caller-Id information in the managed profile is not displayed.
2570 */
2571 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2572 if (mService != null) {
2573 try {
2574 mService.setCrossProfileCallerIdDisabled(who, disabled);
2575 } catch (RemoteException e) {
2576 Log.w(TAG, "Failed talking with device policy service", e);
2577 }
2578 }
2579 }
2580
2581 /**
2582 * Determine whether or not caller-Id information has been disabled.
2583 *
2584 * <p>The calling device admin must be a profile owner. If it is not, a
2585 * security exception will be thrown.
2586 *
2587 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2588 */
2589 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2590 if (mService != null) {
2591 try {
2592 return mService.getCrossProfileCallerIdDisabled(who);
2593 } catch (RemoteException e) {
2594 Log.w(TAG, "Failed talking with device policy service", e);
2595 }
2596 }
2597 return false;
2598 }
2599
2600 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002601 * Determine whether or not caller-Id information has been disabled.
2602 *
2603 * @param userHandle The user for whom to check the caller-id permission
2604 * @hide
2605 */
2606 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2607 if (mService != null) {
2608 try {
2609 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2610 } catch (RemoteException e) {
2611 Log.w(TAG, "Failed talking with device policy service", e);
2612 }
2613 }
2614 return false;
2615 }
2616
2617 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002618 * Called by the profile owner so that some intents sent in the managed profile can also be
2619 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002620 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002621 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2622 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002623 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2624 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002625 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002626 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002627 if (mService != null) {
2628 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002629 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002630 } catch (RemoteException e) {
2631 Log.w(TAG, "Failed talking with device policy service", e);
2632 }
2633 }
2634 }
2635
2636 /**
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002637 * Called by a profile owner to remove the cross-profile intent filters that go from the
2638 * managed profile to the parent, or from the parent to the managed profile.
2639 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002640 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2641 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002642 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002643 if (mService != null) {
2644 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002645 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002646 } catch (RemoteException e) {
2647 Log.w(TAG, "Failed talking with device policy service", e);
2648 }
2649 }
2650 }
2651
2652 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002653 * Called by a profile or device owner to set the permitted accessibility services. When
2654 * set by a device owner or profile owner the restriction applies to all profiles of the
2655 * user the device owner or profile owner is an admin for.
2656 *
2657 * By default the user can use any accessiblity service. When zero or more packages have
2658 * been added, accessiblity services that are not in the list and not part of the system
2659 * can not be enabled by the user.
2660 *
2661 * <p> Calling with a null value for the list disables the restriction so that all services
2662 * can be used, calling with an empty list only allows the builtin system's services.
2663 *
2664 * <p> System accesibility services are always available to the user the list can't modify
2665 * this.
2666 *
2667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2668 * @param packageNames List of accessibility service package names.
2669 *
2670 * @return true if setting the restriction succeeded. It fail if there is
2671 * one or more non-system accessibility services enabled, that are not in the list.
2672 */
2673 public boolean setPermittedAccessibilityServices(ComponentName admin,
2674 List<String> packageNames) {
2675 if (mService != null) {
2676 try {
2677 return mService.setPermittedAccessibilityServices(admin, packageNames);
2678 } catch (RemoteException e) {
2679 Log.w(TAG, "Failed talking with device policy service", e);
2680 }
2681 }
2682 return false;
2683 }
2684
2685 /**
2686 * Returns the list of permitted accessibility services set by this device or profile owner.
2687 *
2688 * <p>An empty list means no accessibility services except system services are allowed.
2689 * Null means all accessibility services are allowed.
2690 *
2691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2692 * @return List of accessiblity service package names.
2693 */
2694 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2695 if (mService != null) {
2696 try {
2697 return mService.getPermittedAccessibilityServices(admin);
2698 } catch (RemoteException e) {
2699 Log.w(TAG, "Failed talking with device policy service", e);
2700 }
2701 }
2702 return null;
2703 }
2704
2705 /**
2706 * Returns the list of accessibility services permitted by the device or profiles
2707 * owners of this user.
2708 *
2709 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2710 * it will contain the intersection of the permitted lists for any device or profile
2711 * owners that apply to this user. It will also include any system accessibility services.
2712 *
2713 * @param userId which user to check for.
2714 * @return List of accessiblity service package names.
2715 * @hide
2716 */
2717 @SystemApi
2718 public List<String> getPermittedAccessibilityServices(int userId) {
2719 if (mService != null) {
2720 try {
2721 return mService.getPermittedAccessibilityServicesForUser(userId);
2722 } catch (RemoteException e) {
2723 Log.w(TAG, "Failed talking with device policy service", e);
2724 }
2725 }
2726 return null;
2727 }
2728
2729 /**
2730 * Called by a profile or device owner to set the permitted input methods services. When
2731 * set by a device owner or profile owner the restriction applies to all profiles of the
2732 * user the device owner or profile owner is an admin for.
2733 *
2734 * By default the user can use any input method. When zero or more packages have
2735 * been added, input method that are not in the list and not part of the system
2736 * can not be enabled by the user.
2737 *
2738 * This method will fail if it is called for a admin that is not for the foreground user
2739 * or a profile of the foreground user.
2740 *
2741 * <p> Calling with a null value for the list disables the restriction so that all input methods
2742 * can be used, calling with an empty list disables all but the system's own input methods.
2743 *
2744 * <p> System input methods are always available to the user this method can't modify this.
2745 *
2746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2747 * @param packageNames List of input method package names.
2748 * @return true if setting the restriction succeeded. It will fail if there is
2749 * one or more input method enabled, that are not in the list or user if the foreground
2750 * user.
2751 */
2752 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2753 if (mService != null) {
2754 try {
2755 return mService.setPermittedInputMethods(admin, packageNames);
2756 } catch (RemoteException e) {
2757 Log.w(TAG, "Failed talking with device policy service", e);
2758 }
2759 }
2760 return false;
2761 }
2762
2763
2764 /**
2765 * Returns the list of permitted input methods set by this device or profile owner.
2766 *
2767 * <p>An empty list means no input methods except system input methods are allowed.
2768 * Null means all input methods are allowed.
2769 *
2770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2771 * @return List of input method package names.
2772 */
2773 public List<String> getPermittedInputMethods(ComponentName admin) {
2774 if (mService != null) {
2775 try {
2776 return mService.getPermittedInputMethods(admin);
2777 } catch (RemoteException e) {
2778 Log.w(TAG, "Failed talking with device policy service", e);
2779 }
2780 }
2781 return null;
2782 }
2783
2784 /**
2785 * Returns the list of input methods permitted by the device or profiles
2786 * owners of the current user.
2787 *
2788 * <p>Null means all input methods are allowed, if a non-null list is returned
2789 * it will contain the intersection of the permitted lists for any device or profile
2790 * owners that apply to this user. It will also include any system input methods.
2791 *
2792 * @return List of input method package names.
2793 * @hide
2794 */
2795 @SystemApi
2796 public List<String> getPermittedInputMethodsForCurrentUser() {
2797 if (mService != null) {
2798 try {
2799 return mService.getPermittedInputMethodsForCurrentUser();
2800 } catch (RemoteException e) {
2801 Log.w(TAG, "Failed talking with device policy service", e);
2802 }
2803 }
2804 return null;
2805 }
2806
2807 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002808 * Called by a device owner to create a user with the specified name. The UserHandle returned
2809 * by this method should not be persisted as user handles are recycled as users are removed and
2810 * created. If you need to persist an identifier for this user, use
2811 * {@link UserManager#getSerialNumberForUser}.
2812 *
2813 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2814 * @param name the user's name
2815 * @see UserHandle
2816 * @return the UserHandle object for the created user, or null if the user could not be created.
2817 */
2818 public UserHandle createUser(ComponentName admin, String name) {
2819 try {
2820 return mService.createUser(admin, name);
2821 } catch (RemoteException re) {
2822 Log.w(TAG, "Could not create a user", re);
2823 }
2824 return null;
2825 }
2826
2827 /**
Jason Monk03978a42014-06-10 15:05:30 -04002828 * Called by a device owner to create a user with the specified name. The UserHandle returned
2829 * by this method should not be persisted as user handles are recycled as users are removed and
2830 * created. If you need to persist an identifier for this user, use
2831 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2832 * immediately.
2833 *
2834 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2835 * as registered as an active admin on the new user. The profile owner package will be
2836 * installed on the new user if it already is installed on the device.
2837 *
2838 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2839 * profileOwnerComponent when onEnable is called.
2840 *
2841 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2842 * @param name the user's name
2843 * @param ownerName the human readable name of the organisation associated with this DPM.
2844 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2845 * the user.
2846 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2847 * on the new user.
2848 * @see UserHandle
2849 * @return the UserHandle object for the created user, or null if the user could not be created.
2850 */
2851 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2852 ComponentName profileOwnerComponent, Bundle adminExtras) {
2853 try {
2854 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2855 adminExtras);
2856 } catch (RemoteException re) {
2857 Log.w(TAG, "Could not create a user", re);
2858 }
2859 return null;
2860 }
2861
2862 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002863 * Called by a device owner to remove a user and all associated data. The primary user can
2864 * not be removed.
2865 *
2866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2867 * @param userHandle the user to remove.
2868 * @return {@code true} if the user was removed, {@code false} otherwise.
2869 */
2870 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2871 try {
2872 return mService.removeUser(admin, userHandle);
2873 } catch (RemoteException re) {
2874 Log.w(TAG, "Could not remove user ", re);
2875 return false;
2876 }
2877 }
2878
2879 /**
Jason Monk582d9112014-07-09 19:57:08 -04002880 * Called by a device owner to switch the specified user to the foreground.
2881 *
2882 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2883 * @param userHandle the user to switch to; null will switch to primary.
2884 * @return {@code true} if the switch was successful, {@code false} otherwise.
2885 *
2886 * @see Intent#ACTION_USER_FOREGROUND
2887 */
2888 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
2889 try {
2890 return mService.switchUser(admin, userHandle);
2891 } catch (RemoteException re) {
2892 Log.w(TAG, "Could not switch user ", re);
2893 return false;
2894 }
2895 }
2896
2897 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002898 * Called by a profile or device owner to get the application restrictions for a given target
2899 * application running in the managed profile.
2900 *
2901 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2902 * exception will be thrown.
2903 *
2904 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2905 * @param packageName The name of the package to fetch restricted settings of.
2906 * @return {@link Bundle} of settings corresponding to what was set last time
2907 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2908 * if no restrictions have been set.
2909 */
2910 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2911 if (mService != null) {
2912 try {
2913 return mService.getApplicationRestrictions(admin, packageName);
2914 } catch (RemoteException e) {
2915 Log.w(TAG, "Failed talking with device policy service", e);
2916 }
2917 }
2918 return null;
2919 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002920
2921 /**
2922 * Called by a profile or device owner to set a user restriction specified
2923 * by the key.
2924 * <p>
2925 * The calling device admin must be a profile or device owner; if it is not,
2926 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002927 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002928 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2929 * with.
2930 * @param key The key of the restriction. See the constants in
2931 * {@link android.os.UserManager} for the list of keys.
2932 */
2933 public void addUserRestriction(ComponentName admin, String key) {
2934 if (mService != null) {
2935 try {
2936 mService.setUserRestriction(admin, key, true);
2937 } catch (RemoteException e) {
2938 Log.w(TAG, "Failed talking with device policy service", e);
2939 }
2940 }
2941 }
2942
2943 /**
2944 * Called by a profile or device owner to clear a user restriction specified
2945 * by the key.
2946 * <p>
2947 * The calling device admin must be a profile or device owner; if it is not,
2948 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002949 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002950 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2951 * with.
2952 * @param key The key of the restriction. See the constants in
2953 * {@link android.os.UserManager} for the list of keys.
2954 */
2955 public void clearUserRestriction(ComponentName admin, String key) {
2956 if (mService != null) {
2957 try {
2958 mService.setUserRestriction(admin, key, false);
2959 } catch (RemoteException e) {
2960 Log.w(TAG, "Failed talking with device policy service", e);
2961 }
2962 }
2963 }
Adam Connors010cfd42014-04-16 12:48:13 +01002964
2965 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002966 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04002967 * is unavailable for use, but the data and actual package file remain.
2968 *
2969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002970 * @param packageName The name of the package to hide or unhide.
2971 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
2972 * unhidden.
2973 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04002974 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002975 public boolean setApplicationHidden(ComponentName admin, String packageName,
2976 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04002977 if (mService != null) {
2978 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002979 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04002980 } catch (RemoteException e) {
2981 Log.w(TAG, "Failed talking with device policy service", e);
2982 }
2983 }
2984 return false;
2985 }
2986
2987 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002988 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04002989 *
2990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002991 * @param packageName The name of the package to retrieve the hidden status of.
2992 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04002993 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002994 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04002995 if (mService != null) {
2996 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002997 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04002998 } catch (RemoteException e) {
2999 Log.w(TAG, "Failed talking with device policy service", e);
3000 }
3001 }
3002 return false;
3003 }
3004
3005 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003006 * Called by profile or device owner to re-enable a system app that was disabled by default
3007 * when the managed profile was created. This can only be called from a profile or device
3008 * owner running within a managed profile.
3009 *
3010 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3011 * @param packageName The package to be re-enabled in the current profile.
3012 */
3013 public void enableSystemApp(ComponentName admin, String packageName) {
3014 if (mService != null) {
3015 try {
3016 mService.enableSystemApp(admin, packageName);
3017 } catch (RemoteException e) {
3018 Log.w(TAG, "Failed to install package: " + packageName);
3019 }
3020 }
3021 }
3022
3023 /**
3024 * Called by profile or device owner to re-enable system apps by intent that were disabled
3025 * by default when the managed profile was created. This can only be called from a profile
3026 * or device owner running within a managed profile.
3027 *
3028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3029 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3030 * intent will be re-enabled in the current profile.
3031 * @return int The number of activities that matched the intent and were installed.
3032 */
3033 public int enableSystemApp(ComponentName admin, Intent intent) {
3034 if (mService != null) {
3035 try {
3036 return mService.enableSystemAppWithIntent(admin, intent);
3037 } catch (RemoteException e) {
3038 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3039 }
3040 }
3041 return 0;
3042 }
3043
3044 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01003045 * Called by a profile owner to disable account management for a specific type of account.
3046 *
3047 * <p>The calling device admin must be a profile owner. If it is not, a
3048 * security exception will be thrown.
3049 *
3050 * <p>When account management is disabled for an account type, adding or removing an account
3051 * of that type will not be possible.
3052 *
3053 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3054 * @param accountType For which account management is disabled or enabled.
3055 * @param disabled The boolean indicating that account management will be disabled (true) or
3056 * enabled (false).
3057 */
3058 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3059 boolean disabled) {
3060 if (mService != null) {
3061 try {
3062 mService.setAccountManagementDisabled(admin, accountType, disabled);
3063 } catch (RemoteException e) {
3064 Log.w(TAG, "Failed talking with device policy service", e);
3065 }
3066 }
3067 }
3068
3069 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003070 * Gets the array of accounts for which account management is disabled by the profile owner.
3071 *
3072 * <p> Account management can be disabled/enabled by calling
3073 * {@link #setAccountManagementDisabled}.
3074 *
3075 * @return a list of account types for which account management has been disabled.
3076 *
3077 * @see #setAccountManagementDisabled
3078 */
3079 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003080 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003081 }
3082
3083 /**
3084 * @see #getAccountTypesWithManagementDisabled()
3085 * @hide
3086 */
3087 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003088 if (mService != null) {
3089 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003090 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003091 } catch (RemoteException e) {
3092 Log.w(TAG, "Failed talking with device policy service", e);
3093 }
3094 }
3095
3096 return null;
3097 }
justinzhang511e0d82014-03-24 16:09:24 -04003098
3099 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003100 * Sets which packages may enter lock task mode.
3101 *
3102 * <p>Any packages that shares uid with an allowed package will also be allowed
3103 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003104 *
Jason Monkc5185f22014-06-24 11:12:42 -04003105 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003106 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003107 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003108 *
3109 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003110 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3111 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003112 */
Jason Monk48aacba2014-08-13 16:29:08 -04003113 public void setLockTaskPackages(ComponentName admin, String[] packages)
3114 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003115 if (mService != null) {
3116 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003117 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003118 } catch (RemoteException e) {
3119 Log.w(TAG, "Failed talking with device policy service", e);
3120 }
3121 }
3122 }
3123
3124 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003125 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003126 *
3127 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003128 * @hide
3129 */
Jason Monk48aacba2014-08-13 16:29:08 -04003130 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003131 if (mService != null) {
3132 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003133 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003134 } catch (RemoteException e) {
3135 Log.w(TAG, "Failed talking with device policy service", e);
3136 }
3137 }
3138 return null;
3139 }
3140
3141 /**
3142 * This function lets the caller know whether the given component is allowed to start the
3143 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003144 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003145 */
Jason Monkd7b86212014-06-16 13:15:38 -04003146 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003147 if (mService != null) {
3148 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003149 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003150 } catch (RemoteException e) {
3151 Log.w(TAG, "Failed talking with device policy service", e);
3152 }
3153 }
3154 return false;
3155 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003156
3157 /**
3158 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3159 * of the setting is in the correct form for the setting type should be performed by the caller.
3160 *
3161 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3162 * @param setting The name of the setting to update.
3163 * @param value The value to update the setting to.
3164 */
3165 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3166 if (mService != null) {
3167 try {
3168 mService.setGlobalSetting(admin, setting, value);
3169 } catch (RemoteException e) {
3170 Log.w(TAG, "Failed talking with device policy service", e);
3171 }
3172 }
3173 }
3174
3175 /**
3176 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3177 * that the value of the setting is in the correct form for the setting type should be performed
3178 * by the caller.
3179 *
3180 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3181 * @param setting The name of the setting to update.
3182 * @param value The value to update the setting to.
3183 */
3184 public void setSecureSetting(ComponentName admin, String setting, String value) {
3185 if (mService != null) {
3186 try {
3187 mService.setSecureSetting(admin, setting, value);
3188 } catch (RemoteException e) {
3189 Log.w(TAG, "Failed talking with device policy service", e);
3190 }
3191 }
3192 }
3193
Amith Yamasanif20d6402014-05-24 15:34:37 -07003194 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003195 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003196 * making permission requests of a local or remote administrator of the user.
3197 * <p/>
3198 * Only a profile owner can designate the restrictions provider.
3199 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003200 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003201 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003202 * it removes the restrictions provider previously assigned.
3203 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003204 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003205 if (mService != null) {
3206 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003207 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003208 } catch (RemoteException re) {
3209 Log.w(TAG, "Failed to set permission provider on device policy service");
3210 }
3211 }
3212 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003213
3214 /**
3215 * Called by profile or device owners to set the master volume mute on or off.
3216 *
3217 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3218 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3219 */
3220 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3221 if (mService != null) {
3222 try {
3223 mService.setMasterVolumeMuted(admin, on);
3224 } catch (RemoteException re) {
3225 Log.w(TAG, "Failed to setMasterMute on device policy service");
3226 }
3227 }
3228 }
3229
3230 /**
3231 * Called by profile or device owners to check whether the master volume mute is on or off.
3232 *
3233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3234 * @return {@code true} if master volume is muted, {@code false} if it's not.
3235 */
3236 public boolean isMasterVolumeMuted(ComponentName admin) {
3237 if (mService != null) {
3238 try {
3239 return mService.isMasterVolumeMuted(admin);
3240 } catch (RemoteException re) {
3241 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3242 }
3243 }
3244 return false;
3245 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003246
3247 /**
3248 * Called by profile or device owners to change whether a user can uninstall
3249 * a package.
3250 *
3251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3252 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003253 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003254 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003255 public void setUninstallBlocked(ComponentName admin, String packageName,
3256 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003257 if (mService != null) {
3258 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003259 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003260 } catch (RemoteException re) {
3261 Log.w(TAG, "Failed to call block uninstall on device policy service");
3262 }
3263 }
3264 }
3265
3266 /**
3267 * Called by profile or device owners to check whether a user has been blocked from
3268 * uninstalling a package.
3269 *
3270 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3271 * @param packageName package to check.
3272 * @return true if the user shouldn't be able to uninstall the package.
3273 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003274 public boolean getUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003275 if (mService != null) {
3276 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003277 return mService.getUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003278 } catch (RemoteException re) {
3279 Log.w(TAG, "Failed to call block uninstall on device policy service");
3280 }
3281 }
3282 return false;
3283 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003284
3285 /**
3286 * Called by the profile owner to enable widget providers from a given package
3287 * to be available in the parent profile. As a result the user will be able to
3288 * add widgets from the white-listed package running under the profile to a widget
3289 * host which runs under the device owner, for example the home screen. Note that
3290 * a package may have zero or more provider components, where each component
3291 * provides a different widget type.
3292 * <p>
3293 * <strong>Note:</strong> By default no widget provider package is white-listed.
3294 * </p>
3295 *
3296 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3297 * @param packageName The package from which widget providers are white-listed.
3298 * @return Whether the package was added.
3299 *
3300 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3301 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3302 */
3303 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3304 if (mService != null) {
3305 try {
3306 return mService.addCrossProfileWidgetProvider(admin, packageName);
3307 } catch (RemoteException re) {
3308 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3309 }
3310 }
3311 return false;
3312 }
3313
3314 /**
3315 * Called by the profile owner to disable widget providers from a given package
3316 * to be available in the parent profile. For this method to take effect the
3317 * package should have been added via {@link #addCrossProfileWidgetProvider(
3318 * android.content.ComponentName, String)}.
3319 * <p>
3320 * <strong>Note:</strong> By default no widget provider package is white-listed.
3321 * </p>
3322 *
3323 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3324 * @param packageName The package from which widget providers are no longer
3325 * white-listed.
3326 * @return Whether the package was removed.
3327 *
3328 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3329 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3330 */
3331 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3332 if (mService != null) {
3333 try {
3334 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3335 } catch (RemoteException re) {
3336 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3337 }
3338 }
3339 return false;
3340 }
3341
3342 /**
3343 * Called by the profile owner to query providers from which packages are
3344 * available in the parent profile.
3345 *
3346 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3347 * @return The white-listed package list.
3348 *
3349 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3350 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3351 */
3352 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3353 if (mService != null) {
3354 try {
3355 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3356 if (providers != null) {
3357 return providers;
3358 }
3359 } catch (RemoteException re) {
3360 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3361 }
3362 }
3363 return Collections.emptyList();
3364 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003365}