blob: 132b468cd12c342403fdb51ad19450e55811e986 [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;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010041import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070042import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080043import android.util.Log;
44
Maggie Benthallda51e682013-08-08 22:35:44 -040045import com.android.org.conscrypt.TrustedCertificateStore;
46
Jessica Hummel91da58d2014-04-10 17:39:43 +010047import org.xmlpull.v1.XmlPullParserException;
48
Maggie Benthallda51e682013-08-08 22:35:44 -040049import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080050import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070051import java.net.InetSocketAddress;
52import java.net.Proxy;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010053import java.security.PrivateKey;
54import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040055import java.security.cert.CertificateException;
56import java.security.cert.CertificateFactory;
57import java.security.cert.X509Certificate;
Jim Miller604e7552014-07-18 19:00:02 -070058import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070059import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080060import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080061
62/**
63 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080064 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080065 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080066 *
67 * <div class="special reference">
68 * <h3>Developer Guides</h3>
69 * <p>For more information about managing policies for device adminstration, read the
70 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
71 * developer guide.</p>
72 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080073 */
74public class DevicePolicyManager {
75 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080076
77 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080078 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070079
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080080 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080081 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080082 mService = IDevicePolicyManager.Stub.asInterface(
83 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
84 }
85
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080086 /** @hide */
87 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080088 DevicePolicyManager me = new DevicePolicyManager(context, handler);
89 return me.mService != null ? me : null;
90 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070091
Dianne Hackbornd6847842010-01-12 18:14:19 -080092 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +000093 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +000094 *
Jessica Hummel9da60392014-05-21 12:32:57 +010095 * <p>A managed profile allows data separation for example for the usage of a
96 * device as a personal and corporate device. The user which provisioning is started from and
97 * the managed profile share a launcher.
98 *
99 * <p>This intent will typically be sent by a mobile device management application (mdm).
100 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
101 * control over the profile
102 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100103 * <p>This intent must contain the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000104 *
105 * <p> When managed provisioning has completed, an intent of the type
106 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100107 * managed profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100108 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100109 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
110 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000111 *
112 * <p>Input: Nothing.</p>
113 * <p>Output: Nothing</p>
114 */
115 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
116 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100117 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000118
119 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700120 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
121 * a mobile device management application that starts managed profile provisioning to pass data
122 * to itself on the managed profile when provisioning completes. The mobile device management
123 * application sends this extra in an intent with the action
124 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
125 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
126 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
127 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100128 */
129 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100130 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100131
132 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100133 * A String extra holding the package name of the mobile device management application that
134 * will be set as the profile owner or device owner.
135 *
136 * <p>If an application starts provisioning directly via an intent with action
137 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
138 * application that started provisioning. The package will be set as profile owner in that case.
139 *
140 * <p>This package is set as device owner when device owner provisioning is started by an Nfc
Esteban Talaveraf057f062014-08-20 14:27:45 +0100141 * message containing an Nfc record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000142 */
143 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100144 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000145
146 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100147 * A String extra that, holds the email address of the account which a managed profile is
148 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
149 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100150 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100151 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
152 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100153 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
154 * contains this extra, it is forwarded in the
155 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
156 * device management application that was set as the profile owner during provisioning.
157 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100158 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100159 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
160 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100161
162 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100163 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
164 * will be set to.
165 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100166 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100167 * provisioning via an Nfc bump.
168 */
169 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100170 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100171
172 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100173 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
174 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100175 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100176 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100177 * provisioning via an Nfc bump.
178 */
179 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100180 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100181
182 /**
183 * A String extra holding the {@link java.util.Locale} that the device will be set to.
184 * Format: xx_yy, where xx is the language code, and yy the country code.
185 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100186 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100187 * provisioning via an Nfc bump.
188 */
189 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100190 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100191
192 /**
193 * A String extra holding the ssid of the wifi network that should be used during nfc device
194 * owner provisioning for downloading the mobile device management application.
195 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100196 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100197 * provisioning via an Nfc bump.
198 */
199 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100200 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100201
202 /**
203 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
204 * is hidden or not.
205 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100206 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100207 * provisioning via an Nfc bump.
208 */
209 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100210 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100211
212 /**
213 * A String extra indicating the security type of the wifi network in
214 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
215 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100216 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100217 * provisioning via an Nfc bump.
218 */
219 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100220 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100221
222 /**
223 * A String extra holding the password of the wifi network in
224 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
225 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100226 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100227 * provisioning via an Nfc bump.
228 */
229 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100230 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100231
232 /**
233 * A String extra holding the proxy host for the wifi network in
234 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
235 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100236 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100237 * provisioning via an Nfc bump.
238 */
239 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100240 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100241
242 /**
243 * An int extra holding the proxy port for the wifi network in
244 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
245 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100246 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100247 * provisioning via an Nfc bump.
248 */
249 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100250 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100251
252 /**
253 * A String extra holding the proxy bypass for the wifi network in
254 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
255 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100256 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100257 * provisioning via an Nfc bump.
258 */
259 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100260 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100261
262 /**
263 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
264 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
265 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100266 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100267 * provisioning via an Nfc bump.
268 */
269 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100270 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100271
272 /**
273 * A String extra holding a url that specifies the download location of the device admin
274 * package. When not provided it is assumed that the device admin package is already installed.
275 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100276 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100277 * provisioning via an Nfc bump.
278 */
279 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100280 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100281
282 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100283 * A String extra holding a http cookie header which should be used in the http request to the
284 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
285 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100286 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse681bce92014-07-24 16:46:26 +0100287 * provisioning via an Nfc bump.
288 */
289 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100290 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100291
292 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100293 * A String extra holding the SHA-1 checksum of the file at download location specified in
294 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
295 * the file at the download location an error will be shown to the user and the user will be
296 * asked to factory reset the device.
297 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100298 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100299 * provisioning via an Nfc bump.
300 */
301 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100302 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100303
304 /**
305 * This MIME type is used for starting the Device Owner provisioning.
306 *
307 * <p>During device owner provisioning a device admin app is set as the owner of the device.
308 * A device owner has full control over the device. The device owner can not be modified by the
309 * user and the only way of resetting the device is if the device owner app calls a factory
310 * reset.
311 *
312 * <p> A typical use case would be a device that is owned by a company, but used by either an
313 * employee or client.
314 *
315 * <p> The Nfc message should be send to an unprovisioned device.
316 *
317 * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which
318 * contains the following properties:
319 * <ul>
320 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
321 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100322 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100323 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
324 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
325 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
326 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
327 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
328 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
329 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
330 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
332 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
333 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
334 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
335 *
336 * <p> When device owner provisioning has completed, an intent of the type
337 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
338 * device owner.
339 *
340 * <p>
341 * If provisioning fails, the device is factory reset.
342 *
343 * <p>Input: Nothing.</p>
344 * <p>Output: Nothing</p>
345 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100346 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100347 = "application/com.android.managedprovisioning";
348
349 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800350 * Activity action: ask the user to add a new device administrator to the system.
351 * The desired policy is the ComponentName of the policy in the
352 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
353 * bring the user through adding the device administrator to the system (or
354 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700355 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800356 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
357 * field to provide the user with additional explanation (in addition
358 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800359 *
360 * <p>If your administrator is already active, this will ordinarily return immediately (without
361 * user intervention). However, if your administrator has been updated and is requesting
362 * additional uses-policy flags, the user will be presented with the new list. New policies
363 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800364 */
365 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
366 public static final String ACTION_ADD_DEVICE_ADMIN
367 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700368
Dianne Hackbornd6847842010-01-12 18:14:19 -0800369 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700370 * @hide
371 * Activity action: ask the user to add a new device administrator as the profile owner
372 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
373 * permission can call this API.
374 *
375 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
376 * field. This will invoke a UI to bring the user through adding the profile owner admin
377 * to remotely control restrictions on the user.
378 *
379 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
380 * result of whether or not the user approved the action. If approved, the result will
381 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
382 * as a profile owner.
383 *
384 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
385 * field to provide the user with additional explanation (in addition
386 * to your component's description) about what is being added.
387 *
388 * <p>If there is already a profile owner active or the caller doesn't have the required
389 * permissions, the operation will return a failure result.
390 */
391 @SystemApi
392 public static final String ACTION_SET_PROFILE_OWNER
393 = "android.app.action.SET_PROFILE_OWNER";
394
395 /**
396 * @hide
397 * Name of the profile owner admin that controls the user.
398 */
399 @SystemApi
400 public static final String EXTRA_PROFILE_OWNER_NAME
401 = "android.app.extra.PROFILE_OWNER_NAME";
402
403 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700404 * Activity action: send when any policy admin changes a policy.
405 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700406 *
Jim Miller284b62e2010-06-08 14:27:42 -0700407 * @hide
408 */
409 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
410 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
411
412 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800413 * The ComponentName of the administrator component.
414 *
415 * @see #ACTION_ADD_DEVICE_ADMIN
416 */
417 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700418
Dianne Hackbornd6847842010-01-12 18:14:19 -0800419 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800420 * An optional CharSequence providing additional explanation for why the
421 * admin is being added.
422 *
423 * @see #ACTION_ADD_DEVICE_ADMIN
424 */
425 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700426
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800427 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700428 * Activity action: have the user enter a new password. This activity should
429 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
430 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
431 * enter a new password that meets the current requirements. You can use
432 * {@link #isActivePasswordSufficient()} to determine whether you need to
433 * have the user select a new password in order to meet the current
434 * constraints. Upon being resumed from this activity, you can check the new
435 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800436 */
437 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
438 public static final String ACTION_SET_NEW_PASSWORD
439 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700440
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000441 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100442 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
443 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000444 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100445 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000446
447 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100448 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
449 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000450 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100451 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700452
Dianne Hackbornd6847842010-01-12 18:14:19 -0800453 /**
454 * Return true if the given administrator component is currently
455 * active (enabled) in the system.
456 */
457 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100458 return isAdminActiveAsUser(who, UserHandle.myUserId());
459 }
460
461 /**
462 * @see #isAdminActive(ComponentName)
463 * @hide
464 */
465 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800466 if (mService != null) {
467 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100468 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800469 } catch (RemoteException e) {
470 Log.w(TAG, "Failed talking with device policy service", e);
471 }
472 }
473 return false;
474 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700475
Dianne Hackbornd6847842010-01-12 18:14:19 -0800476 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800477 * Return a list of all currently active device administrator's component
478 * names. Note that if there are no administrators than null may be
479 * returned.
480 */
481 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100482 return getActiveAdminsAsUser(UserHandle.myUserId());
483 }
484
485 /**
486 * @see #getActiveAdmins()
487 * @hide
488 */
489 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800490 if (mService != null) {
491 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100492 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800493 } catch (RemoteException e) {
494 Log.w(TAG, "Failed talking with device policy service", e);
495 }
496 }
497 return null;
498 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700499
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800500 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700501 * Used by package administration code to determine if a package can be stopped
502 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800503 * @hide
504 */
505 public boolean packageHasActiveAdmins(String packageName) {
506 if (mService != null) {
507 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700508 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800509 } catch (RemoteException e) {
510 Log.w(TAG, "Failed talking with device policy service", e);
511 }
512 }
513 return false;
514 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700515
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800516 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800517 * Remove a current administration component. This can only be called
518 * by the application that owns the administration component; if you
519 * try to remove someone else's component, a security exception will be
520 * thrown.
521 */
522 public void removeActiveAdmin(ComponentName who) {
523 if (mService != null) {
524 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700525 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800526 } catch (RemoteException e) {
527 Log.w(TAG, "Failed talking with device policy service", e);
528 }
529 }
530 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700531
Dianne Hackbornd6847842010-01-12 18:14:19 -0800532 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800533 * Returns true if an administrator has been granted a particular device policy. This can
534 * be used to check if the administrator was activated under an earlier set of policies,
535 * but requires additional policies after an upgrade.
536 *
537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
538 * an active administrator, or an exception will be thrown.
539 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
540 */
541 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
542 if (mService != null) {
543 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700544 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800545 } catch (RemoteException e) {
546 Log.w(TAG, "Failed talking with device policy service", e);
547 }
548 }
549 return false;
550 }
551
552 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800553 * Constant for {@link #setPasswordQuality}: the policy has no requirements
554 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800555 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800556 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800557 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700558
Dianne Hackbornd6847842010-01-12 18:14:19 -0800559 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700560 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
561 * recognition technology. This implies technologies that can recognize the identity of
562 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
563 * Note that quality constants are ordered so that higher values are more restrictive.
564 */
565 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
566
567 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800568 * Constant for {@link #setPasswordQuality}: the policy requires some kind
569 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800570 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800571 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800572 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700573
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800574 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800575 * Constant for {@link #setPasswordQuality}: the user must have entered a
576 * password containing at least numeric characters. Note that quality
577 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800578 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800579 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700580
Dianne Hackbornd6847842010-01-12 18:14:19 -0800581 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800582 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800583 * password containing at least numeric characters with no repeating (4444)
584 * or ordered (1234, 4321, 2468) sequences. Note that quality
585 * constants are ordered so that higher values are more restrictive.
586 */
587 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
588
589 /**
590 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700591 * password containing at least alphabetic (or other symbol) characters.
592 * Note that quality constants are ordered so that higher values are more
593 * restrictive.
594 */
595 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700596
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700597 /**
598 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800599 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700600 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800601 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800602 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700603 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700604
Dianne Hackbornd6847842010-01-12 18:14:19 -0800605 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700606 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700607 * password containing at least a letter, a numerical digit and a special
608 * symbol, by default. With this password quality, passwords can be
609 * restricted to contain various sets of characters, like at least an
610 * uppercase letter, etc. These are specified using various methods,
611 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
612 * that quality constants are ordered so that higher values are more
613 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700614 */
615 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
616
617 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800618 * Called by an application that is administering the device to set the
619 * password restrictions it is imposing. After setting this, the user
620 * will not be able to enter a new password that is not at least as
621 * restrictive as what has been set. Note that the current password
622 * will remain until the user has set a new one, so the change does not
623 * take place immediately. To prompt the user for a new password, use
624 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700625 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800626 * <p>Quality constants are ordered so that higher values are more restrictive;
627 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800628 * the user's preference, and any other considerations) is the one that
629 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700630 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800631 * <p>The calling device admin must have requested
632 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
633 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700634 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800635 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800636 * @param quality The new desired quality. One of
637 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800638 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
639 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
640 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800641 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800642 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800643 if (mService != null) {
644 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700645 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800646 } catch (RemoteException e) {
647 Log.w(TAG, "Failed talking with device policy service", e);
648 }
649 }
650 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700651
Dianne Hackbornd6847842010-01-12 18:14:19 -0800652 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100653 * Retrieve the current minimum password quality for all admins of this user
654 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800655 * @param admin The name of the admin component to check, or null to aggregate
656 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800657 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800658 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700659 return getPasswordQuality(admin, UserHandle.myUserId());
660 }
661
662 /** @hide per-user version */
663 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800664 if (mService != null) {
665 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700666 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800667 } catch (RemoteException e) {
668 Log.w(TAG, "Failed talking with device policy service", e);
669 }
670 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800671 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800672 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700673
Dianne Hackbornd6847842010-01-12 18:14:19 -0800674 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800675 * Called by an application that is administering the device to set the
676 * minimum allowed password length. After setting this, the user
677 * will not be able to enter a new password that is not at least as
678 * restrictive as what has been set. Note that the current password
679 * will remain until the user has set a new one, so the change does not
680 * take place immediately. To prompt the user for a new password, use
681 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
682 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800683 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
684 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
685 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700686 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800687 * <p>The calling device admin must have requested
688 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
689 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700690 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800692 * @param length The new desired minimum password length. A value of 0
693 * means there is no restriction.
694 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800695 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800696 if (mService != null) {
697 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700698 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800699 } catch (RemoteException e) {
700 Log.w(TAG, "Failed talking with device policy service", e);
701 }
702 }
703 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700704
Dianne Hackbornd6847842010-01-12 18:14:19 -0800705 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100706 * Retrieve the current minimum password length for all admins of this
707 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800708 * @param admin The name of the admin component to check, or null to aggregate
709 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800710 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800711 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700712 return getPasswordMinimumLength(admin, UserHandle.myUserId());
713 }
714
715 /** @hide per-user version */
716 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800717 if (mService != null) {
718 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700719 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800720 } catch (RemoteException e) {
721 Log.w(TAG, "Failed talking with device policy service", e);
722 }
723 }
724 return 0;
725 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700726
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700727 /**
728 * Called by an application that is administering the device to set the
729 * minimum number of upper case letters required in the password. After
730 * setting this, the user will not be able to enter a new password that is
731 * not at least as restrictive as what has been set. Note that the current
732 * password will remain until the user has set a new one, so the change does
733 * not take place immediately. To prompt the user for a new password, use
734 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
735 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700736 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
737 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700738 * <p>
739 * The calling device admin must have requested
740 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
741 * this method; if it has not, a security exception will be thrown.
742 *
743 * @param admin Which {@link DeviceAdminReceiver} this request is associated
744 * with.
745 * @param length The new desired minimum number of upper case letters
746 * required in the password. A value of 0 means there is no
747 * restriction.
748 */
749 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
750 if (mService != null) {
751 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700752 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700753 } catch (RemoteException e) {
754 Log.w(TAG, "Failed talking with device policy service", e);
755 }
756 }
757 }
758
759 /**
760 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100761 * password for all admins of this user and its profiles or a particular one.
762 * This is the same value as set by
763 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700764 * and only applies when the password quality is
765 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700766 *
767 * @param admin The name of the admin component to check, or null to
768 * aggregate all admins.
769 * @return The minimum number of upper case letters required in the
770 * password.
771 */
772 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700773 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
774 }
775
776 /** @hide per-user version */
777 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700778 if (mService != null) {
779 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700780 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700781 } catch (RemoteException e) {
782 Log.w(TAG, "Failed talking with device policy service", e);
783 }
784 }
785 return 0;
786 }
787
788 /**
789 * Called by an application that is administering the device to set the
790 * minimum number of lower case letters required in the password. After
791 * setting this, the user will not be able to enter a new password that is
792 * not at least as restrictive as what has been set. Note that the current
793 * password will remain until the user has set a new one, so the change does
794 * not take place immediately. To prompt the user for a new password, use
795 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
796 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700797 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
798 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700799 * <p>
800 * The calling device admin must have requested
801 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
802 * this method; if it has not, a security exception will be thrown.
803 *
804 * @param admin Which {@link DeviceAdminReceiver} this request is associated
805 * with.
806 * @param length The new desired minimum number of lower case letters
807 * required in the password. A value of 0 means there is no
808 * restriction.
809 */
810 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
811 if (mService != null) {
812 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700813 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700814 } catch (RemoteException e) {
815 Log.w(TAG, "Failed talking with device policy service", e);
816 }
817 }
818 }
819
820 /**
821 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100822 * password for all admins of this user and its profiles or a particular one.
823 * This is the same value as set by
824 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700825 * and only applies when the password quality is
826 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700827 *
828 * @param admin The name of the admin component to check, or null to
829 * aggregate all admins.
830 * @return The minimum number of lower case letters required in the
831 * password.
832 */
833 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700834 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
835 }
836
837 /** @hide per-user version */
838 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700839 if (mService != null) {
840 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700841 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700842 } catch (RemoteException e) {
843 Log.w(TAG, "Failed talking with device policy service", e);
844 }
845 }
846 return 0;
847 }
848
849 /**
850 * Called by an application that is administering the device to set the
851 * minimum number of letters required in the password. After setting this,
852 * the user will not be able to enter a new password that is not at least as
853 * restrictive as what has been set. Note that the current password will
854 * remain until the user has set a new one, so the change does not take
855 * place immediately. To prompt the user for a new password, use
856 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
857 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700858 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
859 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700860 * <p>
861 * The calling device admin must have requested
862 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
863 * this method; if it has not, a security exception will be thrown.
864 *
865 * @param admin Which {@link DeviceAdminReceiver} this request is associated
866 * with.
867 * @param length The new desired minimum number of letters required in the
868 * password. A value of 0 means there is no restriction.
869 */
870 public void setPasswordMinimumLetters(ComponentName admin, int length) {
871 if (mService != null) {
872 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700873 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700874 } catch (RemoteException e) {
875 Log.w(TAG, "Failed talking with device policy service", e);
876 }
877 }
878 }
879
880 /**
881 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700882 * admins or a particular one. This is the same value as
883 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
884 * and only applies when the password quality is
885 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700886 *
887 * @param admin The name of the admin component to check, or null to
888 * aggregate all admins.
889 * @return The minimum number of letters required in the password.
890 */
891 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700892 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
893 }
894
895 /** @hide per-user version */
896 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700897 if (mService != null) {
898 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700899 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700900 } catch (RemoteException e) {
901 Log.w(TAG, "Failed talking with device policy service", e);
902 }
903 }
904 return 0;
905 }
906
907 /**
908 * Called by an application that is administering the device to set the
909 * minimum number of numerical digits required in the password. After
910 * setting this, the user will not be able to enter a new password that is
911 * not at least as restrictive as what has been set. Note that the current
912 * password will remain until the user has set a new one, so the change does
913 * not take place immediately. To prompt the user for a new password, use
914 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
915 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700916 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
917 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700918 * <p>
919 * The calling device admin must have requested
920 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
921 * this method; if it has not, a security exception will be thrown.
922 *
923 * @param admin Which {@link DeviceAdminReceiver} this request is associated
924 * with.
925 * @param length The new desired minimum number of numerical digits required
926 * in the password. A value of 0 means there is no restriction.
927 */
928 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
929 if (mService != null) {
930 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700931 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700932 } catch (RemoteException e) {
933 Log.w(TAG, "Failed talking with device policy service", e);
934 }
935 }
936 }
937
938 /**
939 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100940 * for all admins of this user and its profiles or a particular one.
941 * This is the same value as set by
942 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700943 * and only applies when the password quality is
944 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700945 *
946 * @param admin The name of the admin component to check, or null to
947 * aggregate all admins.
948 * @return The minimum number of numerical digits required in the password.
949 */
950 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700951 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
952 }
953
954 /** @hide per-user version */
955 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700956 if (mService != null) {
957 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700958 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700959 } catch (RemoteException e) {
960 Log.w(TAG, "Failed talking with device policy service", e);
961 }
962 }
963 return 0;
964 }
965
966 /**
967 * Called by an application that is administering the device to set the
968 * minimum number of symbols required in the password. After setting this,
969 * the user will not be able to enter a new password that is not at least as
970 * restrictive as what has been set. Note that the current password will
971 * remain until the user has set a new one, so the change does not take
972 * place immediately. To prompt the user for a new password, use
973 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
974 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700975 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
976 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700977 * <p>
978 * The calling device admin must have requested
979 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
980 * this method; if it has not, a security exception will be thrown.
981 *
982 * @param admin Which {@link DeviceAdminReceiver} this request is associated
983 * with.
984 * @param length The new desired minimum number of symbols required in the
985 * password. A value of 0 means there is no restriction.
986 */
987 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
988 if (mService != null) {
989 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700990 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700991 } catch (RemoteException e) {
992 Log.w(TAG, "Failed talking with device policy service", e);
993 }
994 }
995 }
996
997 /**
998 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700999 * admins or a particular one. This is the same value as
1000 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1001 * and only applies when the password quality is
1002 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001003 *
1004 * @param admin The name of the admin component to check, or null to
1005 * aggregate all admins.
1006 * @return The minimum number of symbols required in the password.
1007 */
1008 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001009 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1010 }
1011
1012 /** @hide per-user version */
1013 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001014 if (mService != null) {
1015 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001016 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001017 } catch (RemoteException e) {
1018 Log.w(TAG, "Failed talking with device policy service", e);
1019 }
1020 }
1021 return 0;
1022 }
1023
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001024 /**
1025 * Called by an application that is administering the device to set the
1026 * minimum number of non-letter characters (numerical digits or symbols)
1027 * required in the password. After setting this, the user will not be able
1028 * to enter a new password that is not at least as restrictive as what has
1029 * been set. Note that the current password will remain until the user has
1030 * set a new one, so the change does not take place immediately. To prompt
1031 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1032 * setting this value. This constraint is only imposed if the administrator
1033 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1034 * {@link #setPasswordQuality}. The default value is 0.
1035 * <p>
1036 * The calling device admin must have requested
1037 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1038 * this method; if it has not, a security exception will be thrown.
1039 *
1040 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1041 * with.
1042 * @param length The new desired minimum number of letters required in the
1043 * password. A value of 0 means there is no restriction.
1044 */
1045 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1046 if (mService != null) {
1047 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001048 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001049 } catch (RemoteException e) {
1050 Log.w(TAG, "Failed talking with device policy service", e);
1051 }
1052 }
1053 }
1054
1055 /**
1056 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001057 * password for all admins of this user and its profiles or a particular one.
1058 * This is the same value as set by
1059 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001060 * and only applies when the password quality is
1061 * {@link #PASSWORD_QUALITY_COMPLEX}.
1062 *
1063 * @param admin The name of the admin component to check, or null to
1064 * aggregate all admins.
1065 * @return The minimum number of letters required in the password.
1066 */
1067 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001068 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1069 }
1070
1071 /** @hide per-user version */
1072 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001073 if (mService != null) {
1074 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001075 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001076 } catch (RemoteException e) {
1077 Log.w(TAG, "Failed talking with device policy service", e);
1078 }
1079 }
1080 return 0;
1081 }
1082
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001083 /**
1084 * Called by an application that is administering the device to set the length
1085 * of the password history. After setting this, the user will not be able to
1086 * enter a new password that is the same as any password in the history. Note
1087 * that the current password will remain until the user has set a new one, so
1088 * the change does not take place immediately. To prompt the user for a new
1089 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1090 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001091 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1092 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1093 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001094 *
1095 * <p>
1096 * The calling device admin must have requested
1097 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1098 * method; if it has not, a security exception will be thrown.
1099 *
1100 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1101 * with.
1102 * @param length The new desired length of password history. A value of 0
1103 * means there is no restriction.
1104 */
1105 public void setPasswordHistoryLength(ComponentName admin, int length) {
1106 if (mService != null) {
1107 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001108 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001109 } catch (RemoteException e) {
1110 Log.w(TAG, "Failed talking with device policy service", e);
1111 }
1112 }
1113 }
1114
1115 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001116 * Called by a device admin to set the password expiration timeout. Calling this method
1117 * will restart the countdown for password expiration for the given admin, as will changing
1118 * the device password (for all admins).
1119 *
1120 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1121 * For example, to have the password expire 5 days from now, timeout would be
1122 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1123 *
1124 * <p>To disable password expiration, a value of 0 may be used for timeout.
1125 *
Jim Millera4e28d12010-11-08 16:15:47 -08001126 * <p>The calling device admin must have requested
1127 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1128 * method; if it has not, a security exception will be thrown.
1129 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001130 * <p> Note that setting the password will automatically reset the expiration time for all
1131 * active admins. Active admins do not need to explicitly call this method in that case.
1132 *
Jim Millera4e28d12010-11-08 16:15:47 -08001133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1134 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1135 * means there is no restriction (unlimited).
1136 */
1137 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1138 if (mService != null) {
1139 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001140 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001141 } catch (RemoteException e) {
1142 Log.w(TAG, "Failed talking with device policy service", e);
1143 }
1144 }
1145 }
1146
1147 /**
Jim Miller6b857682011-02-16 16:27:41 -08001148 * Get the password expiration timeout for the given admin. The expiration timeout is the
1149 * recurring expiration timeout provided in the call to
1150 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1151 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001152 *
1153 * @param admin The name of the admin component to check, or null to aggregate all admins.
1154 * @return The timeout for the given admin or the minimum of all timeouts
1155 */
1156 public long getPasswordExpirationTimeout(ComponentName admin) {
1157 if (mService != null) {
1158 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001159 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001160 } catch (RemoteException e) {
1161 Log.w(TAG, "Failed talking with device policy service", e);
1162 }
1163 }
1164 return 0;
1165 }
1166
1167 /**
1168 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001169 * all admins of this user and its profiles if admin is null. If the password is
1170 * expired, this will return the time since the password expired as a negative number.
1171 * If admin is null, then a composite of all expiration timeouts is returned
1172 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001173 *
1174 * @param admin The name of the admin component to check, or null to aggregate all admins.
1175 * @return The password expiration time, in ms.
1176 */
1177 public long getPasswordExpiration(ComponentName admin) {
1178 if (mService != null) {
1179 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001180 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001181 } catch (RemoteException e) {
1182 Log.w(TAG, "Failed talking with device policy service", e);
1183 }
1184 }
1185 return 0;
1186 }
1187
1188 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001189 * Retrieve the current password history length for all admins of this
1190 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001191 * @param admin The name of the admin component to check, or null to aggregate
1192 * all admins.
1193 * @return The length of the password history
1194 */
1195 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001196 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1197 }
1198
1199 /** @hide per-user version */
1200 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001201 if (mService != null) {
1202 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001203 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001204 } catch (RemoteException e) {
1205 Log.w(TAG, "Failed talking with device policy service", e);
1206 }
1207 }
1208 return 0;
1209 }
1210
Dianne Hackbornd6847842010-01-12 18:14:19 -08001211 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001212 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001213 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001214 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001215 * @return Returns the maximum length that the user can enter.
1216 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001217 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001218 // Kind-of arbitrary.
1219 return 16;
1220 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001221
Dianne Hackborn254cb442010-01-27 19:23:59 -08001222 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001223 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001224 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001225 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001226 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001227 * <p>The calling device admin must have requested
1228 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1229 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001230 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001231 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001232 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001233 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001234 if (mService != null) {
1235 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001236 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001237 } catch (RemoteException e) {
1238 Log.w(TAG, "Failed talking with device policy service", e);
1239 }
1240 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001241 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001242 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001243
Dianne Hackbornd6847842010-01-12 18:14:19 -08001244 /**
1245 * Retrieve the number of times the user has failed at entering a
1246 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001247 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001248 * <p>The calling device admin must have requested
1249 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1250 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001251 */
1252 public int getCurrentFailedPasswordAttempts() {
1253 if (mService != null) {
1254 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001255 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001256 } catch (RemoteException e) {
1257 Log.w(TAG, "Failed talking with device policy service", e);
1258 }
1259 }
1260 return -1;
1261 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001262
1263 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001264 * Setting this to a value greater than zero enables a built-in policy
1265 * that will perform a device wipe after too many incorrect
1266 * device-unlock passwords have been entered. This built-in policy combines
1267 * watching for failed passwords and wiping the device, and requires
1268 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001269 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001270 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001271 * <p>To implement any other policy (e.g. wiping data for a particular
1272 * application only, erasing or revoking credentials, or reporting the
1273 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001274 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001275 * instead. Do not use this API, because if the maximum count is reached,
1276 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001277 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001279 * @param num The number of failed password attempts at which point the
1280 * device will wipe its data.
1281 */
1282 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1283 if (mService != null) {
1284 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001285 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001286 } catch (RemoteException e) {
1287 Log.w(TAG, "Failed talking with device policy service", e);
1288 }
1289 }
1290 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001291
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001292 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001293 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001294 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001295 * or a particular one.
1296 * @param admin The name of the admin component to check, or null to aggregate
1297 * all admins.
1298 */
1299 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001300 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1301 }
1302
1303 /** @hide per-user version */
1304 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001305 if (mService != null) {
1306 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001307 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001308 } catch (RemoteException e) {
1309 Log.w(TAG, "Failed talking with device policy service", e);
1310 }
1311 }
1312 return 0;
1313 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001314
Dianne Hackborn254cb442010-01-27 19:23:59 -08001315 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001316 * Flag for {@link #resetPassword}: don't allow other admins to change
1317 * the password again until the user has entered it.
1318 */
1319 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001320
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001321 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001322 * Force a new device unlock password (the password needed to access the
1323 * entire device, not for individual accounts) on the user. This takes
1324 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001325 * The given password must be sufficient for the
1326 * current password quality and length constraints as returned by
1327 * {@link #getPasswordQuality(ComponentName)} and
1328 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1329 * these constraints, then it will be rejected and false returned. Note
1330 * that the password may be a stronger quality (containing alphanumeric
1331 * characters when the requested quality is only numeric), in which case
1332 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001333 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001334 * <p>The calling device admin must have requested
1335 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1336 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001337 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001338 * Can not be called from a managed profile.
1339 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001340 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001341 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001342 * @return Returns true if the password was applied, or false if it is
1343 * not acceptable for the current constraints.
1344 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001345 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001346 if (mService != null) {
1347 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001348 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001349 } catch (RemoteException e) {
1350 Log.w(TAG, "Failed talking with device policy service", e);
1351 }
1352 }
1353 return false;
1354 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001355
Dianne Hackbornd6847842010-01-12 18:14:19 -08001356 /**
1357 * Called by an application that is administering the device to set the
1358 * maximum time for user activity until the device will lock. This limits
1359 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001360 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001361 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001362 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001363 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001364 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001365 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001366 * @param timeMs The new desired maximum time to lock in milliseconds.
1367 * A value of 0 means there is no restriction.
1368 */
1369 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1370 if (mService != null) {
1371 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001372 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001373 } catch (RemoteException e) {
1374 Log.w(TAG, "Failed talking with device policy service", e);
1375 }
1376 }
1377 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001378
Dianne Hackbornd6847842010-01-12 18:14:19 -08001379 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001380 * Retrieve the current maximum time to unlock for all admins of this user
1381 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001382 * @param admin The name of the admin component to check, or null to aggregate
1383 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001384 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001385 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001386 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001387 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001388 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1389 }
1390
1391 /** @hide per-user version */
1392 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001393 if (mService != null) {
1394 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001395 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001396 } catch (RemoteException e) {
1397 Log.w(TAG, "Failed talking with device policy service", e);
1398 }
1399 }
1400 return 0;
1401 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001402
Dianne Hackbornd6847842010-01-12 18:14:19 -08001403 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001404 * Make the device lock immediately, as if the lock screen timeout has
1405 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001406 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001407 * <p>The calling device admin must have requested
1408 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1409 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001410 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001411 public void lockNow() {
1412 if (mService != null) {
1413 try {
1414 mService.lockNow();
1415 } catch (RemoteException e) {
1416 Log.w(TAG, "Failed talking with device policy service", e);
1417 }
1418 }
1419 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001420
Dianne Hackbornd6847842010-01-12 18:14:19 -08001421 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001422 * Flag for {@link #wipeData(int)}: also erase the device's external
1423 * storage.
1424 */
1425 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1426
1427 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001428 * Ask the user data be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001429 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001430 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1431 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001432 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001433 * <p>The calling device admin must have requested
1434 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1435 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001436 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001437 * @param flags Bit mask of additional options: currently 0 and
1438 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001439 */
1440 public void wipeData(int flags) {
1441 if (mService != null) {
1442 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001443 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001444 } catch (RemoteException e) {
1445 Log.w(TAG, "Failed talking with device policy service", e);
1446 }
1447 }
1448 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001449
Dianne Hackbornd6847842010-01-12 18:14:19 -08001450 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001451 * Called by an application that is administering the device to set the
1452 * global proxy and exclusion list.
1453 * <p>
1454 * The calling device admin must have requested
1455 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1456 * this method; if it has not, a security exception will be thrown.
1457 * Only the first device admin can set the proxy. If a second admin attempts
1458 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1459 * proxy will be returned. If successful in setting the proxy, null will
1460 * be returned.
1461 * The method can be called repeatedly by the device admin alrady setting the
1462 * proxy to update the proxy and exclusion list.
1463 *
1464 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1465 * with.
1466 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1467 * Pass Proxy.NO_PROXY to reset the proxy.
1468 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001469 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1470 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001471 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001472 */
1473 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1474 List<String> exclusionList ) {
1475 if (proxySpec == null) {
1476 throw new NullPointerException();
1477 }
1478 if (mService != null) {
1479 try {
1480 String hostSpec;
1481 String exclSpec;
1482 if (proxySpec.equals(Proxy.NO_PROXY)) {
1483 hostSpec = null;
1484 exclSpec = null;
1485 } else {
1486 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1487 throw new IllegalArgumentException();
1488 }
1489 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1490 String hostName = sa.getHostName();
1491 int port = sa.getPort();
1492 StringBuilder hostBuilder = new StringBuilder();
1493 hostSpec = hostBuilder.append(hostName)
1494 .append(":").append(Integer.toString(port)).toString();
1495 if (exclusionList == null) {
1496 exclSpec = "";
1497 } else {
1498 StringBuilder listBuilder = new StringBuilder();
1499 boolean firstDomain = true;
1500 for (String exclDomain : exclusionList) {
1501 if (!firstDomain) {
1502 listBuilder = listBuilder.append(",");
1503 } else {
1504 firstDomain = false;
1505 }
1506 listBuilder = listBuilder.append(exclDomain.trim());
1507 }
1508 exclSpec = listBuilder.toString();
1509 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001510 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1511 != android.net.Proxy.PROXY_VALID)
1512 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001513 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001514 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001515 } catch (RemoteException e) {
1516 Log.w(TAG, "Failed talking with device policy service", e);
1517 }
1518 }
1519 return null;
1520 }
1521
1522 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001523 * Set a network-independent global HTTP proxy. This is not normally what you want
1524 * for typical HTTP proxies - they are generally network dependent. However if you're
1525 * doing something unusual like general internal filtering this may be useful. On
1526 * a private network where the proxy is not accessible, you may break HTTP using this.
1527 *
1528 * <p>This method requires the caller to be the device owner.
1529 *
1530 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1531 * @see ProxyInfo
1532 *
1533 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1534 * with.
1535 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1536 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1537 */
1538 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1539 if (mService != null) {
1540 try {
1541 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1542 } catch (RemoteException e) {
1543 Log.w(TAG, "Failed talking with device policy service", e);
1544 }
1545 }
1546 }
1547
1548 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001549 * Returns the component name setting the global proxy.
1550 * @return ComponentName object of the device admin that set the global proxy, or
1551 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001552 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001553 */
1554 public ComponentName getGlobalProxyAdmin() {
1555 if (mService != null) {
1556 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001557 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001558 } catch (RemoteException e) {
1559 Log.w(TAG, "Failed talking with device policy service", e);
1560 }
1561 }
1562 return null;
1563 }
1564
1565 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001566 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001567 * indicating that encryption is not supported.
1568 */
1569 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1570
1571 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001572 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001573 * indicating that encryption is supported, but is not currently active.
1574 */
1575 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1576
1577 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001578 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001579 * indicating that encryption is not currently active, but is currently
1580 * being activated. This is only reported by devices that support
1581 * encryption of data and only when the storage is currently
1582 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1583 * to become encrypted will never return this value.
1584 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001585 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001586
1587 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001588 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001589 * indicating that encryption is active.
1590 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001591 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001592
1593 /**
1594 * Activity action: begin the process of encrypting data on the device. This activity should
1595 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1596 * After resuming from this activity, use {@link #getStorageEncryption}
1597 * to check encryption status. However, on some devices this activity may never return, as
1598 * it may trigger a reboot and in some cases a complete data wipe of the device.
1599 */
1600 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1601 public static final String ACTION_START_ENCRYPTION
1602 = "android.app.action.START_ENCRYPTION";
1603
1604 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001605 * Widgets are enabled in keyguard
1606 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001607 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001608
1609 /**
Jim Miller50e62182014-04-23 17:25:00 -07001610 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001611 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001612 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1613
1614 /**
1615 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1616 */
1617 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1618
1619 /**
Jim Miller50e62182014-04-23 17:25:00 -07001620 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1621 */
1622 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1623
1624 /**
1625 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1626 */
1627 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1628
1629 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001630 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001631 * (e.g. PIN/Pattern/Password).
1632 */
1633 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1634
1635 /**
Jim Miller06e34502014-07-17 14:46:05 -07001636 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1637 */
1638 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1639
1640 /**
Jim Miller35207742012-11-02 15:33:20 -07001641 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001642 */
1643 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001644
1645 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001646 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001647 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001648 *
1649 * <p>When multiple device administrators attempt to control device
1650 * encryption, the most secure, supported setting will always be
1651 * used. If any device administrator requests device encryption,
1652 * it will be enabled; Conversely, if a device administrator
1653 * attempts to disable device encryption while another
1654 * device administrator has enabled it, the call to disable will
1655 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1656 *
1657 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001658 * written to other storage areas may or may not be encrypted, and this policy does not require
1659 * or control the encryption of any other storage areas.
1660 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1661 * {@code true}, then the directory returned by
1662 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1663 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001664 *
1665 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1666 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1667 * the encryption key may not be fully secured. For maximum security, the administrator should
1668 * also require (and check for) a pattern, PIN, or password.
1669 *
1670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1671 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001672 * @return the new request status (for all active admins) - will be one of
1673 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1674 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1675 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001676 */
1677 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1678 if (mService != null) {
1679 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001680 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001681 } catch (RemoteException e) {
1682 Log.w(TAG, "Failed talking with device policy service", e);
1683 }
1684 }
1685 return ENCRYPTION_STATUS_UNSUPPORTED;
1686 }
1687
1688 /**
1689 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001690 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001691 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001692 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1693 * this will return the requested encryption setting as an aggregate of all active
1694 * administrators.
1695 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001696 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001697 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001698 if (mService != null) {
1699 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001700 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001701 } catch (RemoteException e) {
1702 Log.w(TAG, "Failed talking with device policy service", e);
1703 }
1704 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001705 return false;
1706 }
1707
1708 /**
1709 * Called by an application that is administering the device to
1710 * determine the current encryption status of the device.
1711 *
1712 * Depending on the returned status code, the caller may proceed in different
1713 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1714 * storage system does not support encryption. If the
1715 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1716 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1717 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1718 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1719 *
Robin Lee7e678712014-07-24 16:41:31 +01001720 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001721 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1722 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1723 */
1724 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001725 return getStorageEncryptionStatus(UserHandle.myUserId());
1726 }
1727
1728 /** @hide per-user version */
1729 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001730 if (mService != null) {
1731 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001732 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001733 } catch (RemoteException e) {
1734 Log.w(TAG, "Failed talking with device policy service", e);
1735 }
1736 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001737 return ENCRYPTION_STATUS_UNSUPPORTED;
1738 }
1739
1740 /**
Robin Lee7e678712014-07-24 16:41:31 +01001741 * Installs the given certificate as a user CA.
1742 *
1743 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1744 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001745 *
1746 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001747 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001748 */
Robin Lee7e678712014-07-24 16:41:31 +01001749 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001750 if (mService != null) {
1751 try {
Robin Lee7e678712014-07-24 16:41:31 +01001752 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001753 } catch (RemoteException e) {
1754 Log.w(TAG, "Failed talking with device policy service", e);
1755 }
1756 }
1757 return false;
1758 }
1759
1760 /**
Robin Lee7e678712014-07-24 16:41:31 +01001761 * Uninstalls the given certificate from trusted user CAs, if present.
1762 *
1763 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1764 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001765 */
Robin Lee7e678712014-07-24 16:41:31 +01001766 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001767 if (mService != null) {
1768 try {
Robin Lee306fe082014-06-19 14:04:24 +00001769 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001770 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001771 } catch (CertificateException e) {
1772 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001773 } catch (RemoteException e) {
1774 Log.w(TAG, "Failed talking with device policy service", e);
1775 }
1776 }
1777 }
1778
1779 /**
Robin Lee7e678712014-07-24 16:41:31 +01001780 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1781 * If a user has installed any certificates by other means than device policy these will be
1782 * included too.
1783 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001785 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001786 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001787 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01001788 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001789 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01001790 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001791 mService.enforceCanManageCaCerts(admin);
1792 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1793 for (String alias : certStore.userAliases()) {
1794 try {
1795 certs.add(certStore.getCertificate(alias).getEncoded());
1796 } catch (CertificateException ce) {
1797 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1798 }
1799 }
1800 } catch (RemoteException re) {
1801 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01001802 }
1803 }
1804 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001805 }
1806
1807 /**
Robin Lee7e678712014-07-24 16:41:31 +01001808 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1809 * means other than device policy will also be removed, except for system CA certificates.
1810 *
1811 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1812 */
1813 public void uninstallAllUserCaCerts(ComponentName admin) {
1814 if (mService != null) {
1815 for (String alias : new TrustedCertificateStore().userAliases()) {
1816 try {
1817 mService.uninstallCaCert(admin, alias);
1818 } catch (RemoteException re) {
1819 Log.w(TAG, "Failed talking with device policy service", re);
1820 }
1821 }
1822 }
1823 }
1824
1825 /**
1826 * Returns whether this certificate is installed as a trusted CA.
1827 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001828 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001829 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001830 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001831 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
1832 if (mService != null) {
1833 try {
1834 mService.enforceCanManageCaCerts(admin);
1835 return getCaCertAlias(certBuffer) != null;
1836 } catch (RemoteException re) {
1837 Log.w(TAG, "Failed talking with device policy service", re);
1838 } catch (CertificateException ce) {
1839 Log.w(TAG, "Could not parse certificate", ce);
1840 }
Maggie Benthallda51e682013-08-08 22:35:44 -04001841 }
1842 return false;
1843 }
1844
1845 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001846 * Called by a device or profile owner to install a certificate and private key pair. The
1847 * keypair will be visible to all apps within the profile.
1848 *
1849 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
1850 * @param privKey The private key to install.
1851 * @param cert The certificate to install.
1852 * @param alias The private key alias under which to install the certificate. If a certificate
1853 * with that alias already exists, it will be overwritten.
1854 * @return {@code true} if the keys were installed, {@code false} otherwise.
1855 */
1856 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
1857 String alias) {
1858 try {
1859 final byte[] pemCert = Credentials.convertToPem(cert);
1860 return mService.installKeyPair(who, privKey.getEncoded(), pemCert, alias);
1861 } catch (CertificateException e) {
1862 Log.w(TAG, "Error encoding certificate", e);
1863 } catch (IOException e) {
1864 Log.w(TAG, "Error writing certificate", e);
1865 } catch (RemoteException e) {
1866 Log.w(TAG, "Failed talking with device policy service", e);
1867 }
1868 return false;
1869 }
1870
1871 /**
Robin Lee306fe082014-06-19 14:04:24 +00001872 * Returns the alias of a given CA certificate in the certificate store, or null if it
1873 * doesn't exist.
1874 */
1875 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1876 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1877 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1878 new ByteArrayInputStream(certBuffer));
1879 return new TrustedCertificateStore().getCertificateAlias(cert);
1880 }
1881
1882 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001883 * Called by an application that is administering the device to disable all cameras
1884 * on the device. After setting this, no applications will be able to access any cameras
1885 * on the device.
1886 *
1887 * <p>The calling device admin must have requested
1888 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1889 * this method; if it has not, a security exception will be thrown.
1890 *
1891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1892 * @param disabled Whether or not the camera should be disabled.
1893 */
1894 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1895 if (mService != null) {
1896 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001897 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001898 } catch (RemoteException e) {
1899 Log.w(TAG, "Failed talking with device policy service", e);
1900 }
1901 }
1902 }
1903
1904 /**
1905 * Determine whether or not the device's cameras have been disabled either by the current
1906 * admin, if specified, or all admins.
1907 * @param admin The name of the admin component to check, or null to check if any admins
1908 * have disabled the camera
1909 */
1910 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001911 return getCameraDisabled(admin, UserHandle.myUserId());
1912 }
1913
1914 /** @hide per-user version */
1915 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001916 if (mService != null) {
1917 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001918 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001919 } catch (RemoteException e) {
1920 Log.w(TAG, "Failed talking with device policy service", e);
1921 }
1922 }
1923 return false;
1924 }
1925
1926 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01001927 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
1928 * screen capture also prevents the content from being shown on display devices that do not have
1929 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
1930 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001931 *
1932 * <p>The calling device admin must be a device or profile owner. If it is not, a
1933 * security exception will be thrown.
1934 *
1935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001936 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001937 */
1938 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
1939 if (mService != null) {
1940 try {
1941 mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled);
1942 } catch (RemoteException e) {
1943 Log.w(TAG, "Failed talking with device policy service", e);
1944 }
1945 }
1946 }
1947
1948 /**
1949 * Determine whether or not screen capture has been disabled by the current
1950 * admin, if specified, or all admins.
1951 * @param admin The name of the admin component to check, or null to check if any admins
1952 * have disabled screen capture.
1953 */
1954 public boolean getScreenCaptureDisabled(ComponentName admin) {
1955 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
1956 }
1957
1958 /** @hide per-user version */
1959 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
1960 if (mService != null) {
1961 try {
1962 return mService.getScreenCaptureDisabled(admin, userHandle);
1963 } catch (RemoteException e) {
1964 Log.w(TAG, "Failed talking with device policy service", e);
1965 }
1966 }
1967 return false;
1968 }
1969
1970 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001971 * Called by a device owner to set whether auto time is required. If auto time is
1972 * required the user cannot set the date and time, but has to use network date and time.
1973 *
1974 * <p>Note: if auto time is required the user can still manually set the time zone.
1975 *
1976 * <p>The calling device admin must be a device owner. If it is not, a security exception will
1977 * be thrown.
1978 *
1979 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1980 * @param required Whether auto time is set required or not.
1981 */
1982 public void setAutoTimeRequired(ComponentName admin, boolean required) {
1983 if (mService != null) {
1984 try {
1985 mService.setAutoTimeRequired(admin, UserHandle.myUserId(), required);
1986 } catch (RemoteException e) {
1987 Log.w(TAG, "Failed talking with device policy service", e);
1988 }
1989 }
1990 }
1991
1992 /**
1993 * @return true if auto time is required.
1994 */
1995 public boolean getAutoTimeRequired() {
1996 if (mService != null) {
1997 try {
1998 return mService.getAutoTimeRequired();
1999 } catch (RemoteException e) {
2000 Log.w(TAG, "Failed talking with device policy service", e);
2001 }
2002 }
2003 return false;
2004 }
2005
2006 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002007 * Called by an application that is administering the device to disable keyguard customizations,
2008 * such as widgets. After setting this, keyguard features will be disabled according to the
2009 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002010 *
2011 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002012 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002013 * this method; if it has not, a security exception will be thrown.
2014 *
2015 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002016 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2017 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002018 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2019 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002020 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002021 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002022 if (mService != null) {
2023 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002024 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07002025 } catch (RemoteException e) {
2026 Log.w(TAG, "Failed talking with device policy service", e);
2027 }
2028 }
2029 }
2030
2031 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002032 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002033 * admin, if specified, or all admins.
2034 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002035 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002036 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2037 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002038 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002039 public int getKeyguardDisabledFeatures(ComponentName admin) {
2040 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002041 }
2042
2043 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002044 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002045 if (mService != null) {
2046 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002047 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002048 } catch (RemoteException e) {
2049 Log.w(TAG, "Failed talking with device policy service", e);
2050 }
2051 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002052 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002053 }
2054
2055 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002056 * @hide
2057 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002058 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002059 if (mService != null) {
2060 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002061 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002062 } catch (RemoteException e) {
2063 Log.w(TAG, "Failed talking with device policy service", e);
2064 }
2065 }
2066 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002067
Dianne Hackbornd6847842010-01-12 18:14:19 -08002068 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002069 * @hide
2070 */
2071 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2072 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2073 }
2074
2075 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002076 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002077 * @hide
2078 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002079 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002080 ActivityInfo ai;
2081 try {
2082 ai = mContext.getPackageManager().getReceiverInfo(cn,
2083 PackageManager.GET_META_DATA);
2084 } catch (PackageManager.NameNotFoundException e) {
2085 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2086 return null;
2087 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002088
Dianne Hackbornd6847842010-01-12 18:14:19 -08002089 ResolveInfo ri = new ResolveInfo();
2090 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002091
Dianne Hackbornd6847842010-01-12 18:14:19 -08002092 try {
2093 return new DeviceAdminInfo(mContext, ri);
2094 } catch (XmlPullParserException e) {
2095 Log.w(TAG, "Unable to parse device policy " + cn, e);
2096 return null;
2097 } catch (IOException e) {
2098 Log.w(TAG, "Unable to parse device policy " + cn, e);
2099 return null;
2100 }
2101 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002102
Dianne Hackbornd6847842010-01-12 18:14:19 -08002103 /**
2104 * @hide
2105 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002106 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2107 if (mService != null) {
2108 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002109 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002110 } catch (RemoteException e) {
2111 Log.w(TAG, "Failed talking with device policy service", e);
2112 }
2113 }
2114 }
2115
2116 /**
2117 * @hide
2118 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002119 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002120 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002121 if (mService != null) {
2122 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002123 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002124 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002125 } catch (RemoteException e) {
2126 Log.w(TAG, "Failed talking with device policy service", e);
2127 }
2128 }
2129 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002130
Dianne Hackbornd6847842010-01-12 18:14:19 -08002131 /**
2132 * @hide
2133 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002134 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002135 if (mService != null) {
2136 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002137 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002138 } catch (RemoteException e) {
2139 Log.w(TAG, "Failed talking with device policy service", e);
2140 }
2141 }
2142 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002143
Dianne Hackbornd6847842010-01-12 18:14:19 -08002144 /**
2145 * @hide
2146 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002147 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002148 if (mService != null) {
2149 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002150 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002151 } catch (RemoteException e) {
2152 Log.w(TAG, "Failed talking with device policy service", e);
2153 }
2154 }
2155 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002156
2157 /**
2158 * @hide
2159 * Sets the given package as the device owner. The package must already be installed and there
2160 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2161 * method must be called before the device is provisioned.
2162 * @param packageName the package name of the application to be registered as the device owner.
2163 * @return whether the package was successfully registered as the device owner.
2164 * @throws IllegalArgumentException if the package name is null or invalid
2165 * @throws IllegalStateException if a device owner is already registered or the device has
2166 * already been provisioned.
2167 */
2168 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2169 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002170 return setDeviceOwner(packageName, null);
2171 }
2172
2173 /**
2174 * @hide
2175 * Sets the given package as the device owner. The package must already be installed and there
2176 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2177 * method must be called before the device is provisioned.
2178 * @param packageName the package name of the application to be registered as the device owner.
2179 * @param ownerName the human readable name of the institution that owns this device.
2180 * @return whether the package was successfully registered as the device owner.
2181 * @throws IllegalArgumentException if the package name is null or invalid
2182 * @throws IllegalStateException if a device owner is already registered or the device has
2183 * already been provisioned.
2184 */
2185 public boolean setDeviceOwner(String packageName, String ownerName)
2186 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002187 if (mService != null) {
2188 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002189 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002190 } catch (RemoteException re) {
2191 Log.w(TAG, "Failed to set device owner");
2192 }
2193 }
2194 return false;
2195 }
2196
2197 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002198 * Used to determine if a particular package has been registered as a Device Owner app.
2199 * A device owner app is a special device admin that cannot be deactivated by the user, once
2200 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2201 * package is currently registered as the device owner app, pass in the package name from
2202 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2203 * admin apps that want to check if they are also registered as the device owner app. The
2204 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2205 * the setup process.
2206 * @param packageName the package name of the app, to compare with the registered device owner
2207 * app, if any.
2208 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002209 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002210 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002211 if (mService != null) {
2212 try {
2213 return mService.isDeviceOwner(packageName);
2214 } catch (RemoteException re) {
2215 Log.w(TAG, "Failed to check device owner");
2216 }
2217 }
2218 return false;
2219 }
2220
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002221 /**
2222 * @hide
2223 * Redirect to isDeviceOwnerApp.
2224 */
2225 public boolean isDeviceOwner(String packageName) {
2226 return isDeviceOwnerApp(packageName);
2227 }
2228
Jason Monkb0dced82014-06-06 14:36:20 -04002229 /**
2230 * Clears the current device owner. The caller must be the device owner.
2231 *
2232 * This function should be used cautiously as once it is called it cannot
2233 * be undone. The device owner can only be set as a part of device setup
2234 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002235 *
2236 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002237 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002238 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002239 if (mService != null) {
2240 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002241 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002242 } catch (RemoteException re) {
2243 Log.w(TAG, "Failed to clear device owner");
2244 }
2245 }
2246 }
2247
Amith Yamasani71e6c692013-03-24 17:39:28 -07002248 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002249 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002250 public String getDeviceOwner() {
2251 if (mService != null) {
2252 try {
2253 return mService.getDeviceOwner();
2254 } catch (RemoteException re) {
2255 Log.w(TAG, "Failed to get device owner");
2256 }
2257 }
2258 return null;
2259 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002260
2261 /** @hide */
2262 public String getDeviceOwnerName() {
2263 if (mService != null) {
2264 try {
2265 return mService.getDeviceOwnerName();
2266 } catch (RemoteException re) {
2267 Log.w(TAG, "Failed to get device owner");
2268 }
2269 }
2270 return null;
2271 }
Adam Connors776c5552014-01-09 10:42:56 +00002272
2273 /**
2274 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002275 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302276 * Sets the given component as an active admin and registers the package as the profile
2277 * owner for this user. The package must already be installed and there shouldn't be
2278 * an existing profile owner registered for this user. Also, this method must be called
2279 * before the user setup has been completed.
2280 * <p>
2281 * This method can only be called by system apps that hold MANAGE_USERS permission and
2282 * MANAGE_DEVICE_ADMINS permission.
2283 * @param admin The component to register as an active admin and profile owner.
2284 * @param ownerName The user-visible name of the entity that is managing this user.
2285 * @return whether the admin was successfully registered as the profile owner.
2286 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2287 * the user has already been set up.
2288 */
Justin Morey80440cc2014-07-24 09:16:35 -05002289 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302290 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2291 throws IllegalArgumentException {
2292 if (mService != null) {
2293 try {
2294 final int myUserId = UserHandle.myUserId();
2295 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002296 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302297 } catch (RemoteException re) {
2298 Log.w(TAG, "Failed to set profile owner " + re);
2299 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2300 }
2301 }
2302 return false;
2303 }
2304
2305 /**
2306 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002307 * Clears the active profile owner and removes all user restrictions. The caller must
2308 * be from the same package as the active profile owner for this user, otherwise a
2309 * SecurityException will be thrown.
2310 *
2311 * @param admin The component to remove as the profile owner.
2312 * @return
2313 */
2314 @SystemApi
2315 public void clearProfileOwner(ComponentName admin) {
2316 if (mService != null) {
2317 try {
2318 mService.clearProfileOwner(admin);
2319 } catch (RemoteException re) {
2320 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2321 }
2322 }
2323 }
2324
2325 /**
2326 * @hide
2327 * Checks if the user was already setup.
2328 */
2329 public boolean hasUserSetupCompleted() {
2330 if (mService != null) {
2331 try {
2332 return mService.hasUserSetupCompleted();
2333 } catch (RemoteException re) {
2334 Log.w(TAG, "Failed to check if user setup has completed");
2335 }
2336 }
2337 return true;
2338 }
2339
2340 /**
2341 * @deprecated Use setProfileOwner(ComponentName ...)
2342 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002343 * Sets the given package as the profile owner of the given user profile. The package must
2344 * already be installed and there shouldn't be an existing profile owner registered for this
2345 * user. Also, this method must be called before the user has been used for the first time.
2346 * @param packageName the package name of the application to be registered as profile owner.
2347 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002348 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002349 * @return whether the package was successfully registered as the profile owner.
2350 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2351 * the user has already been set up.
2352 */
Adam Connors661ec472014-02-11 13:59:46 +00002353 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002354 throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002355 if (packageName == null) {
2356 throw new NullPointerException("packageName cannot be null");
2357 }
2358 return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle);
2359 }
2360
2361 /**
2362 * @hide
2363 * Sets the given component as the profile owner of the given user profile. The package must
2364 * already be installed and there shouldn't be an existing profile owner registered for this
2365 * user. Only the system can call this API if the user has already completed setup.
2366 * @param admin the component name to be registered as profile owner.
2367 * @param ownerName the human readable name of the organisation associated with this DPM.
2368 * @param userHandle the userId to set the profile owner for.
2369 * @return whether the component was successfully registered as the profile owner.
2370 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2371 * the user has already been set up.
2372 */
2373 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2374 throws IllegalArgumentException {
2375 if (admin == null) {
2376 throw new NullPointerException("admin cannot be null");
2377 }
Adam Connors776c5552014-01-09 10:42:56 +00002378 if (mService != null) {
2379 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002380 if (ownerName == null) {
2381 ownerName = "";
2382 }
2383 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002384 } catch (RemoteException re) {
2385 Log.w(TAG, "Failed to set profile owner", re);
2386 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2387 }
2388 }
2389 return false;
2390 }
2391
2392 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002393 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2394 * be used. Only the profile owner can call this.
2395 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002396 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002397 *
2398 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2399 */
2400 public void setProfileEnabled(ComponentName admin) {
2401 if (mService != null) {
2402 try {
2403 mService.setProfileEnabled(admin);
2404 } catch (RemoteException e) {
2405 Log.w(TAG, "Failed talking with device policy service", e);
2406 }
2407 }
2408 }
2409
2410 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002411 * Sets the name of the profile. In the device owner case it sets the name of the user
2412 * which it is called from. Only a profile owner or device owner can call this. If this is
Jessica Hummel1333ea12014-06-23 11:20:10 +01002413 * never called by the profile or device owner, the name will be set to default values.
2414 *
2415 * @see #isProfileOwnerApp
2416 * @see #isDeviceOwnerApp
2417 *
2418 * @param profileName The name of the profile.
2419 */
2420 public void setProfileName(ComponentName who, String profileName) {
2421 if (mService != null) {
2422 try {
2423 mService.setProfileName(who, profileName);
2424 } catch (RemoteException e) {
2425 Log.w(TAG, "Failed talking with device policy service", e);
2426 }
2427 }
2428}
2429
2430 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002431 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002432 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002433 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002434 *
2435 * @param packageName The package name of the app to compare with the registered profile owner.
2436 * @return Whether or not the package is registered as the profile owner.
2437 */
2438 public boolean isProfileOwnerApp(String packageName) {
2439 if (mService != null) {
2440 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002441 ComponentName profileOwner = mService.getProfileOwner(
2442 Process.myUserHandle().getIdentifier());
2443 return profileOwner != null
2444 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002445 } catch (RemoteException re) {
2446 Log.w(TAG, "Failed to check profile owner");
2447 }
2448 }
2449 return false;
2450 }
2451
2452 /**
2453 * @hide
2454 * @return the packageName of the owner of the given user profile or null if no profile
2455 * owner has been set for that user.
2456 * @throws IllegalArgumentException if the userId is invalid.
2457 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002458 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002459 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002460 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2461 }
2462
2463 /**
2464 * @see #getProfileOwner()
2465 * @hide
2466 */
2467 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002468 if (mService != null) {
2469 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002470 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002471 } catch (RemoteException re) {
2472 Log.w(TAG, "Failed to get profile owner");
2473 throw new IllegalArgumentException(
2474 "Requested profile owner for invalid userId", re);
2475 }
2476 }
2477 return null;
2478 }
2479
2480 /**
2481 * @hide
2482 * @return the human readable name of the organisation associated with this DPM or null if
2483 * one is not set.
2484 * @throws IllegalArgumentException if the userId is invalid.
2485 */
2486 public String getProfileOwnerName() throws IllegalArgumentException {
2487 if (mService != null) {
2488 try {
2489 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2490 } catch (RemoteException re) {
2491 Log.w(TAG, "Failed to get profile owner");
2492 throw new IllegalArgumentException(
2493 "Requested profile owner for invalid userId", re);
2494 }
2495 }
2496 return null;
2497 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002498
2499 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002500 * @hide
2501 * @param user The user for whom to fetch the profile owner name, if any.
2502 * @return the human readable name of the organisation associated with this profile owner or
2503 * null if one is not set.
2504 * @throws IllegalArgumentException if the userId is invalid.
2505 */
2506 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002507 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002508 if (mService != null) {
2509 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002510 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002511 } catch (RemoteException re) {
2512 Log.w(TAG, "Failed to get profile owner");
2513 throw new IllegalArgumentException(
2514 "Requested profile owner for invalid userId", re);
2515 }
2516 }
2517 return null;
2518 }
2519
2520 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002521 * Called by a profile owner or device owner to add a default intent handler activity for
2522 * intents that match a certain intent filter. This activity will remain the default intent
2523 * handler even if the set of potential event handlers for the intent filter changes and if
2524 * the intent preferences are reset.
2525 *
2526 * <p>The default disambiguation mechanism takes over if the activity is not installed
2527 * (anymore). When the activity is (re)installed, it is automatically reset as default
2528 * intent handler for the filter.
2529 *
2530 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2531 * security exception will be thrown.
2532 *
2533 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2534 * @param filter The IntentFilter for which a default handler is added.
2535 * @param activity The Activity that is added as default intent handler.
2536 */
2537 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2538 ComponentName activity) {
2539 if (mService != null) {
2540 try {
2541 mService.addPersistentPreferredActivity(admin, filter, activity);
2542 } catch (RemoteException e) {
2543 Log.w(TAG, "Failed talking with device policy service", e);
2544 }
2545 }
2546 }
2547
2548 /**
2549 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002550 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002551 *
2552 * <p>The calling device admin must be a profile owner. If it is not, a security
2553 * exception will be thrown.
2554 *
2555 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2556 * @param packageName The name of the package for which preferences are removed.
2557 */
2558 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2559 String packageName) {
2560 if (mService != null) {
2561 try {
2562 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2563 } catch (RemoteException e) {
2564 Log.w(TAG, "Failed talking with device policy service", e);
2565 }
2566 }
2567 }
Robin Lee66e5d962014-04-09 16:44:21 +01002568
2569 /**
2570 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002571 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002572 *
2573 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Amith Yamasanic8c84252014-07-13 17:12:12 -07002574 * boolean, int, String, or String[]. The recommended format for keys
Robin Lee66e5d962014-04-09 16:44:21 +01002575 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2576 * components such as {@link android.webkit.WebView}.
2577 *
2578 * <p>The application restrictions are only made visible to the target application and the
2579 * profile or device owner.
2580 *
2581 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2582 * exception will be thrown.
2583 *
2584 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2585 * @param packageName The name of the package to update restricted settings for.
2586 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2587 * set of active restrictions.
2588 */
2589 public void setApplicationRestrictions(ComponentName admin, String packageName,
2590 Bundle settings) {
2591 if (mService != null) {
2592 try {
2593 mService.setApplicationRestrictions(admin, packageName, settings);
2594 } catch (RemoteException e) {
2595 Log.w(TAG, "Failed talking with device policy service", e);
2596 }
2597 }
2598 }
2599
2600 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002601 * Sets a list of features to enable for a TrustAgent component. This is meant to be
Jim Miller604e7552014-07-18 19:00:02 -07002602 * used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which will disable all
2603 * trust agents but those with features enabled by this function call.
2604 *
2605 * <p>The calling device admin must have requested
2606 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
2607 * this method; if it has not, a security exception will be thrown.
2608 *
2609 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2610 * @param agent Which component to enable features for.
2611 * @param features List of features to enable. Consult specific TrustAgent documentation for
2612 * the feature list.
Jim Millerb1474f42014-08-26 18:42:58 -07002613 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002614 */
2615 public void setTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent,
2616 List<String> features) {
2617 if (mService != null) {
2618 try {
2619 mService.setTrustAgentFeaturesEnabled(admin, agent, features, UserHandle.myUserId());
2620 } catch (RemoteException e) {
2621 Log.w(TAG, "Failed talking with device policy service", e);
2622 }
2623 }
2624 }
2625
2626 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002627 * Gets list of enabled features for the given TrustAgent component. If admin is
Jim Miller604e7552014-07-18 19:00:02 -07002628 * null, this will return the intersection of all features enabled for the given agent by all
2629 * admins.
2630 *
2631 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2632 * @param agent Which component to get enabled features for.
2633 * @return List of enabled features.
Jim Millerb1474f42014-08-26 18:42:58 -07002634 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002635 */
2636 public List<String> getTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent) {
2637 if (mService != null) {
2638 try {
2639 return mService.getTrustAgentFeaturesEnabled(admin, agent, UserHandle.myUserId());
2640 } catch (RemoteException e) {
2641 Log.w(TAG, "Failed talking with device policy service", e);
2642 }
2643 }
2644 return new ArrayList<String>(); // empty list
2645 }
2646
2647 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002648 * Called by a profile owner of a managed profile to set whether caller-Id information from
2649 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01002650 *
2651 * <p>The calling device admin must be a profile owner. If it is not, a
2652 * security exception will be thrown.
2653 *
2654 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2655 * @param disabled If true caller-Id information in the managed profile is not displayed.
2656 */
2657 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2658 if (mService != null) {
2659 try {
2660 mService.setCrossProfileCallerIdDisabled(who, disabled);
2661 } catch (RemoteException e) {
2662 Log.w(TAG, "Failed talking with device policy service", e);
2663 }
2664 }
2665 }
2666
2667 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002668 * Called by a profile owner of a managed profile to determine whether or not caller-Id
2669 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01002670 *
2671 * <p>The calling device admin must be a profile owner. If it is not, a
2672 * security exception will be thrown.
2673 *
2674 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2675 */
2676 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2677 if (mService != null) {
2678 try {
2679 return mService.getCrossProfileCallerIdDisabled(who);
2680 } catch (RemoteException e) {
2681 Log.w(TAG, "Failed talking with device policy service", e);
2682 }
2683 }
2684 return false;
2685 }
2686
2687 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002688 * Determine whether or not caller-Id information has been disabled.
2689 *
2690 * @param userHandle The user for whom to check the caller-id permission
2691 * @hide
2692 */
2693 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2694 if (mService != null) {
2695 try {
2696 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2697 } catch (RemoteException e) {
2698 Log.w(TAG, "Failed talking with device policy service", e);
2699 }
2700 }
2701 return false;
2702 }
2703
2704 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002705 * Called by the profile owner of a managed profile so that some intents sent in the managed
2706 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002707 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002708 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2709 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002710 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2711 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002712 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002713 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002714 if (mService != null) {
2715 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002716 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002717 } catch (RemoteException e) {
2718 Log.w(TAG, "Failed talking with device policy service", e);
2719 }
2720 }
2721 }
2722
2723 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002724 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
2725 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002726 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002727 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2728 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002729 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002730 if (mService != null) {
2731 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002732 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002733 } catch (RemoteException e) {
2734 Log.w(TAG, "Failed talking with device policy service", e);
2735 }
2736 }
2737 }
2738
2739 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002740 * Called by a profile or device owner to set the permitted accessibility services. When
2741 * set by a device owner or profile owner the restriction applies to all profiles of the
2742 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07002743 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002744 * By default the user can use any accessiblity service. When zero or more packages have
2745 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07002746 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002747 *
2748 * <p> Calling with a null value for the list disables the restriction so that all services
2749 * can be used, calling with an empty list only allows the builtin system's services.
2750 *
2751 * <p> System accesibility services are always available to the user the list can't modify
2752 * this.
2753 *
2754 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2755 * @param packageNames List of accessibility service package names.
2756 *
2757 * @return true if setting the restriction succeeded. It fail if there is
2758 * one or more non-system accessibility services enabled, that are not in the list.
2759 */
2760 public boolean setPermittedAccessibilityServices(ComponentName admin,
2761 List<String> packageNames) {
2762 if (mService != null) {
2763 try {
2764 return mService.setPermittedAccessibilityServices(admin, packageNames);
2765 } catch (RemoteException e) {
2766 Log.w(TAG, "Failed talking with device policy service", e);
2767 }
2768 }
2769 return false;
2770 }
2771
2772 /**
2773 * Returns the list of permitted accessibility services set by this device or profile owner.
2774 *
2775 * <p>An empty list means no accessibility services except system services are allowed.
2776 * Null means all accessibility services are allowed.
2777 *
2778 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2779 * @return List of accessiblity service package names.
2780 */
2781 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2782 if (mService != null) {
2783 try {
2784 return mService.getPermittedAccessibilityServices(admin);
2785 } catch (RemoteException e) {
2786 Log.w(TAG, "Failed talking with device policy service", e);
2787 }
2788 }
2789 return null;
2790 }
2791
2792 /**
2793 * Returns the list of accessibility services permitted by the device or profiles
2794 * owners of this user.
2795 *
2796 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2797 * it will contain the intersection of the permitted lists for any device or profile
2798 * owners that apply to this user. It will also include any system accessibility services.
2799 *
2800 * @param userId which user to check for.
2801 * @return List of accessiblity service package names.
2802 * @hide
2803 */
2804 @SystemApi
2805 public List<String> getPermittedAccessibilityServices(int userId) {
2806 if (mService != null) {
2807 try {
2808 return mService.getPermittedAccessibilityServicesForUser(userId);
2809 } catch (RemoteException e) {
2810 Log.w(TAG, "Failed talking with device policy service", e);
2811 }
2812 }
2813 return null;
2814 }
2815
2816 /**
2817 * Called by a profile or device owner to set the permitted input methods services. When
2818 * set by a device owner or profile owner the restriction applies to all profiles of the
2819 * user the device owner or profile owner is an admin for.
2820 *
2821 * By default the user can use any input method. When zero or more packages have
2822 * been added, input method that are not in the list and not part of the system
2823 * can not be enabled by the user.
2824 *
2825 * This method will fail if it is called for a admin that is not for the foreground user
2826 * or a profile of the foreground user.
2827 *
2828 * <p> Calling with a null value for the list disables the restriction so that all input methods
2829 * can be used, calling with an empty list disables all but the system's own input methods.
2830 *
2831 * <p> System input methods are always available to the user this method can't modify this.
2832 *
2833 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2834 * @param packageNames List of input method package names.
2835 * @return true if setting the restriction succeeded. It will fail if there is
2836 * one or more input method enabled, that are not in the list or user if the foreground
2837 * user.
2838 */
2839 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2840 if (mService != null) {
2841 try {
2842 return mService.setPermittedInputMethods(admin, packageNames);
2843 } catch (RemoteException e) {
2844 Log.w(TAG, "Failed talking with device policy service", e);
2845 }
2846 }
2847 return false;
2848 }
2849
2850
2851 /**
2852 * Returns the list of permitted input methods set by this device or profile owner.
2853 *
2854 * <p>An empty list means no input methods except system input methods are allowed.
2855 * Null means all input methods are allowed.
2856 *
2857 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2858 * @return List of input method package names.
2859 */
2860 public List<String> getPermittedInputMethods(ComponentName admin) {
2861 if (mService != null) {
2862 try {
2863 return mService.getPermittedInputMethods(admin);
2864 } catch (RemoteException e) {
2865 Log.w(TAG, "Failed talking with device policy service", e);
2866 }
2867 }
2868 return null;
2869 }
2870
2871 /**
2872 * Returns the list of input methods permitted by the device or profiles
2873 * owners of the current user.
2874 *
2875 * <p>Null means all input methods are allowed, if a non-null list is returned
2876 * it will contain the intersection of the permitted lists for any device or profile
2877 * owners that apply to this user. It will also include any system input methods.
2878 *
2879 * @return List of input method package names.
2880 * @hide
2881 */
2882 @SystemApi
2883 public List<String> getPermittedInputMethodsForCurrentUser() {
2884 if (mService != null) {
2885 try {
2886 return mService.getPermittedInputMethodsForCurrentUser();
2887 } catch (RemoteException e) {
2888 Log.w(TAG, "Failed talking with device policy service", e);
2889 }
2890 }
2891 return null;
2892 }
2893
2894 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002895 * Called by a device owner to create a user with the specified name. The UserHandle returned
2896 * by this method should not be persisted as user handles are recycled as users are removed and
2897 * created. If you need to persist an identifier for this user, use
2898 * {@link UserManager#getSerialNumberForUser}.
2899 *
2900 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2901 * @param name the user's name
2902 * @see UserHandle
2903 * @return the UserHandle object for the created user, or null if the user could not be created.
2904 */
2905 public UserHandle createUser(ComponentName admin, String name) {
2906 try {
2907 return mService.createUser(admin, name);
2908 } catch (RemoteException re) {
2909 Log.w(TAG, "Could not create a user", re);
2910 }
2911 return null;
2912 }
2913
2914 /**
Jason Monk03978a42014-06-10 15:05:30 -04002915 * Called by a device owner to create a user with the specified name. The UserHandle returned
2916 * by this method should not be persisted as user handles are recycled as users are removed and
2917 * created. If you need to persist an identifier for this user, use
2918 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2919 * immediately.
2920 *
2921 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2922 * as registered as an active admin on the new user. The profile owner package will be
2923 * installed on the new user if it already is installed on the device.
2924 *
2925 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2926 * profileOwnerComponent when onEnable is called.
2927 *
2928 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2929 * @param name the user's name
2930 * @param ownerName the human readable name of the organisation associated with this DPM.
2931 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2932 * the user.
2933 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2934 * on the new user.
2935 * @see UserHandle
2936 * @return the UserHandle object for the created user, or null if the user could not be created.
2937 */
2938 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2939 ComponentName profileOwnerComponent, Bundle adminExtras) {
2940 try {
2941 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2942 adminExtras);
2943 } catch (RemoteException re) {
2944 Log.w(TAG, "Could not create a user", re);
2945 }
2946 return null;
2947 }
2948
2949 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002950 * Called by a device owner to remove a user and all associated data. The primary user can
2951 * not be removed.
2952 *
2953 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2954 * @param userHandle the user to remove.
2955 * @return {@code true} if the user was removed, {@code false} otherwise.
2956 */
2957 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2958 try {
2959 return mService.removeUser(admin, userHandle);
2960 } catch (RemoteException re) {
2961 Log.w(TAG, "Could not remove user ", re);
2962 return false;
2963 }
2964 }
2965
2966 /**
Jason Monk582d9112014-07-09 19:57:08 -04002967 * Called by a device owner to switch the specified user to the foreground.
2968 *
2969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2970 * @param userHandle the user to switch to; null will switch to primary.
2971 * @return {@code true} if the switch was successful, {@code false} otherwise.
2972 *
2973 * @see Intent#ACTION_USER_FOREGROUND
2974 */
2975 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
2976 try {
2977 return mService.switchUser(admin, userHandle);
2978 } catch (RemoteException re) {
2979 Log.w(TAG, "Could not switch user ", re);
2980 return false;
2981 }
2982 }
2983
2984 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002985 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002986 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002987 *
2988 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2989 * exception will be thrown.
2990 *
2991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2992 * @param packageName The name of the package to fetch restricted settings of.
2993 * @return {@link Bundle} of settings corresponding to what was set last time
2994 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2995 * if no restrictions have been set.
2996 */
2997 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2998 if (mService != null) {
2999 try {
3000 return mService.getApplicationRestrictions(admin, packageName);
3001 } catch (RemoteException e) {
3002 Log.w(TAG, "Failed talking with device policy service", e);
3003 }
3004 }
3005 return null;
3006 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003007
3008 /**
3009 * Called by a profile or device owner to set a user restriction specified
3010 * by the key.
3011 * <p>
3012 * The calling device admin must be a profile or device owner; if it is not,
3013 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003014 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003015 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3016 * with.
3017 * @param key The key of the restriction. See the constants in
3018 * {@link android.os.UserManager} for the list of keys.
3019 */
3020 public void addUserRestriction(ComponentName admin, String key) {
3021 if (mService != null) {
3022 try {
3023 mService.setUserRestriction(admin, key, true);
3024 } catch (RemoteException e) {
3025 Log.w(TAG, "Failed talking with device policy service", e);
3026 }
3027 }
3028 }
3029
3030 /**
3031 * Called by a profile or device owner to clear a user restriction specified
3032 * by the key.
3033 * <p>
3034 * The calling device admin must be a profile or device owner; if it is not,
3035 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003036 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003037 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3038 * with.
3039 * @param key The key of the restriction. See the constants in
3040 * {@link android.os.UserManager} for the list of keys.
3041 */
3042 public void clearUserRestriction(ComponentName admin, String key) {
3043 if (mService != null) {
3044 try {
3045 mService.setUserRestriction(admin, key, false);
3046 } catch (RemoteException e) {
3047 Log.w(TAG, "Failed talking with device policy service", e);
3048 }
3049 }
3050 }
Adam Connors010cfd42014-04-16 12:48:13 +01003051
3052 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003053 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003054 * is unavailable for use, but the data and actual package file remain.
3055 *
3056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003057 * @param packageName The name of the package to hide or unhide.
3058 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3059 * unhidden.
3060 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003061 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003062 public boolean setApplicationHidden(ComponentName admin, String packageName,
3063 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003064 if (mService != null) {
3065 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003066 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003067 } catch (RemoteException e) {
3068 Log.w(TAG, "Failed talking with device policy service", e);
3069 }
3070 }
3071 return false;
3072 }
3073
3074 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003075 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003076 *
3077 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003078 * @param packageName The name of the package to retrieve the hidden status of.
3079 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003080 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003081 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003082 if (mService != null) {
3083 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003084 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003085 } catch (RemoteException e) {
3086 Log.w(TAG, "Failed talking with device policy service", e);
3087 }
3088 }
3089 return false;
3090 }
3091
3092 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003093 * Called by profile or device owner to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003094 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003095 *
3096 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3097 * @param packageName The package to be re-enabled in the current profile.
3098 */
3099 public void enableSystemApp(ComponentName admin, String packageName) {
3100 if (mService != null) {
3101 try {
3102 mService.enableSystemApp(admin, packageName);
3103 } catch (RemoteException e) {
3104 Log.w(TAG, "Failed to install package: " + packageName);
3105 }
3106 }
3107 }
3108
3109 /**
3110 * Called by profile or device owner to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003111 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003112 *
3113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3114 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3115 * intent will be re-enabled in the current profile.
3116 * @return int The number of activities that matched the intent and were installed.
3117 */
3118 public int enableSystemApp(ComponentName admin, Intent intent) {
3119 if (mService != null) {
3120 try {
3121 return mService.enableSystemAppWithIntent(admin, intent);
3122 } catch (RemoteException e) {
3123 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3124 }
3125 }
3126 return 0;
3127 }
3128
3129 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01003130 * Called by a profile owner to disable account management for a specific type of account.
3131 *
3132 * <p>The calling device admin must be a profile owner. If it is not, a
3133 * security exception will be thrown.
3134 *
3135 * <p>When account management is disabled for an account type, adding or removing an account
3136 * of that type will not be possible.
3137 *
3138 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3139 * @param accountType For which account management is disabled or enabled.
3140 * @param disabled The boolean indicating that account management will be disabled (true) or
3141 * enabled (false).
3142 */
3143 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3144 boolean disabled) {
3145 if (mService != null) {
3146 try {
3147 mService.setAccountManagementDisabled(admin, accountType, disabled);
3148 } catch (RemoteException e) {
3149 Log.w(TAG, "Failed talking with device policy service", e);
3150 }
3151 }
3152 }
3153
3154 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003155 * Gets the array of accounts for which account management is disabled by the profile owner.
3156 *
3157 * <p> Account management can be disabled/enabled by calling
3158 * {@link #setAccountManagementDisabled}.
3159 *
3160 * @return a list of account types for which account management has been disabled.
3161 *
3162 * @see #setAccountManagementDisabled
3163 */
3164 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003165 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003166 }
3167
3168 /**
3169 * @see #getAccountTypesWithManagementDisabled()
3170 * @hide
3171 */
3172 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003173 if (mService != null) {
3174 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003175 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003176 } catch (RemoteException e) {
3177 Log.w(TAG, "Failed talking with device policy service", e);
3178 }
3179 }
3180
3181 return null;
3182 }
justinzhang511e0d82014-03-24 16:09:24 -04003183
3184 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003185 * Sets which packages may enter lock task mode.
3186 *
3187 * <p>Any packages that shares uid with an allowed package will also be allowed
3188 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003189 *
Jason Monkc5185f22014-06-24 11:12:42 -04003190 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003191 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003192 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003193 *
3194 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003195 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3196 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003197 */
Jason Monk48aacba2014-08-13 16:29:08 -04003198 public void setLockTaskPackages(ComponentName admin, String[] packages)
3199 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003200 if (mService != null) {
3201 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003202 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003203 } catch (RemoteException e) {
3204 Log.w(TAG, "Failed talking with device policy service", e);
3205 }
3206 }
3207 }
3208
3209 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003210 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003211 *
3212 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003213 * @hide
3214 */
Jason Monk48aacba2014-08-13 16:29:08 -04003215 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003216 if (mService != null) {
3217 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003218 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003219 } catch (RemoteException e) {
3220 Log.w(TAG, "Failed talking with device policy service", e);
3221 }
3222 }
3223 return null;
3224 }
3225
3226 /**
3227 * This function lets the caller know whether the given component is allowed to start the
3228 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003229 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003230 */
Jason Monkd7b86212014-06-16 13:15:38 -04003231 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003232 if (mService != null) {
3233 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003234 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003235 } catch (RemoteException e) {
3236 Log.w(TAG, "Failed talking with device policy service", e);
3237 }
3238 }
3239 return false;
3240 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003241
3242 /**
3243 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3244 * of the setting is in the correct form for the setting type should be performed by the caller.
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003245 * <p>The settings that can be updated with this method are:
3246 * <ul>
3247 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3248 * <li>{@link Settings.Global#AUTO_TIME}</li>
3249 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
3250 * <li>{@link Settings.Global#BLUETOOTH_ON}</li>
3251 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3252 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3253 * <li>{@link Settings.Global#MODE_RINGER}</li>
3254 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3255 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
3256 * <li>{@link Settings.Global#WIFI_ON}</li>
3257 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3258 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003259 *
3260 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3261 * @param setting The name of the setting to update.
3262 * @param value The value to update the setting to.
3263 */
3264 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3265 if (mService != null) {
3266 try {
3267 mService.setGlobalSetting(admin, setting, value);
3268 } catch (RemoteException e) {
3269 Log.w(TAG, "Failed talking with device policy service", e);
3270 }
3271 }
3272 }
3273
3274 /**
3275 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3276 * that the value of the setting is in the correct form for the setting type should be performed
3277 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003278 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003279 * <ul>
3280 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
3281 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3282 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003283 * <p>A device owner can additionally update the following settings:
3284 * <ul>
3285 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3286 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003287 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3288 * @param setting The name of the setting to update.
3289 * @param value The value to update the setting to.
3290 */
3291 public void setSecureSetting(ComponentName admin, String setting, String value) {
3292 if (mService != null) {
3293 try {
3294 mService.setSecureSetting(admin, setting, value);
3295 } catch (RemoteException e) {
3296 Log.w(TAG, "Failed talking with device policy service", e);
3297 }
3298 }
3299 }
3300
Amith Yamasanif20d6402014-05-24 15:34:37 -07003301 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003302 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003303 * making permission requests of a local or remote administrator of the user.
3304 * <p/>
3305 * Only a profile owner can designate the restrictions provider.
3306 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003307 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003308 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003309 * it removes the restrictions provider previously assigned.
3310 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003311 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003312 if (mService != null) {
3313 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003314 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003315 } catch (RemoteException re) {
3316 Log.w(TAG, "Failed to set permission provider on device policy service");
3317 }
3318 }
3319 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003320
3321 /**
3322 * Called by profile or device owners to set the master volume mute on or off.
3323 *
3324 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3325 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3326 */
3327 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3328 if (mService != null) {
3329 try {
3330 mService.setMasterVolumeMuted(admin, on);
3331 } catch (RemoteException re) {
3332 Log.w(TAG, "Failed to setMasterMute on device policy service");
3333 }
3334 }
3335 }
3336
3337 /**
3338 * Called by profile or device owners to check whether the master volume mute is on or off.
3339 *
3340 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3341 * @return {@code true} if master volume is muted, {@code false} if it's not.
3342 */
3343 public boolean isMasterVolumeMuted(ComponentName admin) {
3344 if (mService != null) {
3345 try {
3346 return mService.isMasterVolumeMuted(admin);
3347 } catch (RemoteException re) {
3348 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3349 }
3350 }
3351 return false;
3352 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003353
3354 /**
3355 * Called by profile or device owners to change whether a user can uninstall
3356 * a package.
3357 *
3358 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3359 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003360 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003361 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003362 public void setUninstallBlocked(ComponentName admin, String packageName,
3363 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003364 if (mService != null) {
3365 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003366 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003367 } catch (RemoteException re) {
3368 Log.w(TAG, "Failed to call block uninstall on device policy service");
3369 }
3370 }
3371 }
3372
3373 /**
3374 * Called by profile or device owners to check whether a user has been blocked from
3375 * uninstalling a package.
3376 *
3377 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3378 * @param packageName package to check.
3379 * @return true if the user shouldn't be able to uninstall the package.
3380 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003381 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003382 if (mService != null) {
3383 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003384 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003385 } catch (RemoteException re) {
3386 Log.w(TAG, "Failed to call block uninstall on device policy service");
3387 }
3388 }
3389 return false;
3390 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003391
3392 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003393 * Called by the profile owner of a managed profile to enable widget providers from a
3394 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003395 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003396 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003397 * a package may have zero or more provider components, where each component
3398 * provides a different widget type.
3399 * <p>
3400 * <strong>Note:</strong> By default no widget provider package is white-listed.
3401 * </p>
3402 *
3403 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3404 * @param packageName The package from which widget providers are white-listed.
3405 * @return Whether the package was added.
3406 *
3407 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3408 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3409 */
3410 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3411 if (mService != null) {
3412 try {
3413 return mService.addCrossProfileWidgetProvider(admin, packageName);
3414 } catch (RemoteException re) {
3415 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3416 }
3417 }
3418 return false;
3419 }
3420
3421 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003422 * Called by the profile owner of a managed profile to disable widget providers from a given
3423 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003424 * package should have been added via {@link #addCrossProfileWidgetProvider(
3425 * android.content.ComponentName, String)}.
3426 * <p>
3427 * <strong>Note:</strong> By default no widget provider package is white-listed.
3428 * </p>
3429 *
3430 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3431 * @param packageName The package from which widget providers are no longer
3432 * white-listed.
3433 * @return Whether the package was removed.
3434 *
3435 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3436 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3437 */
3438 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3439 if (mService != null) {
3440 try {
3441 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3442 } catch (RemoteException re) {
3443 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3444 }
3445 }
3446 return false;
3447 }
3448
3449 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003450 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003451 * available in the parent profile.
3452 *
3453 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3454 * @return The white-listed package list.
3455 *
3456 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3457 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3458 */
3459 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3460 if (mService != null) {
3461 try {
3462 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3463 if (providers != null) {
3464 return providers;
3465 }
3466 } catch (RemoteException re) {
3467 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3468 }
3469 }
3470 return Collections.emptyList();
3471 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003472}