blob: 926a34830f14ec50abdf727f4678230a4efefb02 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Dianne Hackbornd6847842010-01-12 18:14:19 -080019import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050021import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040022import android.app.Activity;
Svetoslav976e8bd2014-07-16 15:12:03 -070023import android.app.admin.IDevicePolicyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.content.ComponentName;
25import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010026import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000027import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080028import android.content.pm.ActivityInfo;
29import android.content.pm.PackageManager;
30import android.content.pm.ResolveInfo;
Jason Monk03bc9912014-05-13 09:44:57 -040031import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010032import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.os.Handler;
Adam Connors776c5552014-01-09 10:42:56 +000034import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080035import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080036import android.os.RemoteException;
37import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070038import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040039import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040040import android.provider.Settings;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070041import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080042import android.util.Log;
43
Maggie Benthallda51e682013-08-08 22:35:44 -040044import com.android.org.conscrypt.TrustedCertificateStore;
45
Jessica Hummel91da58d2014-04-10 17:39:43 +010046import org.xmlpull.v1.XmlPullParserException;
47
Maggie Benthallda51e682013-08-08 22:35:44 -040048import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080049import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070050import java.net.InetSocketAddress;
51import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040052import java.security.cert.CertificateException;
53import java.security.cert.CertificateFactory;
54import java.security.cert.X509Certificate;
Jim Miller604e7552014-07-18 19:00:02 -070055import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070056import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080057import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080058
59/**
60 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080061 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080062 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080063 *
64 * <div class="special reference">
65 * <h3>Developer Guides</h3>
66 * <p>For more information about managing policies for device adminstration, read the
67 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
68 * developer guide.</p>
69 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080070 */
71public class DevicePolicyManager {
72 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080073
74 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080075 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070076
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080077 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080078 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080079 mService = IDevicePolicyManager.Stub.asInterface(
80 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
81 }
82
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080083 /** @hide */
84 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080085 DevicePolicyManager me = new DevicePolicyManager(context, handler);
86 return me.mService != null ? me : null;
87 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070088
Dianne Hackbornd6847842010-01-12 18:14:19 -080089 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +000090 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +000091 *
Jessica Hummel9da60392014-05-21 12:32:57 +010092 * <p>A managed profile allows data separation for example for the usage of a
93 * device as a personal and corporate device. The user which provisioning is started from and
94 * the managed profile share a launcher.
95 *
96 * <p>This intent will typically be sent by a mobile device management application (mdm).
97 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
98 * control over the profile
99 *
100 * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}
101 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000102 *
103 * <p> When managed provisioning has completed, an intent of the type
104 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100105 * managed profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100106 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100107 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
108 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000109 *
110 * <p>Input: Nothing.</p>
111 * <p>Output: Nothing</p>
112 */
113 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
114 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000115 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116
117 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700118 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
119 * a mobile device management application that starts managed profile provisioning to pass data
120 * to itself on the managed profile when provisioning completes. The mobile device management
121 * application sends this extra in an intent with the action
122 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
123 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
124 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
125 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100126 */
127 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100128 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100129
130 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100131 * A String extra holding the package name of the mobile device management application that
132 * will be set as the profile owner or device owner.
133 *
134 * <p>If an application starts provisioning directly via an intent with action
135 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
136 * application that started provisioning. The package will be set as profile owner in that case.
137 *
138 * <p>This package is set as device owner when device owner provisioning is started by an Nfc
Esteban Talaveraf057f062014-08-20 14:27:45 +0100139 * message containing an Nfc record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000140 */
141 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaverafbb28df2014-08-26 15:38:17 +0100142 = "android.app.extra.deviceAdminPackageName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000143
144 /**
145 * A String extra holding the default name of the profile that is created during managed profile
146 * provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100147 *
Jessica Hummelf72078b2014-03-06 16:13:12 +0000148 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
149 */
150 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Esteban Talavera37f01842014-09-05 10:50:57 +0100151 = "android.app.extra.PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000152
153 /**
Sander Alewijnseaff9f4cb2014-09-04 11:23:09 +0100154 * A bundle key, used in the bundle extra {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. The
155 * corresponding value holds the email address of the account which the managed profile is
156 * created for.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100157 */
Sander Alewijnseaff9f4cb2014-09-04 11:23:09 +0100158 public static final String KEY_PROVISIONING_EMAIL_ADDRESS
Esteban Talavera37f01842014-09-05 10:50:57 +0100159 = "android.app.key.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100160
161 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100162 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
163 * will be set to.
164 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100165 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100166 * provisioning via an Nfc bump.
167 */
168 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100169 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100170
171 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100172 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
173 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100174 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100175 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100176 * provisioning via an Nfc bump.
177 */
178 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100179 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100180
181 /**
182 * A String extra holding the {@link java.util.Locale} that the device will be set to.
183 * Format: xx_yy, where xx is the language code, and yy the country code.
184 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100185 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100186 * provisioning via an Nfc bump.
187 */
188 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100189 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100190
191 /**
192 * A String extra holding the ssid of the wifi network that should be used during nfc device
193 * owner provisioning for downloading the mobile device management application.
194 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100195 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100196 * provisioning via an Nfc bump.
197 */
198 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100199 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100200
201 /**
202 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
203 * is hidden or not.
204 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100205 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100206 * provisioning via an Nfc bump.
207 */
208 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100209 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100210
211 /**
212 * A String extra indicating the security type of the wifi network in
213 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
214 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100215 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100216 * provisioning via an Nfc bump.
217 */
218 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100219 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100220
221 /**
222 * A String extra holding the password of the wifi network in
223 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
224 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100225 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100226 * provisioning via an Nfc bump.
227 */
228 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100229 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100230
231 /**
232 * A String extra holding the proxy host for the wifi network in
233 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
234 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100235 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100236 * provisioning via an Nfc bump.
237 */
238 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100239 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100240
241 /**
242 * An int extra holding the proxy port for the wifi network in
243 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
244 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100245 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100246 * provisioning via an Nfc bump.
247 */
248 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100249 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100250
251 /**
252 * A String extra holding the proxy bypass for the wifi network in
253 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
254 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100255 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100256 * provisioning via an Nfc bump.
257 */
258 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100259 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100260
261 /**
262 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
263 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
264 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100265 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100266 * provisioning via an Nfc bump.
267 */
268 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100269 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100270
271 /**
272 * A String extra holding a url that specifies the download location of the device admin
273 * package. When not provided it is assumed that the device admin package is already installed.
274 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100275 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100276 * provisioning via an Nfc bump.
277 */
278 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100279 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100280
281 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100282 * A String extra holding a http cookie header which should be used in the http request to the
283 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
284 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100285 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse681bce92014-07-24 16:46:26 +0100286 * provisioning via an Nfc bump.
287 */
288 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100289 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100290
291 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100292 * A String extra holding the SHA-1 checksum of the file at download location specified in
293 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
294 * the file at the download location an error will be shown to the user and the user will be
295 * asked to factory reset the device.
296 *
Esteban Talaveraf057f062014-08-20 14:27:45 +0100297 * <p>Use in an Nfc record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100298 * provisioning via an Nfc bump.
299 */
300 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100301 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100302
303 /**
304 * This MIME type is used for starting the Device Owner provisioning.
305 *
306 * <p>During device owner provisioning a device admin app is set as the owner of the device.
307 * A device owner has full control over the device. The device owner can not be modified by the
308 * user and the only way of resetting the device is if the device owner app calls a factory
309 * reset.
310 *
311 * <p> A typical use case would be a device that is owned by a company, but used by either an
312 * employee or client.
313 *
314 * <p> The Nfc message should be send to an unprovisioned device.
315 *
316 * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which
317 * contains the following properties:
318 * <ul>
319 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
320 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100321 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100322 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
323 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
324 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
325 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
326 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
327 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
328 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
329 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
330 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
332 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
333 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
334 *
335 * <p> When device owner provisioning has completed, an intent of the type
336 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
337 * device owner.
338 *
339 * <p>
340 * If provisioning fails, the device is factory reset.
341 *
342 * <p>Input: Nothing.</p>
343 * <p>Output: Nothing</p>
344 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100345 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100346 = "application/com.android.managedprovisioning";
347
348 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800349 * Activity action: ask the user to add a new device administrator to the system.
350 * The desired policy is the ComponentName of the policy in the
351 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
352 * bring the user through adding the device administrator to the system (or
353 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700354 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800355 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
356 * field to provide the user with additional explanation (in addition
357 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800358 *
359 * <p>If your administrator is already active, this will ordinarily return immediately (without
360 * user intervention). However, if your administrator has been updated and is requesting
361 * additional uses-policy flags, the user will be presented with the new list. New policies
362 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800363 */
364 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
365 public static final String ACTION_ADD_DEVICE_ADMIN
366 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700367
Dianne Hackbornd6847842010-01-12 18:14:19 -0800368 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700369 * @hide
370 * Activity action: ask the user to add a new device administrator as the profile owner
371 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
372 * permission can call this API.
373 *
374 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
375 * field. This will invoke a UI to bring the user through adding the profile owner admin
376 * to remotely control restrictions on the user.
377 *
378 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
379 * result of whether or not the user approved the action. If approved, the result will
380 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
381 * as a profile owner.
382 *
383 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
384 * field to provide the user with additional explanation (in addition
385 * to your component's description) about what is being added.
386 *
387 * <p>If there is already a profile owner active or the caller doesn't have the required
388 * permissions, the operation will return a failure result.
389 */
390 @SystemApi
391 public static final String ACTION_SET_PROFILE_OWNER
392 = "android.app.action.SET_PROFILE_OWNER";
393
394 /**
395 * @hide
396 * Name of the profile owner admin that controls the user.
397 */
398 @SystemApi
399 public static final String EXTRA_PROFILE_OWNER_NAME
400 = "android.app.extra.PROFILE_OWNER_NAME";
401
402 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700403 * Activity action: send when any policy admin changes a policy.
404 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700405 *
Jim Miller284b62e2010-06-08 14:27:42 -0700406 * @hide
407 */
408 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
409 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
410
411 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800412 * The ComponentName of the administrator component.
413 *
414 * @see #ACTION_ADD_DEVICE_ADMIN
415 */
416 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700417
Dianne Hackbornd6847842010-01-12 18:14:19 -0800418 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800419 * An optional CharSequence providing additional explanation for why the
420 * admin is being added.
421 *
422 * @see #ACTION_ADD_DEVICE_ADMIN
423 */
424 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700425
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800426 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700427 * Activity action: have the user enter a new password. This activity should
428 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
429 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
430 * enter a new password that meets the current requirements. You can use
431 * {@link #isActivePasswordSufficient()} to determine whether you need to
432 * have the user select a new password in order to meet the current
433 * constraints. Upon being resumed from this activity, you can check the new
434 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800435 */
436 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
437 public static final String ACTION_SET_NEW_PASSWORD
438 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700439
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000440 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100441 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
442 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000443 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100444 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000445
446 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100447 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
448 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000449 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100450 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700451
Dianne Hackbornd6847842010-01-12 18:14:19 -0800452 /**
453 * Return true if the given administrator component is currently
454 * active (enabled) in the system.
455 */
456 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100457 return isAdminActiveAsUser(who, UserHandle.myUserId());
458 }
459
460 /**
461 * @see #isAdminActive(ComponentName)
462 * @hide
463 */
464 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800465 if (mService != null) {
466 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100467 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800468 } catch (RemoteException e) {
469 Log.w(TAG, "Failed talking with device policy service", e);
470 }
471 }
472 return false;
473 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700474
Dianne Hackbornd6847842010-01-12 18:14:19 -0800475 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800476 * Return a list of all currently active device administrator's component
477 * names. Note that if there are no administrators than null may be
478 * returned.
479 */
480 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100481 return getActiveAdminsAsUser(UserHandle.myUserId());
482 }
483
484 /**
485 * @see #getActiveAdmins()
486 * @hide
487 */
488 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800489 if (mService != null) {
490 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100491 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800492 } catch (RemoteException e) {
493 Log.w(TAG, "Failed talking with device policy service", e);
494 }
495 }
496 return null;
497 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700498
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800499 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700500 * Used by package administration code to determine if a package can be stopped
501 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800502 * @hide
503 */
504 public boolean packageHasActiveAdmins(String packageName) {
505 if (mService != null) {
506 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700507 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800508 } catch (RemoteException e) {
509 Log.w(TAG, "Failed talking with device policy service", e);
510 }
511 }
512 return false;
513 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700514
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800515 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800516 * Remove a current administration component. This can only be called
517 * by the application that owns the administration component; if you
518 * try to remove someone else's component, a security exception will be
519 * thrown.
520 */
521 public void removeActiveAdmin(ComponentName who) {
522 if (mService != null) {
523 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700524 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800525 } catch (RemoteException e) {
526 Log.w(TAG, "Failed talking with device policy service", e);
527 }
528 }
529 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700530
Dianne Hackbornd6847842010-01-12 18:14:19 -0800531 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800532 * Returns true if an administrator has been granted a particular device policy. This can
533 * be used to check if the administrator was activated under an earlier set of policies,
534 * but requires additional policies after an upgrade.
535 *
536 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
537 * an active administrator, or an exception will be thrown.
538 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
539 */
540 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
541 if (mService != null) {
542 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700543 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800544 } catch (RemoteException e) {
545 Log.w(TAG, "Failed talking with device policy service", e);
546 }
547 }
548 return false;
549 }
550
551 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800552 * Constant for {@link #setPasswordQuality}: the policy has no requirements
553 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800554 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800555 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800556 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700557
Dianne Hackbornd6847842010-01-12 18:14:19 -0800558 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700559 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
560 * recognition technology. This implies technologies that can recognize the identity of
561 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
562 * Note that quality constants are ordered so that higher values are more restrictive.
563 */
564 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
565
566 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800567 * Constant for {@link #setPasswordQuality}: the policy requires some kind
568 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800569 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800570 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800571 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700572
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800573 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800574 * Constant for {@link #setPasswordQuality}: the user must have entered a
575 * password containing at least numeric characters. Note that quality
576 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800577 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800578 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700579
Dianne Hackbornd6847842010-01-12 18:14:19 -0800580 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800581 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800582 * password containing at least numeric characters with no repeating (4444)
583 * or ordered (1234, 4321, 2468) sequences. Note that quality
584 * constants are ordered so that higher values are more restrictive.
585 */
586 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
587
588 /**
589 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700590 * password containing at least alphabetic (or other symbol) characters.
591 * Note that quality constants are ordered so that higher values are more
592 * restrictive.
593 */
594 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700595
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700596 /**
597 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800598 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700599 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800600 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800601 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700602 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700603
Dianne Hackbornd6847842010-01-12 18:14:19 -0800604 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700605 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700606 * password containing at least a letter, a numerical digit and a special
607 * symbol, by default. With this password quality, passwords can be
608 * restricted to contain various sets of characters, like at least an
609 * uppercase letter, etc. These are specified using various methods,
610 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
611 * that quality constants are ordered so that higher values are more
612 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700613 */
614 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
615
616 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800617 * Called by an application that is administering the device to set the
618 * password restrictions it is imposing. After setting this, the user
619 * will not be able to enter a new password that is not at least as
620 * restrictive as what has been set. Note that the current password
621 * will remain until the user has set a new one, so the change does not
622 * take place immediately. To prompt the user for a new password, use
623 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700624 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800625 * <p>Quality constants are ordered so that higher values are more restrictive;
626 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800627 * the user's preference, and any other considerations) is the one that
628 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700629 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800630 * <p>The calling device admin must have requested
631 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
632 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700633 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800635 * @param quality The new desired quality. One of
636 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800637 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
638 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
639 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800640 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800641 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800642 if (mService != null) {
643 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700644 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800645 } catch (RemoteException e) {
646 Log.w(TAG, "Failed talking with device policy service", e);
647 }
648 }
649 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700650
Dianne Hackbornd6847842010-01-12 18:14:19 -0800651 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100652 * Retrieve the current minimum password quality for all admins of this user
653 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800654 * @param admin The name of the admin component to check, or null to aggregate
655 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800656 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800657 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700658 return getPasswordQuality(admin, UserHandle.myUserId());
659 }
660
661 /** @hide per-user version */
662 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800663 if (mService != null) {
664 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700665 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800666 } catch (RemoteException e) {
667 Log.w(TAG, "Failed talking with device policy service", e);
668 }
669 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800670 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800671 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700672
Dianne Hackbornd6847842010-01-12 18:14:19 -0800673 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800674 * Called by an application that is administering the device to set the
675 * minimum allowed password length. After setting this, the user
676 * will not be able to enter a new password that is not at least as
677 * restrictive as what has been set. Note that the current password
678 * will remain until the user has set a new one, so the change does not
679 * take place immediately. To prompt the user for a new password, use
680 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
681 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800682 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
683 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
684 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700685 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800686 * <p>The calling device admin must have requested
687 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
688 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700689 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800690 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800691 * @param length The new desired minimum password length. A value of 0
692 * means there is no restriction.
693 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800694 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800695 if (mService != null) {
696 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700697 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800698 } catch (RemoteException e) {
699 Log.w(TAG, "Failed talking with device policy service", e);
700 }
701 }
702 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700703
Dianne Hackbornd6847842010-01-12 18:14:19 -0800704 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100705 * Retrieve the current minimum password length for all admins of this
706 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800707 * @param admin The name of the admin component to check, or null to aggregate
708 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800709 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800710 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700711 return getPasswordMinimumLength(admin, UserHandle.myUserId());
712 }
713
714 /** @hide per-user version */
715 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800716 if (mService != null) {
717 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700718 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800719 } catch (RemoteException e) {
720 Log.w(TAG, "Failed talking with device policy service", e);
721 }
722 }
723 return 0;
724 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700725
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700726 /**
727 * Called by an application that is administering the device to set the
728 * minimum number of upper case letters required in the password. After
729 * setting this, the user will not be able to enter a new password that is
730 * not at least as restrictive as what has been set. Note that the current
731 * password will remain until the user has set a new one, so the change does
732 * not take place immediately. To prompt the user for a new password, use
733 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
734 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700735 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
736 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700737 * <p>
738 * The calling device admin must have requested
739 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
740 * this method; if it has not, a security exception will be thrown.
741 *
742 * @param admin Which {@link DeviceAdminReceiver} this request is associated
743 * with.
744 * @param length The new desired minimum number of upper case letters
745 * required in the password. A value of 0 means there is no
746 * restriction.
747 */
748 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
749 if (mService != null) {
750 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700751 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700752 } catch (RemoteException e) {
753 Log.w(TAG, "Failed talking with device policy service", e);
754 }
755 }
756 }
757
758 /**
759 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100760 * password for all admins of this user and its profiles or a particular one.
761 * This is the same value as set by
762 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700763 * and only applies when the password quality is
764 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700765 *
766 * @param admin The name of the admin component to check, or null to
767 * aggregate all admins.
768 * @return The minimum number of upper case letters required in the
769 * password.
770 */
771 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700772 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
773 }
774
775 /** @hide per-user version */
776 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700777 if (mService != null) {
778 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700779 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700780 } catch (RemoteException e) {
781 Log.w(TAG, "Failed talking with device policy service", e);
782 }
783 }
784 return 0;
785 }
786
787 /**
788 * Called by an application that is administering the device to set the
789 * minimum number of lower case letters required in the password. After
790 * setting this, the user will not be able to enter a new password that is
791 * not at least as restrictive as what has been set. Note that the current
792 * password will remain until the user has set a new one, so the change does
793 * not take place immediately. To prompt the user for a new password, use
794 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
795 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700796 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
797 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700798 * <p>
799 * The calling device admin must have requested
800 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
801 * this method; if it has not, a security exception will be thrown.
802 *
803 * @param admin Which {@link DeviceAdminReceiver} this request is associated
804 * with.
805 * @param length The new desired minimum number of lower case letters
806 * required in the password. A value of 0 means there is no
807 * restriction.
808 */
809 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
810 if (mService != null) {
811 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700812 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700813 } catch (RemoteException e) {
814 Log.w(TAG, "Failed talking with device policy service", e);
815 }
816 }
817 }
818
819 /**
820 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100821 * password for all admins of this user and its profiles or a particular one.
822 * This is the same value as set by
823 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700824 * and only applies when the password quality is
825 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700826 *
827 * @param admin The name of the admin component to check, or null to
828 * aggregate all admins.
829 * @return The minimum number of lower case letters required in the
830 * password.
831 */
832 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700833 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
834 }
835
836 /** @hide per-user version */
837 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700838 if (mService != null) {
839 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700840 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700841 } catch (RemoteException e) {
842 Log.w(TAG, "Failed talking with device policy service", e);
843 }
844 }
845 return 0;
846 }
847
848 /**
849 * Called by an application that is administering the device to set the
850 * minimum number of letters required in the password. After setting this,
851 * the user will not be able to enter a new password that is not at least as
852 * restrictive as what has been set. Note that the current password will
853 * remain until the user has set a new one, so the change does not take
854 * place immediately. To prompt the user for a new password, use
855 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
856 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700857 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
858 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700859 * <p>
860 * The calling device admin must have requested
861 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
862 * this method; if it has not, a security exception will be thrown.
863 *
864 * @param admin Which {@link DeviceAdminReceiver} this request is associated
865 * with.
866 * @param length The new desired minimum number of letters required in the
867 * password. A value of 0 means there is no restriction.
868 */
869 public void setPasswordMinimumLetters(ComponentName admin, int length) {
870 if (mService != null) {
871 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700872 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700873 } catch (RemoteException e) {
874 Log.w(TAG, "Failed talking with device policy service", e);
875 }
876 }
877 }
878
879 /**
880 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700881 * admins or a particular one. This is the same value as
882 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
883 * and only applies when the password quality is
884 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700885 *
886 * @param admin The name of the admin component to check, or null to
887 * aggregate all admins.
888 * @return The minimum number of letters required in the password.
889 */
890 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700891 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
892 }
893
894 /** @hide per-user version */
895 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700896 if (mService != null) {
897 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700898 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700899 } catch (RemoteException e) {
900 Log.w(TAG, "Failed talking with device policy service", e);
901 }
902 }
903 return 0;
904 }
905
906 /**
907 * Called by an application that is administering the device to set the
908 * minimum number of numerical digits required in the password. After
909 * setting this, the user will not be able to enter a new password that is
910 * not at least as restrictive as what has been set. Note that the current
911 * password will remain until the user has set a new one, so the change does
912 * not take place immediately. To prompt the user for a new password, use
913 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
914 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700915 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
916 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700917 * <p>
918 * The calling device admin must have requested
919 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
920 * this method; if it has not, a security exception will be thrown.
921 *
922 * @param admin Which {@link DeviceAdminReceiver} this request is associated
923 * with.
924 * @param length The new desired minimum number of numerical digits required
925 * in the password. A value of 0 means there is no restriction.
926 */
927 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
928 if (mService != null) {
929 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700930 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700931 } catch (RemoteException e) {
932 Log.w(TAG, "Failed talking with device policy service", e);
933 }
934 }
935 }
936
937 /**
938 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100939 * for all admins of this user and its profiles or a particular one.
940 * This is the same value as set by
941 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700942 * and only applies when the password quality is
943 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700944 *
945 * @param admin The name of the admin component to check, or null to
946 * aggregate all admins.
947 * @return The minimum number of numerical digits required in the password.
948 */
949 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700950 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
951 }
952
953 /** @hide per-user version */
954 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700955 if (mService != null) {
956 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700957 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700958 } catch (RemoteException e) {
959 Log.w(TAG, "Failed talking with device policy service", e);
960 }
961 }
962 return 0;
963 }
964
965 /**
966 * Called by an application that is administering the device to set the
967 * minimum number of symbols required in the password. After setting this,
968 * the user will not be able to enter a new password that is not at least as
969 * restrictive as what has been set. Note that the current password will
970 * remain until the user has set a new one, so the change does not take
971 * place immediately. To prompt the user for a new password, use
972 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
973 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700974 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
975 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700976 * <p>
977 * The calling device admin must have requested
978 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
979 * this method; if it has not, a security exception will be thrown.
980 *
981 * @param admin Which {@link DeviceAdminReceiver} this request is associated
982 * with.
983 * @param length The new desired minimum number of symbols required in the
984 * password. A value of 0 means there is no restriction.
985 */
986 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
987 if (mService != null) {
988 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700989 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700990 } catch (RemoteException e) {
991 Log.w(TAG, "Failed talking with device policy service", e);
992 }
993 }
994 }
995
996 /**
997 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700998 * admins or a particular one. This is the same value as
999 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1000 * and only applies when the password quality is
1001 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001002 *
1003 * @param admin The name of the admin component to check, or null to
1004 * aggregate all admins.
1005 * @return The minimum number of symbols required in the password.
1006 */
1007 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001008 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1009 }
1010
1011 /** @hide per-user version */
1012 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001013 if (mService != null) {
1014 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001015 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001016 } catch (RemoteException e) {
1017 Log.w(TAG, "Failed talking with device policy service", e);
1018 }
1019 }
1020 return 0;
1021 }
1022
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001023 /**
1024 * Called by an application that is administering the device to set the
1025 * minimum number of non-letter characters (numerical digits or symbols)
1026 * required in the password. After setting this, the user will not be able
1027 * to enter a new password that is not at least as restrictive as what has
1028 * been set. Note that the current password will remain until the user has
1029 * set a new one, so the change does not take place immediately. To prompt
1030 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1031 * setting this value. This constraint is only imposed if the administrator
1032 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1033 * {@link #setPasswordQuality}. The default value is 0.
1034 * <p>
1035 * The calling device admin must have requested
1036 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1037 * this method; if it has not, a security exception will be thrown.
1038 *
1039 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1040 * with.
1041 * @param length The new desired minimum number of letters required in the
1042 * password. A value of 0 means there is no restriction.
1043 */
1044 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1045 if (mService != null) {
1046 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001047 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001048 } catch (RemoteException e) {
1049 Log.w(TAG, "Failed talking with device policy service", e);
1050 }
1051 }
1052 }
1053
1054 /**
1055 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001056 * password for all admins of this user and its profiles or a particular one.
1057 * This is the same value as set by
1058 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001059 * and only applies when the password quality is
1060 * {@link #PASSWORD_QUALITY_COMPLEX}.
1061 *
1062 * @param admin The name of the admin component to check, or null to
1063 * aggregate all admins.
1064 * @return The minimum number of letters required in the password.
1065 */
1066 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001067 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1068 }
1069
1070 /** @hide per-user version */
1071 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001072 if (mService != null) {
1073 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001074 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001075 } catch (RemoteException e) {
1076 Log.w(TAG, "Failed talking with device policy service", e);
1077 }
1078 }
1079 return 0;
1080 }
1081
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001082 /**
1083 * Called by an application that is administering the device to set the length
1084 * of the password history. After setting this, the user will not be able to
1085 * enter a new password that is the same as any password in the history. Note
1086 * that the current password will remain until the user has set a new one, so
1087 * the change does not take place immediately. To prompt the user for a new
1088 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1089 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001090 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1091 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1092 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001093 *
1094 * <p>
1095 * The calling device admin must have requested
1096 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1097 * method; if it has not, a security exception will be thrown.
1098 *
1099 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1100 * with.
1101 * @param length The new desired length of password history. A value of 0
1102 * means there is no restriction.
1103 */
1104 public void setPasswordHistoryLength(ComponentName admin, int length) {
1105 if (mService != null) {
1106 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001107 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001108 } catch (RemoteException e) {
1109 Log.w(TAG, "Failed talking with device policy service", e);
1110 }
1111 }
1112 }
1113
1114 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001115 * Called by a device admin to set the password expiration timeout. Calling this method
1116 * will restart the countdown for password expiration for the given admin, as will changing
1117 * the device password (for all admins).
1118 *
1119 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1120 * For example, to have the password expire 5 days from now, timeout would be
1121 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1122 *
1123 * <p>To disable password expiration, a value of 0 may be used for timeout.
1124 *
Jim Millera4e28d12010-11-08 16:15:47 -08001125 * <p>The calling device admin must have requested
1126 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1127 * method; if it has not, a security exception will be thrown.
1128 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001129 * <p> Note that setting the password will automatically reset the expiration time for all
1130 * active admins. Active admins do not need to explicitly call this method in that case.
1131 *
Jim Millera4e28d12010-11-08 16:15:47 -08001132 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1133 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1134 * means there is no restriction (unlimited).
1135 */
1136 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1137 if (mService != null) {
1138 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001139 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001140 } catch (RemoteException e) {
1141 Log.w(TAG, "Failed talking with device policy service", e);
1142 }
1143 }
1144 }
1145
1146 /**
Jim Miller6b857682011-02-16 16:27:41 -08001147 * Get the password expiration timeout for the given admin. The expiration timeout is the
1148 * recurring expiration timeout provided in the call to
1149 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1150 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001151 *
1152 * @param admin The name of the admin component to check, or null to aggregate all admins.
1153 * @return The timeout for the given admin or the minimum of all timeouts
1154 */
1155 public long getPasswordExpirationTimeout(ComponentName admin) {
1156 if (mService != null) {
1157 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001158 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001159 } catch (RemoteException e) {
1160 Log.w(TAG, "Failed talking with device policy service", e);
1161 }
1162 }
1163 return 0;
1164 }
1165
1166 /**
1167 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001168 * all admins of this user and its profiles if admin is null. If the password is
1169 * expired, this will return the time since the password expired as a negative number.
1170 * If admin is null, then a composite of all expiration timeouts is returned
1171 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001172 *
1173 * @param admin The name of the admin component to check, or null to aggregate all admins.
1174 * @return The password expiration time, in ms.
1175 */
1176 public long getPasswordExpiration(ComponentName admin) {
1177 if (mService != null) {
1178 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001179 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001180 } catch (RemoteException e) {
1181 Log.w(TAG, "Failed talking with device policy service", e);
1182 }
1183 }
1184 return 0;
1185 }
1186
1187 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001188 * Retrieve the current password history length for all admins of this
1189 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001190 * @param admin The name of the admin component to check, or null to aggregate
1191 * all admins.
1192 * @return The length of the password history
1193 */
1194 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001195 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1196 }
1197
1198 /** @hide per-user version */
1199 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001200 if (mService != null) {
1201 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001202 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001203 } catch (RemoteException e) {
1204 Log.w(TAG, "Failed talking with device policy service", e);
1205 }
1206 }
1207 return 0;
1208 }
1209
Dianne Hackbornd6847842010-01-12 18:14:19 -08001210 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001211 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001212 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001213 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001214 * @return Returns the maximum length that the user can enter.
1215 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001216 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001217 // Kind-of arbitrary.
1218 return 16;
1219 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001220
Dianne Hackborn254cb442010-01-27 19:23:59 -08001221 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001222 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001223 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001224 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001225 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001226 * <p>The calling device admin must have requested
1227 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1228 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001229 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001230 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001231 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001232 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001233 if (mService != null) {
1234 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001235 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001236 } catch (RemoteException e) {
1237 Log.w(TAG, "Failed talking with device policy service", e);
1238 }
1239 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001240 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001241 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001242
Dianne Hackbornd6847842010-01-12 18:14:19 -08001243 /**
1244 * Retrieve the number of times the user has failed at entering a
1245 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001246 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001247 * <p>The calling device admin must have requested
1248 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1249 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001250 */
1251 public int getCurrentFailedPasswordAttempts() {
1252 if (mService != null) {
1253 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001254 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 } catch (RemoteException e) {
1256 Log.w(TAG, "Failed talking with device policy service", e);
1257 }
1258 }
1259 return -1;
1260 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001261
1262 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001263 * Setting this to a value greater than zero enables a built-in policy
1264 * that will perform a device wipe after too many incorrect
1265 * device-unlock passwords have been entered. This built-in policy combines
1266 * watching for failed passwords and wiping the device, and requires
1267 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001268 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001269 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001270 * <p>To implement any other policy (e.g. wiping data for a particular
1271 * application only, erasing or revoking credentials, or reporting the
1272 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001273 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001274 * instead. Do not use this API, because if the maximum count is reached,
1275 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001276 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001278 * @param num The number of failed password attempts at which point the
1279 * device will wipe its data.
1280 */
1281 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1282 if (mService != null) {
1283 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001284 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001285 } catch (RemoteException e) {
1286 Log.w(TAG, "Failed talking with device policy service", e);
1287 }
1288 }
1289 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001290
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001291 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001292 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001293 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001294 * or a particular one.
1295 * @param admin The name of the admin component to check, or null to aggregate
1296 * all admins.
1297 */
1298 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001299 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1300 }
1301
1302 /** @hide per-user version */
1303 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001304 if (mService != null) {
1305 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001306 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001307 } catch (RemoteException e) {
1308 Log.w(TAG, "Failed talking with device policy service", e);
1309 }
1310 }
1311 return 0;
1312 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001313
Dianne Hackborn254cb442010-01-27 19:23:59 -08001314 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001315 * Flag for {@link #resetPassword}: don't allow other admins to change
1316 * the password again until the user has entered it.
1317 */
1318 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001319
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001320 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001321 * Force a new device unlock password (the password needed to access the
1322 * entire device, not for individual accounts) on the user. This takes
1323 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001324 * The given password must be sufficient for the
1325 * current password quality and length constraints as returned by
1326 * {@link #getPasswordQuality(ComponentName)} and
1327 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1328 * these constraints, then it will be rejected and false returned. Note
1329 * that the password may be a stronger quality (containing alphanumeric
1330 * characters when the requested quality is only numeric), in which case
1331 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001332 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001333 * <p>The calling device admin must have requested
1334 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1335 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001336 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001337 * Can not be called from a managed profile.
1338 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001339 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001340 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001341 * @return Returns true if the password was applied, or false if it is
1342 * not acceptable for the current constraints.
1343 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001344 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001345 if (mService != null) {
1346 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001347 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001348 } catch (RemoteException e) {
1349 Log.w(TAG, "Failed talking with device policy service", e);
1350 }
1351 }
1352 return false;
1353 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001354
Dianne Hackbornd6847842010-01-12 18:14:19 -08001355 /**
1356 * Called by an application that is administering the device to set the
1357 * maximum time for user activity until the device will lock. This limits
1358 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001359 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001360 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001361 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001362 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001363 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001365 * @param timeMs The new desired maximum time to lock in milliseconds.
1366 * A value of 0 means there is no restriction.
1367 */
1368 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1369 if (mService != null) {
1370 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001371 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001372 } catch (RemoteException e) {
1373 Log.w(TAG, "Failed talking with device policy service", e);
1374 }
1375 }
1376 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001377
Dianne Hackbornd6847842010-01-12 18:14:19 -08001378 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001379 * Retrieve the current maximum time to unlock for all admins of this user
1380 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001381 * @param admin The name of the admin component to check, or null to aggregate
1382 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001383 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001384 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001385 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001386 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001387 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1388 }
1389
1390 /** @hide per-user version */
1391 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001392 if (mService != null) {
1393 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001394 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001395 } catch (RemoteException e) {
1396 Log.w(TAG, "Failed talking with device policy service", e);
1397 }
1398 }
1399 return 0;
1400 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001401
Dianne Hackbornd6847842010-01-12 18:14:19 -08001402 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001403 * Make the device lock immediately, as if the lock screen timeout has
1404 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001405 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001406 * <p>The calling device admin must have requested
1407 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1408 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001409 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001410 public void lockNow() {
1411 if (mService != null) {
1412 try {
1413 mService.lockNow();
1414 } catch (RemoteException e) {
1415 Log.w(TAG, "Failed talking with device policy service", e);
1416 }
1417 }
1418 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001419
Dianne Hackbornd6847842010-01-12 18:14:19 -08001420 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001421 * Flag for {@link #wipeData(int)}: also erase the device's external
1422 * storage.
1423 */
1424 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1425
1426 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001427 * Ask the user data be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001428 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001429 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1430 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001431 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001432 * <p>The calling device admin must have requested
1433 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1434 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001435 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001436 * @param flags Bit mask of additional options: currently 0 and
1437 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001438 */
1439 public void wipeData(int flags) {
1440 if (mService != null) {
1441 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001442 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001443 } catch (RemoteException e) {
1444 Log.w(TAG, "Failed talking with device policy service", e);
1445 }
1446 }
1447 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001448
Dianne Hackbornd6847842010-01-12 18:14:19 -08001449 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001450 * Called by an application that is administering the device to set the
1451 * global proxy and exclusion list.
1452 * <p>
1453 * The calling device admin must have requested
1454 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1455 * this method; if it has not, a security exception will be thrown.
1456 * Only the first device admin can set the proxy. If a second admin attempts
1457 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1458 * proxy will be returned. If successful in setting the proxy, null will
1459 * be returned.
1460 * The method can be called repeatedly by the device admin alrady setting the
1461 * proxy to update the proxy and exclusion list.
1462 *
1463 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1464 * with.
1465 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1466 * Pass Proxy.NO_PROXY to reset the proxy.
1467 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001468 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1469 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001470 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001471 */
1472 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1473 List<String> exclusionList ) {
1474 if (proxySpec == null) {
1475 throw new NullPointerException();
1476 }
1477 if (mService != null) {
1478 try {
1479 String hostSpec;
1480 String exclSpec;
1481 if (proxySpec.equals(Proxy.NO_PROXY)) {
1482 hostSpec = null;
1483 exclSpec = null;
1484 } else {
1485 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1486 throw new IllegalArgumentException();
1487 }
1488 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1489 String hostName = sa.getHostName();
1490 int port = sa.getPort();
1491 StringBuilder hostBuilder = new StringBuilder();
1492 hostSpec = hostBuilder.append(hostName)
1493 .append(":").append(Integer.toString(port)).toString();
1494 if (exclusionList == null) {
1495 exclSpec = "";
1496 } else {
1497 StringBuilder listBuilder = new StringBuilder();
1498 boolean firstDomain = true;
1499 for (String exclDomain : exclusionList) {
1500 if (!firstDomain) {
1501 listBuilder = listBuilder.append(",");
1502 } else {
1503 firstDomain = false;
1504 }
1505 listBuilder = listBuilder.append(exclDomain.trim());
1506 }
1507 exclSpec = listBuilder.toString();
1508 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001509 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1510 != android.net.Proxy.PROXY_VALID)
1511 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001512 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001513 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001514 } catch (RemoteException e) {
1515 Log.w(TAG, "Failed talking with device policy service", e);
1516 }
1517 }
1518 return null;
1519 }
1520
1521 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001522 * Set a network-independent global HTTP proxy. This is not normally what you want
1523 * for typical HTTP proxies - they are generally network dependent. However if you're
1524 * doing something unusual like general internal filtering this may be useful. On
1525 * a private network where the proxy is not accessible, you may break HTTP using this.
1526 *
1527 * <p>This method requires the caller to be the device owner.
1528 *
1529 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1530 * @see ProxyInfo
1531 *
1532 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1533 * with.
1534 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1535 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1536 */
1537 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1538 if (mService != null) {
1539 try {
1540 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1541 } catch (RemoteException e) {
1542 Log.w(TAG, "Failed talking with device policy service", e);
1543 }
1544 }
1545 }
1546
1547 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001548 * Returns the component name setting the global proxy.
1549 * @return ComponentName object of the device admin that set the global proxy, or
1550 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001551 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001552 */
1553 public ComponentName getGlobalProxyAdmin() {
1554 if (mService != null) {
1555 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001556 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001557 } catch (RemoteException e) {
1558 Log.w(TAG, "Failed talking with device policy service", e);
1559 }
1560 }
1561 return null;
1562 }
1563
1564 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001565 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001566 * indicating that encryption is not supported.
1567 */
1568 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1569
1570 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001571 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001572 * indicating that encryption is supported, but is not currently active.
1573 */
1574 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1575
1576 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001577 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001578 * indicating that encryption is not currently active, but is currently
1579 * being activated. This is only reported by devices that support
1580 * encryption of data and only when the storage is currently
1581 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1582 * to become encrypted will never return this value.
1583 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001584 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001585
1586 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001587 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001588 * indicating that encryption is active.
1589 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001590 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001591
1592 /**
1593 * Activity action: begin the process of encrypting data on the device. This activity should
1594 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1595 * After resuming from this activity, use {@link #getStorageEncryption}
1596 * to check encryption status. However, on some devices this activity may never return, as
1597 * it may trigger a reboot and in some cases a complete data wipe of the device.
1598 */
1599 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1600 public static final String ACTION_START_ENCRYPTION
1601 = "android.app.action.START_ENCRYPTION";
1602
1603 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001604 * Widgets are enabled in keyguard
1605 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001606 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001607
1608 /**
Jim Miller50e62182014-04-23 17:25:00 -07001609 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001610 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001611 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1612
1613 /**
1614 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1615 */
1616 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1617
1618 /**
Jim Miller50e62182014-04-23 17:25:00 -07001619 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1620 */
1621 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1622
1623 /**
1624 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1625 */
1626 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1627
1628 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001629 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001630 * (e.g. PIN/Pattern/Password).
1631 */
1632 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1633
1634 /**
Jim Miller06e34502014-07-17 14:46:05 -07001635 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1636 */
1637 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1638
1639 /**
Jim Miller35207742012-11-02 15:33:20 -07001640 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001641 */
1642 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001643
1644 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001645 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001646 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001647 *
1648 * <p>When multiple device administrators attempt to control device
1649 * encryption, the most secure, supported setting will always be
1650 * used. If any device administrator requests device encryption,
1651 * it will be enabled; Conversely, if a device administrator
1652 * attempts to disable device encryption while another
1653 * device administrator has enabled it, the call to disable will
1654 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1655 *
1656 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001657 * written to other storage areas may or may not be encrypted, and this policy does not require
1658 * or control the encryption of any other storage areas.
1659 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1660 * {@code true}, then the directory returned by
1661 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1662 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001663 *
1664 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1665 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1666 * the encryption key may not be fully secured. For maximum security, the administrator should
1667 * also require (and check for) a pattern, PIN, or password.
1668 *
1669 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1670 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001671 * @return the new request status (for all active admins) - will be one of
1672 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1673 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1674 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001675 */
1676 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1677 if (mService != null) {
1678 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001679 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001680 } catch (RemoteException e) {
1681 Log.w(TAG, "Failed talking with device policy service", e);
1682 }
1683 }
1684 return ENCRYPTION_STATUS_UNSUPPORTED;
1685 }
1686
1687 /**
1688 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001689 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001690 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1692 * this will return the requested encryption setting as an aggregate of all active
1693 * administrators.
1694 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001695 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001696 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001697 if (mService != null) {
1698 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001699 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001700 } catch (RemoteException e) {
1701 Log.w(TAG, "Failed talking with device policy service", e);
1702 }
1703 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001704 return false;
1705 }
1706
1707 /**
1708 * Called by an application that is administering the device to
1709 * determine the current encryption status of the device.
1710 *
1711 * Depending on the returned status code, the caller may proceed in different
1712 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1713 * storage system does not support encryption. If the
1714 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1715 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1716 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1717 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1718 *
Robin Lee7e678712014-07-24 16:41:31 +01001719 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001720 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1721 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1722 */
1723 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001724 return getStorageEncryptionStatus(UserHandle.myUserId());
1725 }
1726
1727 /** @hide per-user version */
1728 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001729 if (mService != null) {
1730 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001731 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001732 } catch (RemoteException e) {
1733 Log.w(TAG, "Failed talking with device policy service", e);
1734 }
1735 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001736 return ENCRYPTION_STATUS_UNSUPPORTED;
1737 }
1738
1739 /**
Robin Lee7e678712014-07-24 16:41:31 +01001740 * Installs the given certificate as a user CA.
1741 *
1742 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1743 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001744 *
1745 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001746 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001747 */
Robin Lee7e678712014-07-24 16:41:31 +01001748 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001749 if (mService != null) {
1750 try {
Robin Lee7e678712014-07-24 16:41:31 +01001751 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001752 } catch (RemoteException e) {
1753 Log.w(TAG, "Failed talking with device policy service", e);
1754 }
1755 }
1756 return false;
1757 }
1758
1759 /**
Robin Lee7e678712014-07-24 16:41:31 +01001760 * Uninstalls the given certificate from trusted user CAs, if present.
1761 *
1762 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1763 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001764 */
Robin Lee7e678712014-07-24 16:41:31 +01001765 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001766 if (mService != null) {
1767 try {
Robin Lee306fe082014-06-19 14:04:24 +00001768 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001769 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001770 } catch (CertificateException e) {
1771 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001772 } catch (RemoteException e) {
1773 Log.w(TAG, "Failed talking with device policy service", e);
1774 }
1775 }
1776 }
1777
1778 /**
Robin Lee7e678712014-07-24 16:41:31 +01001779 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1780 * If a user has installed any certificates by other means than device policy these will be
1781 * included too.
1782 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001783 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001784 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001785 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001786 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01001787 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001788 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01001789 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001790 mService.enforceCanManageCaCerts(admin);
1791 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1792 for (String alias : certStore.userAliases()) {
1793 try {
1794 certs.add(certStore.getCertificate(alias).getEncoded());
1795 } catch (CertificateException ce) {
1796 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1797 }
1798 }
1799 } catch (RemoteException re) {
1800 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01001801 }
1802 }
1803 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001804 }
1805
1806 /**
Robin Lee7e678712014-07-24 16:41:31 +01001807 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1808 * means other than device policy will also be removed, except for system CA certificates.
1809 *
1810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1811 */
1812 public void uninstallAllUserCaCerts(ComponentName admin) {
1813 if (mService != null) {
1814 for (String alias : new TrustedCertificateStore().userAliases()) {
1815 try {
1816 mService.uninstallCaCert(admin, alias);
1817 } catch (RemoteException re) {
1818 Log.w(TAG, "Failed talking with device policy service", re);
1819 }
1820 }
1821 }
1822 }
1823
1824 /**
1825 * Returns whether this certificate is installed as a trusted CA.
1826 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001827 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001828 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001829 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001830 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
1831 if (mService != null) {
1832 try {
1833 mService.enforceCanManageCaCerts(admin);
1834 return getCaCertAlias(certBuffer) != null;
1835 } catch (RemoteException re) {
1836 Log.w(TAG, "Failed talking with device policy service", re);
1837 } catch (CertificateException ce) {
1838 Log.w(TAG, "Could not parse certificate", ce);
1839 }
Maggie Benthallda51e682013-08-08 22:35:44 -04001840 }
1841 return false;
1842 }
1843
1844 /**
Robin Lee306fe082014-06-19 14:04:24 +00001845 * Returns the alias of a given CA certificate in the certificate store, or null if it
1846 * doesn't exist.
1847 */
1848 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1849 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1850 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1851 new ByteArrayInputStream(certBuffer));
1852 return new TrustedCertificateStore().getCertificateAlias(cert);
1853 }
1854
1855 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001856 * Called by an application that is administering the device to disable all cameras
1857 * on the device. After setting this, no applications will be able to access any cameras
1858 * on the device.
1859 *
1860 * <p>The calling device admin must have requested
1861 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1862 * this method; if it has not, a security exception will be thrown.
1863 *
1864 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1865 * @param disabled Whether or not the camera should be disabled.
1866 */
1867 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1868 if (mService != null) {
1869 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001870 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001871 } catch (RemoteException e) {
1872 Log.w(TAG, "Failed talking with device policy service", e);
1873 }
1874 }
1875 }
1876
1877 /**
1878 * Determine whether or not the device's cameras have been disabled either by the current
1879 * admin, if specified, or all admins.
1880 * @param admin The name of the admin component to check, or null to check if any admins
1881 * have disabled the camera
1882 */
1883 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001884 return getCameraDisabled(admin, UserHandle.myUserId());
1885 }
1886
1887 /** @hide per-user version */
1888 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001889 if (mService != null) {
1890 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001891 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001892 } catch (RemoteException e) {
1893 Log.w(TAG, "Failed talking with device policy service", e);
1894 }
1895 }
1896 return false;
1897 }
1898
1899 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01001900 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
1901 * screen capture also prevents the content from being shown on display devices that do not have
1902 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
1903 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001904 *
1905 * <p>The calling device admin must be a device or profile owner. If it is not, a
1906 * security exception will be thrown.
1907 *
1908 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001909 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01001910 */
1911 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
1912 if (mService != null) {
1913 try {
1914 mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled);
1915 } catch (RemoteException e) {
1916 Log.w(TAG, "Failed talking with device policy service", e);
1917 }
1918 }
1919 }
1920
1921 /**
1922 * Determine whether or not screen capture has been disabled by the current
1923 * admin, if specified, or all admins.
1924 * @param admin The name of the admin component to check, or null to check if any admins
1925 * have disabled screen capture.
1926 */
1927 public boolean getScreenCaptureDisabled(ComponentName admin) {
1928 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
1929 }
1930
1931 /** @hide per-user version */
1932 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
1933 if (mService != null) {
1934 try {
1935 return mService.getScreenCaptureDisabled(admin, userHandle);
1936 } catch (RemoteException e) {
1937 Log.w(TAG, "Failed talking with device policy service", e);
1938 }
1939 }
1940 return false;
1941 }
1942
1943 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01001944 * Called by a device owner to set whether auto time is required. If auto time is
1945 * required the user cannot set the date and time, but has to use network date and time.
1946 *
1947 * <p>Note: if auto time is required the user can still manually set the time zone.
1948 *
1949 * <p>The calling device admin must be a device owner. If it is not, a security exception will
1950 * be thrown.
1951 *
1952 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1953 * @param required Whether auto time is set required or not.
1954 */
1955 public void setAutoTimeRequired(ComponentName admin, boolean required) {
1956 if (mService != null) {
1957 try {
1958 mService.setAutoTimeRequired(admin, UserHandle.myUserId(), required);
1959 } catch (RemoteException e) {
1960 Log.w(TAG, "Failed talking with device policy service", e);
1961 }
1962 }
1963 }
1964
1965 /**
1966 * @return true if auto time is required.
1967 */
1968 public boolean getAutoTimeRequired() {
1969 if (mService != null) {
1970 try {
1971 return mService.getAutoTimeRequired();
1972 } catch (RemoteException e) {
1973 Log.w(TAG, "Failed talking with device policy service", e);
1974 }
1975 }
1976 return false;
1977 }
1978
1979 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001980 * Called by an application that is administering the device to disable keyguard customizations,
1981 * such as widgets. After setting this, keyguard features will be disabled according to the
1982 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001983 *
1984 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001985 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001986 * this method; if it has not, a security exception will be thrown.
1987 *
1988 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001989 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1990 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001991 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1992 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001993 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001994 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001995 if (mService != null) {
1996 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001997 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001998 } catch (RemoteException e) {
1999 Log.w(TAG, "Failed talking with device policy service", e);
2000 }
2001 }
2002 }
2003
2004 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002005 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002006 * admin, if specified, or all admins.
2007 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002008 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002009 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2010 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002011 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002012 public int getKeyguardDisabledFeatures(ComponentName admin) {
2013 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002014 }
2015
2016 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002017 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002018 if (mService != null) {
2019 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002020 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002021 } catch (RemoteException e) {
2022 Log.w(TAG, "Failed talking with device policy service", e);
2023 }
2024 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002025 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002026 }
2027
2028 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002029 * @hide
2030 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002031 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002032 if (mService != null) {
2033 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002034 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002035 } catch (RemoteException e) {
2036 Log.w(TAG, "Failed talking with device policy service", e);
2037 }
2038 }
2039 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002040
Dianne Hackbornd6847842010-01-12 18:14:19 -08002041 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002042 * @hide
2043 */
2044 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2045 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2046 }
2047
2048 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002049 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002050 * @hide
2051 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002052 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002053 ActivityInfo ai;
2054 try {
2055 ai = mContext.getPackageManager().getReceiverInfo(cn,
2056 PackageManager.GET_META_DATA);
2057 } catch (PackageManager.NameNotFoundException e) {
2058 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2059 return null;
2060 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002061
Dianne Hackbornd6847842010-01-12 18:14:19 -08002062 ResolveInfo ri = new ResolveInfo();
2063 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002064
Dianne Hackbornd6847842010-01-12 18:14:19 -08002065 try {
2066 return new DeviceAdminInfo(mContext, ri);
2067 } catch (XmlPullParserException e) {
2068 Log.w(TAG, "Unable to parse device policy " + cn, e);
2069 return null;
2070 } catch (IOException e) {
2071 Log.w(TAG, "Unable to parse device policy " + cn, e);
2072 return null;
2073 }
2074 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002075
Dianne Hackbornd6847842010-01-12 18:14:19 -08002076 /**
2077 * @hide
2078 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002079 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2080 if (mService != null) {
2081 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002082 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002083 } catch (RemoteException e) {
2084 Log.w(TAG, "Failed talking with device policy service", e);
2085 }
2086 }
2087 }
2088
2089 /**
2090 * @hide
2091 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002092 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002093 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002094 if (mService != null) {
2095 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002096 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002097 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002098 } catch (RemoteException e) {
2099 Log.w(TAG, "Failed talking with device policy service", e);
2100 }
2101 }
2102 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002103
Dianne Hackbornd6847842010-01-12 18:14:19 -08002104 /**
2105 * @hide
2106 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002107 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002108 if (mService != null) {
2109 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002110 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002111 } catch (RemoteException e) {
2112 Log.w(TAG, "Failed talking with device policy service", e);
2113 }
2114 }
2115 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002116
Dianne Hackbornd6847842010-01-12 18:14:19 -08002117 /**
2118 * @hide
2119 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002120 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002121 if (mService != null) {
2122 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002123 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002124 } catch (RemoteException e) {
2125 Log.w(TAG, "Failed talking with device policy service", e);
2126 }
2127 }
2128 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002129
2130 /**
2131 * @hide
2132 * Sets the given package as the device owner. The package must already be installed and there
2133 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2134 * method must be called before the device is provisioned.
2135 * @param packageName the package name of the application to be registered as the device owner.
2136 * @return whether the package was successfully registered as the device owner.
2137 * @throws IllegalArgumentException if the package name is null or invalid
2138 * @throws IllegalStateException if a device owner is already registered or the device has
2139 * already been provisioned.
2140 */
2141 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2142 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002143 return setDeviceOwner(packageName, null);
2144 }
2145
2146 /**
2147 * @hide
2148 * Sets the given package as the device owner. The package must already be installed and there
2149 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2150 * method must be called before the device is provisioned.
2151 * @param packageName the package name of the application to be registered as the device owner.
2152 * @param ownerName the human readable name of the institution that owns this device.
2153 * @return whether the package was successfully registered as the device owner.
2154 * @throws IllegalArgumentException if the package name is null or invalid
2155 * @throws IllegalStateException if a device owner is already registered or the device has
2156 * already been provisioned.
2157 */
2158 public boolean setDeviceOwner(String packageName, String ownerName)
2159 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002160 if (mService != null) {
2161 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002162 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002163 } catch (RemoteException re) {
2164 Log.w(TAG, "Failed to set device owner");
2165 }
2166 }
2167 return false;
2168 }
2169
2170 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002171 * Used to determine if a particular package has been registered as a Device Owner app.
2172 * A device owner app is a special device admin that cannot be deactivated by the user, once
2173 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2174 * package is currently registered as the device owner app, pass in the package name from
2175 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2176 * admin apps that want to check if they are also registered as the device owner app. The
2177 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2178 * the setup process.
2179 * @param packageName the package name of the app, to compare with the registered device owner
2180 * app, if any.
2181 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002182 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002183 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002184 if (mService != null) {
2185 try {
2186 return mService.isDeviceOwner(packageName);
2187 } catch (RemoteException re) {
2188 Log.w(TAG, "Failed to check device owner");
2189 }
2190 }
2191 return false;
2192 }
2193
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002194 /**
2195 * @hide
2196 * Redirect to isDeviceOwnerApp.
2197 */
2198 public boolean isDeviceOwner(String packageName) {
2199 return isDeviceOwnerApp(packageName);
2200 }
2201
Jason Monkb0dced82014-06-06 14:36:20 -04002202 /**
2203 * Clears the current device owner. The caller must be the device owner.
2204 *
2205 * This function should be used cautiously as once it is called it cannot
2206 * be undone. The device owner can only be set as a part of device setup
2207 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002208 *
2209 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002210 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002211 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002212 if (mService != null) {
2213 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002214 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002215 } catch (RemoteException re) {
2216 Log.w(TAG, "Failed to clear device owner");
2217 }
2218 }
2219 }
2220
Amith Yamasani71e6c692013-03-24 17:39:28 -07002221 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002222 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002223 public String getDeviceOwner() {
2224 if (mService != null) {
2225 try {
2226 return mService.getDeviceOwner();
2227 } catch (RemoteException re) {
2228 Log.w(TAG, "Failed to get device owner");
2229 }
2230 }
2231 return null;
2232 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002233
2234 /** @hide */
2235 public String getDeviceOwnerName() {
2236 if (mService != null) {
2237 try {
2238 return mService.getDeviceOwnerName();
2239 } catch (RemoteException re) {
2240 Log.w(TAG, "Failed to get device owner");
2241 }
2242 }
2243 return null;
2244 }
Adam Connors776c5552014-01-09 10:42:56 +00002245
2246 /**
2247 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002248 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302249 * Sets the given component as an active admin and registers the package as the profile
2250 * owner for this user. The package must already be installed and there shouldn't be
2251 * an existing profile owner registered for this user. Also, this method must be called
2252 * before the user setup has been completed.
2253 * <p>
2254 * This method can only be called by system apps that hold MANAGE_USERS permission and
2255 * MANAGE_DEVICE_ADMINS permission.
2256 * @param admin The component to register as an active admin and profile owner.
2257 * @param ownerName The user-visible name of the entity that is managing this user.
2258 * @return whether the admin was successfully registered as the profile owner.
2259 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2260 * the user has already been set up.
2261 */
Justin Morey80440cc2014-07-24 09:16:35 -05002262 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302263 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2264 throws IllegalArgumentException {
2265 if (mService != null) {
2266 try {
2267 final int myUserId = UserHandle.myUserId();
2268 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002269 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302270 } catch (RemoteException re) {
2271 Log.w(TAG, "Failed to set profile owner " + re);
2272 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2273 }
2274 }
2275 return false;
2276 }
2277
2278 /**
2279 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002280 * Clears the active profile owner and removes all user restrictions. The caller must
2281 * be from the same package as the active profile owner for this user, otherwise a
2282 * SecurityException will be thrown.
2283 *
2284 * @param admin The component to remove as the profile owner.
2285 * @return
2286 */
2287 @SystemApi
2288 public void clearProfileOwner(ComponentName admin) {
2289 if (mService != null) {
2290 try {
2291 mService.clearProfileOwner(admin);
2292 } catch (RemoteException re) {
2293 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2294 }
2295 }
2296 }
2297
2298 /**
2299 * @hide
2300 * Checks if the user was already setup.
2301 */
2302 public boolean hasUserSetupCompleted() {
2303 if (mService != null) {
2304 try {
2305 return mService.hasUserSetupCompleted();
2306 } catch (RemoteException re) {
2307 Log.w(TAG, "Failed to check if user setup has completed");
2308 }
2309 }
2310 return true;
2311 }
2312
2313 /**
2314 * @deprecated Use setProfileOwner(ComponentName ...)
2315 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002316 * Sets the given package as the profile owner of the given user profile. The package must
2317 * already be installed and there shouldn't be an existing profile owner registered for this
2318 * user. Also, this method must be called before the user has been used for the first time.
2319 * @param packageName the package name of the application to be registered as profile owner.
2320 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002321 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002322 * @return whether the package was successfully registered as the profile owner.
2323 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2324 * the user has already been set up.
2325 */
Adam Connors661ec472014-02-11 13:59:46 +00002326 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002327 throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002328 if (packageName == null) {
2329 throw new NullPointerException("packageName cannot be null");
2330 }
2331 return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle);
2332 }
2333
2334 /**
2335 * @hide
2336 * Sets the given component as the profile owner of the given user profile. The package must
2337 * already be installed and there shouldn't be an existing profile owner registered for this
2338 * user. Only the system can call this API if the user has already completed setup.
2339 * @param admin the component name to be registered as profile owner.
2340 * @param ownerName the human readable name of the organisation associated with this DPM.
2341 * @param userHandle the userId to set the profile owner for.
2342 * @return whether the component was successfully registered as the profile owner.
2343 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2344 * the user has already been set up.
2345 */
2346 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2347 throws IllegalArgumentException {
2348 if (admin == null) {
2349 throw new NullPointerException("admin cannot be null");
2350 }
Adam Connors776c5552014-01-09 10:42:56 +00002351 if (mService != null) {
2352 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002353 if (ownerName == null) {
2354 ownerName = "";
2355 }
2356 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002357 } catch (RemoteException re) {
2358 Log.w(TAG, "Failed to set profile owner", re);
2359 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2360 }
2361 }
2362 return false;
2363 }
2364
2365 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002366 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2367 * be used. Only the profile owner can call this.
2368 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002369 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002370 *
2371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2372 */
2373 public void setProfileEnabled(ComponentName admin) {
2374 if (mService != null) {
2375 try {
2376 mService.setProfileEnabled(admin);
2377 } catch (RemoteException e) {
2378 Log.w(TAG, "Failed talking with device policy service", e);
2379 }
2380 }
2381 }
2382
2383 /**
Jessica Hummel1333ea12014-06-23 11:20:10 +01002384 * Sets the name of the Managed profile. In the device owner case it sets the name of the user
2385 * which it is called from. Only the profile owner or device owner can call this. If this is
2386 * never called by the profile or device owner, the name will be set to default values.
2387 *
2388 * @see #isProfileOwnerApp
2389 * @see #isDeviceOwnerApp
2390 *
2391 * @param profileName The name of the profile.
2392 */
2393 public void setProfileName(ComponentName who, String profileName) {
2394 if (mService != null) {
2395 try {
2396 mService.setProfileName(who, profileName);
2397 } catch (RemoteException e) {
2398 Log.w(TAG, "Failed talking with device policy service", e);
2399 }
2400 }
2401}
2402
2403 /**
Adam Connors776c5552014-01-09 10:42:56 +00002404 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002405 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00002406 * within the managed profile.
2407 *
2408 * @param packageName The package name of the app to compare with the registered profile owner.
2409 * @return Whether or not the package is registered as the profile owner.
2410 */
2411 public boolean isProfileOwnerApp(String packageName) {
2412 if (mService != null) {
2413 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002414 ComponentName profileOwner = mService.getProfileOwner(
2415 Process.myUserHandle().getIdentifier());
2416 return profileOwner != null
2417 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002418 } catch (RemoteException re) {
2419 Log.w(TAG, "Failed to check profile owner");
2420 }
2421 }
2422 return false;
2423 }
2424
2425 /**
2426 * @hide
2427 * @return the packageName of the owner of the given user profile or null if no profile
2428 * owner has been set for that user.
2429 * @throws IllegalArgumentException if the userId is invalid.
2430 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002431 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002432 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002433 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2434 }
2435
2436 /**
2437 * @see #getProfileOwner()
2438 * @hide
2439 */
2440 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002441 if (mService != null) {
2442 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002443 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002444 } catch (RemoteException re) {
2445 Log.w(TAG, "Failed to get profile owner");
2446 throw new IllegalArgumentException(
2447 "Requested profile owner for invalid userId", re);
2448 }
2449 }
2450 return null;
2451 }
2452
2453 /**
2454 * @hide
2455 * @return the human readable name of the organisation associated with this DPM or null if
2456 * one is not set.
2457 * @throws IllegalArgumentException if the userId is invalid.
2458 */
2459 public String getProfileOwnerName() throws IllegalArgumentException {
2460 if (mService != null) {
2461 try {
2462 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2463 } catch (RemoteException re) {
2464 Log.w(TAG, "Failed to get profile owner");
2465 throw new IllegalArgumentException(
2466 "Requested profile owner for invalid userId", re);
2467 }
2468 }
2469 return null;
2470 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002471
2472 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002473 * @hide
2474 * @param user The user for whom to fetch the profile owner name, if any.
2475 * @return the human readable name of the organisation associated with this profile owner or
2476 * null if one is not set.
2477 * @throws IllegalArgumentException if the userId is invalid.
2478 */
2479 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002480 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002481 if (mService != null) {
2482 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002483 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002484 } catch (RemoteException re) {
2485 Log.w(TAG, "Failed to get profile owner");
2486 throw new IllegalArgumentException(
2487 "Requested profile owner for invalid userId", re);
2488 }
2489 }
2490 return null;
2491 }
2492
2493 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002494 * Called by a profile owner or device owner to add a default intent handler activity for
2495 * intents that match a certain intent filter. This activity will remain the default intent
2496 * handler even if the set of potential event handlers for the intent filter changes and if
2497 * the intent preferences are reset.
2498 *
2499 * <p>The default disambiguation mechanism takes over if the activity is not installed
2500 * (anymore). When the activity is (re)installed, it is automatically reset as default
2501 * intent handler for the filter.
2502 *
2503 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2504 * security exception will be thrown.
2505 *
2506 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2507 * @param filter The IntentFilter for which a default handler is added.
2508 * @param activity The Activity that is added as default intent handler.
2509 */
2510 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2511 ComponentName activity) {
2512 if (mService != null) {
2513 try {
2514 mService.addPersistentPreferredActivity(admin, filter, activity);
2515 } catch (RemoteException e) {
2516 Log.w(TAG, "Failed talking with device policy service", e);
2517 }
2518 }
2519 }
2520
2521 /**
2522 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002523 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002524 *
2525 * <p>The calling device admin must be a profile owner. If it is not, a security
2526 * exception will be thrown.
2527 *
2528 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2529 * @param packageName The name of the package for which preferences are removed.
2530 */
2531 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2532 String packageName) {
2533 if (mService != null) {
2534 try {
2535 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2536 } catch (RemoteException e) {
2537 Log.w(TAG, "Failed talking with device policy service", e);
2538 }
2539 }
2540 }
Robin Lee66e5d962014-04-09 16:44:21 +01002541
2542 /**
2543 * Called by a profile or device owner to set the application restrictions for a given target
2544 * application running in the managed profile.
2545 *
2546 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Amith Yamasanic8c84252014-07-13 17:12:12 -07002547 * boolean, int, String, or String[]. The recommended format for keys
Robin Lee66e5d962014-04-09 16:44:21 +01002548 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
2549 * components such as {@link android.webkit.WebView}.
2550 *
2551 * <p>The application restrictions are only made visible to the target application and the
2552 * profile or device owner.
2553 *
2554 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2555 * exception will be thrown.
2556 *
2557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2558 * @param packageName The name of the package to update restricted settings for.
2559 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2560 * set of active restrictions.
2561 */
2562 public void setApplicationRestrictions(ComponentName admin, String packageName,
2563 Bundle settings) {
2564 if (mService != null) {
2565 try {
2566 mService.setApplicationRestrictions(admin, packageName, settings);
2567 } catch (RemoteException e) {
2568 Log.w(TAG, "Failed talking with device policy service", e);
2569 }
2570 }
2571 }
2572
2573 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002574 * Sets a list of features to enable for a TrustAgent component. This is meant to be
Jim Miller604e7552014-07-18 19:00:02 -07002575 * used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which will disable all
2576 * trust agents but those with features enabled by this function call.
2577 *
2578 * <p>The calling device admin must have requested
2579 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
2580 * this method; if it has not, a security exception will be thrown.
2581 *
2582 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2583 * @param agent Which component to enable features for.
2584 * @param features List of features to enable. Consult specific TrustAgent documentation for
2585 * the feature list.
Jim Millerb1474f42014-08-26 18:42:58 -07002586 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002587 */
2588 public void setTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent,
2589 List<String> features) {
2590 if (mService != null) {
2591 try {
2592 mService.setTrustAgentFeaturesEnabled(admin, agent, features, UserHandle.myUserId());
2593 } catch (RemoteException e) {
2594 Log.w(TAG, "Failed talking with device policy service", e);
2595 }
2596 }
2597 }
2598
2599 /**
Adrian Roos489d2df2014-07-29 21:01:39 +02002600 * Gets list of enabled features for the given TrustAgent component. If admin is
Jim Miller604e7552014-07-18 19:00:02 -07002601 * null, this will return the intersection of all features enabled for the given agent by all
2602 * admins.
2603 *
2604 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2605 * @param agent Which component to get enabled features for.
2606 * @return List of enabled features.
Jim Millerb1474f42014-08-26 18:42:58 -07002607 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002608 */
2609 public List<String> getTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent) {
2610 if (mService != null) {
2611 try {
2612 return mService.getTrustAgentFeaturesEnabled(admin, agent, UserHandle.myUserId());
2613 } catch (RemoteException e) {
2614 Log.w(TAG, "Failed talking with device policy service", e);
2615 }
2616 }
2617 return new ArrayList<String>(); // empty list
2618 }
2619
2620 /**
Adam Connors210fe212014-07-17 15:41:43 +01002621 * Called by a profile owner to set whether caller-Id information from the managed
2622 * profile will be shown for incoming calls.
2623 *
2624 * <p>The calling device admin must be a profile owner. If it is not, a
2625 * security exception will be thrown.
2626 *
2627 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2628 * @param disabled If true caller-Id information in the managed profile is not displayed.
2629 */
2630 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2631 if (mService != null) {
2632 try {
2633 mService.setCrossProfileCallerIdDisabled(who, disabled);
2634 } catch (RemoteException e) {
2635 Log.w(TAG, "Failed talking with device policy service", e);
2636 }
2637 }
2638 }
2639
2640 /**
2641 * Determine whether or not caller-Id information has been disabled.
2642 *
2643 * <p>The calling device admin must be a profile owner. If it is not, a
2644 * security exception will be thrown.
2645 *
2646 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2647 */
2648 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2649 if (mService != null) {
2650 try {
2651 return mService.getCrossProfileCallerIdDisabled(who);
2652 } catch (RemoteException e) {
2653 Log.w(TAG, "Failed talking with device policy service", e);
2654 }
2655 }
2656 return false;
2657 }
2658
2659 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002660 * Determine whether or not caller-Id information has been disabled.
2661 *
2662 * @param userHandle The user for whom to check the caller-id permission
2663 * @hide
2664 */
2665 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2666 if (mService != null) {
2667 try {
2668 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2669 } catch (RemoteException e) {
2670 Log.w(TAG, "Failed talking with device policy service", e);
2671 }
2672 }
2673 return false;
2674 }
2675
2676 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002677 * Called by the profile owner so that some intents sent in the managed profile can also be
2678 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002679 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002680 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2681 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002682 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2683 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002684 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002685 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002686 if (mService != null) {
2687 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002688 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002689 } catch (RemoteException e) {
2690 Log.w(TAG, "Failed talking with device policy service", e);
2691 }
2692 }
2693 }
2694
2695 /**
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002696 * Called by a profile owner to remove the cross-profile intent filters that go from the
2697 * managed profile to the parent, or from the parent to the managed profile.
2698 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002699 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2700 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002701 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002702 if (mService != null) {
2703 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002704 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002705 } catch (RemoteException e) {
2706 Log.w(TAG, "Failed talking with device policy service", e);
2707 }
2708 }
2709 }
2710
2711 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002712 * Called by a profile or device owner to set the permitted accessibility services. When
2713 * set by a device owner or profile owner the restriction applies to all profiles of the
2714 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07002715 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002716 * By default the user can use any accessiblity service. When zero or more packages have
2717 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07002718 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002719 *
2720 * <p> Calling with a null value for the list disables the restriction so that all services
2721 * can be used, calling with an empty list only allows the builtin system's services.
2722 *
2723 * <p> System accesibility services are always available to the user the list can't modify
2724 * this.
2725 *
2726 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2727 * @param packageNames List of accessibility service package names.
2728 *
2729 * @return true if setting the restriction succeeded. It fail if there is
2730 * one or more non-system accessibility services enabled, that are not in the list.
2731 */
2732 public boolean setPermittedAccessibilityServices(ComponentName admin,
2733 List<String> packageNames) {
2734 if (mService != null) {
2735 try {
2736 return mService.setPermittedAccessibilityServices(admin, packageNames);
2737 } catch (RemoteException e) {
2738 Log.w(TAG, "Failed talking with device policy service", e);
2739 }
2740 }
2741 return false;
2742 }
2743
2744 /**
2745 * Returns the list of permitted accessibility services set by this device or profile owner.
2746 *
2747 * <p>An empty list means no accessibility services except system services are allowed.
2748 * Null means all accessibility services are allowed.
2749 *
2750 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2751 * @return List of accessiblity service package names.
2752 */
2753 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2754 if (mService != null) {
2755 try {
2756 return mService.getPermittedAccessibilityServices(admin);
2757 } catch (RemoteException e) {
2758 Log.w(TAG, "Failed talking with device policy service", e);
2759 }
2760 }
2761 return null;
2762 }
2763
2764 /**
2765 * Returns the list of accessibility services permitted by the device or profiles
2766 * owners of this user.
2767 *
2768 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2769 * it will contain the intersection of the permitted lists for any device or profile
2770 * owners that apply to this user. It will also include any system accessibility services.
2771 *
2772 * @param userId which user to check for.
2773 * @return List of accessiblity service package names.
2774 * @hide
2775 */
2776 @SystemApi
2777 public List<String> getPermittedAccessibilityServices(int userId) {
2778 if (mService != null) {
2779 try {
2780 return mService.getPermittedAccessibilityServicesForUser(userId);
2781 } catch (RemoteException e) {
2782 Log.w(TAG, "Failed talking with device policy service", e);
2783 }
2784 }
2785 return null;
2786 }
2787
2788 /**
2789 * Called by a profile or device owner to set the permitted input methods services. When
2790 * set by a device owner or profile owner the restriction applies to all profiles of the
2791 * user the device owner or profile owner is an admin for.
2792 *
2793 * By default the user can use any input method. When zero or more packages have
2794 * been added, input method that are not in the list and not part of the system
2795 * can not be enabled by the user.
2796 *
2797 * This method will fail if it is called for a admin that is not for the foreground user
2798 * or a profile of the foreground user.
2799 *
2800 * <p> Calling with a null value for the list disables the restriction so that all input methods
2801 * can be used, calling with an empty list disables all but the system's own input methods.
2802 *
2803 * <p> System input methods are always available to the user this method can't modify this.
2804 *
2805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2806 * @param packageNames List of input method package names.
2807 * @return true if setting the restriction succeeded. It will fail if there is
2808 * one or more input method enabled, that are not in the list or user if the foreground
2809 * user.
2810 */
2811 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2812 if (mService != null) {
2813 try {
2814 return mService.setPermittedInputMethods(admin, packageNames);
2815 } catch (RemoteException e) {
2816 Log.w(TAG, "Failed talking with device policy service", e);
2817 }
2818 }
2819 return false;
2820 }
2821
2822
2823 /**
2824 * Returns the list of permitted input methods set by this device or profile owner.
2825 *
2826 * <p>An empty list means no input methods except system input methods are allowed.
2827 * Null means all input methods are allowed.
2828 *
2829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2830 * @return List of input method package names.
2831 */
2832 public List<String> getPermittedInputMethods(ComponentName admin) {
2833 if (mService != null) {
2834 try {
2835 return mService.getPermittedInputMethods(admin);
2836 } catch (RemoteException e) {
2837 Log.w(TAG, "Failed talking with device policy service", e);
2838 }
2839 }
2840 return null;
2841 }
2842
2843 /**
2844 * Returns the list of input methods permitted by the device or profiles
2845 * owners of the current user.
2846 *
2847 * <p>Null means all input methods are allowed, if a non-null list is returned
2848 * it will contain the intersection of the permitted lists for any device or profile
2849 * owners that apply to this user. It will also include any system input methods.
2850 *
2851 * @return List of input method package names.
2852 * @hide
2853 */
2854 @SystemApi
2855 public List<String> getPermittedInputMethodsForCurrentUser() {
2856 if (mService != null) {
2857 try {
2858 return mService.getPermittedInputMethodsForCurrentUser();
2859 } catch (RemoteException e) {
2860 Log.w(TAG, "Failed talking with device policy service", e);
2861 }
2862 }
2863 return null;
2864 }
2865
2866 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002867 * Called by a device owner to create a user with the specified name. The UserHandle returned
2868 * by this method should not be persisted as user handles are recycled as users are removed and
2869 * created. If you need to persist an identifier for this user, use
2870 * {@link UserManager#getSerialNumberForUser}.
2871 *
2872 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2873 * @param name the user's name
2874 * @see UserHandle
2875 * @return the UserHandle object for the created user, or null if the user could not be created.
2876 */
2877 public UserHandle createUser(ComponentName admin, String name) {
2878 try {
2879 return mService.createUser(admin, name);
2880 } catch (RemoteException re) {
2881 Log.w(TAG, "Could not create a user", re);
2882 }
2883 return null;
2884 }
2885
2886 /**
Jason Monk03978a42014-06-10 15:05:30 -04002887 * Called by a device owner to create a user with the specified name. The UserHandle returned
2888 * by this method should not be persisted as user handles are recycled as users are removed and
2889 * created. If you need to persist an identifier for this user, use
2890 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
2891 * immediately.
2892 *
2893 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
2894 * as registered as an active admin on the new user. The profile owner package will be
2895 * installed on the new user if it already is installed on the device.
2896 *
2897 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
2898 * profileOwnerComponent when onEnable is called.
2899 *
2900 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2901 * @param name the user's name
2902 * @param ownerName the human readable name of the organisation associated with this DPM.
2903 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
2904 * the user.
2905 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
2906 * on the new user.
2907 * @see UserHandle
2908 * @return the UserHandle object for the created user, or null if the user could not be created.
2909 */
2910 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
2911 ComponentName profileOwnerComponent, Bundle adminExtras) {
2912 try {
2913 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
2914 adminExtras);
2915 } catch (RemoteException re) {
2916 Log.w(TAG, "Could not create a user", re);
2917 }
2918 return null;
2919 }
2920
2921 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002922 * Called by a device owner to remove a user and all associated data. The primary user can
2923 * not be removed.
2924 *
2925 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2926 * @param userHandle the user to remove.
2927 * @return {@code true} if the user was removed, {@code false} otherwise.
2928 */
2929 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2930 try {
2931 return mService.removeUser(admin, userHandle);
2932 } catch (RemoteException re) {
2933 Log.w(TAG, "Could not remove user ", re);
2934 return false;
2935 }
2936 }
2937
2938 /**
Jason Monk582d9112014-07-09 19:57:08 -04002939 * Called by a device owner to switch the specified user to the foreground.
2940 *
2941 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2942 * @param userHandle the user to switch to; null will switch to primary.
2943 * @return {@code true} if the switch was successful, {@code false} otherwise.
2944 *
2945 * @see Intent#ACTION_USER_FOREGROUND
2946 */
2947 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
2948 try {
2949 return mService.switchUser(admin, userHandle);
2950 } catch (RemoteException re) {
2951 Log.w(TAG, "Could not switch user ", re);
2952 return false;
2953 }
2954 }
2955
2956 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002957 * Called by a profile or device owner to get the application restrictions for a given target
2958 * application running in the managed profile.
2959 *
2960 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2961 * exception will be thrown.
2962 *
2963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2964 * @param packageName The name of the package to fetch restricted settings of.
2965 * @return {@link Bundle} of settings corresponding to what was set last time
2966 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2967 * if no restrictions have been set.
2968 */
2969 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2970 if (mService != null) {
2971 try {
2972 return mService.getApplicationRestrictions(admin, packageName);
2973 } catch (RemoteException e) {
2974 Log.w(TAG, "Failed talking with device policy service", e);
2975 }
2976 }
2977 return null;
2978 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002979
2980 /**
2981 * Called by a profile or device owner to set a user restriction specified
2982 * by the key.
2983 * <p>
2984 * The calling device admin must be a profile or device owner; if it is not,
2985 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002986 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002987 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2988 * with.
2989 * @param key The key of the restriction. See the constants in
2990 * {@link android.os.UserManager} for the list of keys.
2991 */
2992 public void addUserRestriction(ComponentName admin, String key) {
2993 if (mService != null) {
2994 try {
2995 mService.setUserRestriction(admin, key, true);
2996 } catch (RemoteException e) {
2997 Log.w(TAG, "Failed talking with device policy service", e);
2998 }
2999 }
3000 }
3001
3002 /**
3003 * Called by a profile or device owner to clear a user restriction specified
3004 * by the key.
3005 * <p>
3006 * The calling device admin must be a profile or device owner; if it is not,
3007 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003008 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003009 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3010 * with.
3011 * @param key The key of the restriction. See the constants in
3012 * {@link android.os.UserManager} for the list of keys.
3013 */
3014 public void clearUserRestriction(ComponentName admin, String key) {
3015 if (mService != null) {
3016 try {
3017 mService.setUserRestriction(admin, key, false);
3018 } catch (RemoteException e) {
3019 Log.w(TAG, "Failed talking with device policy service", e);
3020 }
3021 }
3022 }
Adam Connors010cfd42014-04-16 12:48:13 +01003023
3024 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003025 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003026 * is unavailable for use, but the data and actual package file remain.
3027 *
3028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003029 * @param packageName The name of the package to hide or unhide.
3030 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3031 * unhidden.
3032 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003033 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003034 public boolean setApplicationHidden(ComponentName admin, String packageName,
3035 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003036 if (mService != null) {
3037 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003038 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003039 } catch (RemoteException e) {
3040 Log.w(TAG, "Failed talking with device policy service", e);
3041 }
3042 }
3043 return false;
3044 }
3045
3046 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003047 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003048 *
3049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003050 * @param packageName The name of the package to retrieve the hidden status of.
3051 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003052 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003053 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003054 if (mService != null) {
3055 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003056 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003057 } catch (RemoteException e) {
3058 Log.w(TAG, "Failed talking with device policy service", e);
3059 }
3060 }
3061 return false;
3062 }
3063
3064 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003065 * Called by profile or device owner to re-enable a system app that was disabled by default
3066 * when the managed profile was created. This can only be called from a profile or device
3067 * owner running within a managed profile.
3068 *
3069 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3070 * @param packageName The package to be re-enabled in the current profile.
3071 */
3072 public void enableSystemApp(ComponentName admin, String packageName) {
3073 if (mService != null) {
3074 try {
3075 mService.enableSystemApp(admin, packageName);
3076 } catch (RemoteException e) {
3077 Log.w(TAG, "Failed to install package: " + packageName);
3078 }
3079 }
3080 }
3081
3082 /**
3083 * Called by profile or device owner to re-enable system apps by intent that were disabled
3084 * by default when the managed profile was created. This can only be called from a profile
3085 * or device owner running within a managed profile.
3086 *
3087 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3088 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3089 * intent will be re-enabled in the current profile.
3090 * @return int The number of activities that matched the intent and were installed.
3091 */
3092 public int enableSystemApp(ComponentName admin, Intent intent) {
3093 if (mService != null) {
3094 try {
3095 return mService.enableSystemAppWithIntent(admin, intent);
3096 } catch (RemoteException e) {
3097 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3098 }
3099 }
3100 return 0;
3101 }
3102
3103 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01003104 * Called by a profile owner to disable account management for a specific type of account.
3105 *
3106 * <p>The calling device admin must be a profile owner. If it is not, a
3107 * security exception will be thrown.
3108 *
3109 * <p>When account management is disabled for an account type, adding or removing an account
3110 * of that type will not be possible.
3111 *
3112 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3113 * @param accountType For which account management is disabled or enabled.
3114 * @param disabled The boolean indicating that account management will be disabled (true) or
3115 * enabled (false).
3116 */
3117 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3118 boolean disabled) {
3119 if (mService != null) {
3120 try {
3121 mService.setAccountManagementDisabled(admin, accountType, disabled);
3122 } catch (RemoteException e) {
3123 Log.w(TAG, "Failed talking with device policy service", e);
3124 }
3125 }
3126 }
3127
3128 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003129 * Gets the array of accounts for which account management is disabled by the profile owner.
3130 *
3131 * <p> Account management can be disabled/enabled by calling
3132 * {@link #setAccountManagementDisabled}.
3133 *
3134 * @return a list of account types for which account management has been disabled.
3135 *
3136 * @see #setAccountManagementDisabled
3137 */
3138 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003139 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003140 }
3141
3142 /**
3143 * @see #getAccountTypesWithManagementDisabled()
3144 * @hide
3145 */
3146 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003147 if (mService != null) {
3148 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003149 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003150 } catch (RemoteException e) {
3151 Log.w(TAG, "Failed talking with device policy service", e);
3152 }
3153 }
3154
3155 return null;
3156 }
justinzhang511e0d82014-03-24 16:09:24 -04003157
3158 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003159 * Sets which packages may enter lock task mode.
3160 *
3161 * <p>Any packages that shares uid with an allowed package will also be allowed
3162 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003163 *
Jason Monkc5185f22014-06-24 11:12:42 -04003164 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003165 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003167 *
3168 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003169 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3170 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003171 */
Jason Monk48aacba2014-08-13 16:29:08 -04003172 public void setLockTaskPackages(ComponentName admin, String[] packages)
3173 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003174 if (mService != null) {
3175 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003176 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003177 } catch (RemoteException e) {
3178 Log.w(TAG, "Failed talking with device policy service", e);
3179 }
3180 }
3181 }
3182
3183 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003184 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003185 *
3186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003187 * @hide
3188 */
Jason Monk48aacba2014-08-13 16:29:08 -04003189 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003190 if (mService != null) {
3191 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003192 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003193 } catch (RemoteException e) {
3194 Log.w(TAG, "Failed talking with device policy service", e);
3195 }
3196 }
3197 return null;
3198 }
3199
3200 /**
3201 * This function lets the caller know whether the given component is allowed to start the
3202 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003203 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003204 */
Jason Monkd7b86212014-06-16 13:15:38 -04003205 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003206 if (mService != null) {
3207 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003208 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003209 } catch (RemoteException e) {
3210 Log.w(TAG, "Failed talking with device policy service", e);
3211 }
3212 }
3213 return false;
3214 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003215
3216 /**
3217 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3218 * 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 -04003219 * <p>The settings that can be updated with this method are:
3220 * <ul>
3221 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3222 * <li>{@link Settings.Global#AUTO_TIME}</li>
3223 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
3224 * <li>{@link Settings.Global#BLUETOOTH_ON}</li>
3225 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3226 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3227 * <li>{@link Settings.Global#MODE_RINGER}</li>
3228 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3229 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
3230 * <li>{@link Settings.Global#WIFI_ON}</li>
3231 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3232 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003233 *
3234 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3235 * @param setting The name of the setting to update.
3236 * @param value The value to update the setting to.
3237 */
3238 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3239 if (mService != null) {
3240 try {
3241 mService.setGlobalSetting(admin, setting, value);
3242 } catch (RemoteException e) {
3243 Log.w(TAG, "Failed talking with device policy service", e);
3244 }
3245 }
3246 }
3247
3248 /**
3249 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3250 * that the value of the setting is in the correct form for the setting type should be performed
3251 * 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.Secure#DEFAULT_INPUT_METHOD}</li>
3255 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3256 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003257 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3258 * @param setting The name of the setting to update.
3259 * @param value The value to update the setting to.
3260 */
3261 public void setSecureSetting(ComponentName admin, String setting, String value) {
3262 if (mService != null) {
3263 try {
3264 mService.setSecureSetting(admin, setting, value);
3265 } catch (RemoteException e) {
3266 Log.w(TAG, "Failed talking with device policy service", e);
3267 }
3268 }
3269 }
3270
Amith Yamasanif20d6402014-05-24 15:34:37 -07003271 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003272 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003273 * making permission requests of a local or remote administrator of the user.
3274 * <p/>
3275 * Only a profile owner can designate the restrictions provider.
3276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003277 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003278 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003279 * it removes the restrictions provider previously assigned.
3280 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003281 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003282 if (mService != null) {
3283 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003284 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003285 } catch (RemoteException re) {
3286 Log.w(TAG, "Failed to set permission provider on device policy service");
3287 }
3288 }
3289 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003290
3291 /**
3292 * Called by profile or device owners to set the master volume mute on or off.
3293 *
3294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3295 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3296 */
3297 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3298 if (mService != null) {
3299 try {
3300 mService.setMasterVolumeMuted(admin, on);
3301 } catch (RemoteException re) {
3302 Log.w(TAG, "Failed to setMasterMute on device policy service");
3303 }
3304 }
3305 }
3306
3307 /**
3308 * Called by profile or device owners to check whether the master volume mute is on or off.
3309 *
3310 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3311 * @return {@code true} if master volume is muted, {@code false} if it's not.
3312 */
3313 public boolean isMasterVolumeMuted(ComponentName admin) {
3314 if (mService != null) {
3315 try {
3316 return mService.isMasterVolumeMuted(admin);
3317 } catch (RemoteException re) {
3318 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3319 }
3320 }
3321 return false;
3322 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003323
3324 /**
3325 * Called by profile or device owners to change whether a user can uninstall
3326 * a package.
3327 *
3328 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3329 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003330 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003331 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003332 public void setUninstallBlocked(ComponentName admin, String packageName,
3333 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003334 if (mService != null) {
3335 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003336 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003337 } catch (RemoteException re) {
3338 Log.w(TAG, "Failed to call block uninstall on device policy service");
3339 }
3340 }
3341 }
3342
3343 /**
3344 * Called by profile or device owners to check whether a user has been blocked from
3345 * uninstalling a package.
3346 *
3347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3348 * @param packageName package to check.
3349 * @return true if the user shouldn't be able to uninstall the package.
3350 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003351 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003352 if (mService != null) {
3353 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003354 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003355 } catch (RemoteException re) {
3356 Log.w(TAG, "Failed to call block uninstall on device policy service");
3357 }
3358 }
3359 return false;
3360 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003361
3362 /**
3363 * Called by the profile owner to enable widget providers from a given package
3364 * to be available in the parent profile. As a result the user will be able to
3365 * add widgets from the white-listed package running under the profile to a widget
3366 * host which runs under the device owner, for example the home screen. Note that
3367 * a package may have zero or more provider components, where each component
3368 * provides a different widget type.
3369 * <p>
3370 * <strong>Note:</strong> By default no widget provider package is white-listed.
3371 * </p>
3372 *
3373 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3374 * @param packageName The package from which widget providers are white-listed.
3375 * @return Whether the package was added.
3376 *
3377 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3378 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3379 */
3380 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3381 if (mService != null) {
3382 try {
3383 return mService.addCrossProfileWidgetProvider(admin, packageName);
3384 } catch (RemoteException re) {
3385 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3386 }
3387 }
3388 return false;
3389 }
3390
3391 /**
3392 * Called by the profile owner to disable widget providers from a given package
3393 * to be available in the parent profile. For this method to take effect the
3394 * package should have been added via {@link #addCrossProfileWidgetProvider(
3395 * android.content.ComponentName, String)}.
3396 * <p>
3397 * <strong>Note:</strong> By default no widget provider package is white-listed.
3398 * </p>
3399 *
3400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3401 * @param packageName The package from which widget providers are no longer
3402 * white-listed.
3403 * @return Whether the package was removed.
3404 *
3405 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3406 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3407 */
3408 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3409 if (mService != null) {
3410 try {
3411 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3412 } catch (RemoteException re) {
3413 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3414 }
3415 }
3416 return false;
3417 }
3418
3419 /**
3420 * Called by the profile owner to query providers from which packages are
3421 * available in the parent profile.
3422 *
3423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3424 * @return The white-listed package list.
3425 *
3426 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3427 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3428 */
3429 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3430 if (mService != null) {
3431 try {
3432 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3433 if (providers != null) {
3434 return providers;
3435 }
3436 } catch (RemoteException re) {
3437 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3438 }
3439 }
3440 return Collections.emptyList();
3441 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003442}