blob: cee8e8d2654ac7fee11fbf2abc9967c4844d75e1 [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;
Jim Millere303bf42014-08-26 17:12:29 -070034import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000035import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080036import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.os.RemoteException;
38import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070039import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040040import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040041import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010042import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070043import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080044import android.util.Log;
45
Maggie Benthallda51e682013-08-08 22:35:44 -040046import com.android.org.conscrypt.TrustedCertificateStore;
47
Jessica Hummel91da58d2014-04-10 17:39:43 +010048import org.xmlpull.v1.XmlPullParserException;
49
Maggie Benthallda51e682013-08-08 22:35:44 -040050import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070052import java.net.InetSocketAddress;
53import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010054import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010055import java.security.PrivateKey;
56import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040057import java.security.cert.CertificateException;
58import java.security.cert.CertificateFactory;
59import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010060import java.security.spec.PKCS8EncodedKeySpec;
61import java.security.spec.InvalidKeySpecException;
62import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070063import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070064import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080065import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080066
67/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000068 * Public interface for managing policies enforced on a device. Most clients of this class must be
69 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000070 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000071 * a device administrator may be registered as either a profile or device owner. A given method is
72 * accessible to all device administrators unless the documentation for that method specifies that
73 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080074 *
75 * <div class="special reference">
76 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000077 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080078 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
79 * developer guide.</p>
80 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080081 */
82public class DevicePolicyManager {
83 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080084
85 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080086 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070087
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080088 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080089 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 mService = IDevicePolicyManager.Stub.asInterface(
91 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
92 }
93
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080094 /** @hide */
95 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080096 DevicePolicyManager me = new DevicePolicyManager(context, handler);
97 return me.mService != null ? me : null;
98 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070099
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000101 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000102 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100103 * <p>A managed profile allows data separation for example for the usage of a
104 * device as a personal and corporate device. The user which provisioning is started from and
105 * the managed profile share a launcher.
106 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800107 * <p>This intent will typically be sent by a mobile device management application (MDM).
108 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
109 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100110 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100111 * <p>This intent must contain the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000112 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000113 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
114 * in the provisioning intent. The
115 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
116 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
117 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100118 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100119 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
120 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000121 *
122 * <p>Input: Nothing.</p>
123 * <p>Output: Nothing</p>
124 */
125 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
126 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100127 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000128
129 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700130 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
131 * a mobile device management application that starts managed profile provisioning to pass data
132 * to itself on the managed profile when provisioning completes. The mobile device management
133 * application sends this extra in an intent with the action
134 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
135 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
136 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
137 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100138 */
139 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100140 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100141
142 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100143 * A String extra holding the package name of the mobile device management application that
144 * will be set as the profile owner or device owner.
145 *
146 * <p>If an application starts provisioning directly via an intent with action
147 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
148 * application that started provisioning. The package will be set as profile owner in that case.
149 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000150 * <p>This package is set as device owner when device owner provisioning is started by an NFC
151 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000152 */
153 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100154 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000155
156 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000157 * An {@link android.accounts.Account} extra holding the account to migrate during managed
158 * profile provisioning. If the account supplied is present in the primary user, it will be
159 * copied, along with its credentials to the managed profile and removed from the primary user.
160 *
161 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
162 */
163
164 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
165 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
166
167 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100168 * A String extra that, holds the email address of the account which a managed profile is
169 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
170 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100171 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100172 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
173 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100174 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
175 * contains this extra, it is forwarded in the
176 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
177 * device management application that was set as the profile owner during provisioning.
178 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100179 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100180 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
181 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100182
183 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000184 * A Boolean extra that can be used by the mobile device management application to skip the
185 * disabling of system apps during provisioning when set to <code>true</code>.
186 *
187 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
188 * provisioning via an NFC bump.
189 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000190 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
191 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000192
193 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100194 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
195 * will be set to.
196 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000197 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
198 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100199 */
200 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100201 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100202
203 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100204 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
205 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100206 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000207 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
208 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100209 */
210 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100211 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100212
213 /**
214 * A String extra holding the {@link java.util.Locale} that the device will be set to.
215 * Format: xx_yy, where xx is the language code, and yy the country code.
216 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000217 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
218 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100219 */
220 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100221 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100222
223 /**
224 * A String extra holding the ssid of the wifi network that should be used during nfc device
225 * owner provisioning for downloading the mobile device management application.
226 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000227 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
228 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100229 */
230 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100231 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100232
233 /**
234 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
235 * is hidden or not.
236 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000237 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
238 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100239 */
240 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100241 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100242
243 /**
244 * A String extra indicating the security type of the wifi network in
245 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
246 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000247 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
248 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100249 */
250 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100251 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100252
253 /**
254 * A String extra holding the password of the wifi network in
255 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
256 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000257 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
258 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100259 */
260 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100261 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100262
263 /**
264 * A String extra holding the proxy host for the wifi network in
265 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
266 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000267 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
268 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100269 */
270 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100271 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100272
273 /**
274 * An int extra holding the proxy port for the wifi network in
275 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
276 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000277 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
278 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100279 */
280 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100281 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100282
283 /**
284 * A String extra holding the proxy bypass for the wifi network in
285 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
286 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000287 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
288 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100289 */
290 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100291 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100292
293 /**
294 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
295 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
296 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000297 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
298 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100299 */
300 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100301 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100302
303 /**
304 * A String extra holding a url that specifies the download location of the device admin
305 * package. When not provided it is assumed that the device admin package is already installed.
306 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000307 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
308 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100309 */
310 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100311 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100312
313 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100314 * A String extra holding a http cookie header which should be used in the http request to the
315 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
316 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000317 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
318 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100319 */
320 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100321 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100322
323 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100324 * A String extra holding the SHA-1 checksum of the file at download location specified in
325 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
326 * the file at the download location an error will be shown to the user and the user will be
327 * asked to factory reset the device.
328 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000329 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
330 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100331 */
332 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100333 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100334
335 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000336 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
337 * has completed successfully.
338 *
339 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
340 * intent (@see #ACTION_PROVISION_MANAGED_PROFILE).
341 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800342 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000343 * corresponds to the account requested to be migrated at provisioning time, if any.
344 */
345 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
346 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
347 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
348
349 /**
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500350 * A boolean extra indicating whether device encryption is required as part of Device Owner
351 * provisioning.
352 *
353 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
354 * provisioning via an NFC bump.
355 */
356 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
357 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
358
359 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500360 * On devices managed by a device owner app, a String representation of a Component name extra
361 * indicating the component of the application that is temporarily granted device owner
362 * privileges during device initialization and profile owner privileges during secondary user
363 * initialization.
364 *
365 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
366 * provisioning via an NFC bump.
367 * @see ComponentName#unflattenFromString()
368 */
369 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
370 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
371
372 /**
373 * A String extra holding an http url that specifies the download location of the device
374 * initializer package. When not provided it is assumed that the device initializer package is
375 * already installed.
376 *
377 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
378 * provisioning via an NFC bump.
379 */
380 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
381 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
382
383 /**
384 * A String extra holding a http cookie header which should be used in the http request to the
385 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
386 *
387 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
388 * provisioning via an NFC bump.
389 */
390 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
391 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
392
393 /**
394 * A String extra holding the SHA-1 checksum of the file at download location specified in
395 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't
396 * match the file at the download location an error will be shown to the user and the user will
397 * be asked to factory reset the device.
398 *
399 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
400 * provisioning via an NFC bump.
401 */
402 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
403 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
404
405 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100406 * This MIME type is used for starting the Device Owner provisioning.
407 *
408 * <p>During device owner provisioning a device admin app is set as the owner of the device.
409 * A device owner has full control over the device. The device owner can not be modified by the
410 * user and the only way of resetting the device is if the device owner app calls a factory
411 * reset.
412 *
413 * <p> A typical use case would be a device that is owned by a company, but used by either an
414 * employee or client.
415 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000416 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100417 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000418 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100419 * contains the following properties:
420 * <ul>
421 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
422 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100423 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100424 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
425 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
426 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
427 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
428 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
429 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
430 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
431 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
432 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
433 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
434 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500435 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
436 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100437 *
438 * <p> When device owner provisioning has completed, an intent of the type
439 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
440 * device owner.
441 *
442 * <p>
443 * If provisioning fails, the device is factory reset.
444 *
445 * <p>Input: Nothing.</p>
446 * <p>Output: Nothing</p>
447 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100448 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100449 = "application/com.android.managedprovisioning";
450
451 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800452 * Activity action: ask the user to add a new device administrator to the system.
453 * The desired policy is the ComponentName of the policy in the
454 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
455 * bring the user through adding the device administrator to the system (or
456 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700457 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800458 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
459 * field to provide the user with additional explanation (in addition
460 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800461 *
462 * <p>If your administrator is already active, this will ordinarily return immediately (without
463 * user intervention). However, if your administrator has been updated and is requesting
464 * additional uses-policy flags, the user will be presented with the new list. New policies
465 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800466 */
467 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
468 public static final String ACTION_ADD_DEVICE_ADMIN
469 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700470
Dianne Hackbornd6847842010-01-12 18:14:19 -0800471 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700472 * @hide
473 * Activity action: ask the user to add a new device administrator as the profile owner
474 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
475 * permission can call this API.
476 *
477 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
478 * field. This will invoke a UI to bring the user through adding the profile owner admin
479 * to remotely control restrictions on the user.
480 *
481 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
482 * result of whether or not the user approved the action. If approved, the result will
483 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
484 * as a profile owner.
485 *
486 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
487 * field to provide the user with additional explanation (in addition
488 * to your component's description) about what is being added.
489 *
490 * <p>If there is already a profile owner active or the caller doesn't have the required
491 * permissions, the operation will return a failure result.
492 */
493 @SystemApi
494 public static final String ACTION_SET_PROFILE_OWNER
495 = "android.app.action.SET_PROFILE_OWNER";
496
497 /**
498 * @hide
499 * Name of the profile owner admin that controls the user.
500 */
501 @SystemApi
502 public static final String EXTRA_PROFILE_OWNER_NAME
503 = "android.app.extra.PROFILE_OWNER_NAME";
504
505 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700506 * Activity action: send when any policy admin changes a policy.
507 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700508 *
Jim Miller284b62e2010-06-08 14:27:42 -0700509 * @hide
510 */
511 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
512 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
513
514 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800515 * The ComponentName of the administrator component.
516 *
517 * @see #ACTION_ADD_DEVICE_ADMIN
518 */
519 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700520
Dianne Hackbornd6847842010-01-12 18:14:19 -0800521 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800522 * An optional CharSequence providing additional explanation for why the
523 * admin is being added.
524 *
525 * @see #ACTION_ADD_DEVICE_ADMIN
526 */
527 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700528
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800529 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700530 * Activity action: have the user enter a new password. This activity should
531 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
532 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
533 * enter a new password that meets the current requirements. You can use
534 * {@link #isActivePasswordSufficient()} to determine whether you need to
535 * have the user select a new password in order to meet the current
536 * constraints. Upon being resumed from this activity, you can check the new
537 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800538 */
539 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
540 public static final String ACTION_SET_NEW_PASSWORD
541 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700542
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000543 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000544 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
545 * the parent profile to access intents sent from the managed profile.
546 * That is, when an app in the managed profile calls
547 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
548 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000549 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100550 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000551
552 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000553 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
554 * the managed profile to access intents sent from the parent profile.
555 * That is, when an app in the parent profile calls
556 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
557 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000558 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100559 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700560
Dianne Hackbornd6847842010-01-12 18:14:19 -0800561 /**
562 * Return true if the given administrator component is currently
563 * active (enabled) in the system.
564 */
565 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100566 return isAdminActiveAsUser(who, UserHandle.myUserId());
567 }
568
569 /**
570 * @see #isAdminActive(ComponentName)
571 * @hide
572 */
573 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800574 if (mService != null) {
575 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100576 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800577 } catch (RemoteException e) {
578 Log.w(TAG, "Failed talking with device policy service", e);
579 }
580 }
581 return false;
582 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800583 /**
584 * Return true if the given administrator component is currently being removed
585 * for the user.
586 * @hide
587 */
588 public boolean isRemovingAdmin(ComponentName who, int userId) {
589 if (mService != null) {
590 try {
591 return mService.isRemovingAdmin(who, userId);
592 } catch (RemoteException e) {
593 Log.w(TAG, "Failed talking with device policy service", e);
594 }
595 }
596 return false;
597 }
598
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700599
Dianne Hackbornd6847842010-01-12 18:14:19 -0800600 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800601 * Return a list of all currently active device administrator's component
602 * names. Note that if there are no administrators than null may be
603 * returned.
604 */
605 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100606 return getActiveAdminsAsUser(UserHandle.myUserId());
607 }
608
609 /**
610 * @see #getActiveAdmins()
611 * @hide
612 */
613 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800614 if (mService != null) {
615 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100616 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800617 } catch (RemoteException e) {
618 Log.w(TAG, "Failed talking with device policy service", e);
619 }
620 }
621 return null;
622 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700623
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800624 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700625 * Used by package administration code to determine if a package can be stopped
626 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800627 * @hide
628 */
629 public boolean packageHasActiveAdmins(String packageName) {
630 if (mService != null) {
631 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700632 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800633 } catch (RemoteException e) {
634 Log.w(TAG, "Failed talking with device policy service", e);
635 }
636 }
637 return false;
638 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700639
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800640 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800641 * Remove a current administration component. This can only be called
642 * by the application that owns the administration component; if you
643 * try to remove someone else's component, a security exception will be
644 * thrown.
645 */
646 public void removeActiveAdmin(ComponentName who) {
647 if (mService != null) {
648 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700649 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800650 } catch (RemoteException e) {
651 Log.w(TAG, "Failed talking with device policy service", e);
652 }
653 }
654 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700655
Dianne Hackbornd6847842010-01-12 18:14:19 -0800656 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800657 * Returns true if an administrator has been granted a particular device policy. This can
658 * be used to check if the administrator was activated under an earlier set of policies,
659 * but requires additional policies after an upgrade.
660 *
661 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
662 * an active administrator, or an exception will be thrown.
663 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
664 */
665 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
666 if (mService != null) {
667 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700668 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800669 } catch (RemoteException e) {
670 Log.w(TAG, "Failed talking with device policy service", e);
671 }
672 }
673 return false;
674 }
675
676 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800677 * Constant for {@link #setPasswordQuality}: the policy has no requirements
678 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800679 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800680 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800681 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700682
Dianne Hackbornd6847842010-01-12 18:14:19 -0800683 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700684 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
685 * recognition technology. This implies technologies that can recognize the identity of
686 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
687 * Note that quality constants are ordered so that higher values are more restrictive.
688 */
689 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
690
691 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800692 * Constant for {@link #setPasswordQuality}: the policy requires some kind
693 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800694 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800695 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800696 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700697
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800698 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800699 * Constant for {@link #setPasswordQuality}: the user must have entered a
700 * password containing at least numeric characters. Note that quality
701 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800702 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800703 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700704
Dianne Hackbornd6847842010-01-12 18:14:19 -0800705 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800706 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800707 * password containing at least numeric characters with no repeating (4444)
708 * or ordered (1234, 4321, 2468) sequences. Note that quality
709 * constants are ordered so that higher values are more restrictive.
710 */
711 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
712
713 /**
714 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700715 * password containing at least alphabetic (or other symbol) characters.
716 * Note that quality constants are ordered so that higher values are more
717 * restrictive.
718 */
719 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700720
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700721 /**
722 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800723 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700724 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800725 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800726 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700727 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700728
Dianne Hackbornd6847842010-01-12 18:14:19 -0800729 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700730 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700731 * password containing at least a letter, a numerical digit and a special
732 * symbol, by default. With this password quality, passwords can be
733 * restricted to contain various sets of characters, like at least an
734 * uppercase letter, etc. These are specified using various methods,
735 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
736 * that quality constants are ordered so that higher values are more
737 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700738 */
739 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
740
741 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800742 * Called by an application that is administering the device to set the
743 * password restrictions it is imposing. After setting this, the user
744 * will not be able to enter a new password that is not at least as
745 * restrictive as what has been set. Note that the current password
746 * will remain until the user has set a new one, so the change does not
747 * take place immediately. To prompt the user for a new password, use
748 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700749 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800750 * <p>Quality constants are ordered so that higher values are more restrictive;
751 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800752 * the user's preference, and any other considerations) is the one that
753 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700754 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800755 * <p>The calling device admin must have requested
756 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
757 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700758 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800759 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800760 * @param quality The new desired quality. One of
761 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800762 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
763 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
764 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800765 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800766 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800767 if (mService != null) {
768 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800769 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800770 } catch (RemoteException e) {
771 Log.w(TAG, "Failed talking with device policy service", e);
772 }
773 }
774 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700775
Dianne Hackbornd6847842010-01-12 18:14:19 -0800776 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100777 * Retrieve the current minimum password quality for all admins of this user
778 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800779 * @param admin The name of the admin component to check, or null to aggregate
780 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800781 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800782 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700783 return getPasswordQuality(admin, UserHandle.myUserId());
784 }
785
786 /** @hide per-user version */
787 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800788 if (mService != null) {
789 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700790 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800791 } catch (RemoteException e) {
792 Log.w(TAG, "Failed talking with device policy service", e);
793 }
794 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800795 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800796 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700797
Dianne Hackbornd6847842010-01-12 18:14:19 -0800798 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800799 * Called by an application that is administering the device to set the
800 * minimum allowed password length. After setting this, the user
801 * will not be able to enter a new password that is not at least as
802 * restrictive as what has been set. Note that the current password
803 * will remain until the user has set a new one, so the change does not
804 * take place immediately. To prompt the user for a new password, use
805 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
806 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800807 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
808 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
809 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700810 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800811 * <p>The calling device admin must have requested
812 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
813 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700814 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800815 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800816 * @param length The new desired minimum password length. A value of 0
817 * means there is no restriction.
818 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800819 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800820 if (mService != null) {
821 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800822 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800823 } catch (RemoteException e) {
824 Log.w(TAG, "Failed talking with device policy service", e);
825 }
826 }
827 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700828
Dianne Hackbornd6847842010-01-12 18:14:19 -0800829 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100830 * Retrieve the current minimum password length for all admins of this
831 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800832 * @param admin The name of the admin component to check, or null to aggregate
833 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800834 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800835 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700836 return getPasswordMinimumLength(admin, UserHandle.myUserId());
837 }
838
839 /** @hide per-user version */
840 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800841 if (mService != null) {
842 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700843 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800844 } catch (RemoteException e) {
845 Log.w(TAG, "Failed talking with device policy service", e);
846 }
847 }
848 return 0;
849 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700850
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700851 /**
852 * Called by an application that is administering the device to set the
853 * minimum number of upper case letters required in the password. After
854 * setting this, the user will not be able to enter a new password that is
855 * not at least as restrictive as what has been set. Note that the current
856 * password will remain until the user has set a new one, so the change does
857 * not take place immediately. To prompt the user for a new password, use
858 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
859 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700860 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
861 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700862 * <p>
863 * The calling device admin must have requested
864 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
865 * this method; if it has not, a security exception will be thrown.
866 *
867 * @param admin Which {@link DeviceAdminReceiver} this request is associated
868 * with.
869 * @param length The new desired minimum number of upper case letters
870 * required in the password. A value of 0 means there is no
871 * restriction.
872 */
873 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
874 if (mService != null) {
875 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800876 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700877 } catch (RemoteException e) {
878 Log.w(TAG, "Failed talking with device policy service", e);
879 }
880 }
881 }
882
883 /**
884 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100885 * password for all admins of this user and its profiles or a particular one.
886 * This is the same value as set by
887 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700888 * and only applies when the password quality is
889 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700890 *
891 * @param admin The name of the admin component to check, or null to
892 * aggregate all admins.
893 * @return The minimum number of upper case letters required in the
894 * password.
895 */
896 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700897 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
898 }
899
900 /** @hide per-user version */
901 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700902 if (mService != null) {
903 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700904 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700905 } catch (RemoteException e) {
906 Log.w(TAG, "Failed talking with device policy service", e);
907 }
908 }
909 return 0;
910 }
911
912 /**
913 * Called by an application that is administering the device to set the
914 * minimum number of lower case letters required in the password. After
915 * setting this, the user will not be able to enter a new password that is
916 * not at least as restrictive as what has been set. Note that the current
917 * password will remain until the user has set a new one, so the change does
918 * not take place immediately. To prompt the user for a new password, use
919 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
920 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700921 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
922 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700923 * <p>
924 * The calling device admin must have requested
925 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
926 * this method; if it has not, a security exception will be thrown.
927 *
928 * @param admin Which {@link DeviceAdminReceiver} this request is associated
929 * with.
930 * @param length The new desired minimum number of lower case letters
931 * required in the password. A value of 0 means there is no
932 * restriction.
933 */
934 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
935 if (mService != null) {
936 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800937 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700938 } catch (RemoteException e) {
939 Log.w(TAG, "Failed talking with device policy service", e);
940 }
941 }
942 }
943
944 /**
945 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100946 * password for all admins of this user and its profiles or a particular one.
947 * This is the same value as set by
948 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700949 * and only applies when the password quality is
950 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700951 *
952 * @param admin The name of the admin component to check, or null to
953 * aggregate all admins.
954 * @return The minimum number of lower case letters required in the
955 * password.
956 */
957 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700958 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
959 }
960
961 /** @hide per-user version */
962 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700963 if (mService != null) {
964 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700965 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700966 } catch (RemoteException e) {
967 Log.w(TAG, "Failed talking with device policy service", e);
968 }
969 }
970 return 0;
971 }
972
973 /**
974 * Called by an application that is administering the device to set the
975 * minimum number of letters required in the password. After setting this,
976 * the user will not be able to enter a new password that is not at least as
977 * restrictive as what has been set. Note that the current password will
978 * remain until the user has set a new one, so the change does not take
979 * place immediately. To prompt the user for a new password, use
980 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
981 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700982 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
983 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700984 * <p>
985 * The calling device admin must have requested
986 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
987 * this method; if it has not, a security exception will be thrown.
988 *
989 * @param admin Which {@link DeviceAdminReceiver} this request is associated
990 * with.
991 * @param length The new desired minimum number of letters required in the
992 * password. A value of 0 means there is no restriction.
993 */
994 public void setPasswordMinimumLetters(ComponentName admin, int length) {
995 if (mService != null) {
996 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800997 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700998 } catch (RemoteException e) {
999 Log.w(TAG, "Failed talking with device policy service", e);
1000 }
1001 }
1002 }
1003
1004 /**
1005 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001006 * admins or a particular one. This is the same value as
1007 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1008 * and only applies when the password quality is
1009 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001010 *
1011 * @param admin The name of the admin component to check, or null to
1012 * aggregate all admins.
1013 * @return The minimum number of letters required in the password.
1014 */
1015 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001016 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1017 }
1018
1019 /** @hide per-user version */
1020 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001021 if (mService != null) {
1022 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001023 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001024 } catch (RemoteException e) {
1025 Log.w(TAG, "Failed talking with device policy service", e);
1026 }
1027 }
1028 return 0;
1029 }
1030
1031 /**
1032 * Called by an application that is administering the device to set the
1033 * minimum number of numerical digits required in the password. After
1034 * setting this, the user will not be able to enter a new password that is
1035 * not at least as restrictive as what has been set. Note that the current
1036 * password will remain until the user has set a new one, so the change does
1037 * not take place immediately. To prompt the user for a new password, use
1038 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1039 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001040 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1041 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001042 * <p>
1043 * The calling device admin must have requested
1044 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1045 * this method; if it has not, a security exception will be thrown.
1046 *
1047 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1048 * with.
1049 * @param length The new desired minimum number of numerical digits required
1050 * in the password. A value of 0 means there is no restriction.
1051 */
1052 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1053 if (mService != null) {
1054 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001055 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001056 } catch (RemoteException e) {
1057 Log.w(TAG, "Failed talking with device policy service", e);
1058 }
1059 }
1060 }
1061
1062 /**
1063 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001064 * for all admins of this user and its profiles or a particular one.
1065 * This is the same value as set by
1066 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001067 * and only applies when the password quality is
1068 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001069 *
1070 * @param admin The name of the admin component to check, or null to
1071 * aggregate all admins.
1072 * @return The minimum number of numerical digits required in the password.
1073 */
1074 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001075 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1076 }
1077
1078 /** @hide per-user version */
1079 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001080 if (mService != null) {
1081 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001082 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001083 } catch (RemoteException e) {
1084 Log.w(TAG, "Failed talking with device policy service", e);
1085 }
1086 }
1087 return 0;
1088 }
1089
1090 /**
1091 * Called by an application that is administering the device to set the
1092 * minimum number of symbols required in the password. After setting this,
1093 * the user will not be able to enter a new password that is not at least as
1094 * restrictive as what has been set. Note that the current password will
1095 * remain until the user has set a new one, so the change does not take
1096 * place immediately. To prompt the user for a new password, use
1097 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1098 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001099 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1100 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001101 * <p>
1102 * The calling device admin must have requested
1103 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1104 * this method; if it has not, a security exception will be thrown.
1105 *
1106 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1107 * with.
1108 * @param length The new desired minimum number of symbols required in the
1109 * password. A value of 0 means there is no restriction.
1110 */
1111 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1112 if (mService != null) {
1113 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001114 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001115 } catch (RemoteException e) {
1116 Log.w(TAG, "Failed talking with device policy service", e);
1117 }
1118 }
1119 }
1120
1121 /**
1122 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001123 * admins or a particular one. This is the same value as
1124 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1125 * and only applies when the password quality is
1126 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001127 *
1128 * @param admin The name of the admin component to check, or null to
1129 * aggregate all admins.
1130 * @return The minimum number of symbols required in the password.
1131 */
1132 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001133 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1134 }
1135
1136 /** @hide per-user version */
1137 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001138 if (mService != null) {
1139 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001140 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001141 } catch (RemoteException e) {
1142 Log.w(TAG, "Failed talking with device policy service", e);
1143 }
1144 }
1145 return 0;
1146 }
1147
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001148 /**
1149 * Called by an application that is administering the device to set the
1150 * minimum number of non-letter characters (numerical digits or symbols)
1151 * required in the password. After setting this, the user will not be able
1152 * to enter a new password that is not at least as restrictive as what has
1153 * been set. Note that the current password will remain until the user has
1154 * set a new one, so the change does not take place immediately. To prompt
1155 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1156 * setting this value. This constraint is only imposed if the administrator
1157 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1158 * {@link #setPasswordQuality}. The default value is 0.
1159 * <p>
1160 * The calling device admin must have requested
1161 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1162 * this method; if it has not, a security exception will be thrown.
1163 *
1164 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1165 * with.
1166 * @param length The new desired minimum number of letters required in the
1167 * password. A value of 0 means there is no restriction.
1168 */
1169 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1170 if (mService != null) {
1171 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001172 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001173 } catch (RemoteException e) {
1174 Log.w(TAG, "Failed talking with device policy service", e);
1175 }
1176 }
1177 }
1178
1179 /**
1180 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001181 * password for all admins of this user and its profiles or a particular one.
1182 * This is the same value as set by
1183 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001184 * and only applies when the password quality is
1185 * {@link #PASSWORD_QUALITY_COMPLEX}.
1186 *
1187 * @param admin The name of the admin component to check, or null to
1188 * aggregate all admins.
1189 * @return The minimum number of letters required in the password.
1190 */
1191 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001192 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1193 }
1194
1195 /** @hide per-user version */
1196 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001197 if (mService != null) {
1198 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001199 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001200 } catch (RemoteException e) {
1201 Log.w(TAG, "Failed talking with device policy service", e);
1202 }
1203 }
1204 return 0;
1205 }
1206
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001207 /**
1208 * Called by an application that is administering the device to set the length
1209 * of the password history. After setting this, the user will not be able to
1210 * enter a new password that is the same as any password in the history. Note
1211 * that the current password will remain until the user has set a new one, so
1212 * the change does not take place immediately. To prompt the user for a new
1213 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1214 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001215 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1216 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1217 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001218 *
1219 * <p>
1220 * The calling device admin must have requested
1221 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1222 * method; if it has not, a security exception will be thrown.
1223 *
1224 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1225 * with.
1226 * @param length The new desired length of password history. A value of 0
1227 * means there is no restriction.
1228 */
1229 public void setPasswordHistoryLength(ComponentName admin, int length) {
1230 if (mService != null) {
1231 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001232 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001233 } catch (RemoteException e) {
1234 Log.w(TAG, "Failed talking with device policy service", e);
1235 }
1236 }
1237 }
1238
1239 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001240 * Called by a device admin to set the password expiration timeout. Calling this method
1241 * will restart the countdown for password expiration for the given admin, as will changing
1242 * the device password (for all admins).
1243 *
1244 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1245 * For example, to have the password expire 5 days from now, timeout would be
1246 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1247 *
1248 * <p>To disable password expiration, a value of 0 may be used for timeout.
1249 *
Jim Millera4e28d12010-11-08 16:15:47 -08001250 * <p>The calling device admin must have requested
1251 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1252 * method; if it has not, a security exception will be thrown.
1253 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001254 * <p> Note that setting the password will automatically reset the expiration time for all
1255 * active admins. Active admins do not need to explicitly call this method in that case.
1256 *
Jim Millera4e28d12010-11-08 16:15:47 -08001257 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1258 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1259 * means there is no restriction (unlimited).
1260 */
1261 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1262 if (mService != null) {
1263 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001264 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001265 } catch (RemoteException e) {
1266 Log.w(TAG, "Failed talking with device policy service", e);
1267 }
1268 }
1269 }
1270
1271 /**
Jim Miller6b857682011-02-16 16:27:41 -08001272 * Get the password expiration timeout for the given admin. The expiration timeout is the
1273 * recurring expiration timeout provided in the call to
1274 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1275 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001276 *
1277 * @param admin The name of the admin component to check, or null to aggregate all admins.
1278 * @return The timeout for the given admin or the minimum of all timeouts
1279 */
1280 public long getPasswordExpirationTimeout(ComponentName admin) {
1281 if (mService != null) {
1282 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001283 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001284 } catch (RemoteException e) {
1285 Log.w(TAG, "Failed talking with device policy service", e);
1286 }
1287 }
1288 return 0;
1289 }
1290
1291 /**
1292 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001293 * all admins of this user and its profiles if admin is null. If the password is
1294 * expired, this will return the time since the password expired as a negative number.
1295 * If admin is null, then a composite of all expiration timeouts is returned
1296 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001297 *
1298 * @param admin The name of the admin component to check, or null to aggregate all admins.
1299 * @return The password expiration time, in ms.
1300 */
1301 public long getPasswordExpiration(ComponentName admin) {
1302 if (mService != null) {
1303 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001304 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001305 } catch (RemoteException e) {
1306 Log.w(TAG, "Failed talking with device policy service", e);
1307 }
1308 }
1309 return 0;
1310 }
1311
1312 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001313 * Retrieve the current password history length for all admins of this
1314 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001315 * @param admin The name of the admin component to check, or null to aggregate
1316 * all admins.
1317 * @return The length of the password history
1318 */
1319 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001320 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1321 }
1322
1323 /** @hide per-user version */
1324 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001325 if (mService != null) {
1326 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001327 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001328 } catch (RemoteException e) {
1329 Log.w(TAG, "Failed talking with device policy service", e);
1330 }
1331 }
1332 return 0;
1333 }
1334
Dianne Hackbornd6847842010-01-12 18:14:19 -08001335 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001336 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001337 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001338 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001339 * @return Returns the maximum length that the user can enter.
1340 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001341 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001342 // Kind-of arbitrary.
1343 return 16;
1344 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001345
Dianne Hackborn254cb442010-01-27 19:23:59 -08001346 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001347 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001348 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001349 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001350 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001351 * <p>The calling device admin must have requested
1352 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1353 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001354 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001355 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001356 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001357 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001358 if (mService != null) {
1359 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001360 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001361 } catch (RemoteException e) {
1362 Log.w(TAG, "Failed talking with device policy service", e);
1363 }
1364 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001365 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001366 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001367
Dianne Hackbornd6847842010-01-12 18:14:19 -08001368 /**
1369 * Retrieve the number of times the user has failed at entering a
1370 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001371 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001372 * <p>The calling device admin must have requested
1373 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1374 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001375 */
1376 public int getCurrentFailedPasswordAttempts() {
1377 if (mService != null) {
1378 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001379 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001380 } catch (RemoteException e) {
1381 Log.w(TAG, "Failed talking with device policy service", e);
1382 }
1383 }
1384 return -1;
1385 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001386
1387 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001388 * Setting this to a value greater than zero enables a built-in policy
1389 * that will perform a device wipe after too many incorrect
1390 * device-unlock passwords have been entered. This built-in policy combines
1391 * watching for failed passwords and wiping the device, and requires
1392 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001393 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001394 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001395 * <p>To implement any other policy (e.g. wiping data for a particular
1396 * application only, erasing or revoking credentials, or reporting the
1397 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001398 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001399 * instead. Do not use this API, because if the maximum count is reached,
1400 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001401 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001402 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001403 * @param num The number of failed password attempts at which point the
1404 * device will wipe its data.
1405 */
1406 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1407 if (mService != null) {
1408 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001409 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001410 } catch (RemoteException e) {
1411 Log.w(TAG, "Failed talking with device policy service", e);
1412 }
1413 }
1414 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001415
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001416 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001417 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001418 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001419 * or a particular one.
1420 * @param admin The name of the admin component to check, or null to aggregate
1421 * all admins.
1422 */
1423 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001424 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1425 }
1426
1427 /** @hide per-user version */
1428 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001429 if (mService != null) {
1430 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001431 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001432 } catch (RemoteException e) {
1433 Log.w(TAG, "Failed talking with device policy service", e);
1434 }
1435 }
1436 return 0;
1437 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001438
Dianne Hackborn254cb442010-01-27 19:23:59 -08001439 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001440 * Returns the profile with the smallest maximum failed passwords for wipe,
1441 * for the given user. So for primary user, it might return the primary or
1442 * a managed profile. For a secondary user, it would be the same as the
1443 * user passed in.
1444 * @hide Used only by Keyguard
1445 */
1446 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1447 if (mService != null) {
1448 try {
1449 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1450 } catch (RemoteException e) {
1451 Log.w(TAG, "Failed talking with device policy service", e);
1452 }
1453 }
1454 return UserHandle.USER_NULL;
1455 }
1456
1457 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001458 * Flag for {@link #resetPassword}: don't allow other admins to change
1459 * the password again until the user has entered it.
1460 */
1461 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001462
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001463 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001464 * Force a new device unlock password (the password needed to access the
1465 * entire device, not for individual accounts) on the user. This takes
1466 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001467 * The given password must be sufficient for the
1468 * current password quality and length constraints as returned by
1469 * {@link #getPasswordQuality(ComponentName)} and
1470 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1471 * these constraints, then it will be rejected and false returned. Note
1472 * that the password may be a stronger quality (containing alphanumeric
1473 * characters when the requested quality is only numeric), in which case
1474 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001475 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001476 * <p>Calling with a null or empty password will clear any existing PIN,
1477 * pattern or password if the current password constraints allow it.
1478 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001479 * <p>The calling device admin must have requested
1480 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1481 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001482 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001483 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001484 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001485 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001486 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001487 * @return Returns true if the password was applied, or false if it is
1488 * not acceptable for the current constraints.
1489 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001490 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001491 if (mService != null) {
1492 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001493 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001494 } catch (RemoteException e) {
1495 Log.w(TAG, "Failed talking with device policy service", e);
1496 }
1497 }
1498 return false;
1499 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001500
Dianne Hackbornd6847842010-01-12 18:14:19 -08001501 /**
1502 * Called by an application that is administering the device to set the
1503 * maximum time for user activity until the device will lock. This limits
1504 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001505 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001506 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001507 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001508 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001509 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001511 * @param timeMs The new desired maximum time to lock in milliseconds.
1512 * A value of 0 means there is no restriction.
1513 */
1514 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1515 if (mService != null) {
1516 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001517 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001518 } catch (RemoteException e) {
1519 Log.w(TAG, "Failed talking with device policy service", e);
1520 }
1521 }
1522 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001523
Dianne Hackbornd6847842010-01-12 18:14:19 -08001524 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001525 * Retrieve the current maximum time to unlock for all admins of this user
1526 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001527 * @param admin The name of the admin component to check, or null to aggregate
1528 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001529 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001530 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001531 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001532 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001533 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1534 }
1535
1536 /** @hide per-user version */
1537 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001538 if (mService != null) {
1539 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001540 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001541 } catch (RemoteException e) {
1542 Log.w(TAG, "Failed talking with device policy service", e);
1543 }
1544 }
1545 return 0;
1546 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001547
Dianne Hackbornd6847842010-01-12 18:14:19 -08001548 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001549 * Make the device lock immediately, as if the lock screen timeout has
1550 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001551 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001552 * <p>The calling device admin must have requested
1553 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1554 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001555 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001556 public void lockNow() {
1557 if (mService != null) {
1558 try {
1559 mService.lockNow();
1560 } catch (RemoteException e) {
1561 Log.w(TAG, "Failed talking with device policy service", e);
1562 }
1563 }
1564 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001565
Dianne Hackbornd6847842010-01-12 18:14:19 -08001566 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001567 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001568 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001569 */
1570 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1571
1572 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001573 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1574 * data.
1575 *
Paul Crowley2934b262014-12-02 11:21:13 +00001576 * <p>This flag may only be set by device owner admins; if it is set by
1577 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001578 */
1579 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1580
1581 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001582 * Ask the user data be wiped. Wiping the primary user will cause the
1583 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001584 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001585 * <p>The calling device admin must have requested
1586 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1587 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001588 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001589 * @param flags Bit mask of additional options: currently supported flags
1590 * are {@link #WIPE_EXTERNAL_STORAGE} and
1591 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001592 */
1593 public void wipeData(int flags) {
1594 if (mService != null) {
1595 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001596 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001597 } catch (RemoteException e) {
1598 Log.w(TAG, "Failed talking with device policy service", e);
1599 }
1600 }
1601 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001602
Dianne Hackbornd6847842010-01-12 18:14:19 -08001603 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001604 * Called by an application that is administering the device to set the
1605 * global proxy and exclusion list.
1606 * <p>
1607 * The calling device admin must have requested
1608 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1609 * this method; if it has not, a security exception will be thrown.
1610 * Only the first device admin can set the proxy. If a second admin attempts
1611 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1612 * proxy will be returned. If successful in setting the proxy, null will
1613 * be returned.
1614 * The method can be called repeatedly by the device admin alrady setting the
1615 * proxy to update the proxy and exclusion list.
1616 *
1617 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1618 * with.
1619 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1620 * Pass Proxy.NO_PROXY to reset the proxy.
1621 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001622 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1623 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001624 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001625 */
1626 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1627 List<String> exclusionList ) {
1628 if (proxySpec == null) {
1629 throw new NullPointerException();
1630 }
1631 if (mService != null) {
1632 try {
1633 String hostSpec;
1634 String exclSpec;
1635 if (proxySpec.equals(Proxy.NO_PROXY)) {
1636 hostSpec = null;
1637 exclSpec = null;
1638 } else {
1639 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1640 throw new IllegalArgumentException();
1641 }
1642 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1643 String hostName = sa.getHostName();
1644 int port = sa.getPort();
1645 StringBuilder hostBuilder = new StringBuilder();
1646 hostSpec = hostBuilder.append(hostName)
1647 .append(":").append(Integer.toString(port)).toString();
1648 if (exclusionList == null) {
1649 exclSpec = "";
1650 } else {
1651 StringBuilder listBuilder = new StringBuilder();
1652 boolean firstDomain = true;
1653 for (String exclDomain : exclusionList) {
1654 if (!firstDomain) {
1655 listBuilder = listBuilder.append(",");
1656 } else {
1657 firstDomain = false;
1658 }
1659 listBuilder = listBuilder.append(exclDomain.trim());
1660 }
1661 exclSpec = listBuilder.toString();
1662 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001663 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1664 != android.net.Proxy.PROXY_VALID)
1665 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001666 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001667 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001668 } catch (RemoteException e) {
1669 Log.w(TAG, "Failed talking with device policy service", e);
1670 }
1671 }
1672 return null;
1673 }
1674
1675 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001676 * Set a network-independent global HTTP proxy. This is not normally what you want
1677 * for typical HTTP proxies - they are generally network dependent. However if you're
1678 * doing something unusual like general internal filtering this may be useful. On
1679 * a private network where the proxy is not accessible, you may break HTTP using this.
1680 *
1681 * <p>This method requires the caller to be the device owner.
1682 *
1683 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1684 * @see ProxyInfo
1685 *
1686 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1687 * with.
1688 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1689 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1690 */
1691 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1692 if (mService != null) {
1693 try {
1694 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1695 } catch (RemoteException e) {
1696 Log.w(TAG, "Failed talking with device policy service", e);
1697 }
1698 }
1699 }
1700
1701 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001702 * Returns the component name setting the global proxy.
1703 * @return ComponentName object of the device admin that set the global proxy, or
1704 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001705 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001706 */
1707 public ComponentName getGlobalProxyAdmin() {
1708 if (mService != null) {
1709 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001710 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001711 } catch (RemoteException e) {
1712 Log.w(TAG, "Failed talking with device policy service", e);
1713 }
1714 }
1715 return null;
1716 }
1717
1718 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001719 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001720 * indicating that encryption is not supported.
1721 */
1722 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1723
1724 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001725 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001726 * indicating that encryption is supported, but is not currently active.
1727 */
1728 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1729
1730 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001731 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001732 * indicating that encryption is not currently active, but is currently
1733 * being activated. This is only reported by devices that support
1734 * encryption of data and only when the storage is currently
1735 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1736 * to become encrypted will never return this value.
1737 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001738 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001739
1740 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001741 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001742 * indicating that encryption is active.
1743 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001744 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001745
1746 /**
1747 * Activity action: begin the process of encrypting data on the device. This activity should
1748 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1749 * After resuming from this activity, use {@link #getStorageEncryption}
1750 * to check encryption status. However, on some devices this activity may never return, as
1751 * it may trigger a reboot and in some cases a complete data wipe of the device.
1752 */
1753 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1754 public static final String ACTION_START_ENCRYPTION
1755 = "android.app.action.START_ENCRYPTION";
1756
1757 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001758 * Widgets are enabled in keyguard
1759 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001760 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001761
1762 /**
Jim Miller50e62182014-04-23 17:25:00 -07001763 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001764 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001765 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1766
1767 /**
1768 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1769 */
1770 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1771
1772 /**
Jim Miller50e62182014-04-23 17:25:00 -07001773 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1774 */
1775 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1776
1777 /**
1778 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1779 */
1780 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1781
1782 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001783 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001784 * (e.g. PIN/Pattern/Password).
1785 */
1786 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1787
1788 /**
Jim Miller06e34502014-07-17 14:46:05 -07001789 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1790 */
1791 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1792
1793 /**
Jim Miller35207742012-11-02 15:33:20 -07001794 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001795 */
1796 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001797
1798 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001799 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001800 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001801 *
1802 * <p>When multiple device administrators attempt to control device
1803 * encryption, the most secure, supported setting will always be
1804 * used. If any device administrator requests device encryption,
1805 * it will be enabled; Conversely, if a device administrator
1806 * attempts to disable device encryption while another
1807 * device administrator has enabled it, the call to disable will
1808 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1809 *
1810 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001811 * written to other storage areas may or may not be encrypted, and this policy does not require
1812 * or control the encryption of any other storage areas.
1813 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1814 * {@code true}, then the directory returned by
1815 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1816 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001817 *
1818 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1819 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1820 * the encryption key may not be fully secured. For maximum security, the administrator should
1821 * also require (and check for) a pattern, PIN, or password.
1822 *
1823 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1824 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001825 * @return the new request status (for all active admins) - will be one of
1826 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1827 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1828 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001829 */
1830 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1831 if (mService != null) {
1832 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001833 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001834 } catch (RemoteException e) {
1835 Log.w(TAG, "Failed talking with device policy service", e);
1836 }
1837 }
1838 return ENCRYPTION_STATUS_UNSUPPORTED;
1839 }
1840
1841 /**
1842 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001843 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001844 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001845 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1846 * this will return the requested encryption setting as an aggregate of all active
1847 * administrators.
1848 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001849 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001850 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001851 if (mService != null) {
1852 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001853 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001854 } catch (RemoteException e) {
1855 Log.w(TAG, "Failed talking with device policy service", e);
1856 }
1857 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001858 return false;
1859 }
1860
1861 /**
1862 * Called by an application that is administering the device to
1863 * determine the current encryption status of the device.
1864 *
1865 * Depending on the returned status code, the caller may proceed in different
1866 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1867 * storage system does not support encryption. If the
1868 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1869 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1870 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1871 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1872 *
Robin Lee7e678712014-07-24 16:41:31 +01001873 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001874 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1875 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1876 */
1877 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001878 return getStorageEncryptionStatus(UserHandle.myUserId());
1879 }
1880
1881 /** @hide per-user version */
1882 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001883 if (mService != null) {
1884 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001885 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001886 } catch (RemoteException e) {
1887 Log.w(TAG, "Failed talking with device policy service", e);
1888 }
1889 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001890 return ENCRYPTION_STATUS_UNSUPPORTED;
1891 }
1892
1893 /**
Robin Lee7e678712014-07-24 16:41:31 +01001894 * Installs the given certificate as a user CA.
1895 *
1896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1897 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001898 *
1899 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001900 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001901 */
Robin Lee7e678712014-07-24 16:41:31 +01001902 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001903 if (mService != null) {
1904 try {
Robin Lee7e678712014-07-24 16:41:31 +01001905 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001906 } catch (RemoteException e) {
1907 Log.w(TAG, "Failed talking with device policy service", e);
1908 }
1909 }
1910 return false;
1911 }
1912
1913 /**
Robin Lee7e678712014-07-24 16:41:31 +01001914 * Uninstalls the given certificate from trusted user CAs, if present.
1915 *
1916 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1917 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001918 */
Robin Lee7e678712014-07-24 16:41:31 +01001919 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001920 if (mService != null) {
1921 try {
Robin Lee306fe082014-06-19 14:04:24 +00001922 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001923 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001924 } catch (CertificateException e) {
1925 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001926 } catch (RemoteException e) {
1927 Log.w(TAG, "Failed talking with device policy service", e);
1928 }
1929 }
1930 }
1931
1932 /**
Robin Lee7e678712014-07-24 16:41:31 +01001933 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1934 * If a user has installed any certificates by other means than device policy these will be
1935 * included too.
1936 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001937 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001938 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001939 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001940 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01001941 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001942 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01001943 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001944 mService.enforceCanManageCaCerts(admin);
1945 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1946 for (String alias : certStore.userAliases()) {
1947 try {
1948 certs.add(certStore.getCertificate(alias).getEncoded());
1949 } catch (CertificateException ce) {
1950 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1951 }
1952 }
1953 } catch (RemoteException re) {
1954 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01001955 }
1956 }
1957 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001958 }
1959
1960 /**
Robin Lee7e678712014-07-24 16:41:31 +01001961 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1962 * means other than device policy will also be removed, except for system CA certificates.
1963 *
1964 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1965 */
1966 public void uninstallAllUserCaCerts(ComponentName admin) {
1967 if (mService != null) {
1968 for (String alias : new TrustedCertificateStore().userAliases()) {
1969 try {
1970 mService.uninstallCaCert(admin, alias);
1971 } catch (RemoteException re) {
1972 Log.w(TAG, "Failed talking with device policy service", re);
1973 }
1974 }
1975 }
1976 }
1977
1978 /**
1979 * Returns whether this certificate is installed as a trusted CA.
1980 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001981 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001982 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001983 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001984 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
1985 if (mService != null) {
1986 try {
1987 mService.enforceCanManageCaCerts(admin);
1988 return getCaCertAlias(certBuffer) != null;
1989 } catch (RemoteException re) {
1990 Log.w(TAG, "Failed talking with device policy service", re);
1991 } catch (CertificateException ce) {
1992 Log.w(TAG, "Could not parse certificate", ce);
1993 }
Maggie Benthallda51e682013-08-08 22:35:44 -04001994 }
1995 return false;
1996 }
1997
1998 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001999 * Called by a device or profile owner to install a certificate and private key pair. The
2000 * keypair will be visible to all apps within the profile.
2001 *
2002 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2003 * @param privKey The private key to install.
2004 * @param cert The certificate to install.
2005 * @param alias The private key alias under which to install the certificate. If a certificate
2006 * with that alias already exists, it will be overwritten.
2007 * @return {@code true} if the keys were installed, {@code false} otherwise.
2008 */
2009 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2010 String alias) {
2011 try {
2012 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002013 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2014 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2015 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002016 } catch (RemoteException e) {
2017 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002018 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2019 Log.w(TAG, "Failed to obtain private key material", e);
2020 } catch (CertificateException | IOException e) {
2021 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002022 }
2023 return false;
2024 }
2025
2026 /**
Robin Lee306fe082014-06-19 14:04:24 +00002027 * Returns the alias of a given CA certificate in the certificate store, or null if it
2028 * doesn't exist.
2029 */
2030 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2031 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2032 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2033 new ByteArrayInputStream(certBuffer));
2034 return new TrustedCertificateStore().getCertificateAlias(cert);
2035 }
2036
2037 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002038 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002039 * on the device, for this user. After setting this, no applications running as this user
2040 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002041 *
2042 * <p>The calling device admin must have requested
2043 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2044 * this method; if it has not, a security exception will be thrown.
2045 *
2046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2047 * @param disabled Whether or not the camera should be disabled.
2048 */
2049 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2050 if (mService != null) {
2051 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002052 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002053 } catch (RemoteException e) {
2054 Log.w(TAG, "Failed talking with device policy service", e);
2055 }
2056 }
2057 }
2058
2059 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002060 * Determine whether or not the device's cameras have been disabled for this user,
2061 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002062 * @param admin The name of the admin component to check, or null to check if any admins
2063 * have disabled the camera
2064 */
2065 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002066 return getCameraDisabled(admin, UserHandle.myUserId());
2067 }
2068
2069 /** @hide per-user version */
2070 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002071 if (mService != null) {
2072 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002073 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002074 } catch (RemoteException e) {
2075 Log.w(TAG, "Failed talking with device policy service", e);
2076 }
2077 }
2078 return false;
2079 }
2080
2081 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002082 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2083 * screen capture also prevents the content from being shown on display devices that do not have
2084 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2085 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002086 *
2087 * <p>The calling device admin must be a device or profile owner. If it is not, a
2088 * security exception will be thrown.
2089 *
2090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002091 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002092 */
2093 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2094 if (mService != null) {
2095 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002096 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002097 } catch (RemoteException e) {
2098 Log.w(TAG, "Failed talking with device policy service", e);
2099 }
2100 }
2101 }
2102
2103 /**
2104 * Determine whether or not screen capture has been disabled by the current
2105 * admin, if specified, or all admins.
2106 * @param admin The name of the admin component to check, or null to check if any admins
2107 * have disabled screen capture.
2108 */
2109 public boolean getScreenCaptureDisabled(ComponentName admin) {
2110 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2111 }
2112
2113 /** @hide per-user version */
2114 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2115 if (mService != null) {
2116 try {
2117 return mService.getScreenCaptureDisabled(admin, userHandle);
2118 } catch (RemoteException e) {
2119 Log.w(TAG, "Failed talking with device policy service", e);
2120 }
2121 }
2122 return false;
2123 }
2124
2125 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002126 * Called by a device owner to set whether auto time is required. If auto time is
2127 * required the user cannot set the date and time, but has to use network date and time.
2128 *
2129 * <p>Note: if auto time is required the user can still manually set the time zone.
2130 *
2131 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2132 * be thrown.
2133 *
2134 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2135 * @param required Whether auto time is set required or not.
2136 */
2137 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2138 if (mService != null) {
2139 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002140 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002141 } catch (RemoteException e) {
2142 Log.w(TAG, "Failed talking with device policy service", e);
2143 }
2144 }
2145 }
2146
2147 /**
2148 * @return true if auto time is required.
2149 */
2150 public boolean getAutoTimeRequired() {
2151 if (mService != null) {
2152 try {
2153 return mService.getAutoTimeRequired();
2154 } catch (RemoteException e) {
2155 Log.w(TAG, "Failed talking with device policy service", e);
2156 }
2157 }
2158 return false;
2159 }
2160
2161 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002162 * Called by an application that is administering the device to disable keyguard customizations,
2163 * such as widgets. After setting this, keyguard features will be disabled according to the
2164 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002165 *
2166 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002167 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002168 * this method; if it has not, a security exception will be thrown.
2169 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002170 * <p>Calling this from a managed profile will throw a security exception.
2171 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002173 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2174 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002175 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2176 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002177 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002178 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002179 if (mService != null) {
2180 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002181 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002182 } catch (RemoteException e) {
2183 Log.w(TAG, "Failed talking with device policy service", e);
2184 }
2185 }
2186 }
2187
2188 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002189 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002190 * admin, if specified, or all admins.
2191 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002192 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002193 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2194 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002195 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002196 public int getKeyguardDisabledFeatures(ComponentName admin) {
2197 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002198 }
2199
2200 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002201 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002202 if (mService != null) {
2203 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002204 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002205 } catch (RemoteException e) {
2206 Log.w(TAG, "Failed talking with device policy service", e);
2207 }
2208 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002209 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002210 }
2211
2212 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002213 * @hide
2214 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002215 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002216 if (mService != null) {
2217 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002218 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002219 } catch (RemoteException e) {
2220 Log.w(TAG, "Failed talking with device policy service", e);
2221 }
2222 }
2223 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002224
Dianne Hackbornd6847842010-01-12 18:14:19 -08002225 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002226 * @hide
2227 */
2228 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2229 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2230 }
2231
2232 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002233 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002234 * @hide
2235 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002236 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002237 ActivityInfo ai;
2238 try {
2239 ai = mContext.getPackageManager().getReceiverInfo(cn,
2240 PackageManager.GET_META_DATA);
2241 } catch (PackageManager.NameNotFoundException e) {
2242 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2243 return null;
2244 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002245
Dianne Hackbornd6847842010-01-12 18:14:19 -08002246 ResolveInfo ri = new ResolveInfo();
2247 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002248
Dianne Hackbornd6847842010-01-12 18:14:19 -08002249 try {
2250 return new DeviceAdminInfo(mContext, ri);
2251 } catch (XmlPullParserException e) {
2252 Log.w(TAG, "Unable to parse device policy " + cn, e);
2253 return null;
2254 } catch (IOException e) {
2255 Log.w(TAG, "Unable to parse device policy " + cn, e);
2256 return null;
2257 }
2258 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002259
Dianne Hackbornd6847842010-01-12 18:14:19 -08002260 /**
2261 * @hide
2262 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002263 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2264 if (mService != null) {
2265 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002266 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002267 } catch (RemoteException e) {
2268 Log.w(TAG, "Failed talking with device policy service", e);
2269 }
2270 }
2271 }
2272
2273 /**
2274 * @hide
2275 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002276 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002277 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002278 if (mService != null) {
2279 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002280 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002281 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002282 } catch (RemoteException e) {
2283 Log.w(TAG, "Failed talking with device policy service", e);
2284 }
2285 }
2286 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002287
Dianne Hackbornd6847842010-01-12 18:14:19 -08002288 /**
2289 * @hide
2290 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002291 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002292 if (mService != null) {
2293 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002294 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002295 } catch (RemoteException e) {
2296 Log.w(TAG, "Failed talking with device policy service", e);
2297 }
2298 }
2299 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002300
Dianne Hackbornd6847842010-01-12 18:14:19 -08002301 /**
2302 * @hide
2303 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002304 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002305 if (mService != null) {
2306 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002307 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002308 } catch (RemoteException e) {
2309 Log.w(TAG, "Failed talking with device policy service", e);
2310 }
2311 }
2312 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002313
2314 /**
2315 * @hide
2316 * Sets the given package as the device owner. The package must already be installed and there
2317 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2318 * method must be called before the device is provisioned.
2319 * @param packageName the package name of the application to be registered as the device owner.
2320 * @return whether the package was successfully registered as the device owner.
2321 * @throws IllegalArgumentException if the package name is null or invalid
2322 * @throws IllegalStateException if a device owner is already registered or the device has
2323 * already been provisioned.
2324 */
2325 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2326 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002327 return setDeviceOwner(packageName, null);
2328 }
2329
2330 /**
2331 * @hide
2332 * Sets the given package as the device owner. The package must already be installed and there
2333 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2334 * method must be called before the device is provisioned.
2335 * @param packageName the package name of the application to be registered as the device owner.
2336 * @param ownerName the human readable name of the institution that owns this device.
2337 * @return whether the package was successfully registered as the device owner.
2338 * @throws IllegalArgumentException if the package name is null or invalid
2339 * @throws IllegalStateException if a device owner is already registered or the device has
2340 * already been provisioned.
2341 */
2342 public boolean setDeviceOwner(String packageName, String ownerName)
2343 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002344 if (mService != null) {
2345 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002346 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002347 } catch (RemoteException re) {
2348 Log.w(TAG, "Failed to set device owner");
2349 }
2350 }
2351 return false;
2352 }
2353
2354 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002355 * Used to determine if a particular package has been registered as a Device Owner app.
2356 * A device owner app is a special device admin that cannot be deactivated by the user, once
2357 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2358 * package is currently registered as the device owner app, pass in the package name from
2359 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2360 * admin apps that want to check if they are also registered as the device owner app. The
2361 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2362 * the setup process.
2363 * @param packageName the package name of the app, to compare with the registered device owner
2364 * app, if any.
2365 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002366 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002367 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002368 if (mService != null) {
2369 try {
2370 return mService.isDeviceOwner(packageName);
2371 } catch (RemoteException re) {
2372 Log.w(TAG, "Failed to check device owner");
2373 }
2374 }
2375 return false;
2376 }
2377
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002378 /**
2379 * @hide
2380 * Redirect to isDeviceOwnerApp.
2381 */
2382 public boolean isDeviceOwner(String packageName) {
2383 return isDeviceOwnerApp(packageName);
2384 }
2385
Jason Monkb0dced82014-06-06 14:36:20 -04002386 /**
2387 * Clears the current device owner. The caller must be the device owner.
2388 *
2389 * This function should be used cautiously as once it is called it cannot
2390 * be undone. The device owner can only be set as a part of device setup
2391 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002392 *
2393 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002394 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002395 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002396 if (mService != null) {
2397 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002398 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002399 } catch (RemoteException re) {
2400 Log.w(TAG, "Failed to clear device owner");
2401 }
2402 }
2403 }
2404
Amith Yamasani71e6c692013-03-24 17:39:28 -07002405 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002406 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002407 public String getDeviceOwner() {
2408 if (mService != null) {
2409 try {
2410 return mService.getDeviceOwner();
2411 } catch (RemoteException re) {
2412 Log.w(TAG, "Failed to get device owner");
2413 }
2414 }
2415 return null;
2416 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002417
2418 /** @hide */
2419 public String getDeviceOwnerName() {
2420 if (mService != null) {
2421 try {
2422 return mService.getDeviceOwnerName();
2423 } catch (RemoteException re) {
2424 Log.w(TAG, "Failed to get device owner");
2425 }
2426 }
2427 return null;
2428 }
Adam Connors776c5552014-01-09 10:42:56 +00002429
2430 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002431 * Sets the given component as the device initializer. The package must already be installed and
2432 * set as an active device administrator, and there must not be an existing device initializer,
2433 * for this call to succeed. This method can only be called by an app holding the
2434 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2435 * device initializer app is granted device owner privileges during device initialization and
2436 * profile owner privileges during secondary user initialization.
2437 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2438 * called by the device owner.
2439 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2440 * @param initializerName The user-visible name of the device initializer.
2441 * @return whether the package was successfully registered as the device initializer.
2442 * @throws IllegalArgumentException if the package name is null or invalid
2443 * @throws IllegalStateException if the caller is not device owner or the device has
2444 * already been provisioned or a device initializer already exists.
2445 */
2446 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2447 String initializerName) throws IllegalArgumentException, IllegalStateException {
2448 if (mService != null) {
2449 try {
2450 return mService.setDeviceInitializer(who, initializer, initializerName);
2451 } catch (RemoteException re) {
2452 Log.w(TAG, "Failed to set device initializer");
2453 }
2454 }
2455 return false;
2456 }
2457
2458 /**
2459 * Used to determine if a particular package has been registered as the device initializer.
2460 *
2461 * @param packageName the package name of the app, to compare with the registered device
2462 * initializer app, if any.
2463 * @return whether or not the caller is registered as the device initializer app.
2464 */
2465 public boolean isDeviceInitializerApp(String packageName) {
2466 if (mService != null) {
2467 try {
2468 return mService.isDeviceInitializer(packageName);
2469 } catch (RemoteException re) {
2470 Log.w(TAG, "Failed to check device initializer");
2471 }
2472 }
2473 return false;
2474 }
2475
2476 /**
2477 * Clears the current device initializer. The caller must be the device initializer.
2478 *
2479 * This function should be used cautiously as once it is called it cannot
2480 * be undone.
2481 */
2482 public void clearDeviceInitializerApp() {
2483 if (mService != null) {
2484 try {
2485 mService.clearDeviceInitializer(mContext.getPackageName());
2486 } catch (RemoteException re) {
2487 Log.w(TAG, "Failed to clear device initializer");
2488 }
2489 }
2490 }
2491
2492 /**
2493 * @hide
2494 * Gets the device initializer of the system.
2495 *
2496 * @return the package name of the device initializer.
2497 */
2498 @SystemApi
2499 public String getDeviceInitializerApp() {
2500 if (mService != null) {
2501 try {
2502 return mService.getDeviceInitializer();
2503 } catch (RemoteException re) {
2504 Log.w(TAG, "Failed to get device initializer");
2505 }
2506 }
2507 return null;
2508 }
2509
2510 /**
2511 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2512 * be used.
2513 *
2514 * <p>Device initializer must call this method to mark the user as functional.
2515 * Only the device initializer agent can call this.
2516 *
2517 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2518 * device initializer will no longer have elevated permissions to call methods in this class.
2519 * Additionally, it will be removed as an active administrator and its
2520 * {@link DeviceAdminReceiver} will be disabled.
2521 *
2522 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2523 * @return whether the user is now enabled.
2524 */
2525 public boolean setUserEnabled(ComponentName admin) {
2526 if (mService != null) {
2527 try {
2528 return mService.setUserEnabled(admin);
2529 } catch (RemoteException e) {
2530 Log.w(TAG, "Failed talking with device policy service", e);
2531 }
2532 }
2533 return false;
2534 }
2535
2536 /**
Adam Connors776c5552014-01-09 10:42:56 +00002537 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002538 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302539 * Sets the given component as an active admin and registers the package as the profile
2540 * owner for this user. The package must already be installed and there shouldn't be
2541 * an existing profile owner registered for this user. Also, this method must be called
2542 * before the user setup has been completed.
2543 * <p>
2544 * This method can only be called by system apps that hold MANAGE_USERS permission and
2545 * MANAGE_DEVICE_ADMINS permission.
2546 * @param admin The component to register as an active admin and profile owner.
2547 * @param ownerName The user-visible name of the entity that is managing this user.
2548 * @return whether the admin was successfully registered as the profile owner.
2549 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2550 * the user has already been set up.
2551 */
Justin Morey80440cc2014-07-24 09:16:35 -05002552 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302553 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2554 throws IllegalArgumentException {
2555 if (mService != null) {
2556 try {
2557 final int myUserId = UserHandle.myUserId();
2558 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002559 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302560 } catch (RemoteException re) {
2561 Log.w(TAG, "Failed to set profile owner " + re);
2562 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2563 }
2564 }
2565 return false;
2566 }
2567
2568 /**
2569 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002570 * Clears the active profile owner and removes all user restrictions. The caller must
2571 * be from the same package as the active profile owner for this user, otherwise a
2572 * SecurityException will be thrown.
2573 *
2574 * @param admin The component to remove as the profile owner.
2575 * @return
2576 */
2577 @SystemApi
2578 public void clearProfileOwner(ComponentName admin) {
2579 if (mService != null) {
2580 try {
2581 mService.clearProfileOwner(admin);
2582 } catch (RemoteException re) {
2583 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2584 }
2585 }
2586 }
2587
2588 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002589 * Checks if the user was already setup.
2590 */
2591 public boolean hasUserSetupCompleted() {
2592 if (mService != null) {
2593 try {
2594 return mService.hasUserSetupCompleted();
2595 } catch (RemoteException re) {
2596 Log.w(TAG, "Failed to check if user setup has completed");
2597 }
2598 }
2599 return true;
2600 }
2601
2602 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002603 * @hide
2604 * Sets the given component as the profile owner of the given user profile. The package must
2605 * already be installed and there shouldn't be an existing profile owner registered for this
2606 * user. Only the system can call this API if the user has already completed setup.
2607 * @param admin the component name to be registered as profile owner.
2608 * @param ownerName the human readable name of the organisation associated with this DPM.
2609 * @param userHandle the userId to set the profile owner for.
2610 * @return whether the component was successfully registered as the profile owner.
2611 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2612 * the user has already been set up.
2613 */
2614 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2615 throws IllegalArgumentException {
2616 if (admin == null) {
2617 throw new NullPointerException("admin cannot be null");
2618 }
Adam Connors776c5552014-01-09 10:42:56 +00002619 if (mService != null) {
2620 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002621 if (ownerName == null) {
2622 ownerName = "";
2623 }
2624 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002625 } catch (RemoteException re) {
2626 Log.w(TAG, "Failed to set profile owner", re);
2627 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2628 }
2629 }
2630 return false;
2631 }
2632
2633 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002634 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2635 * be used. Only the profile owner can call this.
2636 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002637 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002638 *
2639 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2640 */
2641 public void setProfileEnabled(ComponentName admin) {
2642 if (mService != null) {
2643 try {
2644 mService.setProfileEnabled(admin);
2645 } catch (RemoteException e) {
2646 Log.w(TAG, "Failed talking with device policy service", e);
2647 }
2648 }
2649 }
2650
2651 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002652 * Sets the name of the profile. In the device owner case it sets the name of the user
2653 * which it is called from. Only a profile owner or device owner can call this. If this is
Jessica Hummel1333ea12014-06-23 11:20:10 +01002654 * never called by the profile or device owner, the name will be set to default values.
2655 *
2656 * @see #isProfileOwnerApp
2657 * @see #isDeviceOwnerApp
2658 *
2659 * @param profileName The name of the profile.
2660 */
2661 public void setProfileName(ComponentName who, String profileName) {
2662 if (mService != null) {
2663 try {
2664 mService.setProfileName(who, profileName);
2665 } catch (RemoteException e) {
2666 Log.w(TAG, "Failed talking with device policy service", e);
2667 }
2668 }
2669}
2670
2671 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002672 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002673 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002674 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002675 *
2676 * @param packageName The package name of the app to compare with the registered profile owner.
2677 * @return Whether or not the package is registered as the profile owner.
2678 */
2679 public boolean isProfileOwnerApp(String packageName) {
2680 if (mService != null) {
2681 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002682 ComponentName profileOwner = mService.getProfileOwner(
2683 Process.myUserHandle().getIdentifier());
2684 return profileOwner != null
2685 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002686 } catch (RemoteException re) {
2687 Log.w(TAG, "Failed to check profile owner");
2688 }
2689 }
2690 return false;
2691 }
2692
2693 /**
2694 * @hide
2695 * @return the packageName of the owner of the given user profile or null if no profile
2696 * owner has been set for that user.
2697 * @throws IllegalArgumentException if the userId is invalid.
2698 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002699 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002700 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002701 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2702 }
2703
2704 /**
2705 * @see #getProfileOwner()
2706 * @hide
2707 */
2708 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002709 if (mService != null) {
2710 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002711 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002712 } catch (RemoteException re) {
2713 Log.w(TAG, "Failed to get profile owner");
2714 throw new IllegalArgumentException(
2715 "Requested profile owner for invalid userId", re);
2716 }
2717 }
2718 return null;
2719 }
2720
2721 /**
2722 * @hide
2723 * @return the human readable name of the organisation associated with this DPM or null if
2724 * one is not set.
2725 * @throws IllegalArgumentException if the userId is invalid.
2726 */
2727 public String getProfileOwnerName() throws IllegalArgumentException {
2728 if (mService != null) {
2729 try {
2730 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2731 } catch (RemoteException re) {
2732 Log.w(TAG, "Failed to get profile owner");
2733 throw new IllegalArgumentException(
2734 "Requested profile owner for invalid userId", re);
2735 }
2736 }
2737 return null;
2738 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002739
2740 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002741 * @hide
2742 * @param user The user for whom to fetch the profile owner name, if any.
2743 * @return the human readable name of the organisation associated with this profile owner or
2744 * null if one is not set.
2745 * @throws IllegalArgumentException if the userId is invalid.
2746 */
2747 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002748 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002749 if (mService != null) {
2750 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002751 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002752 } catch (RemoteException re) {
2753 Log.w(TAG, "Failed to get profile owner");
2754 throw new IllegalArgumentException(
2755 "Requested profile owner for invalid userId", re);
2756 }
2757 }
2758 return null;
2759 }
2760
2761 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002762 * Called by a profile owner or device owner to add a default intent handler activity for
2763 * intents that match a certain intent filter. This activity will remain the default intent
2764 * handler even if the set of potential event handlers for the intent filter changes and if
2765 * the intent preferences are reset.
2766 *
2767 * <p>The default disambiguation mechanism takes over if the activity is not installed
2768 * (anymore). When the activity is (re)installed, it is automatically reset as default
2769 * intent handler for the filter.
2770 *
2771 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2772 * security exception will be thrown.
2773 *
2774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2775 * @param filter The IntentFilter for which a default handler is added.
2776 * @param activity The Activity that is added as default intent handler.
2777 */
2778 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2779 ComponentName activity) {
2780 if (mService != null) {
2781 try {
2782 mService.addPersistentPreferredActivity(admin, filter, activity);
2783 } catch (RemoteException e) {
2784 Log.w(TAG, "Failed talking with device policy service", e);
2785 }
2786 }
2787 }
2788
2789 /**
2790 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002791 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002792 *
2793 * <p>The calling device admin must be a profile owner. If it is not, a security
2794 * exception will be thrown.
2795 *
2796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2797 * @param packageName The name of the package for which preferences are removed.
2798 */
2799 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2800 String packageName) {
2801 if (mService != null) {
2802 try {
2803 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2804 } catch (RemoteException e) {
2805 Log.w(TAG, "Failed talking with device policy service", e);
2806 }
2807 }
2808 }
Robin Lee66e5d962014-04-09 16:44:21 +01002809
2810 /**
2811 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002812 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002813 *
2814 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01002815 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01002816 *
2817 * <p>The application restrictions are only made visible to the target application and the
2818 * profile or device owner.
2819 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002820 * <p>If the restrictions are not available yet, but may be applied in the near future,
2821 * the admin can notify the target application of that by adding
2822 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
2823 *
Robin Lee66e5d962014-04-09 16:44:21 +01002824 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2825 * exception will be thrown.
2826 *
2827 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2828 * @param packageName The name of the package to update restricted settings for.
2829 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2830 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002831 *
2832 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01002833 */
2834 public void setApplicationRestrictions(ComponentName admin, String packageName,
2835 Bundle settings) {
2836 if (mService != null) {
2837 try {
2838 mService.setApplicationRestrictions(admin, packageName, settings);
2839 } catch (RemoteException e) {
2840 Log.w(TAG, "Failed talking with device policy service", e);
2841 }
2842 }
2843 }
2844
2845 /**
Jim Millere303bf42014-08-26 17:12:29 -07002846 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
2847 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
2848 * trust agents but those enabled by this function call. If flag
2849 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07002850 *
2851 * <p>The calling device admin must have requested
2852 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07002853 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07002854 *
2855 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07002856 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08002857 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07002858 * will be strictly disabled according to the state of the
2859 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
2860 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
2861 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
2862 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Millerbc4f2cc2015-02-24 18:00:25 -08002863 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002864 */
Jim Millere303bf42014-08-26 17:12:29 -07002865 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08002866 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07002867 if (mService != null) {
2868 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002869 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07002870 } catch (RemoteException e) {
2871 Log.w(TAG, "Failed talking with device policy service", e);
2872 }
2873 }
2874 }
2875
2876 /**
Jim Millere303bf42014-08-26 17:12:29 -07002877 * Gets configuration for the given trust agent based on aggregating all calls to
2878 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
2879 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07002880 *
Jim Millerb5db57a2015-01-14 18:17:19 -08002881 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2882 * this function returns a list of configurations for all admins that declare
2883 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
2884 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
2885 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
2886 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07002887 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07002888 * @return configuration for the given trust agent.
Jim Millerbc4f2cc2015-02-24 18:00:25 -08002889 * @hide
Jim Miller604e7552014-07-18 19:00:02 -07002890 */
Jim Millere303bf42014-08-26 17:12:29 -07002891 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2892 ComponentName agent) {
2893 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
2894 }
2895
2896 /** @hide per-user version */
2897 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2898 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07002899 if (mService != null) {
2900 try {
Jim Millere303bf42014-08-26 17:12:29 -07002901 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07002902 } catch (RemoteException e) {
2903 Log.w(TAG, "Failed talking with device policy service", e);
2904 }
2905 }
Jim Millere303bf42014-08-26 17:12:29 -07002906 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07002907 }
2908
2909 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002910 * Called by a profile owner of a managed profile to set whether caller-Id information from
2911 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01002912 *
2913 * <p>The calling device admin must be a profile owner. If it is not, a
2914 * security exception will be thrown.
2915 *
2916 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2917 * @param disabled If true caller-Id information in the managed profile is not displayed.
2918 */
2919 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2920 if (mService != null) {
2921 try {
2922 mService.setCrossProfileCallerIdDisabled(who, disabled);
2923 } catch (RemoteException e) {
2924 Log.w(TAG, "Failed talking with device policy service", e);
2925 }
2926 }
2927 }
2928
2929 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002930 * Called by a profile owner of a managed profile to determine whether or not caller-Id
2931 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01002932 *
2933 * <p>The calling device admin must be a profile owner. If it is not, a
2934 * security exception will be thrown.
2935 *
2936 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2937 */
2938 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2939 if (mService != null) {
2940 try {
2941 return mService.getCrossProfileCallerIdDisabled(who);
2942 } catch (RemoteException e) {
2943 Log.w(TAG, "Failed talking with device policy service", e);
2944 }
2945 }
2946 return false;
2947 }
2948
2949 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002950 * Determine whether or not caller-Id information has been disabled.
2951 *
2952 * @param userHandle The user for whom to check the caller-id permission
2953 * @hide
2954 */
2955 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2956 if (mService != null) {
2957 try {
2958 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2959 } catch (RemoteException e) {
2960 Log.w(TAG, "Failed talking with device policy service", e);
2961 }
2962 }
2963 return false;
2964 }
2965
2966 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002967 * Called by the profile owner of a managed profile so that some intents sent in the managed
2968 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00002969 * Only activity intents are supported.
2970 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002971 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002972 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2973 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002974 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2975 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002976 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002977 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002978 if (mService != null) {
2979 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002980 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002981 } catch (RemoteException e) {
2982 Log.w(TAG, "Failed talking with device policy service", e);
2983 }
2984 }
2985 }
2986
2987 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002988 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
2989 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002990 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2992 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002993 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002994 if (mService != null) {
2995 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002996 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002997 } catch (RemoteException e) {
2998 Log.w(TAG, "Failed talking with device policy service", e);
2999 }
3000 }
3001 }
3002
3003 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003004 * Called by a profile or device owner to set the permitted accessibility services. When
3005 * set by a device owner or profile owner the restriction applies to all profiles of the
3006 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003007 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003008 * By default the user can use any accessiblity service. When zero or more packages have
3009 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003010 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003011 *
3012 * <p> Calling with a null value for the list disables the restriction so that all services
3013 * can be used, calling with an empty list only allows the builtin system's services.
3014 *
3015 * <p> System accesibility services are always available to the user the list can't modify
3016 * this.
3017 *
3018 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3019 * @param packageNames List of accessibility service package names.
3020 *
3021 * @return true if setting the restriction succeeded. It fail if there is
3022 * one or more non-system accessibility services enabled, that are not in the list.
3023 */
3024 public boolean setPermittedAccessibilityServices(ComponentName admin,
3025 List<String> packageNames) {
3026 if (mService != null) {
3027 try {
3028 return mService.setPermittedAccessibilityServices(admin, packageNames);
3029 } catch (RemoteException e) {
3030 Log.w(TAG, "Failed talking with device policy service", e);
3031 }
3032 }
3033 return false;
3034 }
3035
3036 /**
3037 * Returns the list of permitted accessibility services set by this device or profile owner.
3038 *
3039 * <p>An empty list means no accessibility services except system services are allowed.
3040 * Null means all accessibility services are allowed.
3041 *
3042 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3043 * @return List of accessiblity service package names.
3044 */
3045 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3046 if (mService != null) {
3047 try {
3048 return mService.getPermittedAccessibilityServices(admin);
3049 } catch (RemoteException e) {
3050 Log.w(TAG, "Failed talking with device policy service", e);
3051 }
3052 }
3053 return null;
3054 }
3055
3056 /**
3057 * Returns the list of accessibility services permitted by the device or profiles
3058 * owners of this user.
3059 *
3060 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3061 * it will contain the intersection of the permitted lists for any device or profile
3062 * owners that apply to this user. It will also include any system accessibility services.
3063 *
3064 * @param userId which user to check for.
3065 * @return List of accessiblity service package names.
3066 * @hide
3067 */
3068 @SystemApi
3069 public List<String> getPermittedAccessibilityServices(int userId) {
3070 if (mService != null) {
3071 try {
3072 return mService.getPermittedAccessibilityServicesForUser(userId);
3073 } catch (RemoteException e) {
3074 Log.w(TAG, "Failed talking with device policy service", e);
3075 }
3076 }
3077 return null;
3078 }
3079
3080 /**
3081 * Called by a profile or device owner to set the permitted input methods services. When
3082 * set by a device owner or profile owner the restriction applies to all profiles of the
3083 * user the device owner or profile owner is an admin for.
3084 *
3085 * By default the user can use any input method. When zero or more packages have
3086 * been added, input method that are not in the list and not part of the system
3087 * can not be enabled by the user.
3088 *
3089 * This method will fail if it is called for a admin that is not for the foreground user
3090 * or a profile of the foreground user.
3091 *
3092 * <p> Calling with a null value for the list disables the restriction so that all input methods
3093 * can be used, calling with an empty list disables all but the system's own input methods.
3094 *
3095 * <p> System input methods are always available to the user this method can't modify this.
3096 *
3097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3098 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003099 * @return true if setting the restriction succeeded. It will fail if there are
3100 * one or more non-system input methods currently enabled that are not in
3101 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003102 */
3103 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3104 if (mService != null) {
3105 try {
3106 return mService.setPermittedInputMethods(admin, packageNames);
3107 } catch (RemoteException e) {
3108 Log.w(TAG, "Failed talking with device policy service", e);
3109 }
3110 }
3111 return false;
3112 }
3113
3114
3115 /**
3116 * Returns the list of permitted input methods set by this device or profile owner.
3117 *
3118 * <p>An empty list means no input methods except system input methods are allowed.
3119 * Null means all input methods are allowed.
3120 *
3121 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3122 * @return List of input method package names.
3123 */
3124 public List<String> getPermittedInputMethods(ComponentName admin) {
3125 if (mService != null) {
3126 try {
3127 return mService.getPermittedInputMethods(admin);
3128 } catch (RemoteException e) {
3129 Log.w(TAG, "Failed talking with device policy service", e);
3130 }
3131 }
3132 return null;
3133 }
3134
3135 /**
3136 * Returns the list of input methods permitted by the device or profiles
3137 * owners of the current user.
3138 *
3139 * <p>Null means all input methods are allowed, if a non-null list is returned
3140 * it will contain the intersection of the permitted lists for any device or profile
3141 * owners that apply to this user. It will also include any system input methods.
3142 *
3143 * @return List of input method package names.
3144 * @hide
3145 */
3146 @SystemApi
3147 public List<String> getPermittedInputMethodsForCurrentUser() {
3148 if (mService != null) {
3149 try {
3150 return mService.getPermittedInputMethodsForCurrentUser();
3151 } catch (RemoteException e) {
3152 Log.w(TAG, "Failed talking with device policy service", e);
3153 }
3154 }
3155 return null;
3156 }
3157
3158 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003159 * Called by a device owner to create a user with the specified name. The UserHandle returned
3160 * by this method should not be persisted as user handles are recycled as users are removed and
3161 * created. If you need to persist an identifier for this user, use
3162 * {@link UserManager#getSerialNumberForUser}.
3163 *
3164 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3165 * @param name the user's name
3166 * @see UserHandle
3167 * @return the UserHandle object for the created user, or null if the user could not be created.
3168 */
3169 public UserHandle createUser(ComponentName admin, String name) {
3170 try {
3171 return mService.createUser(admin, name);
3172 } catch (RemoteException re) {
3173 Log.w(TAG, "Could not create a user", re);
3174 }
3175 return null;
3176 }
3177
3178 /**
Jason Monk03978a42014-06-10 15:05:30 -04003179 * Called by a device owner to create a user with the specified name. The UserHandle returned
3180 * by this method should not be persisted as user handles are recycled as users are removed and
3181 * created. If you need to persist an identifier for this user, use
3182 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3183 * immediately.
3184 *
3185 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3186 * as registered as an active admin on the new user. The profile owner package will be
3187 * installed on the new user if it already is installed on the device.
3188 *
3189 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3190 * profileOwnerComponent when onEnable is called.
3191 *
3192 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3193 * @param name the user's name
3194 * @param ownerName the human readable name of the organisation associated with this DPM.
3195 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3196 * the user.
3197 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3198 * on the new user.
3199 * @see UserHandle
3200 * @return the UserHandle object for the created user, or null if the user could not be created.
3201 */
3202 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3203 ComponentName profileOwnerComponent, Bundle adminExtras) {
3204 try {
3205 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3206 adminExtras);
3207 } catch (RemoteException re) {
3208 Log.w(TAG, "Could not create a user", re);
3209 }
3210 return null;
3211 }
3212
3213 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003214 * Called by a device owner to remove a user and all associated data. The primary user can
3215 * not be removed.
3216 *
3217 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3218 * @param userHandle the user to remove.
3219 * @return {@code true} if the user was removed, {@code false} otherwise.
3220 */
3221 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3222 try {
3223 return mService.removeUser(admin, userHandle);
3224 } catch (RemoteException re) {
3225 Log.w(TAG, "Could not remove user ", re);
3226 return false;
3227 }
3228 }
3229
3230 /**
Jason Monk582d9112014-07-09 19:57:08 -04003231 * Called by a device owner to switch the specified user to the foreground.
3232 *
3233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3234 * @param userHandle the user to switch to; null will switch to primary.
3235 * @return {@code true} if the switch was successful, {@code false} otherwise.
3236 *
3237 * @see Intent#ACTION_USER_FOREGROUND
3238 */
3239 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3240 try {
3241 return mService.switchUser(admin, userHandle);
3242 } catch (RemoteException re) {
3243 Log.w(TAG, "Could not switch user ", re);
3244 return false;
3245 }
3246 }
3247
3248 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003249 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003250 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003251 *
3252 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3253 * exception will be thrown.
3254 *
3255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3256 * @param packageName The name of the package to fetch restricted settings of.
3257 * @return {@link Bundle} of settings corresponding to what was set last time
3258 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3259 * if no restrictions have been set.
3260 */
3261 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3262 if (mService != null) {
3263 try {
3264 return mService.getApplicationRestrictions(admin, packageName);
3265 } catch (RemoteException e) {
3266 Log.w(TAG, "Failed talking with device policy service", e);
3267 }
3268 }
3269 return null;
3270 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003271
3272 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003273 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003274 * <p>
3275 * The calling device admin must be a profile or device owner; if it is not,
3276 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003277 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003278 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3279 * with.
3280 * @param key The key of the restriction. See the constants in
3281 * {@link android.os.UserManager} for the list of keys.
3282 */
3283 public void addUserRestriction(ComponentName admin, String key) {
3284 if (mService != null) {
3285 try {
3286 mService.setUserRestriction(admin, key, true);
3287 } catch (RemoteException e) {
3288 Log.w(TAG, "Failed talking with device policy service", e);
3289 }
3290 }
3291 }
3292
3293 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003294 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003295 * <p>
3296 * The calling device admin must be a profile or device owner; if it is not,
3297 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003298 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003299 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3300 * with.
3301 * @param key The key of the restriction. See the constants in
3302 * {@link android.os.UserManager} for the list of keys.
3303 */
3304 public void clearUserRestriction(ComponentName admin, String key) {
3305 if (mService != null) {
3306 try {
3307 mService.setUserRestriction(admin, key, false);
3308 } catch (RemoteException e) {
3309 Log.w(TAG, "Failed talking with device policy service", e);
3310 }
3311 }
3312 }
Adam Connors010cfd42014-04-16 12:48:13 +01003313
3314 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003315 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003316 * is unavailable for use, but the data and actual package file remain.
3317 *
3318 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003319 * @param packageName The name of the package to hide or unhide.
3320 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3321 * unhidden.
3322 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003323 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003324 public boolean setApplicationHidden(ComponentName admin, String packageName,
3325 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003326 if (mService != null) {
3327 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003328 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003329 } catch (RemoteException e) {
3330 Log.w(TAG, "Failed talking with device policy service", e);
3331 }
3332 }
3333 return false;
3334 }
3335
3336 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003337 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003338 *
3339 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003340 * @param packageName The name of the package to retrieve the hidden status of.
3341 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003342 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003343 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003344 if (mService != null) {
3345 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003346 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003347 } catch (RemoteException e) {
3348 Log.w(TAG, "Failed talking with device policy service", e);
3349 }
3350 }
3351 return false;
3352 }
3353
3354 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003355 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003356 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003357 *
3358 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3359 * @param packageName The package to be re-enabled in the current profile.
3360 */
3361 public void enableSystemApp(ComponentName admin, String packageName) {
3362 if (mService != null) {
3363 try {
3364 mService.enableSystemApp(admin, packageName);
3365 } catch (RemoteException e) {
3366 Log.w(TAG, "Failed to install package: " + packageName);
3367 }
3368 }
3369 }
3370
3371 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003372 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003373 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003374 *
3375 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3376 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3377 * intent will be re-enabled in the current profile.
3378 * @return int The number of activities that matched the intent and were installed.
3379 */
3380 public int enableSystemApp(ComponentName admin, Intent intent) {
3381 if (mService != null) {
3382 try {
3383 return mService.enableSystemAppWithIntent(admin, intent);
3384 } catch (RemoteException e) {
3385 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3386 }
3387 }
3388 return 0;
3389 }
3390
3391 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003392 * Called by a device owner or profile owner to disable account management for a specific type
3393 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003394 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003395 * <p>The calling device admin must be a device owner or profile owner. If it is not, a
Sander Alewijnse650c3342014-05-08 18:00:50 +01003396 * security exception will be thrown.
3397 *
3398 * <p>When account management is disabled for an account type, adding or removing an account
3399 * of that type will not be possible.
3400 *
3401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3402 * @param accountType For which account management is disabled or enabled.
3403 * @param disabled The boolean indicating that account management will be disabled (true) or
3404 * enabled (false).
3405 */
3406 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3407 boolean disabled) {
3408 if (mService != null) {
3409 try {
3410 mService.setAccountManagementDisabled(admin, accountType, disabled);
3411 } catch (RemoteException e) {
3412 Log.w(TAG, "Failed talking with device policy service", e);
3413 }
3414 }
3415 }
3416
3417 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003418 * Gets the array of accounts for which account management is disabled by the profile owner.
3419 *
3420 * <p> Account management can be disabled/enabled by calling
3421 * {@link #setAccountManagementDisabled}.
3422 *
3423 * @return a list of account types for which account management has been disabled.
3424 *
3425 * @see #setAccountManagementDisabled
3426 */
3427 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003428 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003429 }
3430
3431 /**
3432 * @see #getAccountTypesWithManagementDisabled()
3433 * @hide
3434 */
3435 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003436 if (mService != null) {
3437 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003438 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003439 } catch (RemoteException e) {
3440 Log.w(TAG, "Failed talking with device policy service", e);
3441 }
3442 }
3443
3444 return null;
3445 }
justinzhang511e0d82014-03-24 16:09:24 -04003446
3447 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003448 * Sets which packages may enter lock task mode.
3449 *
3450 * <p>Any packages that shares uid with an allowed package will also be allowed
3451 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003452 *
Jason Monkc5185f22014-06-24 11:12:42 -04003453 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003454 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003455 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003456 *
3457 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003458 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3459 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003460 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003461 */
Jason Monk48aacba2014-08-13 16:29:08 -04003462 public void setLockTaskPackages(ComponentName admin, String[] packages)
3463 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003464 if (mService != null) {
3465 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003466 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003467 } catch (RemoteException e) {
3468 Log.w(TAG, "Failed talking with device policy service", e);
3469 }
3470 }
3471 }
3472
3473 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003474 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003475 *
3476 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003477 * @hide
3478 */
Jason Monk48aacba2014-08-13 16:29:08 -04003479 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003480 if (mService != null) {
3481 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003482 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003483 } catch (RemoteException e) {
3484 Log.w(TAG, "Failed talking with device policy service", e);
3485 }
3486 }
3487 return null;
3488 }
3489
3490 /**
3491 * This function lets the caller know whether the given component is allowed to start the
3492 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003493 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003494 */
Jason Monkd7b86212014-06-16 13:15:38 -04003495 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003496 if (mService != null) {
3497 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003498 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003499 } catch (RemoteException e) {
3500 Log.w(TAG, "Failed talking with device policy service", e);
3501 }
3502 }
3503 return false;
3504 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003505
3506 /**
3507 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3508 * 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 -04003509 * <p>The settings that can be updated with this method are:
3510 * <ul>
3511 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3512 * <li>{@link Settings.Global#AUTO_TIME}</li>
3513 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003514 * <li>{@link Settings.Global#BLUETOOTH_ON}
3515 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3516 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3517 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003518 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3519 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3520 * <li>{@link Settings.Global#MODE_RINGER}</li>
3521 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3522 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003523 * <li>{@link Settings.Global#WIFI_ON}
3524 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3525 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003526 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3527 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003528 *
3529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3530 * @param setting The name of the setting to update.
3531 * @param value The value to update the setting to.
3532 */
3533 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3534 if (mService != null) {
3535 try {
3536 mService.setGlobalSetting(admin, setting, value);
3537 } catch (RemoteException e) {
3538 Log.w(TAG, "Failed talking with device policy service", e);
3539 }
3540 }
3541 }
3542
3543 /**
3544 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3545 * that the value of the setting is in the correct form for the setting type should be performed
3546 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003547 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003548 * <ul>
3549 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003550 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003551 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3552 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003553 * <p>A device owner can additionally update the following settings:
3554 * <ul>
3555 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3556 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3558 * @param setting The name of the setting to update.
3559 * @param value The value to update the setting to.
3560 */
3561 public void setSecureSetting(ComponentName admin, String setting, String value) {
3562 if (mService != null) {
3563 try {
3564 mService.setSecureSetting(admin, setting, value);
3565 } catch (RemoteException e) {
3566 Log.w(TAG, "Failed talking with device policy service", e);
3567 }
3568 }
3569 }
3570
Amith Yamasanif20d6402014-05-24 15:34:37 -07003571 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003572 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003573 * making permission requests of a local or remote administrator of the user.
3574 * <p/>
3575 * Only a profile owner can designate the restrictions provider.
3576 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003577 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003578 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003579 * it removes the restrictions provider previously assigned.
3580 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003581 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003582 if (mService != null) {
3583 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003584 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003585 } catch (RemoteException re) {
3586 Log.w(TAG, "Failed to set permission provider on device policy service");
3587 }
3588 }
3589 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003590
3591 /**
3592 * Called by profile or device owners to set the master volume mute on or off.
3593 *
3594 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3595 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3596 */
3597 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3598 if (mService != null) {
3599 try {
3600 mService.setMasterVolumeMuted(admin, on);
3601 } catch (RemoteException re) {
3602 Log.w(TAG, "Failed to setMasterMute on device policy service");
3603 }
3604 }
3605 }
3606
3607 /**
3608 * Called by profile or device owners to check whether the master volume mute is on or off.
3609 *
3610 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3611 * @return {@code true} if master volume is muted, {@code false} if it's not.
3612 */
3613 public boolean isMasterVolumeMuted(ComponentName admin) {
3614 if (mService != null) {
3615 try {
3616 return mService.isMasterVolumeMuted(admin);
3617 } catch (RemoteException re) {
3618 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3619 }
3620 }
3621 return false;
3622 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003623
3624 /**
3625 * Called by profile or device owners to change whether a user can uninstall
3626 * a package.
3627 *
3628 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3629 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003630 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003631 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003632 public void setUninstallBlocked(ComponentName admin, String packageName,
3633 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003634 if (mService != null) {
3635 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003636 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003637 } catch (RemoteException re) {
3638 Log.w(TAG, "Failed to call block uninstall on device policy service");
3639 }
3640 }
3641 }
3642
3643 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003644 * Check whether the current user has been blocked by device policy from uninstalling a package.
3645 * Requires the caller to be the profile owner if checking a specific admin's policy.
Kenny Guyc13053b2014-05-29 14:17:17 +01003646 *
Rubin Xua97855b2014-11-07 05:41:00 +00003647 * @param admin The name of the admin component whose blocking policy will be checked, or null
3648 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003649 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003650 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003651 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003652 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003653 if (mService != null) {
3654 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003655 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003656 } catch (RemoteException re) {
3657 Log.w(TAG, "Failed to call block uninstall on device policy service");
3658 }
3659 }
3660 return false;
3661 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003662
3663 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003664 * Called by the profile owner of a managed profile to enable widget providers from a
3665 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003666 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003667 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003668 * a package may have zero or more provider components, where each component
3669 * provides a different widget type.
3670 * <p>
3671 * <strong>Note:</strong> By default no widget provider package is white-listed.
3672 * </p>
3673 *
3674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3675 * @param packageName The package from which widget providers are white-listed.
3676 * @return Whether the package was added.
3677 *
3678 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3679 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3680 */
3681 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3682 if (mService != null) {
3683 try {
3684 return mService.addCrossProfileWidgetProvider(admin, packageName);
3685 } catch (RemoteException re) {
3686 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3687 }
3688 }
3689 return false;
3690 }
3691
3692 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003693 * Called by the profile owner of a managed profile to disable widget providers from a given
3694 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003695 * package should have been added via {@link #addCrossProfileWidgetProvider(
3696 * android.content.ComponentName, String)}.
3697 * <p>
3698 * <strong>Note:</strong> By default no widget provider package is white-listed.
3699 * </p>
3700 *
3701 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3702 * @param packageName The package from which widget providers are no longer
3703 * white-listed.
3704 * @return Whether the package was removed.
3705 *
3706 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3707 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3708 */
3709 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3710 if (mService != null) {
3711 try {
3712 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3713 } catch (RemoteException re) {
3714 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3715 }
3716 }
3717 return false;
3718 }
3719
3720 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003721 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003722 * available in the parent profile.
3723 *
3724 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3725 * @return The white-listed package list.
3726 *
3727 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3728 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3729 */
3730 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3731 if (mService != null) {
3732 try {
3733 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3734 if (providers != null) {
3735 return providers;
3736 }
3737 } catch (RemoteException re) {
3738 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3739 }
3740 }
3741 return Collections.emptyList();
3742 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003743}