blob: 74502fce9a525d32bccdcbb57fd5b221f3af0700 [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 /**
Jeff Sharkey97978802014-10-14 10:48:18 -0700442 * Flag used by {@link #addCrossProfileIntentFilter} to allow access
443 * <em>from</em> a managed profile <em>to</em> its parent. That is, any
444 * matching activities in the parent profile are included in the
445 * disambiguation list shown when an app in the managed profile calls
446 * {@link Activity#startActivity(Intent)}.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000447 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100448 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000449
450 /**
Jeff Sharkey97978802014-10-14 10:48:18 -0700451 * Flag used by {@link #addCrossProfileIntentFilter} to allow access
452 * <em>from</em> a parent <em>to</em> its managed profile. That is, any
453 * matching activities in the managed profile are included in the
454 * disambiguation list shown when an app in the parent profile calls
455 * {@link Activity#startActivity(Intent)}.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000456 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100457 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700458
Dianne Hackbornd6847842010-01-12 18:14:19 -0800459 /**
460 * Return true if the given administrator component is currently
461 * active (enabled) in the system.
462 */
463 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100464 return isAdminActiveAsUser(who, UserHandle.myUserId());
465 }
466
467 /**
468 * @see #isAdminActive(ComponentName)
469 * @hide
470 */
471 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800472 if (mService != null) {
473 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100474 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800475 } catch (RemoteException e) {
476 Log.w(TAG, "Failed talking with device policy service", e);
477 }
478 }
479 return false;
480 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700481
Dianne Hackbornd6847842010-01-12 18:14:19 -0800482 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800483 * Return a list of all currently active device administrator's component
484 * names. Note that if there are no administrators than null may be
485 * returned.
486 */
487 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100488 return getActiveAdminsAsUser(UserHandle.myUserId());
489 }
490
491 /**
492 * @see #getActiveAdmins()
493 * @hide
494 */
495 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800496 if (mService != null) {
497 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100498 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800499 } catch (RemoteException e) {
500 Log.w(TAG, "Failed talking with device policy service", e);
501 }
502 }
503 return null;
504 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700505
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800506 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700507 * Used by package administration code to determine if a package can be stopped
508 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800509 * @hide
510 */
511 public boolean packageHasActiveAdmins(String packageName) {
512 if (mService != null) {
513 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700514 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800515 } catch (RemoteException e) {
516 Log.w(TAG, "Failed talking with device policy service", e);
517 }
518 }
519 return false;
520 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700521
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800522 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800523 * Remove a current administration component. This can only be called
524 * by the application that owns the administration component; if you
525 * try to remove someone else's component, a security exception will be
526 * thrown.
527 */
528 public void removeActiveAdmin(ComponentName who) {
529 if (mService != null) {
530 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700531 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800532 } catch (RemoteException e) {
533 Log.w(TAG, "Failed talking with device policy service", e);
534 }
535 }
536 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700537
Dianne Hackbornd6847842010-01-12 18:14:19 -0800538 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800539 * Returns true if an administrator has been granted a particular device policy. This can
540 * be used to check if the administrator was activated under an earlier set of policies,
541 * but requires additional policies after an upgrade.
542 *
543 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
544 * an active administrator, or an exception will be thrown.
545 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
546 */
547 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
548 if (mService != null) {
549 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700550 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800551 } catch (RemoteException e) {
552 Log.w(TAG, "Failed talking with device policy service", e);
553 }
554 }
555 return false;
556 }
557
558 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800559 * Constant for {@link #setPasswordQuality}: the policy has no requirements
560 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800561 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800562 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800563 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700564
Dianne Hackbornd6847842010-01-12 18:14:19 -0800565 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700566 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
567 * recognition technology. This implies technologies that can recognize the identity of
568 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
569 * Note that quality constants are ordered so that higher values are more restrictive.
570 */
571 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
572
573 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800574 * Constant for {@link #setPasswordQuality}: the policy requires some kind
575 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800576 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800577 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800578 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700579
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800580 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800581 * Constant for {@link #setPasswordQuality}: the user must have entered a
582 * password containing at least numeric characters. Note that quality
583 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800584 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800585 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700586
Dianne Hackbornd6847842010-01-12 18:14:19 -0800587 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800588 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800589 * password containing at least numeric characters with no repeating (4444)
590 * or ordered (1234, 4321, 2468) sequences. Note that quality
591 * constants are ordered so that higher values are more restrictive.
592 */
593 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
594
595 /**
596 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700597 * password containing at least alphabetic (or other symbol) characters.
598 * Note that quality constants are ordered so that higher values are more
599 * restrictive.
600 */
601 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700602
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700603 /**
604 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800605 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700606 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800607 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800608 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700609 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700610
Dianne Hackbornd6847842010-01-12 18:14:19 -0800611 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700612 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700613 * password containing at least a letter, a numerical digit and a special
614 * symbol, by default. With this password quality, passwords can be
615 * restricted to contain various sets of characters, like at least an
616 * uppercase letter, etc. These are specified using various methods,
617 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
618 * that quality constants are ordered so that higher values are more
619 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700620 */
621 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
622
623 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800624 * Called by an application that is administering the device to set the
625 * password restrictions it is imposing. After setting this, the user
626 * will not be able to enter a new password that is not at least as
627 * restrictive as what has been set. Note that the current password
628 * will remain until the user has set a new one, so the change does not
629 * take place immediately. To prompt the user for a new password, use
630 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700631 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800632 * <p>Quality constants are ordered so that higher values are more restrictive;
633 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800634 * the user's preference, and any other considerations) is the one that
635 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700636 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800637 * <p>The calling device admin must have requested
638 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
639 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700640 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800641 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800642 * @param quality The new desired quality. One of
643 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800644 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
645 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
646 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800647 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800648 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800649 if (mService != null) {
650 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700651 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800652 } catch (RemoteException e) {
653 Log.w(TAG, "Failed talking with device policy service", e);
654 }
655 }
656 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700657
Dianne Hackbornd6847842010-01-12 18:14:19 -0800658 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100659 * Retrieve the current minimum password quality for all admins of this user
660 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800661 * @param admin The name of the admin component to check, or null to aggregate
662 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800663 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800664 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700665 return getPasswordQuality(admin, UserHandle.myUserId());
666 }
667
668 /** @hide per-user version */
669 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800670 if (mService != null) {
671 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700672 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800673 } catch (RemoteException e) {
674 Log.w(TAG, "Failed talking with device policy service", e);
675 }
676 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800677 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800678 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700679
Dianne Hackbornd6847842010-01-12 18:14:19 -0800680 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800681 * Called by an application that is administering the device to set the
682 * minimum allowed password length. After setting this, the user
683 * will not be able to enter a new password that is not at least as
684 * restrictive as what has been set. Note that the current password
685 * will remain until the user has set a new one, so the change does not
686 * take place immediately. To prompt the user for a new password, use
687 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
688 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800689 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
690 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
691 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700692 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800693 * <p>The calling device admin must have requested
694 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
695 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700696 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800698 * @param length The new desired minimum password length. A value of 0
699 * means there is no restriction.
700 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800701 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800702 if (mService != null) {
703 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700704 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800705 } catch (RemoteException e) {
706 Log.w(TAG, "Failed talking with device policy service", e);
707 }
708 }
709 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700710
Dianne Hackbornd6847842010-01-12 18:14:19 -0800711 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100712 * Retrieve the current minimum password length for all admins of this
713 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800714 * @param admin The name of the admin component to check, or null to aggregate
715 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800716 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800717 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700718 return getPasswordMinimumLength(admin, UserHandle.myUserId());
719 }
720
721 /** @hide per-user version */
722 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800723 if (mService != null) {
724 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700725 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800726 } catch (RemoteException e) {
727 Log.w(TAG, "Failed talking with device policy service", e);
728 }
729 }
730 return 0;
731 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700732
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700733 /**
734 * Called by an application that is administering the device to set the
735 * minimum number of upper case letters required in the password. After
736 * setting this, the user will not be able to enter a new password that is
737 * not at least as restrictive as what has been set. Note that the current
738 * password will remain until the user has set a new one, so the change does
739 * not take place immediately. To prompt the user for a new password, use
740 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
741 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700742 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
743 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700744 * <p>
745 * The calling device admin must have requested
746 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
747 * this method; if it has not, a security exception will be thrown.
748 *
749 * @param admin Which {@link DeviceAdminReceiver} this request is associated
750 * with.
751 * @param length The new desired minimum number of upper case letters
752 * required in the password. A value of 0 means there is no
753 * restriction.
754 */
755 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
756 if (mService != null) {
757 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700758 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700759 } catch (RemoteException e) {
760 Log.w(TAG, "Failed talking with device policy service", e);
761 }
762 }
763 }
764
765 /**
766 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100767 * password for all admins of this user and its profiles or a particular one.
768 * This is the same value as set by
769 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700770 * and only applies when the password quality is
771 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700772 *
773 * @param admin The name of the admin component to check, or null to
774 * aggregate all admins.
775 * @return The minimum number of upper case letters required in the
776 * password.
777 */
778 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700779 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
780 }
781
782 /** @hide per-user version */
783 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700784 if (mService != null) {
785 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700786 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700787 } catch (RemoteException e) {
788 Log.w(TAG, "Failed talking with device policy service", e);
789 }
790 }
791 return 0;
792 }
793
794 /**
795 * Called by an application that is administering the device to set the
796 * minimum number of lower case letters required in the password. After
797 * setting this, the user will not be able to enter a new password that is
798 * not at least as restrictive as what has been set. Note that the current
799 * password will remain until the user has set a new one, so the change does
800 * not take place immediately. To prompt the user for a new password, use
801 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
802 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700803 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
804 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700805 * <p>
806 * The calling device admin must have requested
807 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
808 * this method; if it has not, a security exception will be thrown.
809 *
810 * @param admin Which {@link DeviceAdminReceiver} this request is associated
811 * with.
812 * @param length The new desired minimum number of lower case letters
813 * required in the password. A value of 0 means there is no
814 * restriction.
815 */
816 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
817 if (mService != null) {
818 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700819 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700820 } catch (RemoteException e) {
821 Log.w(TAG, "Failed talking with device policy service", e);
822 }
823 }
824 }
825
826 /**
827 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100828 * password for all admins of this user and its profiles or a particular one.
829 * This is the same value as set by
830 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700831 * and only applies when the password quality is
832 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700833 *
834 * @param admin The name of the admin component to check, or null to
835 * aggregate all admins.
836 * @return The minimum number of lower case letters required in the
837 * password.
838 */
839 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700840 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
841 }
842
843 /** @hide per-user version */
844 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700845 if (mService != null) {
846 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700847 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700848 } catch (RemoteException e) {
849 Log.w(TAG, "Failed talking with device policy service", e);
850 }
851 }
852 return 0;
853 }
854
855 /**
856 * Called by an application that is administering the device to set the
857 * minimum number of letters required in the password. After setting this,
858 * the user will not be able to enter a new password that is not at least as
859 * restrictive as what has been set. Note that the current password will
860 * remain until the user has set a new one, so the change does not take
861 * place immediately. To prompt the user for a new password, use
862 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
863 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700864 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
865 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700866 * <p>
867 * The calling device admin must have requested
868 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
869 * this method; if it has not, a security exception will be thrown.
870 *
871 * @param admin Which {@link DeviceAdminReceiver} this request is associated
872 * with.
873 * @param length The new desired minimum number of letters required in the
874 * password. A value of 0 means there is no restriction.
875 */
876 public void setPasswordMinimumLetters(ComponentName admin, int length) {
877 if (mService != null) {
878 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700879 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700880 } catch (RemoteException e) {
881 Log.w(TAG, "Failed talking with device policy service", e);
882 }
883 }
884 }
885
886 /**
887 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700888 * admins or a particular one. This is the same value as
889 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
890 * and only applies when the password quality is
891 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700892 *
893 * @param admin The name of the admin component to check, or null to
894 * aggregate all admins.
895 * @return The minimum number of letters required in the password.
896 */
897 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700898 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
899 }
900
901 /** @hide per-user version */
902 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700903 if (mService != null) {
904 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700905 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700906 } catch (RemoteException e) {
907 Log.w(TAG, "Failed talking with device policy service", e);
908 }
909 }
910 return 0;
911 }
912
913 /**
914 * Called by an application that is administering the device to set the
915 * minimum number of numerical digits required in the password. After
916 * setting this, the user will not be able to enter a new password that is
917 * not at least as restrictive as what has been set. Note that the current
918 * password will remain until the user has set a new one, so the change does
919 * not take place immediately. To prompt the user for a new password, use
920 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
921 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700922 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
923 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700924 * <p>
925 * The calling device admin must have requested
926 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
927 * this method; if it has not, a security exception will be thrown.
928 *
929 * @param admin Which {@link DeviceAdminReceiver} this request is associated
930 * with.
931 * @param length The new desired minimum number of numerical digits required
932 * in the password. A value of 0 means there is no restriction.
933 */
934 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
935 if (mService != null) {
936 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700937 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700938 } catch (RemoteException e) {
939 Log.w(TAG, "Failed talking with device policy service", e);
940 }
941 }
942 }
943
944 /**
945 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100946 * for all admins of this user and its profiles or a particular one.
947 * This is the same value as set by
948 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700949 * and only applies when the password quality is
950 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700951 *
952 * @param admin The name of the admin component to check, or null to
953 * aggregate all admins.
954 * @return The minimum number of numerical digits required in the password.
955 */
956 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700957 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
958 }
959
960 /** @hide per-user version */
961 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700962 if (mService != null) {
963 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700964 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700965 } catch (RemoteException e) {
966 Log.w(TAG, "Failed talking with device policy service", e);
967 }
968 }
969 return 0;
970 }
971
972 /**
973 * Called by an application that is administering the device to set the
974 * minimum number of symbols required in the password. After setting this,
975 * the user will not be able to enter a new password that is not at least as
976 * restrictive as what has been set. Note that the current password will
977 * remain until the user has set a new one, so the change does not take
978 * place immediately. To prompt the user for a new password, use
979 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
980 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700981 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
982 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700983 * <p>
984 * The calling device admin must have requested
985 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
986 * this method; if it has not, a security exception will be thrown.
987 *
988 * @param admin Which {@link DeviceAdminReceiver} this request is associated
989 * with.
990 * @param length The new desired minimum number of symbols required in the
991 * password. A value of 0 means there is no restriction.
992 */
993 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
994 if (mService != null) {
995 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700996 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700997 } catch (RemoteException e) {
998 Log.w(TAG, "Failed talking with device policy service", e);
999 }
1000 }
1001 }
1002
1003 /**
1004 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001005 * admins or a particular one. This is the same value as
1006 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1007 * and only applies when the password quality is
1008 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001009 *
1010 * @param admin The name of the admin component to check, or null to
1011 * aggregate all admins.
1012 * @return The minimum number of symbols required in the password.
1013 */
1014 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001015 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1016 }
1017
1018 /** @hide per-user version */
1019 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001020 if (mService != null) {
1021 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001022 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001023 } catch (RemoteException e) {
1024 Log.w(TAG, "Failed talking with device policy service", e);
1025 }
1026 }
1027 return 0;
1028 }
1029
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001030 /**
1031 * Called by an application that is administering the device to set the
1032 * minimum number of non-letter characters (numerical digits or symbols)
1033 * required in the password. After setting this, the user will not be able
1034 * to enter a new password that is not at least as restrictive as what has
1035 * been set. Note that the current password will remain until the user has
1036 * set a new one, so the change does not take place immediately. To prompt
1037 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1038 * setting this value. This constraint is only imposed if the administrator
1039 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1040 * {@link #setPasswordQuality}. The default value is 0.
1041 * <p>
1042 * The calling device admin must have requested
1043 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1044 * this method; if it has not, a security exception will be thrown.
1045 *
1046 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1047 * with.
1048 * @param length The new desired minimum number of letters required in the
1049 * password. A value of 0 means there is no restriction.
1050 */
1051 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1052 if (mService != null) {
1053 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001054 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001055 } catch (RemoteException e) {
1056 Log.w(TAG, "Failed talking with device policy service", e);
1057 }
1058 }
1059 }
1060
1061 /**
1062 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001063 * password for all admins of this user and its profiles or a particular one.
1064 * This is the same value as set by
1065 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001066 * and only applies when the password quality is
1067 * {@link #PASSWORD_QUALITY_COMPLEX}.
1068 *
1069 * @param admin The name of the admin component to check, or null to
1070 * aggregate all admins.
1071 * @return The minimum number of letters required in the password.
1072 */
1073 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001074 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1075 }
1076
1077 /** @hide per-user version */
1078 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001079 if (mService != null) {
1080 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001081 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001082 } catch (RemoteException e) {
1083 Log.w(TAG, "Failed talking with device policy service", e);
1084 }
1085 }
1086 return 0;
1087 }
1088
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001089 /**
1090 * Called by an application that is administering the device to set the length
1091 * of the password history. After setting this, the user will not be able to
1092 * enter a new password that is the same as any password in the history. Note
1093 * that the current password will remain until the user has set a new one, so
1094 * the change does not take place immediately. To prompt the user for a new
1095 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1096 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001097 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1098 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1099 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001100 *
1101 * <p>
1102 * The calling device admin must have requested
1103 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1104 * method; if it has not, a security exception will be thrown.
1105 *
1106 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1107 * with.
1108 * @param length The new desired length of password history. A value of 0
1109 * means there is no restriction.
1110 */
1111 public void setPasswordHistoryLength(ComponentName admin, int length) {
1112 if (mService != null) {
1113 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001114 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001115 } catch (RemoteException e) {
1116 Log.w(TAG, "Failed talking with device policy service", e);
1117 }
1118 }
1119 }
1120
1121 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001122 * Called by a device admin to set the password expiration timeout. Calling this method
1123 * will restart the countdown for password expiration for the given admin, as will changing
1124 * the device password (for all admins).
1125 *
1126 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1127 * For example, to have the password expire 5 days from now, timeout would be
1128 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1129 *
1130 * <p>To disable password expiration, a value of 0 may be used for timeout.
1131 *
Jim Millera4e28d12010-11-08 16:15:47 -08001132 * <p>The calling device admin must have requested
1133 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1134 * method; if it has not, a security exception will be thrown.
1135 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001136 * <p> Note that setting the password will automatically reset the expiration time for all
1137 * active admins. Active admins do not need to explicitly call this method in that case.
1138 *
Jim Millera4e28d12010-11-08 16:15:47 -08001139 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1140 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1141 * means there is no restriction (unlimited).
1142 */
1143 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1144 if (mService != null) {
1145 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001146 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001147 } catch (RemoteException e) {
1148 Log.w(TAG, "Failed talking with device policy service", e);
1149 }
1150 }
1151 }
1152
1153 /**
Jim Miller6b857682011-02-16 16:27:41 -08001154 * Get the password expiration timeout for the given admin. The expiration timeout is the
1155 * recurring expiration timeout provided in the call to
1156 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1157 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001158 *
1159 * @param admin The name of the admin component to check, or null to aggregate all admins.
1160 * @return The timeout for the given admin or the minimum of all timeouts
1161 */
1162 public long getPasswordExpirationTimeout(ComponentName admin) {
1163 if (mService != null) {
1164 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001165 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001166 } catch (RemoteException e) {
1167 Log.w(TAG, "Failed talking with device policy service", e);
1168 }
1169 }
1170 return 0;
1171 }
1172
1173 /**
1174 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001175 * all admins of this user and its profiles if admin is null. If the password is
1176 * expired, this will return the time since the password expired as a negative number.
1177 * If admin is null, then a composite of all expiration timeouts is returned
1178 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001179 *
1180 * @param admin The name of the admin component to check, or null to aggregate all admins.
1181 * @return The password expiration time, in ms.
1182 */
1183 public long getPasswordExpiration(ComponentName admin) {
1184 if (mService != null) {
1185 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001186 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001187 } catch (RemoteException e) {
1188 Log.w(TAG, "Failed talking with device policy service", e);
1189 }
1190 }
1191 return 0;
1192 }
1193
1194 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001195 * Retrieve the current password history length for all admins of this
1196 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001197 * @param admin The name of the admin component to check, or null to aggregate
1198 * all admins.
1199 * @return The length of the password history
1200 */
1201 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001202 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1203 }
1204
1205 /** @hide per-user version */
1206 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001207 if (mService != null) {
1208 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001209 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001210 } catch (RemoteException e) {
1211 Log.w(TAG, "Failed talking with device policy service", e);
1212 }
1213 }
1214 return 0;
1215 }
1216
Dianne Hackbornd6847842010-01-12 18:14:19 -08001217 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001218 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001219 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001220 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001221 * @return Returns the maximum length that the user can enter.
1222 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001223 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001224 // Kind-of arbitrary.
1225 return 16;
1226 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001227
Dianne Hackborn254cb442010-01-27 19:23:59 -08001228 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001229 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001230 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001231 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001232 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001233 * <p>The calling device admin must have requested
1234 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1235 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001236 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001237 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001238 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001239 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001240 if (mService != null) {
1241 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001242 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001243 } catch (RemoteException e) {
1244 Log.w(TAG, "Failed talking with device policy service", e);
1245 }
1246 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001247 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001248 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001249
Dianne Hackbornd6847842010-01-12 18:14:19 -08001250 /**
1251 * Retrieve the number of times the user has failed at entering a
1252 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001253 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001254 * <p>The calling device admin must have requested
1255 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1256 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001257 */
1258 public int getCurrentFailedPasswordAttempts() {
1259 if (mService != null) {
1260 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001261 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001262 } catch (RemoteException e) {
1263 Log.w(TAG, "Failed talking with device policy service", e);
1264 }
1265 }
1266 return -1;
1267 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001268
1269 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001270 * Setting this to a value greater than zero enables a built-in policy
1271 * that will perform a device wipe after too many incorrect
1272 * device-unlock passwords have been entered. This built-in policy combines
1273 * watching for failed passwords and wiping the device, and requires
1274 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001275 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001276 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001277 * <p>To implement any other policy (e.g. wiping data for a particular
1278 * application only, erasing or revoking credentials, or reporting the
1279 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001280 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001281 * instead. Do not use this API, because if the maximum count is reached,
1282 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001283 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001284 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001285 * @param num The number of failed password attempts at which point the
1286 * device will wipe its data.
1287 */
1288 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1289 if (mService != null) {
1290 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001291 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001292 } catch (RemoteException e) {
1293 Log.w(TAG, "Failed talking with device policy service", e);
1294 }
1295 }
1296 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001297
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001298 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001299 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001300 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001301 * or a particular one.
1302 * @param admin The name of the admin component to check, or null to aggregate
1303 * all admins.
1304 */
1305 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001306 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1307 }
1308
1309 /** @hide per-user version */
1310 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001311 if (mService != null) {
1312 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001313 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001314 } catch (RemoteException e) {
1315 Log.w(TAG, "Failed talking with device policy service", e);
1316 }
1317 }
1318 return 0;
1319 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001320
Dianne Hackborn254cb442010-01-27 19:23:59 -08001321 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001322 * Flag for {@link #resetPassword}: don't allow other admins to change
1323 * the password again until the user has entered it.
1324 */
1325 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001326
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001327 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001328 * Force a new device unlock password (the password needed to access the
1329 * entire device, not for individual accounts) on the user. This takes
1330 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001331 * The given password must be sufficient for the
1332 * current password quality and length constraints as returned by
1333 * {@link #getPasswordQuality(ComponentName)} and
1334 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1335 * these constraints, then it will be rejected and false returned. Note
1336 * that the password may be a stronger quality (containing alphanumeric
1337 * characters when the requested quality is only numeric), in which case
1338 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001339 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001340 * <p>The calling device admin must have requested
1341 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1342 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001343 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001344 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001345 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001346 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001347 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001348 * @return Returns true if the password was applied, or false if it is
1349 * not acceptable for the current constraints.
1350 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001351 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001352 if (mService != null) {
1353 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001354 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001355 } catch (RemoteException e) {
1356 Log.w(TAG, "Failed talking with device policy service", e);
1357 }
1358 }
1359 return false;
1360 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001361
Dianne Hackbornd6847842010-01-12 18:14:19 -08001362 /**
1363 * Called by an application that is administering the device to set the
1364 * maximum time for user activity until the device will lock. This limits
1365 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001366 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001367 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001368 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001369 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001370 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001372 * @param timeMs The new desired maximum time to lock in milliseconds.
1373 * A value of 0 means there is no restriction.
1374 */
1375 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1376 if (mService != null) {
1377 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001378 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001379 } catch (RemoteException e) {
1380 Log.w(TAG, "Failed talking with device policy service", e);
1381 }
1382 }
1383 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001384
Dianne Hackbornd6847842010-01-12 18:14:19 -08001385 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001386 * Retrieve the current maximum time to unlock for all admins of this user
1387 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001388 * @param admin The name of the admin component to check, or null to aggregate
1389 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001390 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001391 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001392 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001393 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001394 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1395 }
1396
1397 /** @hide per-user version */
1398 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001399 if (mService != null) {
1400 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001401 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001402 } catch (RemoteException e) {
1403 Log.w(TAG, "Failed talking with device policy service", e);
1404 }
1405 }
1406 return 0;
1407 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001408
Dianne Hackbornd6847842010-01-12 18:14:19 -08001409 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001410 * Make the device lock immediately, as if the lock screen timeout has
1411 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001412 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001413 * <p>The calling device admin must have requested
1414 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1415 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001416 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001417 public void lockNow() {
1418 if (mService != null) {
1419 try {
1420 mService.lockNow();
1421 } catch (RemoteException e) {
1422 Log.w(TAG, "Failed talking with device policy service", e);
1423 }
1424 }
1425 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001426
Dianne Hackbornd6847842010-01-12 18:14:19 -08001427 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001428 * Flag for {@link #wipeData(int)}: also erase the device's external
1429 * storage.
1430 */
1431 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1432
1433 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001434 * Ask the user data be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001435 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001436 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1437 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001438 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001439 * <p>The calling device admin must have requested
1440 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1441 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001442 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001443 * @param flags Bit mask of additional options: currently 0 and
1444 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001445 */
1446 public void wipeData(int flags) {
1447 if (mService != null) {
1448 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001449 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001450 } catch (RemoteException e) {
1451 Log.w(TAG, "Failed talking with device policy service", e);
1452 }
1453 }
1454 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001455
Dianne Hackbornd6847842010-01-12 18:14:19 -08001456 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001457 * Called by an application that is administering the device to set the
1458 * global proxy and exclusion list.
1459 * <p>
1460 * The calling device admin must have requested
1461 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1462 * this method; if it has not, a security exception will be thrown.
1463 * Only the first device admin can set the proxy. If a second admin attempts
1464 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1465 * proxy will be returned. If successful in setting the proxy, null will
1466 * be returned.
1467 * The method can be called repeatedly by the device admin alrady setting the
1468 * proxy to update the proxy and exclusion list.
1469 *
1470 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1471 * with.
1472 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1473 * Pass Proxy.NO_PROXY to reset the proxy.
1474 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001475 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1476 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001477 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001478 */
1479 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1480 List<String> exclusionList ) {
1481 if (proxySpec == null) {
1482 throw new NullPointerException();
1483 }
1484 if (mService != null) {
1485 try {
1486 String hostSpec;
1487 String exclSpec;
1488 if (proxySpec.equals(Proxy.NO_PROXY)) {
1489 hostSpec = null;
1490 exclSpec = null;
1491 } else {
1492 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1493 throw new IllegalArgumentException();
1494 }
1495 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1496 String hostName = sa.getHostName();
1497 int port = sa.getPort();
1498 StringBuilder hostBuilder = new StringBuilder();
1499 hostSpec = hostBuilder.append(hostName)
1500 .append(":").append(Integer.toString(port)).toString();
1501 if (exclusionList == null) {
1502 exclSpec = "";
1503 } else {
1504 StringBuilder listBuilder = new StringBuilder();
1505 boolean firstDomain = true;
1506 for (String exclDomain : exclusionList) {
1507 if (!firstDomain) {
1508 listBuilder = listBuilder.append(",");
1509 } else {
1510 firstDomain = false;
1511 }
1512 listBuilder = listBuilder.append(exclDomain.trim());
1513 }
1514 exclSpec = listBuilder.toString();
1515 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001516 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1517 != android.net.Proxy.PROXY_VALID)
1518 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001519 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001520 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001521 } catch (RemoteException e) {
1522 Log.w(TAG, "Failed talking with device policy service", e);
1523 }
1524 }
1525 return null;
1526 }
1527
1528 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001529 * Set a network-independent global HTTP proxy. This is not normally what you want
1530 * for typical HTTP proxies - they are generally network dependent. However if you're
1531 * doing something unusual like general internal filtering this may be useful. On
1532 * a private network where the proxy is not accessible, you may break HTTP using this.
1533 *
1534 * <p>This method requires the caller to be the device owner.
1535 *
1536 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1537 * @see ProxyInfo
1538 *
1539 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1540 * with.
1541 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1542 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1543 */
1544 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1545 if (mService != null) {
1546 try {
1547 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1548 } catch (RemoteException e) {
1549 Log.w(TAG, "Failed talking with device policy service", e);
1550 }
1551 }
1552 }
1553
1554 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001555 * Returns the component name setting the global proxy.
1556 * @return ComponentName object of the device admin that set the global proxy, or
1557 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001558 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001559 */
1560 public ComponentName getGlobalProxyAdmin() {
1561 if (mService != null) {
1562 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001563 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001564 } catch (RemoteException e) {
1565 Log.w(TAG, "Failed talking with device policy service", e);
1566 }
1567 }
1568 return null;
1569 }
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 not supported.
1574 */
1575 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
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 supported, but is not currently active.
1580 */
1581 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1582
1583 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001584 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001585 * indicating that encryption is not currently active, but is currently
1586 * being activated. This is only reported by devices that support
1587 * encryption of data and only when the storage is currently
1588 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1589 * to become encrypted will never return this value.
1590 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001591 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001592
1593 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001594 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001595 * indicating that encryption is active.
1596 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001597 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001598
1599 /**
1600 * Activity action: begin the process of encrypting data on the device. This activity should
1601 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1602 * After resuming from this activity, use {@link #getStorageEncryption}
1603 * to check encryption status. However, on some devices this activity may never return, as
1604 * it may trigger a reboot and in some cases a complete data wipe of the device.
1605 */
1606 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1607 public static final String ACTION_START_ENCRYPTION
1608 = "android.app.action.START_ENCRYPTION";
1609
1610 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001611 * Widgets are enabled in keyguard
1612 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001613 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001614
1615 /**
Jim Miller50e62182014-04-23 17:25:00 -07001616 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001617 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001618 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1619
1620 /**
1621 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1622 */
1623 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1624
1625 /**
Jim Miller50e62182014-04-23 17:25:00 -07001626 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1627 */
1628 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1629
1630 /**
1631 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1632 */
1633 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1634
1635 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001636 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001637 * (e.g. PIN/Pattern/Password).
1638 */
1639 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1640
1641 /**
Jim Miller06e34502014-07-17 14:46:05 -07001642 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1643 */
1644 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1645
1646 /**
Jim Miller35207742012-11-02 15:33:20 -07001647 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001648 */
1649 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001650
1651 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001652 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001653 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001654 *
1655 * <p>When multiple device administrators attempt to control device
1656 * encryption, the most secure, supported setting will always be
1657 * used. If any device administrator requests device encryption,
1658 * it will be enabled; Conversely, if a device administrator
1659 * attempts to disable device encryption while another
1660 * device administrator has enabled it, the call to disable will
1661 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1662 *
1663 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001664 * written to other storage areas may or may not be encrypted, and this policy does not require
1665 * or control the encryption of any other storage areas.
1666 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1667 * {@code true}, then the directory returned by
1668 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1669 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001670 *
1671 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1672 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1673 * the encryption key may not be fully secured. For maximum security, the administrator should
1674 * also require (and check for) a pattern, PIN, or password.
1675 *
1676 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1677 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001678 * @return the new request status (for all active admins) - will be one of
1679 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1680 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1681 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001682 */
1683 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1684 if (mService != null) {
1685 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001686 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001687 } catch (RemoteException e) {
1688 Log.w(TAG, "Failed talking with device policy service", e);
1689 }
1690 }
1691 return ENCRYPTION_STATUS_UNSUPPORTED;
1692 }
1693
1694 /**
1695 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001696 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001697 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001698 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1699 * this will return the requested encryption setting as an aggregate of all active
1700 * administrators.
1701 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001702 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001703 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001704 if (mService != null) {
1705 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001706 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001707 } catch (RemoteException e) {
1708 Log.w(TAG, "Failed talking with device policy service", e);
1709 }
1710 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001711 return false;
1712 }
1713
1714 /**
1715 * Called by an application that is administering the device to
1716 * determine the current encryption status of the device.
1717 *
1718 * Depending on the returned status code, the caller may proceed in different
1719 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1720 * storage system does not support encryption. If the
1721 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1722 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1723 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1724 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1725 *
Robin Lee7e678712014-07-24 16:41:31 +01001726 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001727 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1728 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1729 */
1730 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001731 return getStorageEncryptionStatus(UserHandle.myUserId());
1732 }
1733
1734 /** @hide per-user version */
1735 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001736 if (mService != null) {
1737 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001738 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001739 } catch (RemoteException e) {
1740 Log.w(TAG, "Failed talking with device policy service", e);
1741 }
1742 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001743 return ENCRYPTION_STATUS_UNSUPPORTED;
1744 }
1745
1746 /**
Robin Lee7e678712014-07-24 16:41:31 +01001747 * Installs the given certificate as a user CA.
1748 *
1749 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1750 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001751 *
1752 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001753 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001754 */
Robin Lee7e678712014-07-24 16:41:31 +01001755 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001756 if (mService != null) {
1757 try {
Robin Lee7e678712014-07-24 16:41:31 +01001758 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001759 } catch (RemoteException e) {
1760 Log.w(TAG, "Failed talking with device policy service", e);
1761 }
1762 }
1763 return false;
1764 }
1765
1766 /**
Robin Lee7e678712014-07-24 16:41:31 +01001767 * Uninstalls the given certificate from trusted user CAs, if present.
1768 *
1769 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1770 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001771 */
Robin Lee7e678712014-07-24 16:41:31 +01001772 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001773 if (mService != null) {
1774 try {
Robin Lee306fe082014-06-19 14:04:24 +00001775 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001776 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001777 } catch (CertificateException e) {
1778 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001779 } catch (RemoteException e) {
1780 Log.w(TAG, "Failed talking with device policy service", e);
1781 }
1782 }
1783 }
1784
1785 /**
Robin Lee7e678712014-07-24 16:41:31 +01001786 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1787 * If a user has installed any certificates by other means than device policy these will be
1788 * included too.
1789 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001790 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001791 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001792 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001793 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01001794 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001795 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01001796 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001797 mService.enforceCanManageCaCerts(admin);
1798 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1799 for (String alias : certStore.userAliases()) {
1800 try {
1801 certs.add(certStore.getCertificate(alias).getEncoded());
1802 } catch (CertificateException ce) {
1803 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1804 }
1805 }
1806 } catch (RemoteException re) {
1807 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01001808 }
1809 }
1810 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001811 }
1812
1813 /**
Robin Lee7e678712014-07-24 16:41:31 +01001814 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1815 * means other than device policy will also be removed, except for system CA certificates.
1816 *
1817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1818 */
1819 public void uninstallAllUserCaCerts(ComponentName admin) {
1820 if (mService != null) {
1821 for (String alias : new TrustedCertificateStore().userAliases()) {
1822 try {
1823 mService.uninstallCaCert(admin, alias);
1824 } catch (RemoteException re) {
1825 Log.w(TAG, "Failed talking with device policy service", re);
1826 }
1827 }
1828 }
1829 }
1830
1831 /**
1832 * Returns whether this certificate is installed as a trusted CA.
1833 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001835 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001836 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001837 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
1838 if (mService != null) {
1839 try {
1840 mService.enforceCanManageCaCerts(admin);
1841 return getCaCertAlias(certBuffer) != null;
1842 } catch (RemoteException re) {
1843 Log.w(TAG, "Failed talking with device policy service", re);
1844 } catch (CertificateException ce) {
1845 Log.w(TAG, "Could not parse certificate", ce);
1846 }
Maggie Benthallda51e682013-08-08 22:35:44 -04001847 }
1848 return false;
1849 }
1850
1851 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001852 * Called by a device or profile owner to install a certificate and private key pair. The
1853 * keypair will be visible to all apps within the profile.
1854 *
1855 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
1856 * @param privKey The private key to install.
1857 * @param cert The certificate to install.
1858 * @param alias The private key alias under which to install the certificate. If a certificate
1859 * with that alias already exists, it will be overwritten.
1860 * @return {@code true} if the keys were installed, {@code false} otherwise.
1861 */
1862 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
1863 String alias) {
1864 try {
1865 final byte[] pemCert = Credentials.convertToPem(cert);
1866 return mService.installKeyPair(who, privKey.getEncoded(), pemCert, alias);
1867 } catch (CertificateException e) {
1868 Log.w(TAG, "Error encoding certificate", e);
1869 } catch (IOException e) {
1870 Log.w(TAG, "Error writing certificate", e);
1871 } catch (RemoteException e) {
1872 Log.w(TAG, "Failed talking with device policy service", e);
1873 }
1874 return false;
1875 }
1876
1877 /**
Robin Lee306fe082014-06-19 14:04:24 +00001878 * Returns the alias of a given CA certificate in the certificate store, or null if it
1879 * doesn't exist.
1880 */
1881 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1882 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1883 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1884 new ByteArrayInputStream(certBuffer));
1885 return new TrustedCertificateStore().getCertificateAlias(cert);
1886 }
1887
1888 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001889 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07001890 * on the device, for this user. After setting this, no applications running as this user
1891 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07001892 *
1893 * <p>The calling device admin must have requested
1894 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1895 * this method; if it has not, a security exception will be thrown.
1896 *
1897 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1898 * @param disabled Whether or not the camera should be disabled.
1899 */
1900 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1901 if (mService != null) {
1902 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001903 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001904 } catch (RemoteException e) {
1905 Log.w(TAG, "Failed talking with device policy service", e);
1906 }
1907 }
1908 }
1909
1910 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07001911 * Determine whether or not the device's cameras have been disabled for this user,
1912 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07001913 * @param admin The name of the admin component to check, or null to check if any admins
1914 * have disabled the camera
1915 */
1916 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001917 return getCameraDisabled(admin, UserHandle.myUserId());
1918 }
1919
1920 /** @hide per-user version */
1921 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001922 if (mService != null) {
1923 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001924 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001925 } catch (RemoteException e) {
1926 Log.w(TAG, "Failed talking with device policy service", e);
1927 }
1928 }
1929 return false;
1930 }
1931
1932 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01001933 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
1934 * screen capture also prevents the content from being shown on display devices that do not have
1935 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
1936 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001937 *
1938 * <p>The calling device admin must be a device or profile owner. If it is not, a
1939 * security exception will be thrown.
1940 *
1941 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001942 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001943 */
1944 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
1945 if (mService != null) {
1946 try {
1947 mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled);
1948 } catch (RemoteException e) {
1949 Log.w(TAG, "Failed talking with device policy service", e);
1950 }
1951 }
1952 }
1953
1954 /**
1955 * Determine whether or not screen capture has been disabled by the current
1956 * admin, if specified, or all admins.
1957 * @param admin The name of the admin component to check, or null to check if any admins
1958 * have disabled screen capture.
1959 */
1960 public boolean getScreenCaptureDisabled(ComponentName admin) {
1961 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
1962 }
1963
1964 /** @hide per-user version */
1965 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
1966 if (mService != null) {
1967 try {
1968 return mService.getScreenCaptureDisabled(admin, userHandle);
1969 } catch (RemoteException e) {
1970 Log.w(TAG, "Failed talking with device policy service", e);
1971 }
1972 }
1973 return false;
1974 }
1975
1976 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001977 * Called by a device owner to set whether auto time is required. If auto time is
1978 * required the user cannot set the date and time, but has to use network date and time.
1979 *
1980 * <p>Note: if auto time is required the user can still manually set the time zone.
1981 *
1982 * <p>The calling device admin must be a device owner. If it is not, a security exception will
1983 * be thrown.
1984 *
1985 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1986 * @param required Whether auto time is set required or not.
1987 */
1988 public void setAutoTimeRequired(ComponentName admin, boolean required) {
1989 if (mService != null) {
1990 try {
1991 mService.setAutoTimeRequired(admin, UserHandle.myUserId(), required);
1992 } catch (RemoteException e) {
1993 Log.w(TAG, "Failed talking with device policy service", e);
1994 }
1995 }
1996 }
1997
1998 /**
1999 * @return true if auto time is required.
2000 */
2001 public boolean getAutoTimeRequired() {
2002 if (mService != null) {
2003 try {
2004 return mService.getAutoTimeRequired();
2005 } catch (RemoteException e) {
2006 Log.w(TAG, "Failed talking with device policy service", e);
2007 }
2008 }
2009 return false;
2010 }
2011
2012 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002013 * Called by an application that is administering the device to disable keyguard customizations,
2014 * such as widgets. After setting this, keyguard features will be disabled according to the
2015 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002016 *
2017 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002018 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002019 * this method; if it has not, a security exception will be thrown.
2020 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002021 * <p>Calling this from a managed profile will throw a security exception.
2022 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002023 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002024 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2025 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002026 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2027 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002028 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002029 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002030 if (mService != null) {
2031 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002032 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07002033 } catch (RemoteException e) {
2034 Log.w(TAG, "Failed talking with device policy service", e);
2035 }
2036 }
2037 }
2038
2039 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002040 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002041 * admin, if specified, or all admins.
2042 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002043 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002044 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2045 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002046 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002047 public int getKeyguardDisabledFeatures(ComponentName admin) {
2048 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002049 }
2050
2051 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002052 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002053 if (mService != null) {
2054 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002055 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002056 } catch (RemoteException e) {
2057 Log.w(TAG, "Failed talking with device policy service", e);
2058 }
2059 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002060 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002061 }
2062
2063 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002064 * @hide
2065 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002066 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002067 if (mService != null) {
2068 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002069 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002070 } catch (RemoteException e) {
2071 Log.w(TAG, "Failed talking with device policy service", e);
2072 }
2073 }
2074 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002075
Dianne Hackbornd6847842010-01-12 18:14:19 -08002076 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002077 * @hide
2078 */
2079 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2080 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2081 }
2082
2083 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002084 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002085 * @hide
2086 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002087 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002088 ActivityInfo ai;
2089 try {
2090 ai = mContext.getPackageManager().getReceiverInfo(cn,
2091 PackageManager.GET_META_DATA);
2092 } catch (PackageManager.NameNotFoundException e) {
2093 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2094 return null;
2095 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002096
Dianne Hackbornd6847842010-01-12 18:14:19 -08002097 ResolveInfo ri = new ResolveInfo();
2098 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002099
Dianne Hackbornd6847842010-01-12 18:14:19 -08002100 try {
2101 return new DeviceAdminInfo(mContext, ri);
2102 } catch (XmlPullParserException e) {
2103 Log.w(TAG, "Unable to parse device policy " + cn, e);
2104 return null;
2105 } catch (IOException e) {
2106 Log.w(TAG, "Unable to parse device policy " + cn, e);
2107 return null;
2108 }
2109 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002110
Dianne Hackbornd6847842010-01-12 18:14:19 -08002111 /**
2112 * @hide
2113 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002114 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2115 if (mService != null) {
2116 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002117 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002118 } catch (RemoteException e) {
2119 Log.w(TAG, "Failed talking with device policy service", e);
2120 }
2121 }
2122 }
2123
2124 /**
2125 * @hide
2126 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002127 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002128 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002129 if (mService != null) {
2130 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002131 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002132 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002133 } catch (RemoteException e) {
2134 Log.w(TAG, "Failed talking with device policy service", e);
2135 }
2136 }
2137 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002138
Dianne Hackbornd6847842010-01-12 18:14:19 -08002139 /**
2140 * @hide
2141 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002142 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002143 if (mService != null) {
2144 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002145 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002146 } catch (RemoteException e) {
2147 Log.w(TAG, "Failed talking with device policy service", e);
2148 }
2149 }
2150 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002151
Dianne Hackbornd6847842010-01-12 18:14:19 -08002152 /**
2153 * @hide
2154 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002155 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002156 if (mService != null) {
2157 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002158 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002159 } catch (RemoteException e) {
2160 Log.w(TAG, "Failed talking with device policy service", e);
2161 }
2162 }
2163 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002164
2165 /**
2166 * @hide
2167 * Sets the given package as the device owner. The package must already be installed and there
2168 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2169 * method must be called before the device is provisioned.
2170 * @param packageName the package name of the application to be registered as the device owner.
2171 * @return whether the package was successfully registered as the device owner.
2172 * @throws IllegalArgumentException if the package name is null or invalid
2173 * @throws IllegalStateException if a device owner is already registered or the device has
2174 * already been provisioned.
2175 */
2176 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2177 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002178 return setDeviceOwner(packageName, null);
2179 }
2180
2181 /**
2182 * @hide
2183 * Sets the given package as the device owner. The package must already be installed and there
2184 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2185 * method must be called before the device is provisioned.
2186 * @param packageName the package name of the application to be registered as the device owner.
2187 * @param ownerName the human readable name of the institution that owns this device.
2188 * @return whether the package was successfully registered as the device owner.
2189 * @throws IllegalArgumentException if the package name is null or invalid
2190 * @throws IllegalStateException if a device owner is already registered or the device has
2191 * already been provisioned.
2192 */
2193 public boolean setDeviceOwner(String packageName, String ownerName)
2194 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002195 if (mService != null) {
2196 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002197 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002198 } catch (RemoteException re) {
2199 Log.w(TAG, "Failed to set device owner");
2200 }
2201 }
2202 return false;
2203 }
2204
2205 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002206 * Used to determine if a particular package has been registered as a Device Owner app.
2207 * A device owner app is a special device admin that cannot be deactivated by the user, once
2208 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2209 * package is currently registered as the device owner app, pass in the package name from
2210 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2211 * admin apps that want to check if they are also registered as the device owner app. The
2212 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2213 * the setup process.
2214 * @param packageName the package name of the app, to compare with the registered device owner
2215 * app, if any.
2216 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002217 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002218 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002219 if (mService != null) {
2220 try {
2221 return mService.isDeviceOwner(packageName);
2222 } catch (RemoteException re) {
2223 Log.w(TAG, "Failed to check device owner");
2224 }
2225 }
2226 return false;
2227 }
2228
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002229 /**
2230 * @hide
2231 * Redirect to isDeviceOwnerApp.
2232 */
2233 public boolean isDeviceOwner(String packageName) {
2234 return isDeviceOwnerApp(packageName);
2235 }
2236
Jason Monkb0dced82014-06-06 14:36:20 -04002237 /**
2238 * Clears the current device owner. The caller must be the device owner.
2239 *
2240 * This function should be used cautiously as once it is called it cannot
2241 * be undone. The device owner can only be set as a part of device setup
2242 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002243 *
2244 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002245 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002246 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002247 if (mService != null) {
2248 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002249 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002250 } catch (RemoteException re) {
2251 Log.w(TAG, "Failed to clear device owner");
2252 }
2253 }
2254 }
2255
Amith Yamasani71e6c692013-03-24 17:39:28 -07002256 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002257 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002258 public String getDeviceOwner() {
2259 if (mService != null) {
2260 try {
2261 return mService.getDeviceOwner();
2262 } catch (RemoteException re) {
2263 Log.w(TAG, "Failed to get device owner");
2264 }
2265 }
2266 return null;
2267 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002268
2269 /** @hide */
2270 public String getDeviceOwnerName() {
2271 if (mService != null) {
2272 try {
2273 return mService.getDeviceOwnerName();
2274 } catch (RemoteException re) {
2275 Log.w(TAG, "Failed to get device owner");
2276 }
2277 }
2278 return null;
2279 }
Adam Connors776c5552014-01-09 10:42:56 +00002280
2281 /**
2282 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002283 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302284 * Sets the given component as an active admin and registers the package as the profile
2285 * owner for this user. The package must already be installed and there shouldn't be
2286 * an existing profile owner registered for this user. Also, this method must be called
2287 * before the user setup has been completed.
2288 * <p>
2289 * This method can only be called by system apps that hold MANAGE_USERS permission and
2290 * MANAGE_DEVICE_ADMINS permission.
2291 * @param admin The component to register as an active admin and profile owner.
2292 * @param ownerName The user-visible name of the entity that is managing this user.
2293 * @return whether the admin was successfully registered as the profile owner.
2294 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2295 * the user has already been set up.
2296 */
Justin Morey80440cc2014-07-24 09:16:35 -05002297 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302298 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2299 throws IllegalArgumentException {
2300 if (mService != null) {
2301 try {
2302 final int myUserId = UserHandle.myUserId();
2303 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002304 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302305 } catch (RemoteException re) {
2306 Log.w(TAG, "Failed to set profile owner " + re);
2307 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2308 }
2309 }
2310 return false;
2311 }
2312
2313 /**
2314 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002315 * Clears the active profile owner and removes all user restrictions. The caller must
2316 * be from the same package as the active profile owner for this user, otherwise a
2317 * SecurityException will be thrown.
2318 *
2319 * @param admin The component to remove as the profile owner.
2320 * @return
2321 */
2322 @SystemApi
2323 public void clearProfileOwner(ComponentName admin) {
2324 if (mService != null) {
2325 try {
2326 mService.clearProfileOwner(admin);
2327 } catch (RemoteException re) {
2328 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2329 }
2330 }
2331 }
2332
2333 /**
2334 * @hide
2335 * Checks if the user was already setup.
2336 */
2337 public boolean hasUserSetupCompleted() {
2338 if (mService != null) {
2339 try {
2340 return mService.hasUserSetupCompleted();
2341 } catch (RemoteException re) {
2342 Log.w(TAG, "Failed to check if user setup has completed");
2343 }
2344 }
2345 return true;
2346 }
2347
2348 /**
2349 * @deprecated Use setProfileOwner(ComponentName ...)
2350 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002351 * Sets the given package as the profile owner of the given user profile. The package must
2352 * already be installed and there shouldn't be an existing profile owner registered for this
2353 * user. Also, this method must be called before the user has been used for the first time.
2354 * @param packageName the package name of the application to be registered as profile owner.
2355 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002356 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002357 * @return whether the package was successfully registered as the profile owner.
2358 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2359 * the user has already been set up.
2360 */
Adam Connors661ec472014-02-11 13:59:46 +00002361 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002362 throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002363 if (packageName == null) {
2364 throw new NullPointerException("packageName cannot be null");
2365 }
2366 return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle);
2367 }
2368
2369 /**
2370 * @hide
2371 * Sets the given component as the profile owner of the given user profile. The package must
2372 * already be installed and there shouldn't be an existing profile owner registered for this
2373 * user. Only the system can call this API if the user has already completed setup.
2374 * @param admin the component name to be registered as profile owner.
2375 * @param ownerName the human readable name of the organisation associated with this DPM.
2376 * @param userHandle the userId to set the profile owner for.
2377 * @return whether the component was successfully registered as the profile owner.
2378 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2379 * the user has already been set up.
2380 */
2381 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2382 throws IllegalArgumentException {
2383 if (admin == null) {
2384 throw new NullPointerException("admin cannot be null");
2385 }
Adam Connors776c5552014-01-09 10:42:56 +00002386 if (mService != null) {
2387 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002388 if (ownerName == null) {
2389 ownerName = "";
2390 }
2391 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002392 } catch (RemoteException re) {
2393 Log.w(TAG, "Failed to set profile owner", re);
2394 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2395 }
2396 }
2397 return false;
2398 }
2399
2400 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002401 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2402 * be used. Only the profile owner can call this.
2403 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002404 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002405 *
2406 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2407 */
2408 public void setProfileEnabled(ComponentName admin) {
2409 if (mService != null) {
2410 try {
2411 mService.setProfileEnabled(admin);
2412 } catch (RemoteException e) {
2413 Log.w(TAG, "Failed talking with device policy service", e);
2414 }
2415 }
2416 }
2417
2418 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002419 * Sets the name of the profile. In the device owner case it sets the name of the user
2420 * 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 +01002421 * never called by the profile or device owner, the name will be set to default values.
2422 *
2423 * @see #isProfileOwnerApp
2424 * @see #isDeviceOwnerApp
2425 *
2426 * @param profileName The name of the profile.
2427 */
2428 public void setProfileName(ComponentName who, String profileName) {
2429 if (mService != null) {
2430 try {
2431 mService.setProfileName(who, profileName);
2432 } catch (RemoteException e) {
2433 Log.w(TAG, "Failed talking with device policy service", e);
2434 }
2435 }
2436}
2437
2438 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002439 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002440 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002441 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002442 *
2443 * @param packageName The package name of the app to compare with the registered profile owner.
2444 * @return Whether or not the package is registered as the profile owner.
2445 */
2446 public boolean isProfileOwnerApp(String packageName) {
2447 if (mService != null) {
2448 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002449 ComponentName profileOwner = mService.getProfileOwner(
2450 Process.myUserHandle().getIdentifier());
2451 return profileOwner != null
2452 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002453 } catch (RemoteException re) {
2454 Log.w(TAG, "Failed to check profile owner");
2455 }
2456 }
2457 return false;
2458 }
2459
2460 /**
2461 * @hide
2462 * @return the packageName of the owner of the given user profile or null if no profile
2463 * owner has been set for that user.
2464 * @throws IllegalArgumentException if the userId is invalid.
2465 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002466 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002467 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002468 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2469 }
2470
2471 /**
2472 * @see #getProfileOwner()
2473 * @hide
2474 */
2475 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002476 if (mService != null) {
2477 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002478 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002479 } catch (RemoteException re) {
2480 Log.w(TAG, "Failed to get profile owner");
2481 throw new IllegalArgumentException(
2482 "Requested profile owner for invalid userId", re);
2483 }
2484 }
2485 return null;
2486 }
2487
2488 /**
2489 * @hide
2490 * @return the human readable name of the organisation associated with this DPM or null if
2491 * one is not set.
2492 * @throws IllegalArgumentException if the userId is invalid.
2493 */
2494 public String getProfileOwnerName() throws IllegalArgumentException {
2495 if (mService != null) {
2496 try {
2497 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2498 } catch (RemoteException re) {
2499 Log.w(TAG, "Failed to get profile owner");
2500 throw new IllegalArgumentException(
2501 "Requested profile owner for invalid userId", re);
2502 }
2503 }
2504 return null;
2505 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002506
2507 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002508 * @hide
2509 * @param user The user for whom to fetch the profile owner name, if any.
2510 * @return the human readable name of the organisation associated with this profile owner or
2511 * null if one is not set.
2512 * @throws IllegalArgumentException if the userId is invalid.
2513 */
2514 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002515 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002516 if (mService != null) {
2517 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002518 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002519 } catch (RemoteException re) {
2520 Log.w(TAG, "Failed to get profile owner");
2521 throw new IllegalArgumentException(
2522 "Requested profile owner for invalid userId", re);
2523 }
2524 }
2525 return null;
2526 }
2527
2528 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002529 * Called by a profile owner or device owner to add a default intent handler activity for
2530 * intents that match a certain intent filter. This activity will remain the default intent
2531 * handler even if the set of potential event handlers for the intent filter changes and if
2532 * the intent preferences are reset.
2533 *
2534 * <p>The default disambiguation mechanism takes over if the activity is not installed
2535 * (anymore). When the activity is (re)installed, it is automatically reset as default
2536 * intent handler for the filter.
2537 *
2538 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2539 * security exception will be thrown.
2540 *
2541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2542 * @param filter The IntentFilter for which a default handler is added.
2543 * @param activity The Activity that is added as default intent handler.
2544 */
2545 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2546 ComponentName activity) {
2547 if (mService != null) {
2548 try {
2549 mService.addPersistentPreferredActivity(admin, filter, activity);
2550 } catch (RemoteException e) {
2551 Log.w(TAG, "Failed talking with device policy service", e);
2552 }
2553 }
2554 }
2555
2556 /**
2557 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002558 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002559 *
2560 * <p>The calling device admin must be a profile owner. If it is not, a security
2561 * exception will be thrown.
2562 *
2563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2564 * @param packageName The name of the package for which preferences are removed.
2565 */
2566 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2567 String packageName) {
2568 if (mService != null) {
2569 try {
2570 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2571 } catch (RemoteException e) {
2572 Log.w(TAG, "Failed talking with device policy service", e);
2573 }
2574 }
2575 }
Robin Lee66e5d962014-04-09 16:44:21 +01002576
2577 /**
2578 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002579 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002580 *
2581 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01002582 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01002583 *
2584 * <p>The application restrictions are only made visible to the target application and the
2585 * profile or device owner.
2586 *
2587 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2588 * exception will be thrown.
2589 *
2590 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2591 * @param packageName The name of the package to update restricted settings for.
2592 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2593 * set of active restrictions.
2594 */
2595 public void setApplicationRestrictions(ComponentName admin, String packageName,
2596 Bundle settings) {
2597 if (mService != null) {
2598 try {
2599 mService.setApplicationRestrictions(admin, packageName, settings);
2600 } catch (RemoteException e) {
2601 Log.w(TAG, "Failed talking with device policy service", e);
2602 }
2603 }
2604 }
2605
2606 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002607 * Sets a list of features to enable for a TrustAgent component. This is meant to be
Jim Miller604e7552014-07-18 19:00:02 -07002608 * used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which will disable all
2609 * trust agents but those with features enabled by this function call.
2610 *
2611 * <p>The calling device admin must have requested
2612 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
2613 * this method; if it has not, a security exception will be thrown.
2614 *
2615 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2616 * @param agent Which component to enable features for.
2617 * @param features List of features to enable. Consult specific TrustAgent documentation for
2618 * the feature list.
Jim Millerb1474f42014-08-26 18:42:58 -07002619 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002620 */
2621 public void setTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent,
2622 List<String> features) {
2623 if (mService != null) {
2624 try {
2625 mService.setTrustAgentFeaturesEnabled(admin, agent, features, UserHandle.myUserId());
2626 } catch (RemoteException e) {
2627 Log.w(TAG, "Failed talking with device policy service", e);
2628 }
2629 }
2630 }
2631
2632 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002633 * Gets list of enabled features for the given TrustAgent component. If admin is
Jim Miller604e7552014-07-18 19:00:02 -07002634 * null, this will return the intersection of all features enabled for the given agent by all
2635 * admins.
2636 *
2637 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2638 * @param agent Which component to get enabled features for.
2639 * @return List of enabled features.
Jim Millerb1474f42014-08-26 18:42:58 -07002640 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002641 */
2642 public List<String> getTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent) {
2643 if (mService != null) {
2644 try {
2645 return mService.getTrustAgentFeaturesEnabled(admin, agent, UserHandle.myUserId());
2646 } catch (RemoteException e) {
2647 Log.w(TAG, "Failed talking with device policy service", e);
2648 }
2649 }
2650 return new ArrayList<String>(); // empty list
2651 }
2652
2653 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002654 * Called by a profile owner of a managed profile to set whether caller-Id information from
2655 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01002656 *
2657 * <p>The calling device admin must be a profile owner. If it is not, a
2658 * security exception will be thrown.
2659 *
2660 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2661 * @param disabled If true caller-Id information in the managed profile is not displayed.
2662 */
2663 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2664 if (mService != null) {
2665 try {
2666 mService.setCrossProfileCallerIdDisabled(who, disabled);
2667 } catch (RemoteException e) {
2668 Log.w(TAG, "Failed talking with device policy service", e);
2669 }
2670 }
2671 }
2672
2673 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002674 * Called by a profile owner of a managed profile to determine whether or not caller-Id
2675 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01002676 *
2677 * <p>The calling device admin must be a profile owner. If it is not, a
2678 * security exception will be thrown.
2679 *
2680 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2681 */
2682 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2683 if (mService != null) {
2684 try {
2685 return mService.getCrossProfileCallerIdDisabled(who);
2686 } catch (RemoteException e) {
2687 Log.w(TAG, "Failed talking with device policy service", e);
2688 }
2689 }
2690 return false;
2691 }
2692
2693 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002694 * Determine whether or not caller-Id information has been disabled.
2695 *
2696 * @param userHandle The user for whom to check the caller-id permission
2697 * @hide
2698 */
2699 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2700 if (mService != null) {
2701 try {
2702 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2703 } catch (RemoteException e) {
2704 Log.w(TAG, "Failed talking with device policy service", e);
2705 }
2706 }
2707 return false;
2708 }
2709
2710 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002711 * Called by the profile owner of a managed profile so that some intents sent in the managed
2712 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002713 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002714 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2715 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002716 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2717 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002718 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002719 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002720 if (mService != null) {
2721 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002722 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002723 } catch (RemoteException e) {
2724 Log.w(TAG, "Failed talking with device policy service", e);
2725 }
2726 }
2727 }
2728
2729 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002730 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
2731 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002732 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002733 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2734 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002735 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002736 if (mService != null) {
2737 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002738 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002739 } catch (RemoteException e) {
2740 Log.w(TAG, "Failed talking with device policy service", e);
2741 }
2742 }
2743 }
2744
2745 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002746 * Called by a profile or device owner to set the permitted accessibility services. When
2747 * set by a device owner or profile owner the restriction applies to all profiles of the
2748 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07002749 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002750 * By default the user can use any accessiblity service. When zero or more packages have
2751 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07002752 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002753 *
2754 * <p> Calling with a null value for the list disables the restriction so that all services
2755 * can be used, calling with an empty list only allows the builtin system's services.
2756 *
2757 * <p> System accesibility services are always available to the user the list can't modify
2758 * this.
2759 *
2760 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2761 * @param packageNames List of accessibility service package names.
2762 *
2763 * @return true if setting the restriction succeeded. It fail if there is
2764 * one or more non-system accessibility services enabled, that are not in the list.
2765 */
2766 public boolean setPermittedAccessibilityServices(ComponentName admin,
2767 List<String> packageNames) {
2768 if (mService != null) {
2769 try {
2770 return mService.setPermittedAccessibilityServices(admin, packageNames);
2771 } catch (RemoteException e) {
2772 Log.w(TAG, "Failed talking with device policy service", e);
2773 }
2774 }
2775 return false;
2776 }
2777
2778 /**
2779 * Returns the list of permitted accessibility services set by this device or profile owner.
2780 *
2781 * <p>An empty list means no accessibility services except system services are allowed.
2782 * Null means all accessibility services are allowed.
2783 *
2784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2785 * @return List of accessiblity service package names.
2786 */
2787 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2788 if (mService != null) {
2789 try {
2790 return mService.getPermittedAccessibilityServices(admin);
2791 } catch (RemoteException e) {
2792 Log.w(TAG, "Failed talking with device policy service", e);
2793 }
2794 }
2795 return null;
2796 }
2797
2798 /**
2799 * Returns the list of accessibility services permitted by the device or profiles
2800 * owners of this user.
2801 *
2802 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2803 * it will contain the intersection of the permitted lists for any device or profile
2804 * owners that apply to this user. It will also include any system accessibility services.
2805 *
2806 * @param userId which user to check for.
2807 * @return List of accessiblity service package names.
2808 * @hide
2809 */
2810 @SystemApi
2811 public List<String> getPermittedAccessibilityServices(int userId) {
2812 if (mService != null) {
2813 try {
2814 return mService.getPermittedAccessibilityServicesForUser(userId);
2815 } catch (RemoteException e) {
2816 Log.w(TAG, "Failed talking with device policy service", e);
2817 }
2818 }
2819 return null;
2820 }
2821
2822 /**
2823 * Called by a profile or device owner to set the permitted input methods services. When
2824 * set by a device owner or profile owner the restriction applies to all profiles of the
2825 * user the device owner or profile owner is an admin for.
2826 *
2827 * By default the user can use any input method. When zero or more packages have
2828 * been added, input method that are not in the list and not part of the system
2829 * can not be enabled by the user.
2830 *
2831 * This method will fail if it is called for a admin that is not for the foreground user
2832 * or a profile of the foreground user.
2833 *
2834 * <p> Calling with a null value for the list disables the restriction so that all input methods
2835 * can be used, calling with an empty list disables all but the system's own input methods.
2836 *
2837 * <p> System input methods are always available to the user this method can't modify this.
2838 *
2839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2840 * @param packageNames List of input method package names.
2841 * @return true if setting the restriction succeeded. It will fail if there is
2842 * one or more input method enabled, that are not in the list or user if the foreground
2843 * user.
2844 */
2845 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2846 if (mService != null) {
2847 try {
2848 return mService.setPermittedInputMethods(admin, packageNames);
2849 } catch (RemoteException e) {
2850 Log.w(TAG, "Failed talking with device policy service", e);
2851 }
2852 }
2853 return false;
2854 }
2855
2856
2857 /**
2858 * Returns the list of permitted input methods set by this device or profile owner.
2859 *
2860 * <p>An empty list means no input methods except system input methods are allowed.
2861 * Null means all input methods are allowed.
2862 *
2863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2864 * @return List of input method package names.
2865 */
2866 public List<String> getPermittedInputMethods(ComponentName admin) {
2867 if (mService != null) {
2868 try {
2869 return mService.getPermittedInputMethods(admin);
2870 } catch (RemoteException e) {
2871 Log.w(TAG, "Failed talking with device policy service", e);
2872 }
2873 }
2874 return null;
2875 }
2876
2877 /**
2878 * Returns the list of input methods permitted by the device or profiles
2879 * owners of the current user.
2880 *
2881 * <p>Null means all input methods are allowed, if a non-null list is returned
2882 * it will contain the intersection of the permitted lists for any device or profile
2883 * owners that apply to this user. It will also include any system input methods.
2884 *
2885 * @return List of input method package names.
2886 * @hide
2887 */
2888 @SystemApi
2889 public List<String> getPermittedInputMethodsForCurrentUser() {
2890 if (mService != null) {
2891 try {
2892 return mService.getPermittedInputMethodsForCurrentUser();
2893 } catch (RemoteException e) {
2894 Log.w(TAG, "Failed talking with device policy service", e);
2895 }
2896 }
2897 return null;
2898 }
2899
2900 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002901 * Called by a device owner to create a user with the specified name. The UserHandle returned
2902 * by this method should not be persisted as user handles are recycled as users are removed and
2903 * created. If you need to persist an identifier for this user, use
2904 * {@link UserManager#getSerialNumberForUser}.
2905 *
2906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2907 * @param name the user's name
2908 * @see UserHandle
2909 * @return the UserHandle object for the created user, or null if the user could not be created.
2910 */
2911 public UserHandle createUser(ComponentName admin, String name) {
2912 try {
2913 return mService.createUser(admin, name);
2914 } catch (RemoteException re) {
2915 Log.w(TAG, "Could not create a user", re);
2916 }
2917 return null;
2918 }
2919
2920 /**
Jason Monk03978a42014-06-10 15:05:30 -04002921 * Called by a device owner to create a user with the specified name. The UserHandle returned
2922 * by this method should not be persisted as user handles are recycled as users are removed and
2923 * created. If you need to persist an identifier for this user, use
2924 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2925 * immediately.
2926 *
2927 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2928 * as registered as an active admin on the new user. The profile owner package will be
2929 * installed on the new user if it already is installed on the device.
2930 *
2931 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2932 * profileOwnerComponent when onEnable is called.
2933 *
2934 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2935 * @param name the user's name
2936 * @param ownerName the human readable name of the organisation associated with this DPM.
2937 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2938 * the user.
2939 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2940 * on the new user.
2941 * @see UserHandle
2942 * @return the UserHandle object for the created user, or null if the user could not be created.
2943 */
2944 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2945 ComponentName profileOwnerComponent, Bundle adminExtras) {
2946 try {
2947 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2948 adminExtras);
2949 } catch (RemoteException re) {
2950 Log.w(TAG, "Could not create a user", re);
2951 }
2952 return null;
2953 }
2954
2955 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002956 * Called by a device owner to remove a user and all associated data. The primary user can
2957 * not be removed.
2958 *
2959 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2960 * @param userHandle the user to remove.
2961 * @return {@code true} if the user was removed, {@code false} otherwise.
2962 */
2963 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2964 try {
2965 return mService.removeUser(admin, userHandle);
2966 } catch (RemoteException re) {
2967 Log.w(TAG, "Could not remove user ", re);
2968 return false;
2969 }
2970 }
2971
2972 /**
Jason Monk582d9112014-07-09 19:57:08 -04002973 * Called by a device owner to switch the specified user to the foreground.
2974 *
2975 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2976 * @param userHandle the user to switch to; null will switch to primary.
2977 * @return {@code true} if the switch was successful, {@code false} otherwise.
2978 *
2979 * @see Intent#ACTION_USER_FOREGROUND
2980 */
2981 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
2982 try {
2983 return mService.switchUser(admin, userHandle);
2984 } catch (RemoteException re) {
2985 Log.w(TAG, "Could not switch user ", re);
2986 return false;
2987 }
2988 }
2989
2990 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002991 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002992 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002993 *
2994 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2995 * exception will be thrown.
2996 *
2997 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2998 * @param packageName The name of the package to fetch restricted settings of.
2999 * @return {@link Bundle} of settings corresponding to what was set last time
3000 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3001 * if no restrictions have been set.
3002 */
3003 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3004 if (mService != null) {
3005 try {
3006 return mService.getApplicationRestrictions(admin, packageName);
3007 } catch (RemoteException e) {
3008 Log.w(TAG, "Failed talking with device policy service", e);
3009 }
3010 }
3011 return null;
3012 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003013
3014 /**
3015 * Called by a profile or device owner to set a user restriction specified
3016 * by the key.
3017 * <p>
3018 * The calling device admin must be a profile or device owner; if it is not,
3019 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003020 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003021 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3022 * with.
3023 * @param key The key of the restriction. See the constants in
3024 * {@link android.os.UserManager} for the list of keys.
3025 */
3026 public void addUserRestriction(ComponentName admin, String key) {
3027 if (mService != null) {
3028 try {
3029 mService.setUserRestriction(admin, key, true);
3030 } catch (RemoteException e) {
3031 Log.w(TAG, "Failed talking with device policy service", e);
3032 }
3033 }
3034 }
3035
3036 /**
3037 * Called by a profile or device owner to clear a user restriction specified
3038 * by the key.
3039 * <p>
3040 * The calling device admin must be a profile or device owner; if it is not,
3041 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003042 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003043 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3044 * with.
3045 * @param key The key of the restriction. See the constants in
3046 * {@link android.os.UserManager} for the list of keys.
3047 */
3048 public void clearUserRestriction(ComponentName admin, String key) {
3049 if (mService != null) {
3050 try {
3051 mService.setUserRestriction(admin, key, false);
3052 } catch (RemoteException e) {
3053 Log.w(TAG, "Failed talking with device policy service", e);
3054 }
3055 }
3056 }
Adam Connors010cfd42014-04-16 12:48:13 +01003057
3058 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003059 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003060 * is unavailable for use, but the data and actual package file remain.
3061 *
3062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003063 * @param packageName The name of the package to hide or unhide.
3064 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3065 * unhidden.
3066 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003067 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003068 public boolean setApplicationHidden(ComponentName admin, String packageName,
3069 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003070 if (mService != null) {
3071 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003072 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003073 } catch (RemoteException e) {
3074 Log.w(TAG, "Failed talking with device policy service", e);
3075 }
3076 }
3077 return false;
3078 }
3079
3080 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003081 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003082 *
3083 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003084 * @param packageName The name of the package to retrieve the hidden status of.
3085 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003086 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003087 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003088 if (mService != null) {
3089 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003090 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003091 } catch (RemoteException e) {
3092 Log.w(TAG, "Failed talking with device policy service", e);
3093 }
3094 }
3095 return false;
3096 }
3097
3098 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003099 * Called by profile or device owner to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003100 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003101 *
3102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3103 * @param packageName The package to be re-enabled in the current profile.
3104 */
3105 public void enableSystemApp(ComponentName admin, String packageName) {
3106 if (mService != null) {
3107 try {
3108 mService.enableSystemApp(admin, packageName);
3109 } catch (RemoteException e) {
3110 Log.w(TAG, "Failed to install package: " + packageName);
3111 }
3112 }
3113 }
3114
3115 /**
3116 * Called by profile or device owner to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003117 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003118 *
3119 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3120 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3121 * intent will be re-enabled in the current profile.
3122 * @return int The number of activities that matched the intent and were installed.
3123 */
3124 public int enableSystemApp(ComponentName admin, Intent intent) {
3125 if (mService != null) {
3126 try {
3127 return mService.enableSystemAppWithIntent(admin, intent);
3128 } catch (RemoteException e) {
3129 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3130 }
3131 }
3132 return 0;
3133 }
3134
3135 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003136 * Called by a device owner or profile owner to disable account management for a specific type
3137 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003138 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003139 * <p>The calling device admin must be a device owner or profile owner. If it is not, a
Sander Alewijnse650c3342014-05-08 18:00:50 +01003140 * security exception will be thrown.
3141 *
3142 * <p>When account management is disabled for an account type, adding or removing an account
3143 * of that type will not be possible.
3144 *
3145 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3146 * @param accountType For which account management is disabled or enabled.
3147 * @param disabled The boolean indicating that account management will be disabled (true) or
3148 * enabled (false).
3149 */
3150 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3151 boolean disabled) {
3152 if (mService != null) {
3153 try {
3154 mService.setAccountManagementDisabled(admin, accountType, disabled);
3155 } catch (RemoteException e) {
3156 Log.w(TAG, "Failed talking with device policy service", e);
3157 }
3158 }
3159 }
3160
3161 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003162 * Gets the array of accounts for which account management is disabled by the profile owner.
3163 *
3164 * <p> Account management can be disabled/enabled by calling
3165 * {@link #setAccountManagementDisabled}.
3166 *
3167 * @return a list of account types for which account management has been disabled.
3168 *
3169 * @see #setAccountManagementDisabled
3170 */
3171 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003172 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003173 }
3174
3175 /**
3176 * @see #getAccountTypesWithManagementDisabled()
3177 * @hide
3178 */
3179 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003180 if (mService != null) {
3181 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003182 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003183 } catch (RemoteException e) {
3184 Log.w(TAG, "Failed talking with device policy service", e);
3185 }
3186 }
3187
3188 return null;
3189 }
justinzhang511e0d82014-03-24 16:09:24 -04003190
3191 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003192 * Sets which packages may enter lock task mode.
3193 *
3194 * <p>Any packages that shares uid with an allowed package will also be allowed
3195 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003196 *
Jason Monkc5185f22014-06-24 11:12:42 -04003197 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003198 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003199 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003200 *
3201 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003202 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3203 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003204 */
Jason Monk48aacba2014-08-13 16:29:08 -04003205 public void setLockTaskPackages(ComponentName admin, String[] packages)
3206 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003207 if (mService != null) {
3208 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003209 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003210 } catch (RemoteException e) {
3211 Log.w(TAG, "Failed talking with device policy service", e);
3212 }
3213 }
3214 }
3215
3216 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003217 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003218 *
3219 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003220 * @hide
3221 */
Jason Monk48aacba2014-08-13 16:29:08 -04003222 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003223 if (mService != null) {
3224 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003225 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003226 } catch (RemoteException e) {
3227 Log.w(TAG, "Failed talking with device policy service", e);
3228 }
3229 }
3230 return null;
3231 }
3232
3233 /**
3234 * This function lets the caller know whether the given component is allowed to start the
3235 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003236 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003237 */
Jason Monkd7b86212014-06-16 13:15:38 -04003238 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003239 if (mService != null) {
3240 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003241 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003242 } catch (RemoteException e) {
3243 Log.w(TAG, "Failed talking with device policy service", e);
3244 }
3245 }
3246 return false;
3247 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003248
3249 /**
3250 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3251 * 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 -04003252 * <p>The settings that can be updated with this method are:
3253 * <ul>
3254 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3255 * <li>{@link Settings.Global#AUTO_TIME}</li>
3256 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
3257 * <li>{@link Settings.Global#BLUETOOTH_ON}</li>
3258 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3259 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3260 * <li>{@link Settings.Global#MODE_RINGER}</li>
3261 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3262 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
3263 * <li>{@link Settings.Global#WIFI_ON}</li>
3264 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3265 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003266 *
3267 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3268 * @param setting The name of the setting to update.
3269 * @param value The value to update the setting to.
3270 */
3271 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3272 if (mService != null) {
3273 try {
3274 mService.setGlobalSetting(admin, setting, value);
3275 } catch (RemoteException e) {
3276 Log.w(TAG, "Failed talking with device policy service", e);
3277 }
3278 }
3279 }
3280
3281 /**
3282 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3283 * that the value of the setting is in the correct form for the setting type should be performed
3284 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003285 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003286 * <ul>
3287 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
3288 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3289 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003290 * <p>A device owner can additionally update the following settings:
3291 * <ul>
3292 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3293 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3295 * @param setting The name of the setting to update.
3296 * @param value The value to update the setting to.
3297 */
3298 public void setSecureSetting(ComponentName admin, String setting, String value) {
3299 if (mService != null) {
3300 try {
3301 mService.setSecureSetting(admin, setting, value);
3302 } catch (RemoteException e) {
3303 Log.w(TAG, "Failed talking with device policy service", e);
3304 }
3305 }
3306 }
3307
Amith Yamasanif20d6402014-05-24 15:34:37 -07003308 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003309 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003310 * making permission requests of a local or remote administrator of the user.
3311 * <p/>
3312 * Only a profile owner can designate the restrictions provider.
3313 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003314 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003315 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003316 * it removes the restrictions provider previously assigned.
3317 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003318 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003319 if (mService != null) {
3320 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003321 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003322 } catch (RemoteException re) {
3323 Log.w(TAG, "Failed to set permission provider on device policy service");
3324 }
3325 }
3326 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003327
3328 /**
3329 * Called by profile or device owners to set the master volume mute on or off.
3330 *
3331 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3332 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3333 */
3334 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3335 if (mService != null) {
3336 try {
3337 mService.setMasterVolumeMuted(admin, on);
3338 } catch (RemoteException re) {
3339 Log.w(TAG, "Failed to setMasterMute on device policy service");
3340 }
3341 }
3342 }
3343
3344 /**
3345 * Called by profile or device owners to check whether the master volume mute is on or off.
3346 *
3347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3348 * @return {@code true} if master volume is muted, {@code false} if it's not.
3349 */
3350 public boolean isMasterVolumeMuted(ComponentName admin) {
3351 if (mService != null) {
3352 try {
3353 return mService.isMasterVolumeMuted(admin);
3354 } catch (RemoteException re) {
3355 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3356 }
3357 }
3358 return false;
3359 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003360
3361 /**
3362 * Called by profile or device owners to change whether a user can uninstall
3363 * a package.
3364 *
3365 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3366 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003367 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003368 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003369 public void setUninstallBlocked(ComponentName admin, String packageName,
3370 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003371 if (mService != null) {
3372 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003373 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003374 } catch (RemoteException re) {
3375 Log.w(TAG, "Failed to call block uninstall on device policy service");
3376 }
3377 }
3378 }
3379
3380 /**
3381 * Called by profile or device owners to check whether a user has been blocked from
3382 * uninstalling a package.
3383 *
3384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3385 * @param packageName package to check.
3386 * @return true if the user shouldn't be able to uninstall the package.
3387 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003388 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003389 if (mService != null) {
3390 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003391 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003392 } catch (RemoteException re) {
3393 Log.w(TAG, "Failed to call block uninstall on device policy service");
3394 }
3395 }
3396 return false;
3397 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003398
3399 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003400 * Called by the profile owner of a managed profile to enable widget providers from a
3401 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003402 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003403 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003404 * a package may have zero or more provider components, where each component
3405 * provides a different widget type.
3406 * <p>
3407 * <strong>Note:</strong> By default no widget provider package is white-listed.
3408 * </p>
3409 *
3410 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3411 * @param packageName The package from which widget providers are white-listed.
3412 * @return Whether the package was added.
3413 *
3414 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3415 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3416 */
3417 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3418 if (mService != null) {
3419 try {
3420 return mService.addCrossProfileWidgetProvider(admin, packageName);
3421 } catch (RemoteException re) {
3422 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3423 }
3424 }
3425 return false;
3426 }
3427
3428 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003429 * Called by the profile owner of a managed profile to disable widget providers from a given
3430 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003431 * package should have been added via {@link #addCrossProfileWidgetProvider(
3432 * android.content.ComponentName, String)}.
3433 * <p>
3434 * <strong>Note:</strong> By default no widget provider package is white-listed.
3435 * </p>
3436 *
3437 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3438 * @param packageName The package from which widget providers are no longer
3439 * white-listed.
3440 * @return Whether the package was removed.
3441 *
3442 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3443 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3444 */
3445 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3446 if (mService != null) {
3447 try {
3448 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3449 } catch (RemoteException re) {
3450 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3451 }
3452 }
3453 return false;
3454 }
3455
3456 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003457 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003458 * available in the parent profile.
3459 *
3460 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3461 * @return The white-listed package list.
3462 *
3463 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3464 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3465 */
3466 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3467 if (mService != null) {
3468 try {
3469 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3470 if (providers != null) {
3471 return providers;
3472 }
3473 } catch (RemoteException re) {
3474 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3475 }
3476 }
3477 return Collections.emptyList();
3478 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003479}