blob: a916a432c1ffda3d2e8c02f936f3a3a9e346b228 [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;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.content.ComponentName;
24import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010025import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000026import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080027import android.content.pm.ActivityInfo;
28import android.content.pm.PackageManager;
29import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050030import android.graphics.Bitmap;
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 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000111 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
112 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
113 * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain the extra
114 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
115 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000117 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
118 * in the provisioning intent. The
119 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
120 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
121 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100122 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100123 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
124 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000125 *
126 * <p>Input: Nothing.</p>
127 * <p>Output: Nothing</p>
128 */
129 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
130 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100131 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000132
133 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700134 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
135 * a mobile device management application that starts managed profile provisioning to pass data
136 * to itself on the managed profile when provisioning completes. The mobile device management
137 * application sends this extra in an intent with the action
138 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
139 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
140 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
141 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100142 */
143 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100144 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100145
146 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100147 * A String extra holding the package name of the mobile device management application that
148 * will be set as the profile owner or device owner.
149 *
150 * <p>If an application starts provisioning directly via an intent with action
151 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
152 * application that started provisioning. The package will be set as profile owner in that case.
153 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000154 * <p>This package is set as device owner when device owner provisioning is started by an NFC
155 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000156 *
157 * <p> When this extra is set, the application must have exactly one device admin receiver.
158 * This receiver will be set as the profile or device owner and active admin.</p>
159
160 * @see DeviceAdminReceiver
161 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
162 * supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000163 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000164 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000165 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100166 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000167
168 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000169 * A ComponentName extra indicating the device admin receiver of the mobile device management
170 * application that will be set as the profile owner or device owner and active admin.
171 *
172 * <p>If an application starts provisioning directly via an intent with action
173 * {@link #ACTION_PROVISION_MANAGED_PROFILE} the package name of this component has to match the
174 * package name of the application that started provisioning.
175 *
176 * <p>This component is set as device owner and active admin when device owner provisioning is
177 * started by an NFC message containing an NFC record with MIME type
Rubin Xu44ef750b2015-03-23 16:51:33 +0000178 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}. For the NFC record, the component name should be
179 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000180 *
181 * @see DeviceAdminReceiver
182 */
183 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
184 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
185
186 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000187 * An {@link android.accounts.Account} extra holding the account to migrate during managed
188 * profile provisioning. If the account supplied is present in the primary user, it will be
189 * copied, along with its credentials to the managed profile and removed from the primary user.
190 *
191 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
192 */
193
194 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
195 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
196
197 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100198 * A String extra that, holds the email address of the account which a managed profile is
199 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
200 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100201 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100202 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
203 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100204 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
205 * contains this extra, it is forwarded in the
206 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
207 * device management application that was set as the profile owner during provisioning.
208 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100209 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100210 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
211 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100212
213 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000214 * A Boolean extra that can be used by the mobile device management application to skip the
215 * disabling of system apps during provisioning when set to <code>true</code>.
216 *
217 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
218 * provisioning via an NFC bump.
219 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000220 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
221 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000222
223 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100224 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
225 * will be set to.
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_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100231 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100232
233 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100234 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
235 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100236 *
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_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100241 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100242
243 /**
244 * A String extra holding the {@link java.util.Locale} that the device will be set to.
245 * Format: xx_yy, where xx is the language code, and yy the country code.
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_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100251 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100252
253 /**
254 * A String extra holding the ssid of the wifi network that should be used during nfc device
255 * owner provisioning for downloading the mobile device management application.
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_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100261 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100262
263 /**
264 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
265 * is hidden or not.
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_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100271 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100272
273 /**
274 * A String extra indicating the security type of 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_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100281 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100282
283 /**
284 * A String extra holding the password of 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_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100291 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100292
293 /**
294 * A String extra holding the proxy host 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_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100301 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100302
303 /**
304 * An int extra holding the proxy port for the wifi network in
305 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
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_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100311 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100312
313 /**
314 * A String extra holding the proxy bypass for the wifi network in
315 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
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 Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319 */
320 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100321 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100322
323 /**
324 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
325 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
326 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000327 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
328 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329 */
330 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100331 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100332
333 /**
334 * A String extra holding a url that specifies the download location of the device admin
335 * package. When not provided it is assumed that the device admin package is already installed.
336 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000337 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
338 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100339 */
340 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100341 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100342
343 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400344 * An int extra holding a minimum required version code for the device admin package. If the
345 * device admin is already installed on the device, it will only be re-downloaded from
346 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
347 * installed package is less than this version code.
348 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400349 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400350 * provisioning via an NFC bump.
351 */
352 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
353 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
354
355 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100356 * A String extra holding a http cookie header which should be used in the http request to the
357 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
358 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000359 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
360 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100361 */
362 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100363 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100364
365 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000366 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100367 * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
368 *
369 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM} should be
370 * present. The provided checksum should match the checksum of the file at the download
371 * location. If the checksum doesn't match an error will be shown to the user and the user will
372 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000374 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
375 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100376 */
377 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100378 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100379
380 /**
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100381 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any certificate of the
382 * android package archive at the download location specified in {@link
383 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
384 *
385 * <p>The certificates of an android package archive can be obtained using
386 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
387 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
388 *
389 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
390 * present. The provided checksum should match the checksum of any certificate of the file at
391 * the download location. If the checksum does not match an error will be shown to the user and
392 * the user will be asked to factory reset the device.
393 *
394 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
395 * provisioning via an NFC bump.
396 */
397 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM
398 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM";
399
400 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000401 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
402 * has completed successfully.
403 *
404 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
405 * intent (@see #ACTION_PROVISION_MANAGED_PROFILE).
406 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800407 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000408 * corresponds to the account requested to be migrated at provisioning time, if any.
409 */
410 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
411 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
412 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
413
414 /**
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500415 * A boolean extra indicating whether device encryption is required as part of Device Owner
416 * provisioning.
417 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400418 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500419 * provisioning via an NFC bump.
420 */
421 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
422 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
423
424 /**
Rubin Xu44ef750b2015-03-23 16:51:33 +0000425 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
426 * component of the application that is temporarily granted device owner privileges during
427 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500428 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000429 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000430 * It can also be used in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts
Rubin Xu44ef750b2015-03-23 16:51:33 +0000431 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
432 * string first.
433 *
434 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500435 */
436 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
437 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
438
439 /**
440 * A String extra holding an http url that specifies the download location of the device
441 * initializer package. When not provided it is assumed that the device initializer package is
442 * already installed.
443 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400444 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500445 * provisioning via an NFC bump.
446 */
447 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
448 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
449
450 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400451 * An int extra holding a minimum required version code for the device initializer package.
452 * If the initializer is already installed on the device, it will only be re-downloaded from
453 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
454 * the installed package is less than this version code.
455 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400456 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400457 * provisioning via an NFC bump.
458 */
459 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
460 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
461
462 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500463 * A String extra holding a http cookie header which should be used in the http request to the
464 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
465 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400466 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500467 * provisioning via an NFC bump.
468 */
469 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
470 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
471
472 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000473 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
474 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100475 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
476 *
477 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM}
478 * should be present. The provided checksum should match the checksum of the file at the
479 * download location. If the checksum doesn't match an error will be shown to the user and the
480 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500481 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400482 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500483 * provisioning via an NFC bump.
484 */
485 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
486 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
487
488 /**
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100489 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any certificate of the
490 * android package archive at the download location specified in {@link
491 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
492 *
493 * <p>The certificates of an android package archive can be obtained using
494 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
495 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
496 *
497 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
498 * should be present. The provided checksum should match the checksum of any certificate of the
499 * file at the download location. If the checksum doesn't match an error will be shown to the
500 * user and the user will be asked to factory reset the device.
501 *
502 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
503 * provisioning via an NFC bump.
504 */
505 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM
506 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM";
507
508 /**
Craig Lafayette97e473e2015-03-19 10:19:38 -0400509 * A String extra holding the MAC address of the Bluetooth device to connect to with status
510 * updates during provisioning.
511 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400512 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400513 * provisioning via an NFC bump.
514 */
515 public static final String EXTRA_PROVISIONING_BT_MAC_ADDRESS
516 = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS";
517
518 /**
519 * A String extra holding the Bluetooth service UUID on the device to connect to with status
520 * updates during provisioning.
521 *
522 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
523 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400524 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400525 * provisioning via an NFC bump.
526 */
527 public static final String EXTRA_PROVISIONING_BT_UUID
528 = "android.app.extra.PROVISIONING_BT_UUID";
529
530 /**
531 * A String extra holding a unique identifier used to identify the device connecting over
532 * Bluetooth. This identifier will be part of every status message sent to the remote device.
533 *
534 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
535 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400536 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400537 * provisioning via an NFC bump.
538 */
539 public static final String EXTRA_PROVISIONING_BT_DEVICE_ID
540 = "android.app.extra.PROVISIONING_BT_DEVICE_ID";
541
542 /**
543 * A Boolean extra that that will cause a provisioned device to temporarily proxy network
544 * traffic over Bluetooth. When a Wi-Fi network is available, the network proxy will stop.
545 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400546 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400547 * provisioning via an NFC bump.
548 */
549 public static final String EXTRA_PROVISIONING_BT_USE_PROXY
550 = "android.app.extra.PROVISIONING_BT_USE_PROXY";
Craig Lafayette8e27c4d2015-03-19 08:36:38 -0400551
552 /**
553 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
554 * holds data needed by the system to wipe factory reset protection. The data needed to wipe
555 * the device depend on the installed factory reset protection implementation. For example,
556 * if an account is needed to unlock a device, this extra may contain data used to
557 * authenticate that account.
558 *
559 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
560 * provisioning via an NFC bump.
561 */
562 public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS
563 = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
564
Craig Lafayette97e473e2015-03-19 10:19:38 -0400565 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400566 * This MIME type is used for starting the Device Owner provisioning that does not require
567 * provisioning features introduced in Android API level
568 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100569 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400570 * <p>For more information about the provisioning process see
571 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000573 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574 * contains the following properties:
575 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400576 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
577 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100578 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400579 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
581 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
582 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
583 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
584 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
585 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
586 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
587 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
588 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
589 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400590 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100591 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000592 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400593 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
594 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
595 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
596 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
597 *
598 * @see #MIME_TYPE_PROVISIONING_NFC_V2
599 *
600 */
601 public static final String MIME_TYPE_PROVISIONING_NFC
602 = "application/com.android.managedprovisioning";
603
604
605 /**
606 * This MIME type is used for starting the Device Owner provisioning that requires
607 * new provisioning features introduced in API version
608 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
609 * versions.
610 *
611 * <p>During device owner provisioning a device admin app is set as the owner of the device.
612 * A device owner has full control over the device. The device owner can not be modified by the
613 * user and the only way of resetting the device is if the device owner app calls a factory
614 * reset.
615 *
616 * <p> A typical use case would be a device that is owned by a company, but used by either an
617 * employee or client.
618 *
619 * <p> The NFC message should be sent to an unprovisioned device.
620 *
621 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
622 * contains the following properties in addition to properties listed at
623 * {@link #MIME_TYPE_PROVISIONING_NFC}:
624 * <ul>
625 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
626 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
627 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
628 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
629 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
630 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
631 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
632 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
633 * should be converted to a String via
634 * {@link android.content.ComponentName#flattenToString()}</li>
635 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li>
636 * <li>{@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, optional</li>
637 * <li>{@link #EXTRA_PROVISIONING_BT_UUID}, optional</li>
638 * <li>{@link #EXTRA_PROVISIONING_BT_DEVICE_ID}, optional</li>
639 * <li>{@link #EXTRA_PROVISIONING_BT_USE_PROXY}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000640 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100641 * <p> When device owner provisioning has completed, an intent of the type
642 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
643 * device owner.
644 *
645 * <p>
646 * If provisioning fails, the device is factory reset.
647 *
648 * <p>Input: Nothing.</p>
649 * <p>Output: Nothing</p>
650 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400651 public static final String MIME_TYPE_PROVISIONING_NFC_V2
652 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653
654 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800655 * Activity action: ask the user to add a new device administrator to the system.
656 * The desired policy is the ComponentName of the policy in the
657 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
658 * bring the user through adding the device administrator to the system (or
659 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700660 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800661 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
662 * field to provide the user with additional explanation (in addition
663 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800664 *
665 * <p>If your administrator is already active, this will ordinarily return immediately (without
666 * user intervention). However, if your administrator has been updated and is requesting
667 * additional uses-policy flags, the user will be presented with the new list. New policies
668 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800669 */
670 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
671 public static final String ACTION_ADD_DEVICE_ADMIN
672 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700673
Dianne Hackbornd6847842010-01-12 18:14:19 -0800674 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700675 * @hide
676 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700677 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700678 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700679 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
680 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700681 * to remotely control restrictions on the user.
682 *
683 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
684 * result of whether or not the user approved the action. If approved, the result will
685 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
686 * as a profile owner.
687 *
688 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
689 * field to provide the user with additional explanation (in addition
690 * to your component's description) about what is being added.
691 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700692 * <p>If there is already a profile owner active or the caller is not a system app, the
693 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700694 */
695 @SystemApi
696 public static final String ACTION_SET_PROFILE_OWNER
697 = "android.app.action.SET_PROFILE_OWNER";
698
699 /**
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400700 * Protected broadcast action that will be sent to managed provisioning to notify it that a
701 * status update has been reported by the device initializer. The status update will be
702 * reported to the remote setup device over Bluetooth.
703 *
704 * <p>Broadcasts with this action must supply a
705 * {@linkplain DeviceInitializerStatus#isCustomStatus(int) custom} status code in the
706 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_CODE} extra.
707 *
708 * <p>Broadcasts may optionally contain a description in the
709 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION} extra.
710 * @hide
711 */
712 @SystemApi
713 public static final String ACTION_SEND_DEVICE_INITIALIZER_STATUS
714 = "android.app.action.SEND_DEVICE_INITIALIZER_STATUS";
715
716 /**
717 * An integer extra that contains the status code that defines a status update. This extra must
718 * sent as part of a broadcast with an action of {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
719 *
720 * <p>The status code sent with this extra must be a custom status code as defined by
721 * {@link DeviceInitializerStatus#isCustomStatus(int)}.
722 * @hide
723 */
724 @SystemApi
725 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_CODE
726 = "android.app.extra.DEVICE_INITIALIZER_STATUS_CODE";
727
728 /**
729 * A {@code String} extra that contains an optional description accompanying a status update.
730 * This extra my be sent as part of a broadcast with an action of
731 * {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
732 * @hide
733 */
734 @SystemApi
735 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION
736 = "android.app.extra.DEVICE_INITIALIZER_STATUS_DESCRIPTION";
737
738 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700739 * @hide
740 * Name of the profile owner admin that controls the user.
741 */
742 @SystemApi
743 public static final String EXTRA_PROFILE_OWNER_NAME
744 = "android.app.extra.PROFILE_OWNER_NAME";
745
746 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700747 * Activity action: send when any policy admin changes a policy.
748 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700749 *
Jim Miller284b62e2010-06-08 14:27:42 -0700750 * @hide
751 */
752 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
753 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
754
755 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800756 * The ComponentName of the administrator component.
757 *
758 * @see #ACTION_ADD_DEVICE_ADMIN
759 */
760 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700761
Dianne Hackbornd6847842010-01-12 18:14:19 -0800762 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800763 * An optional CharSequence providing additional explanation for why the
764 * admin is being added.
765 *
766 * @see #ACTION_ADD_DEVICE_ADMIN
767 */
768 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700769
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800770 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700771 * Activity action: have the user enter a new password. This activity should
772 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
773 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
774 * enter a new password that meets the current requirements. You can use
775 * {@link #isActivePasswordSufficient()} to determine whether you need to
776 * have the user select a new password in order to meet the current
777 * constraints. Upon being resumed from this activity, you can check the new
778 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800779 */
780 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
781 public static final String ACTION_SET_NEW_PASSWORD
782 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700783
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000784 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000785 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
786 * the parent profile to access intents sent from the managed profile.
787 * That is, when an app in the managed profile calls
788 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
789 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000790 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100791 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000792
793 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000794 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
795 * the managed profile to access intents sent from the parent profile.
796 * That is, when an app in the parent profile calls
797 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
798 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000799 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100800 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700801
Dianne Hackbornd6847842010-01-12 18:14:19 -0800802 /**
Rubin Xu8027a4f2015-03-10 17:52:37 +0000803 * Broadcast action: notify that a new local OTA policy has been set by the device owner.
804 * The new policy can be retrieved by {@link #getOtaPolicy()}.
805 */
806 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
807 public static final String ACTION_OTA_POLICY_CHANGED = "android.app.action.OTA_POLICY_CHANGED";
808
809
810 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800811 * Return true if the given administrator component is currently
812 * active (enabled) in the system.
813 */
814 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100815 return isAdminActiveAsUser(who, UserHandle.myUserId());
816 }
817
818 /**
819 * @see #isAdminActive(ComponentName)
820 * @hide
821 */
822 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800823 if (mService != null) {
824 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100825 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800826 } catch (RemoteException e) {
827 Log.w(TAG, "Failed talking with device policy service", e);
828 }
829 }
830 return false;
831 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800832 /**
833 * Return true if the given administrator component is currently being removed
834 * for the user.
835 * @hide
836 */
837 public boolean isRemovingAdmin(ComponentName who, int userId) {
838 if (mService != null) {
839 try {
840 return mService.isRemovingAdmin(who, userId);
841 } catch (RemoteException e) {
842 Log.w(TAG, "Failed talking with device policy service", e);
843 }
844 }
845 return false;
846 }
847
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700848
Dianne Hackbornd6847842010-01-12 18:14:19 -0800849 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800850 * Return a list of all currently active device administrator's component
851 * names. Note that if there are no administrators than null may be
852 * returned.
853 */
854 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100855 return getActiveAdminsAsUser(UserHandle.myUserId());
856 }
857
858 /**
859 * @see #getActiveAdmins()
860 * @hide
861 */
862 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800863 if (mService != null) {
864 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100865 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800866 } catch (RemoteException e) {
867 Log.w(TAG, "Failed talking with device policy service", e);
868 }
869 }
870 return null;
871 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700872
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800873 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700874 * Used by package administration code to determine if a package can be stopped
875 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800876 * @hide
877 */
878 public boolean packageHasActiveAdmins(String packageName) {
879 if (mService != null) {
880 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700881 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800882 } catch (RemoteException e) {
883 Log.w(TAG, "Failed talking with device policy service", e);
884 }
885 }
886 return false;
887 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700888
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800889 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800890 * Remove a current administration component. This can only be called
891 * by the application that owns the administration component; if you
892 * try to remove someone else's component, a security exception will be
893 * thrown.
894 */
895 public void removeActiveAdmin(ComponentName who) {
896 if (mService != null) {
897 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700898 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800899 } catch (RemoteException e) {
900 Log.w(TAG, "Failed talking with device policy service", e);
901 }
902 }
903 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700904
Dianne Hackbornd6847842010-01-12 18:14:19 -0800905 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800906 * Returns true if an administrator has been granted a particular device policy. This can
907 * be used to check if the administrator was activated under an earlier set of policies,
908 * but requires additional policies after an upgrade.
909 *
910 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
911 * an active administrator, or an exception will be thrown.
912 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
913 */
914 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
915 if (mService != null) {
916 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700917 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800918 } catch (RemoteException e) {
919 Log.w(TAG, "Failed talking with device policy service", e);
920 }
921 }
922 return false;
923 }
924
925 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800926 * Constant for {@link #setPasswordQuality}: the policy has no requirements
927 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800928 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800929 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800930 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700931
Dianne Hackbornd6847842010-01-12 18:14:19 -0800932 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700933 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
934 * recognition technology. This implies technologies that can recognize the identity of
935 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
936 * Note that quality constants are ordered so that higher values are more restrictive.
937 */
938 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
939
940 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800941 * Constant for {@link #setPasswordQuality}: the policy requires some kind
942 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800943 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800944 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800945 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700946
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800947 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800948 * Constant for {@link #setPasswordQuality}: the user must have entered a
949 * password containing at least numeric characters. Note that quality
950 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800951 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800952 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700953
Dianne Hackbornd6847842010-01-12 18:14:19 -0800954 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800955 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800956 * password containing at least numeric characters with no repeating (4444)
957 * or ordered (1234, 4321, 2468) sequences. Note that quality
958 * constants are ordered so that higher values are more restrictive.
959 */
960 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
961
962 /**
963 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700964 * password containing at least alphabetic (or other symbol) characters.
965 * Note that quality constants are ordered so that higher values are more
966 * restrictive.
967 */
968 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700969
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700970 /**
971 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800972 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700973 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800974 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800975 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700976 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700977
Dianne Hackbornd6847842010-01-12 18:14:19 -0800978 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700979 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700980 * password containing at least a letter, a numerical digit and a special
981 * symbol, by default. With this password quality, passwords can be
982 * restricted to contain various sets of characters, like at least an
983 * uppercase letter, etc. These are specified using various methods,
984 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
985 * that quality constants are ordered so that higher values are more
986 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700987 */
988 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
989
990 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800991 * Called by an application that is administering the device to set the
992 * password restrictions it is imposing. After setting this, the user
993 * will not be able to enter a new password that is not at least as
994 * restrictive as what has been set. Note that the current password
995 * will remain until the user has set a new one, so the change does not
996 * take place immediately. To prompt the user for a new password, use
997 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700998 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800999 * <p>Quality constants are ordered so that higher values are more restrictive;
1000 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001001 * the user's preference, and any other considerations) is the one that
1002 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001003 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001004 * <p>The calling device admin must have requested
1005 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1006 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001007 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001008 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001009 * @param quality The new desired quality. One of
1010 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001011 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1012 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1013 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001015 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001016 if (mService != null) {
1017 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001018 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001019 } catch (RemoteException e) {
1020 Log.w(TAG, "Failed talking with device policy service", e);
1021 }
1022 }
1023 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001024
Dianne Hackbornd6847842010-01-12 18:14:19 -08001025 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001026 * Retrieve the current minimum password quality for all admins of this user
1027 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001028 * @param admin The name of the admin component to check, or null to aggregate
1029 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001030 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001031 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001032 return getPasswordQuality(admin, UserHandle.myUserId());
1033 }
1034
1035 /** @hide per-user version */
1036 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001037 if (mService != null) {
1038 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001039 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001040 } catch (RemoteException e) {
1041 Log.w(TAG, "Failed talking with device policy service", e);
1042 }
1043 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001044 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001045 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001046
Dianne Hackbornd6847842010-01-12 18:14:19 -08001047 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 * Called by an application that is administering the device to set the
1049 * minimum allowed password length. After setting this, the user
1050 * will not be able to enter a new password that is not at least as
1051 * restrictive as what has been set. Note that the current password
1052 * will remain until the user has set a new one, so the change does not
1053 * take place immediately. To prompt the user for a new password, use
1054 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1055 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001056 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1057 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1058 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001059 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001060 * <p>The calling device admin must have requested
1061 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1062 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001063 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001064 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001065 * @param length The new desired minimum password length. A value of 0
1066 * means there is no restriction.
1067 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001068 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 if (mService != null) {
1070 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001071 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001072 } catch (RemoteException e) {
1073 Log.w(TAG, "Failed talking with device policy service", e);
1074 }
1075 }
1076 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001077
Dianne Hackbornd6847842010-01-12 18:14:19 -08001078 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001079 * Retrieve the current minimum password length for all admins of this
1080 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001081 * @param admin The name of the admin component to check, or null to aggregate
1082 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001083 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001084 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001085 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1086 }
1087
1088 /** @hide per-user version */
1089 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001090 if (mService != null) {
1091 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001092 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001093 } catch (RemoteException e) {
1094 Log.w(TAG, "Failed talking with device policy service", e);
1095 }
1096 }
1097 return 0;
1098 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001099
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001100 /**
1101 * Called by an application that is administering the device to set the
1102 * minimum number of upper case letters required in the password. After
1103 * setting this, the user will not be able to enter a new password that is
1104 * not at least as restrictive as what has been set. Note that the current
1105 * password will remain until the user has set a new one, so the change does
1106 * not take place immediately. To prompt the user for a new password, use
1107 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1108 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001109 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1110 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001111 * <p>
1112 * The calling device admin must have requested
1113 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1114 * this method; if it has not, a security exception will be thrown.
1115 *
1116 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1117 * with.
1118 * @param length The new desired minimum number of upper case letters
1119 * required in the password. A value of 0 means there is no
1120 * restriction.
1121 */
1122 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
1123 if (mService != null) {
1124 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001125 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001126 } catch (RemoteException e) {
1127 Log.w(TAG, "Failed talking with device policy service", e);
1128 }
1129 }
1130 }
1131
1132 /**
1133 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001134 * password for all admins of this user and its profiles or a particular one.
1135 * This is the same value as set by
1136 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001137 * and only applies when the password quality is
1138 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001139 *
1140 * @param admin The name of the admin component to check, or null to
1141 * aggregate all admins.
1142 * @return The minimum number of upper case letters required in the
1143 * password.
1144 */
1145 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001146 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1147 }
1148
1149 /** @hide per-user version */
1150 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001151 if (mService != null) {
1152 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001153 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001154 } catch (RemoteException e) {
1155 Log.w(TAG, "Failed talking with device policy service", e);
1156 }
1157 }
1158 return 0;
1159 }
1160
1161 /**
1162 * Called by an application that is administering the device to set the
1163 * minimum number of lower case letters required in the password. After
1164 * setting this, the user will not be able to enter a new password that is
1165 * not at least as restrictive as what has been set. Note that the current
1166 * password will remain until the user has set a new one, so the change does
1167 * not take place immediately. To prompt the user for a new password, use
1168 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1169 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001170 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1171 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001172 * <p>
1173 * The calling device admin must have requested
1174 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1175 * this method; if it has not, a security exception will be thrown.
1176 *
1177 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1178 * with.
1179 * @param length The new desired minimum number of lower case letters
1180 * required in the password. A value of 0 means there is no
1181 * restriction.
1182 */
1183 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
1184 if (mService != null) {
1185 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001186 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001187 } catch (RemoteException e) {
1188 Log.w(TAG, "Failed talking with device policy service", e);
1189 }
1190 }
1191 }
1192
1193 /**
1194 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001195 * password for all admins of this user and its profiles or a particular one.
1196 * This is the same value as set by
1197 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001198 * and only applies when the password quality is
1199 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001200 *
1201 * @param admin The name of the admin component to check, or null to
1202 * aggregate all admins.
1203 * @return The minimum number of lower case letters required in the
1204 * password.
1205 */
1206 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001207 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1208 }
1209
1210 /** @hide per-user version */
1211 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001212 if (mService != null) {
1213 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001214 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001215 } catch (RemoteException e) {
1216 Log.w(TAG, "Failed talking with device policy service", e);
1217 }
1218 }
1219 return 0;
1220 }
1221
1222 /**
1223 * Called by an application that is administering the device to set the
1224 * minimum number of letters required in the password. After setting this,
1225 * the user will not be able to enter a new password that is not at least as
1226 * restrictive as what has been set. Note that the current password will
1227 * remain until the user has set a new one, so the change does not take
1228 * place immediately. To prompt the user for a new password, use
1229 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1230 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001231 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1232 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001233 * <p>
1234 * The calling device admin must have requested
1235 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1236 * this method; if it has not, a security exception will be thrown.
1237 *
1238 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1239 * with.
1240 * @param length The new desired minimum number of letters required in the
1241 * password. A value of 0 means there is no restriction.
1242 */
1243 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1244 if (mService != null) {
1245 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001246 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001247 } catch (RemoteException e) {
1248 Log.w(TAG, "Failed talking with device policy service", e);
1249 }
1250 }
1251 }
1252
1253 /**
1254 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001255 * admins or a particular one. This is the same value as
1256 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1257 * and only applies when the password quality is
1258 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001259 *
1260 * @param admin The name of the admin component to check, or null to
1261 * aggregate all admins.
1262 * @return The minimum number of letters required in the password.
1263 */
1264 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001265 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1266 }
1267
1268 /** @hide per-user version */
1269 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001270 if (mService != null) {
1271 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001272 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001273 } catch (RemoteException e) {
1274 Log.w(TAG, "Failed talking with device policy service", e);
1275 }
1276 }
1277 return 0;
1278 }
1279
1280 /**
1281 * Called by an application that is administering the device to set the
1282 * minimum number of numerical digits required in the password. After
1283 * setting this, the user will not be able to enter a new password that is
1284 * not at least as restrictive as what has been set. Note that the current
1285 * password will remain until the user has set a new one, so the change does
1286 * not take place immediately. To prompt the user for a new password, use
1287 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1288 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001289 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1290 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001291 * <p>
1292 * The calling device admin must have requested
1293 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1294 * this method; if it has not, a security exception will be thrown.
1295 *
1296 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1297 * with.
1298 * @param length The new desired minimum number of numerical digits required
1299 * in the password. A value of 0 means there is no restriction.
1300 */
1301 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1302 if (mService != null) {
1303 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001304 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001305 } catch (RemoteException e) {
1306 Log.w(TAG, "Failed talking with device policy service", e);
1307 }
1308 }
1309 }
1310
1311 /**
1312 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001313 * for all admins of this user and its profiles or a particular one.
1314 * This is the same value as set by
1315 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001316 * and only applies when the password quality is
1317 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001318 *
1319 * @param admin The name of the admin component to check, or null to
1320 * aggregate all admins.
1321 * @return The minimum number of numerical digits required in the password.
1322 */
1323 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001324 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1325 }
1326
1327 /** @hide per-user version */
1328 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001329 if (mService != null) {
1330 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001331 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001332 } catch (RemoteException e) {
1333 Log.w(TAG, "Failed talking with device policy service", e);
1334 }
1335 }
1336 return 0;
1337 }
1338
1339 /**
1340 * Called by an application that is administering the device to set the
1341 * minimum number of symbols required in the password. After setting this,
1342 * the user will not be able to enter a new password that is not at least as
1343 * restrictive as what has been set. Note that the current password will
1344 * remain until the user has set a new one, so the change does not take
1345 * place immediately. To prompt the user for a new password, use
1346 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1347 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001348 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1349 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001350 * <p>
1351 * 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.
1354 *
1355 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1356 * with.
1357 * @param length The new desired minimum number of symbols required in the
1358 * password. A value of 0 means there is no restriction.
1359 */
1360 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1361 if (mService != null) {
1362 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001363 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001364 } catch (RemoteException e) {
1365 Log.w(TAG, "Failed talking with device policy service", e);
1366 }
1367 }
1368 }
1369
1370 /**
1371 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001372 * admins or a particular one. This is the same value as
1373 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1374 * and only applies when the password quality is
1375 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001376 *
1377 * @param admin The name of the admin component to check, or null to
1378 * aggregate all admins.
1379 * @return The minimum number of symbols required in the password.
1380 */
1381 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001382 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1383 }
1384
1385 /** @hide per-user version */
1386 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001387 if (mService != null) {
1388 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001389 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001390 } catch (RemoteException e) {
1391 Log.w(TAG, "Failed talking with device policy service", e);
1392 }
1393 }
1394 return 0;
1395 }
1396
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001397 /**
1398 * Called by an application that is administering the device to set the
1399 * minimum number of non-letter characters (numerical digits or symbols)
1400 * required in the password. After setting this, the user will not be able
1401 * to enter a new password that is not at least as restrictive as what has
1402 * been set. Note that the current password will remain until the user has
1403 * set a new one, so the change does not take place immediately. To prompt
1404 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1405 * setting this value. This constraint is only imposed if the administrator
1406 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1407 * {@link #setPasswordQuality}. The default value is 0.
1408 * <p>
1409 * The calling device admin must have requested
1410 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1411 * this method; if it has not, a security exception will be thrown.
1412 *
1413 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1414 * with.
1415 * @param length The new desired minimum number of letters required in the
1416 * password. A value of 0 means there is no restriction.
1417 */
1418 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1419 if (mService != null) {
1420 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001421 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001422 } catch (RemoteException e) {
1423 Log.w(TAG, "Failed talking with device policy service", e);
1424 }
1425 }
1426 }
1427
1428 /**
1429 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001430 * password for all admins of this user and its profiles or a particular one.
1431 * This is the same value as set by
1432 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001433 * and only applies when the password quality is
1434 * {@link #PASSWORD_QUALITY_COMPLEX}.
1435 *
1436 * @param admin The name of the admin component to check, or null to
1437 * aggregate all admins.
1438 * @return The minimum number of letters required in the password.
1439 */
1440 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001441 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1442 }
1443
1444 /** @hide per-user version */
1445 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001446 if (mService != null) {
1447 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001448 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001449 } catch (RemoteException e) {
1450 Log.w(TAG, "Failed talking with device policy service", e);
1451 }
1452 }
1453 return 0;
1454 }
1455
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001456 /**
1457 * Called by an application that is administering the device to set the length
1458 * of the password history. After setting this, the user will not be able to
1459 * enter a new password that is the same as any password in the history. Note
1460 * that the current password will remain until the user has set a new one, so
1461 * the change does not take place immediately. To prompt the user for a new
1462 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1463 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001464 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1465 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1466 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001467 *
1468 * <p>
1469 * The calling device admin must have requested
1470 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1471 * method; if it has not, a security exception will be thrown.
1472 *
1473 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1474 * with.
1475 * @param length The new desired length of password history. A value of 0
1476 * means there is no restriction.
1477 */
1478 public void setPasswordHistoryLength(ComponentName admin, int length) {
1479 if (mService != null) {
1480 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001481 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001482 } catch (RemoteException e) {
1483 Log.w(TAG, "Failed talking with device policy service", e);
1484 }
1485 }
1486 }
1487
1488 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001489 * Called by a device admin to set the password expiration timeout. Calling this method
1490 * will restart the countdown for password expiration for the given admin, as will changing
1491 * the device password (for all admins).
1492 *
1493 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1494 * For example, to have the password expire 5 days from now, timeout would be
1495 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1496 *
1497 * <p>To disable password expiration, a value of 0 may be used for timeout.
1498 *
Jim Millera4e28d12010-11-08 16:15:47 -08001499 * <p>The calling device admin must have requested
1500 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1501 * method; if it has not, a security exception will be thrown.
1502 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001503 * <p> Note that setting the password will automatically reset the expiration time for all
1504 * active admins. Active admins do not need to explicitly call this method in that case.
1505 *
Jim Millera4e28d12010-11-08 16:15:47 -08001506 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1507 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1508 * means there is no restriction (unlimited).
1509 */
1510 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1511 if (mService != null) {
1512 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001513 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001514 } catch (RemoteException e) {
1515 Log.w(TAG, "Failed talking with device policy service", e);
1516 }
1517 }
1518 }
1519
1520 /**
Jim Miller6b857682011-02-16 16:27:41 -08001521 * Get the password expiration timeout for the given admin. The expiration timeout is the
1522 * recurring expiration timeout provided in the call to
1523 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1524 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001525 *
1526 * @param admin The name of the admin component to check, or null to aggregate all admins.
1527 * @return The timeout for the given admin or the minimum of all timeouts
1528 */
1529 public long getPasswordExpirationTimeout(ComponentName admin) {
1530 if (mService != null) {
1531 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001532 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001533 } catch (RemoteException e) {
1534 Log.w(TAG, "Failed talking with device policy service", e);
1535 }
1536 }
1537 return 0;
1538 }
1539
1540 /**
1541 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001542 * all admins of this user and its profiles if admin is null. If the password is
1543 * expired, this will return the time since the password expired as a negative number.
1544 * If admin is null, then a composite of all expiration timeouts is returned
1545 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001546 *
1547 * @param admin The name of the admin component to check, or null to aggregate all admins.
1548 * @return The password expiration time, in ms.
1549 */
1550 public long getPasswordExpiration(ComponentName admin) {
1551 if (mService != null) {
1552 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001553 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001554 } catch (RemoteException e) {
1555 Log.w(TAG, "Failed talking with device policy service", e);
1556 }
1557 }
1558 return 0;
1559 }
1560
1561 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001562 * Retrieve the current password history length for all admins of this
1563 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001564 * @param admin The name of the admin component to check, or null to aggregate
1565 * all admins.
1566 * @return The length of the password history
1567 */
1568 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001569 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1570 }
1571
1572 /** @hide per-user version */
1573 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001574 if (mService != null) {
1575 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001576 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001577 } catch (RemoteException e) {
1578 Log.w(TAG, "Failed talking with device policy service", e);
1579 }
1580 }
1581 return 0;
1582 }
1583
Dianne Hackbornd6847842010-01-12 18:14:19 -08001584 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001585 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001586 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001587 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001588 * @return Returns the maximum length that the user can enter.
1589 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001590 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001591 // Kind-of arbitrary.
1592 return 16;
1593 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001594
Dianne Hackborn254cb442010-01-27 19:23:59 -08001595 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001596 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001597 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001598 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001599 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001600 * <p>The calling device admin must have requested
1601 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1602 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001603 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001604 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001605 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001606 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001607 if (mService != null) {
1608 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001609 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001610 } catch (RemoteException e) {
1611 Log.w(TAG, "Failed talking with device policy service", e);
1612 }
1613 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001614 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001615 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001616
Dianne Hackbornd6847842010-01-12 18:14:19 -08001617 /**
1618 * Retrieve the number of times the user has failed at entering a
1619 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001620 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001621 * <p>The calling device admin must have requested
1622 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1623 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001624 */
1625 public int getCurrentFailedPasswordAttempts() {
1626 if (mService != null) {
1627 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001628 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001629 } catch (RemoteException e) {
1630 Log.w(TAG, "Failed talking with device policy service", e);
1631 }
1632 }
1633 return -1;
1634 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001635
1636 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001637 * Setting this to a value greater than zero enables a built-in policy
1638 * that will perform a device wipe after too many incorrect
1639 * device-unlock passwords have been entered. This built-in policy combines
1640 * watching for failed passwords and wiping the device, and requires
1641 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001642 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001643 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001644 * <p>To implement any other policy (e.g. wiping data for a particular
1645 * application only, erasing or revoking credentials, or reporting the
1646 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001647 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001648 * instead. Do not use this API, because if the maximum count is reached,
1649 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001650 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001652 * @param num The number of failed password attempts at which point the
1653 * device will wipe its data.
1654 */
1655 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1656 if (mService != null) {
1657 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001658 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001659 } catch (RemoteException e) {
1660 Log.w(TAG, "Failed talking with device policy service", e);
1661 }
1662 }
1663 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001664
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001665 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001666 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001667 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001668 * or a particular one.
1669 * @param admin The name of the admin component to check, or null to aggregate
1670 * all admins.
1671 */
1672 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001673 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1674 }
1675
1676 /** @hide per-user version */
1677 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001678 if (mService != null) {
1679 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001680 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001681 } catch (RemoteException e) {
1682 Log.w(TAG, "Failed talking with device policy service", e);
1683 }
1684 }
1685 return 0;
1686 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001687
Dianne Hackborn254cb442010-01-27 19:23:59 -08001688 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001689 * Returns the profile with the smallest maximum failed passwords for wipe,
1690 * for the given user. So for primary user, it might return the primary or
1691 * a managed profile. For a secondary user, it would be the same as the
1692 * user passed in.
1693 * @hide Used only by Keyguard
1694 */
1695 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1696 if (mService != null) {
1697 try {
1698 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1699 } catch (RemoteException e) {
1700 Log.w(TAG, "Failed talking with device policy service", e);
1701 }
1702 }
1703 return UserHandle.USER_NULL;
1704 }
1705
1706 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001707 * Flag for {@link #resetPassword}: don't allow other admins to change
1708 * the password again until the user has entered it.
1709 */
1710 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001711
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001712 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001713 * Force a new device unlock password (the password needed to access the
1714 * entire device, not for individual accounts) on the user. This takes
1715 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001716 * The given password must be sufficient for the
1717 * current password quality and length constraints as returned by
1718 * {@link #getPasswordQuality(ComponentName)} and
1719 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1720 * these constraints, then it will be rejected and false returned. Note
1721 * that the password may be a stronger quality (containing alphanumeric
1722 * characters when the requested quality is only numeric), in which case
1723 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001724 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001725 * <p>Calling with a null or empty password will clear any existing PIN,
1726 * pattern or password if the current password constraints allow it.
1727 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001728 * <p>The calling device admin must have requested
1729 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1730 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001731 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001732 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001733 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001734 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001735 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001736 * @return Returns true if the password was applied, or false if it is
1737 * not acceptable for the current constraints.
1738 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001739 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001740 if (mService != null) {
1741 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001742 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001743 } catch (RemoteException e) {
1744 Log.w(TAG, "Failed talking with device policy service", e);
1745 }
1746 }
1747 return false;
1748 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001749
Dianne Hackbornd6847842010-01-12 18:14:19 -08001750 /**
1751 * Called by an application that is administering the device to set the
1752 * maximum time for user activity until the device will lock. This limits
1753 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001754 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001755 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001756 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001757 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001758 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001759 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001760 * @param timeMs The new desired maximum time to lock in milliseconds.
1761 * A value of 0 means there is no restriction.
1762 */
1763 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1764 if (mService != null) {
1765 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001766 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001767 } catch (RemoteException e) {
1768 Log.w(TAG, "Failed talking with device policy service", e);
1769 }
1770 }
1771 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001772
Dianne Hackbornd6847842010-01-12 18:14:19 -08001773 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001774 * Retrieve the current maximum time to unlock for all admins of this user
1775 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001776 * @param admin The name of the admin component to check, or null to aggregate
1777 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001778 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001779 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001780 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001781 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001782 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1783 }
1784
1785 /** @hide per-user version */
1786 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001787 if (mService != null) {
1788 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001789 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001790 } catch (RemoteException e) {
1791 Log.w(TAG, "Failed talking with device policy service", e);
1792 }
1793 }
1794 return 0;
1795 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001796
Dianne Hackbornd6847842010-01-12 18:14:19 -08001797 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001798 * Make the device lock immediately, as if the lock screen timeout has
1799 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001800 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001801 * <p>The calling device admin must have requested
1802 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1803 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001804 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001805 public void lockNow() {
1806 if (mService != null) {
1807 try {
1808 mService.lockNow();
1809 } catch (RemoteException e) {
1810 Log.w(TAG, "Failed talking with device policy service", e);
1811 }
1812 }
1813 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001814
Dianne Hackbornd6847842010-01-12 18:14:19 -08001815 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001816 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001817 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001818 */
1819 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1820
1821 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001822 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1823 * data.
1824 *
Paul Crowley2934b262014-12-02 11:21:13 +00001825 * <p>This flag may only be set by device owner admins; if it is set by
1826 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001827 */
1828 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1829
1830 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001831 * Ask the user data be wiped. Wiping the primary user will cause the
1832 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001833 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001834 * <p>The calling device admin must have requested
1835 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1836 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001837 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001838 * @param flags Bit mask of additional options: currently supported flags
1839 * are {@link #WIPE_EXTERNAL_STORAGE} and
1840 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001841 */
1842 public void wipeData(int flags) {
1843 if (mService != null) {
1844 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001845 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001846 } catch (RemoteException e) {
1847 Log.w(TAG, "Failed talking with device policy service", e);
1848 }
1849 }
1850 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001851
Dianne Hackbornd6847842010-01-12 18:14:19 -08001852 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001853 * Called by an application that is administering the device to set the
1854 * global proxy and exclusion list.
1855 * <p>
1856 * The calling device admin must have requested
1857 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1858 * this method; if it has not, a security exception will be thrown.
1859 * Only the first device admin can set the proxy. If a second admin attempts
1860 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1861 * proxy will be returned. If successful in setting the proxy, null will
1862 * be returned.
1863 * The method can be called repeatedly by the device admin alrady setting the
1864 * proxy to update the proxy and exclusion list.
1865 *
1866 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1867 * with.
1868 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1869 * Pass Proxy.NO_PROXY to reset the proxy.
1870 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001871 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1872 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001873 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001874 */
1875 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1876 List<String> exclusionList ) {
1877 if (proxySpec == null) {
1878 throw new NullPointerException();
1879 }
1880 if (mService != null) {
1881 try {
1882 String hostSpec;
1883 String exclSpec;
1884 if (proxySpec.equals(Proxy.NO_PROXY)) {
1885 hostSpec = null;
1886 exclSpec = null;
1887 } else {
1888 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1889 throw new IllegalArgumentException();
1890 }
1891 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1892 String hostName = sa.getHostName();
1893 int port = sa.getPort();
1894 StringBuilder hostBuilder = new StringBuilder();
1895 hostSpec = hostBuilder.append(hostName)
1896 .append(":").append(Integer.toString(port)).toString();
1897 if (exclusionList == null) {
1898 exclSpec = "";
1899 } else {
1900 StringBuilder listBuilder = new StringBuilder();
1901 boolean firstDomain = true;
1902 for (String exclDomain : exclusionList) {
1903 if (!firstDomain) {
1904 listBuilder = listBuilder.append(",");
1905 } else {
1906 firstDomain = false;
1907 }
1908 listBuilder = listBuilder.append(exclDomain.trim());
1909 }
1910 exclSpec = listBuilder.toString();
1911 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001912 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1913 != android.net.Proxy.PROXY_VALID)
1914 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001915 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001916 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001917 } catch (RemoteException e) {
1918 Log.w(TAG, "Failed talking with device policy service", e);
1919 }
1920 }
1921 return null;
1922 }
1923
1924 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001925 * Set a network-independent global HTTP proxy. This is not normally what you want
1926 * for typical HTTP proxies - they are generally network dependent. However if you're
1927 * doing something unusual like general internal filtering this may be useful. On
1928 * a private network where the proxy is not accessible, you may break HTTP using this.
1929 *
1930 * <p>This method requires the caller to be the device owner.
1931 *
1932 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1933 * @see ProxyInfo
1934 *
1935 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1936 * with.
1937 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1938 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1939 */
1940 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1941 if (mService != null) {
1942 try {
1943 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1944 } catch (RemoteException e) {
1945 Log.w(TAG, "Failed talking with device policy service", e);
1946 }
1947 }
1948 }
1949
1950 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001951 * Returns the component name setting the global proxy.
1952 * @return ComponentName object of the device admin that set the global proxy, or
1953 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001954 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001955 */
1956 public ComponentName getGlobalProxyAdmin() {
1957 if (mService != null) {
1958 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001959 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001960 } catch (RemoteException e) {
1961 Log.w(TAG, "Failed talking with device policy service", e);
1962 }
1963 }
1964 return null;
1965 }
1966
1967 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001968 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001969 * indicating that encryption is not supported.
1970 */
1971 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1972
1973 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001974 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001975 * indicating that encryption is supported, but is not currently active.
1976 */
1977 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1978
1979 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001980 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001981 * indicating that encryption is not currently active, but is currently
1982 * being activated. This is only reported by devices that support
1983 * encryption of data and only when the storage is currently
1984 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1985 * to become encrypted will never return this value.
1986 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001987 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001988
1989 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001990 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001991 * indicating that encryption is active.
1992 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001993 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001994
1995 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001996 * Result code for {@link #getStorageEncryptionStatus}:
1997 * indicating that encryption is active, but an encryption key has not
1998 * been set by the user.
1999 */
2000 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2001
2002 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002003 * Activity action: begin the process of encrypting data on the device. This activity should
2004 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2005 * After resuming from this activity, use {@link #getStorageEncryption}
2006 * to check encryption status. However, on some devices this activity may never return, as
2007 * it may trigger a reboot and in some cases a complete data wipe of the device.
2008 */
2009 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2010 public static final String ACTION_START_ENCRYPTION
2011 = "android.app.action.START_ENCRYPTION";
2012
2013 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002014 * Widgets are enabled in keyguard
2015 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002016 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002017
2018 /**
Jim Miller50e62182014-04-23 17:25:00 -07002019 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002020 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002021 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2022
2023 /**
2024 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2025 */
2026 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2027
2028 /**
Jim Miller50e62182014-04-23 17:25:00 -07002029 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2030 */
2031 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2032
2033 /**
2034 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2035 */
2036 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2037
2038 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002039 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002040 * (e.g. PIN/Pattern/Password).
2041 */
2042 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2043
2044 /**
Jim Miller06e34502014-07-17 14:46:05 -07002045 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2046 */
2047 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2048
2049 /**
Jim Miller35207742012-11-02 15:33:20 -07002050 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002051 */
2052 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002053
2054 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002055 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002056 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002057 *
2058 * <p>When multiple device administrators attempt to control device
2059 * encryption, the most secure, supported setting will always be
2060 * used. If any device administrator requests device encryption,
2061 * it will be enabled; Conversely, if a device administrator
2062 * attempts to disable device encryption while another
2063 * device administrator has enabled it, the call to disable will
2064 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2065 *
2066 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002067 * written to other storage areas may or may not be encrypted, and this policy does not require
2068 * or control the encryption of any other storage areas.
2069 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2070 * {@code true}, then the directory returned by
2071 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2072 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002073 *
2074 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2075 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2076 * the encryption key may not be fully secured. For maximum security, the administrator should
2077 * also require (and check for) a pattern, PIN, or password.
2078 *
2079 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2080 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002081 * @return the new request status (for all active admins) - will be one of
2082 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2083 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2084 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002085 */
2086 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
2087 if (mService != null) {
2088 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002089 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002090 } catch (RemoteException e) {
2091 Log.w(TAG, "Failed talking with device policy service", e);
2092 }
2093 }
2094 return ENCRYPTION_STATUS_UNSUPPORTED;
2095 }
2096
2097 /**
2098 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002099 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002100 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002101 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2102 * this will return the requested encryption setting as an aggregate of all active
2103 * administrators.
2104 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002105 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002106 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002107 if (mService != null) {
2108 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002109 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002110 } catch (RemoteException e) {
2111 Log.w(TAG, "Failed talking with device policy service", e);
2112 }
2113 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002114 return false;
2115 }
2116
2117 /**
2118 * Called by an application that is administering the device to
2119 * determine the current encryption status of the device.
2120 *
2121 * Depending on the returned status code, the caller may proceed in different
2122 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2123 * storage system does not support encryption. If the
2124 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2125 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002126 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2127 * storage system has enabled encryption but no password is set so further action
2128 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002129 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2130 *
Robin Lee7e678712014-07-24 16:41:31 +01002131 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002132 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002133 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2134 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002135 */
2136 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002137 return getStorageEncryptionStatus(UserHandle.myUserId());
2138 }
2139
2140 /** @hide per-user version */
2141 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002142 if (mService != null) {
2143 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002144 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002145 } catch (RemoteException e) {
2146 Log.w(TAG, "Failed talking with device policy service", e);
2147 }
2148 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002149 return ENCRYPTION_STATUS_UNSUPPORTED;
2150 }
2151
2152 /**
Robin Lee7e678712014-07-24 16:41:31 +01002153 * Installs the given certificate as a user CA.
2154 *
Rubin Xuec32b562015-03-03 17:34:05 +00002155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2156 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002157 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002158 *
2159 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002160 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002161 */
Robin Lee7e678712014-07-24 16:41:31 +01002162 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002163 if (mService != null) {
2164 try {
Robin Lee7e678712014-07-24 16:41:31 +01002165 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002166 } catch (RemoteException e) {
2167 Log.w(TAG, "Failed talking with device policy service", e);
2168 }
2169 }
2170 return false;
2171 }
2172
2173 /**
Robin Lee7e678712014-07-24 16:41:31 +01002174 * Uninstalls the given certificate from trusted user CAs, if present.
2175 *
Rubin Xuec32b562015-03-03 17:34:05 +00002176 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2177 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002178 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002179 */
Robin Lee7e678712014-07-24 16:41:31 +01002180 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002181 if (mService != null) {
2182 try {
Robin Lee306fe082014-06-19 14:04:24 +00002183 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002184 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002185 } catch (CertificateException e) {
2186 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002187 } catch (RemoteException e) {
2188 Log.w(TAG, "Failed talking with device policy service", e);
2189 }
2190 }
2191 }
2192
2193 /**
Robin Lee7e678712014-07-24 16:41:31 +01002194 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2195 * If a user has installed any certificates by other means than device policy these will be
2196 * included too.
2197 *
Rubin Xuec32b562015-03-03 17:34:05 +00002198 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2199 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002200 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002201 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002202 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002203 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002204 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002205 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002206 mService.enforceCanManageCaCerts(admin);
2207 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2208 for (String alias : certStore.userAliases()) {
2209 try {
2210 certs.add(certStore.getCertificate(alias).getEncoded());
2211 } catch (CertificateException ce) {
2212 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2213 }
2214 }
2215 } catch (RemoteException re) {
2216 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002217 }
2218 }
2219 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002220 }
2221
2222 /**
Robin Lee7e678712014-07-24 16:41:31 +01002223 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2224 * means other than device policy will also be removed, except for system CA certificates.
2225 *
Rubin Xuec32b562015-03-03 17:34:05 +00002226 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2227 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002228 */
2229 public void uninstallAllUserCaCerts(ComponentName admin) {
2230 if (mService != null) {
2231 for (String alias : new TrustedCertificateStore().userAliases()) {
2232 try {
2233 mService.uninstallCaCert(admin, alias);
2234 } catch (RemoteException re) {
2235 Log.w(TAG, "Failed talking with device policy service", re);
2236 }
2237 }
2238 }
2239 }
2240
2241 /**
2242 * Returns whether this certificate is installed as a trusted CA.
2243 *
Rubin Xuec32b562015-03-03 17:34:05 +00002244 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2245 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002246 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002247 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002248 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2249 if (mService != null) {
2250 try {
2251 mService.enforceCanManageCaCerts(admin);
2252 return getCaCertAlias(certBuffer) != null;
2253 } catch (RemoteException re) {
2254 Log.w(TAG, "Failed talking with device policy service", re);
2255 } catch (CertificateException ce) {
2256 Log.w(TAG, "Could not parse certificate", ce);
2257 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002258 }
2259 return false;
2260 }
2261
2262 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002263 * Called by a device or profile owner to install a certificate and private key pair. The
2264 * keypair will be visible to all apps within the profile.
2265 *
Rubin Xuacdc1832015-04-02 12:40:20 +01002266 * @param who Which {@link DeviceAdminReceiver} this request is associated with. Use
2267 * <code>null</code> if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002268 * @param privKey The private key to install.
2269 * @param cert The certificate to install.
2270 * @param alias The private key alias under which to install the certificate. If a certificate
2271 * with that alias already exists, it will be overwritten.
2272 * @return {@code true} if the keys were installed, {@code false} otherwise.
2273 */
2274 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2275 String alias) {
2276 try {
2277 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002278 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2279 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2280 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002281 } catch (RemoteException e) {
2282 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002283 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2284 Log.w(TAG, "Failed to obtain private key material", e);
2285 } catch (CertificateException | IOException e) {
2286 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002287 }
2288 return false;
2289 }
2290
2291 /**
Robin Lee306fe082014-06-19 14:04:24 +00002292 * Returns the alias of a given CA certificate in the certificate store, or null if it
2293 * doesn't exist.
2294 */
2295 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2296 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2297 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2298 new ByteArrayInputStream(certBuffer));
2299 return new TrustedCertificateStore().getCertificateAlias(cert);
2300 }
2301
2302 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002303 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002304 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002305 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002306 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002307 * <p>
2308 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2309 * it is later cleared by calling this method with a null value or uninstallling the certificate
2310 * installer.
2311 *
2312 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2313 * @param installerPackage The package name of the certificate installer which will be given
2314 * access. If <code>null</code> is given the current package will be cleared.
2315 */
2316 public void setCertInstallerPackage(ComponentName who, String installerPackage)
2317 throws SecurityException {
2318 if (mService != null) {
2319 try {
2320 mService.setCertInstallerPackage(who, installerPackage);
2321 } catch (RemoteException e) {
2322 Log.w(TAG, "Failed talking with device policy service", e);
2323 }
2324 }
2325 }
2326
2327 /**
2328 * Called by a profile owner or device owner to retrieve the certificate installer for the
2329 * current user. null if none is set.
2330 *
2331 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2332 * @return The package name of the current delegated certificate installer. <code>null</code>
2333 * if none is set.
2334 */
2335 public String getCertInstallerPackage(ComponentName who) throws SecurityException {
2336 if (mService != null) {
2337 try {
2338 return mService.getCertInstallerPackage(who);
2339 } catch (RemoteException e) {
2340 Log.w(TAG, "Failed talking with device policy service", e);
2341 }
2342 }
2343 return null;
2344 }
2345
2346 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002347 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002348 * on the device, for this user. After setting this, no applications running as this user
2349 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002350 *
2351 * <p>The calling device admin must have requested
2352 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2353 * this method; if it has not, a security exception will be thrown.
2354 *
2355 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2356 * @param disabled Whether or not the camera should be disabled.
2357 */
2358 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2359 if (mService != null) {
2360 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002361 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002362 } catch (RemoteException e) {
2363 Log.w(TAG, "Failed talking with device policy service", e);
2364 }
2365 }
2366 }
2367
2368 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002369 * Determine whether or not the device's cameras have been disabled for this user,
2370 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002371 * @param admin The name of the admin component to check, or null to check if any admins
2372 * have disabled the camera
2373 */
2374 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002375 return getCameraDisabled(admin, UserHandle.myUserId());
2376 }
2377
2378 /** @hide per-user version */
2379 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002380 if (mService != null) {
2381 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002382 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002383 } catch (RemoteException e) {
2384 Log.w(TAG, "Failed talking with device policy service", e);
2385 }
2386 }
2387 return false;
2388 }
2389
2390 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002391 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2392 * screen capture also prevents the content from being shown on display devices that do not have
2393 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2394 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002395 *
2396 * <p>The calling device admin must be a device or profile owner. If it is not, a
2397 * security exception will be thrown.
2398 *
2399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002400 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002401 */
2402 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2403 if (mService != null) {
2404 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002405 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002406 } catch (RemoteException e) {
2407 Log.w(TAG, "Failed talking with device policy service", e);
2408 }
2409 }
2410 }
2411
2412 /**
2413 * Determine whether or not screen capture has been disabled by the current
2414 * admin, if specified, or all admins.
2415 * @param admin The name of the admin component to check, or null to check if any admins
2416 * have disabled screen capture.
2417 */
2418 public boolean getScreenCaptureDisabled(ComponentName admin) {
2419 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2420 }
2421
2422 /** @hide per-user version */
2423 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2424 if (mService != null) {
2425 try {
2426 return mService.getScreenCaptureDisabled(admin, userHandle);
2427 } catch (RemoteException e) {
2428 Log.w(TAG, "Failed talking with device policy service", e);
2429 }
2430 }
2431 return false;
2432 }
2433
2434 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002435 * Called by a device owner to set whether auto time is required. If auto time is
2436 * required the user cannot set the date and time, but has to use network date and time.
2437 *
2438 * <p>Note: if auto time is required the user can still manually set the time zone.
2439 *
2440 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2441 * be thrown.
2442 *
2443 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2444 * @param required Whether auto time is set required or not.
2445 */
2446 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2447 if (mService != null) {
2448 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002449 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002450 } catch (RemoteException e) {
2451 Log.w(TAG, "Failed talking with device policy service", e);
2452 }
2453 }
2454 }
2455
2456 /**
2457 * @return true if auto time is required.
2458 */
2459 public boolean getAutoTimeRequired() {
2460 if (mService != null) {
2461 try {
2462 return mService.getAutoTimeRequired();
2463 } catch (RemoteException e) {
2464 Log.w(TAG, "Failed talking with device policy service", e);
2465 }
2466 }
2467 return false;
2468 }
2469
2470 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002471 * Called by an application that is administering the device to disable keyguard customizations,
2472 * such as widgets. After setting this, keyguard features will be disabled according to the
2473 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002474 *
2475 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002476 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002477 * this method; if it has not, a security exception will be thrown.
2478 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002479 * <p>Calling this from a managed profile will throw a security exception.
2480 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002481 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002482 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2483 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002484 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2485 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002486 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002487 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002488 if (mService != null) {
2489 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002490 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002491 } catch (RemoteException e) {
2492 Log.w(TAG, "Failed talking with device policy service", e);
2493 }
2494 }
2495 }
2496
2497 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002498 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002499 * admin, if specified, or all admins.
2500 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002501 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002502 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2503 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002504 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002505 public int getKeyguardDisabledFeatures(ComponentName admin) {
2506 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002507 }
2508
2509 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002510 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002511 if (mService != null) {
2512 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002513 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002514 } catch (RemoteException e) {
2515 Log.w(TAG, "Failed talking with device policy service", e);
2516 }
2517 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002518 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002519 }
2520
2521 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002522 * @hide
2523 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002524 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002525 if (mService != null) {
2526 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002527 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002528 } catch (RemoteException e) {
2529 Log.w(TAG, "Failed talking with device policy service", e);
2530 }
2531 }
2532 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002533
Dianne Hackbornd6847842010-01-12 18:14:19 -08002534 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002535 * @hide
2536 */
2537 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2538 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2539 }
2540
2541 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002542 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002543 * @hide
2544 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002545 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002546 ActivityInfo ai;
2547 try {
2548 ai = mContext.getPackageManager().getReceiverInfo(cn,
2549 PackageManager.GET_META_DATA);
2550 } catch (PackageManager.NameNotFoundException e) {
2551 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2552 return null;
2553 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002554
Dianne Hackbornd6847842010-01-12 18:14:19 -08002555 ResolveInfo ri = new ResolveInfo();
2556 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002557
Dianne Hackbornd6847842010-01-12 18:14:19 -08002558 try {
2559 return new DeviceAdminInfo(mContext, ri);
2560 } catch (XmlPullParserException e) {
2561 Log.w(TAG, "Unable to parse device policy " + cn, e);
2562 return null;
2563 } catch (IOException e) {
2564 Log.w(TAG, "Unable to parse device policy " + cn, e);
2565 return null;
2566 }
2567 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002568
Dianne Hackbornd6847842010-01-12 18:14:19 -08002569 /**
2570 * @hide
2571 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002572 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2573 if (mService != null) {
2574 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002575 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002576 } catch (RemoteException e) {
2577 Log.w(TAG, "Failed talking with device policy service", e);
2578 }
2579 }
2580 }
2581
2582 /**
2583 * @hide
2584 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002585 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002586 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002587 if (mService != null) {
2588 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002589 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002590 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002591 } catch (RemoteException e) {
2592 Log.w(TAG, "Failed talking with device policy service", e);
2593 }
2594 }
2595 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002596
Dianne Hackbornd6847842010-01-12 18:14:19 -08002597 /**
2598 * @hide
2599 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002600 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002601 if (mService != null) {
2602 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002603 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002604 } catch (RemoteException e) {
2605 Log.w(TAG, "Failed talking with device policy service", e);
2606 }
2607 }
2608 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002609
Dianne Hackbornd6847842010-01-12 18:14:19 -08002610 /**
2611 * @hide
2612 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002613 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002614 if (mService != null) {
2615 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002616 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002617 } catch (RemoteException e) {
2618 Log.w(TAG, "Failed talking with device policy service", e);
2619 }
2620 }
2621 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002622
2623 /**
2624 * @hide
2625 * Sets the given package as the device owner. The package must already be installed and there
2626 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2627 * method must be called before the device is provisioned.
2628 * @param packageName the package name of the application to be registered as the device owner.
2629 * @return whether the package was successfully registered as the device owner.
2630 * @throws IllegalArgumentException if the package name is null or invalid
2631 * @throws IllegalStateException if a device owner is already registered or the device has
2632 * already been provisioned.
2633 */
2634 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2635 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002636 return setDeviceOwner(packageName, null);
2637 }
2638
2639 /**
2640 * @hide
2641 * Sets the given package as the device owner. The package must already be installed and there
2642 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2643 * method must be called before the device is provisioned.
2644 * @param packageName the package name of the application to be registered as the device owner.
2645 * @param ownerName the human readable name of the institution that owns this device.
2646 * @return whether the package was successfully registered as the device owner.
2647 * @throws IllegalArgumentException if the package name is null or invalid
2648 * @throws IllegalStateException if a device owner is already registered or the device has
2649 * already been provisioned.
2650 */
2651 public boolean setDeviceOwner(String packageName, String ownerName)
2652 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002653 if (mService != null) {
2654 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002655 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002656 } catch (RemoteException re) {
2657 Log.w(TAG, "Failed to set device owner");
2658 }
2659 }
2660 return false;
2661 }
2662
2663 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002664 * Used to determine if a particular package has been registered as a Device Owner app.
2665 * A device owner app is a special device admin that cannot be deactivated by the user, once
2666 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2667 * package is currently registered as the device owner app, pass in the package name from
2668 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2669 * admin apps that want to check if they are also registered as the device owner app. The
2670 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2671 * the setup process.
2672 * @param packageName the package name of the app, to compare with the registered device owner
2673 * app, if any.
2674 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002675 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002676 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002677 if (mService != null) {
2678 try {
2679 return mService.isDeviceOwner(packageName);
2680 } catch (RemoteException re) {
2681 Log.w(TAG, "Failed to check device owner");
2682 }
2683 }
2684 return false;
2685 }
2686
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002687 /**
2688 * @hide
2689 * Redirect to isDeviceOwnerApp.
2690 */
2691 public boolean isDeviceOwner(String packageName) {
2692 return isDeviceOwnerApp(packageName);
2693 }
2694
Jason Monkb0dced82014-06-06 14:36:20 -04002695 /**
2696 * Clears the current device owner. The caller must be the device owner.
2697 *
2698 * This function should be used cautiously as once it is called it cannot
2699 * be undone. The device owner can only be set as a part of device setup
2700 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002701 *
2702 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002703 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002704 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002705 if (mService != null) {
2706 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002707 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002708 } catch (RemoteException re) {
2709 Log.w(TAG, "Failed to clear device owner");
2710 }
2711 }
2712 }
2713
Amith Yamasani71e6c692013-03-24 17:39:28 -07002714 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002715 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002716 public String getDeviceOwner() {
2717 if (mService != null) {
2718 try {
2719 return mService.getDeviceOwner();
2720 } catch (RemoteException re) {
2721 Log.w(TAG, "Failed to get device owner");
2722 }
2723 }
2724 return null;
2725 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002726
2727 /** @hide */
2728 public String getDeviceOwnerName() {
2729 if (mService != null) {
2730 try {
2731 return mService.getDeviceOwnerName();
2732 } catch (RemoteException re) {
2733 Log.w(TAG, "Failed to get device owner");
2734 }
2735 }
2736 return null;
2737 }
Adam Connors776c5552014-01-09 10:42:56 +00002738
2739 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002740 * Sets the given component as the device initializer. The package must already be installed and
2741 * set as an active device administrator, and there must not be an existing device initializer,
2742 * for this call to succeed. This method can only be called by an app holding the
2743 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2744 * device initializer app is granted device owner privileges during device initialization and
2745 * profile owner privileges during secondary user initialization.
2746 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2747 * called by the device owner.
2748 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2749 * @param initializerName The user-visible name of the device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002750 * @return whether the component was successfully registered as the device initializer.
2751 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002752 * @throws IllegalStateException if the caller is not device owner or the device has
2753 * already been provisioned or a device initializer already exists.
2754 */
2755 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2756 String initializerName) throws IllegalArgumentException, IllegalStateException {
2757 if (mService != null) {
2758 try {
2759 return mService.setDeviceInitializer(who, initializer, initializerName);
2760 } catch (RemoteException re) {
2761 Log.w(TAG, "Failed to set device initializer");
2762 }
2763 }
2764 return false;
2765 }
2766
2767 /**
2768 * Used to determine if a particular package has been registered as the device initializer.
2769 *
2770 * @param packageName the package name of the app, to compare with the registered device
2771 * initializer app, if any.
2772 * @return whether or not the caller is registered as the device initializer app.
2773 */
2774 public boolean isDeviceInitializerApp(String packageName) {
2775 if (mService != null) {
2776 try {
2777 return mService.isDeviceInitializer(packageName);
2778 } catch (RemoteException re) {
2779 Log.w(TAG, "Failed to check device initializer");
2780 }
2781 }
2782 return false;
2783 }
2784
2785 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002786 * Removes the device initializer, so that it will not be invoked on user initialization for any
2787 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002788 * initializer itself. The caller must be an active administrator.
2789 *
2790 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002791 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002792 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002793 if (mService != null) {
2794 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002795 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002796 } catch (RemoteException re) {
2797 Log.w(TAG, "Failed to clear device initializer");
2798 }
2799 }
2800 }
2801
2802 /**
2803 * @hide
2804 * Gets the device initializer of the system.
2805 *
2806 * @return the package name of the device initializer.
2807 */
2808 @SystemApi
2809 public String getDeviceInitializerApp() {
2810 if (mService != null) {
2811 try {
2812 return mService.getDeviceInitializer();
2813 } catch (RemoteException re) {
2814 Log.w(TAG, "Failed to get device initializer");
2815 }
2816 }
2817 return null;
2818 }
2819
2820 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002821 * @hide
2822 * Gets the device initializer component of the system.
2823 *
2824 * @return the component name of the device initializer.
2825 */
2826 @SystemApi
2827 public ComponentName getDeviceInitializerComponent() {
2828 if (mService != null) {
2829 try {
2830 return mService.getDeviceInitializerComponent();
2831 } catch (RemoteException re) {
2832 Log.w(TAG, "Failed to get device initializer");
2833 }
2834 }
2835 return null;
2836 }
2837
2838
2839 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002840 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2841 * be used.
2842 *
2843 * <p>Device initializer must call this method to mark the user as functional.
2844 * Only the device initializer agent can call this.
2845 *
2846 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2847 * device initializer will no longer have elevated permissions to call methods in this class.
2848 * Additionally, it will be removed as an active administrator and its
2849 * {@link DeviceAdminReceiver} will be disabled.
2850 *
2851 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2852 * @return whether the user is now enabled.
2853 */
2854 public boolean setUserEnabled(ComponentName admin) {
2855 if (mService != null) {
2856 try {
2857 return mService.setUserEnabled(admin);
2858 } catch (RemoteException e) {
2859 Log.w(TAG, "Failed talking with device policy service", e);
2860 }
2861 }
2862 return false;
2863 }
2864
2865 /**
Adam Connors776c5552014-01-09 10:42:56 +00002866 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002867 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302868 * Sets the given component as an active admin and registers the package as the profile
2869 * owner for this user. The package must already be installed and there shouldn't be
2870 * an existing profile owner registered for this user. Also, this method must be called
2871 * before the user setup has been completed.
2872 * <p>
2873 * This method can only be called by system apps that hold MANAGE_USERS permission and
2874 * MANAGE_DEVICE_ADMINS permission.
2875 * @param admin The component to register as an active admin and profile owner.
2876 * @param ownerName The user-visible name of the entity that is managing this user.
2877 * @return whether the admin was successfully registered as the profile owner.
2878 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2879 * the user has already been set up.
2880 */
Justin Morey80440cc2014-07-24 09:16:35 -05002881 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302882 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2883 throws IllegalArgumentException {
2884 if (mService != null) {
2885 try {
2886 final int myUserId = UserHandle.myUserId();
2887 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002888 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302889 } catch (RemoteException re) {
2890 Log.w(TAG, "Failed to set profile owner " + re);
2891 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2892 }
2893 }
2894 return false;
2895 }
2896
2897 /**
2898 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002899 * Clears the active profile owner and removes all user restrictions. The caller must
2900 * be from the same package as the active profile owner for this user, otherwise a
2901 * SecurityException will be thrown.
2902 *
2903 * @param admin The component to remove as the profile owner.
2904 * @return
2905 */
2906 @SystemApi
2907 public void clearProfileOwner(ComponentName admin) {
2908 if (mService != null) {
2909 try {
2910 mService.clearProfileOwner(admin);
2911 } catch (RemoteException re) {
2912 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2913 }
2914 }
2915 }
2916
2917 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002918 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002919 * Checks if the user was already setup.
2920 */
2921 public boolean hasUserSetupCompleted() {
2922 if (mService != null) {
2923 try {
2924 return mService.hasUserSetupCompleted();
2925 } catch (RemoteException re) {
2926 Log.w(TAG, "Failed to check if user setup has completed");
2927 }
2928 }
2929 return true;
2930 }
2931
2932 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002933 * @hide
2934 * Sets the given component as the profile owner of the given user profile. The package must
2935 * already be installed and there shouldn't be an existing profile owner registered for this
2936 * user. Only the system can call this API if the user has already completed setup.
2937 * @param admin the component name to be registered as profile owner.
2938 * @param ownerName the human readable name of the organisation associated with this DPM.
2939 * @param userHandle the userId to set the profile owner for.
2940 * @return whether the component was successfully registered as the profile owner.
2941 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2942 * the user has already been set up.
2943 */
2944 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2945 throws IllegalArgumentException {
2946 if (admin == null) {
2947 throw new NullPointerException("admin cannot be null");
2948 }
Adam Connors776c5552014-01-09 10:42:56 +00002949 if (mService != null) {
2950 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002951 if (ownerName == null) {
2952 ownerName = "";
2953 }
2954 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002955 } catch (RemoteException re) {
2956 Log.w(TAG, "Failed to set profile owner", re);
2957 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2958 }
2959 }
2960 return false;
2961 }
2962
2963 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002964 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2965 * be used. Only the profile owner can call this.
2966 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002967 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002968 *
2969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2970 */
2971 public void setProfileEnabled(ComponentName admin) {
2972 if (mService != null) {
2973 try {
2974 mService.setProfileEnabled(admin);
2975 } catch (RemoteException e) {
2976 Log.w(TAG, "Failed talking with device policy service", e);
2977 }
2978 }
2979 }
2980
2981 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002982 * Sets the name of the profile. In the device owner case it sets the name of the user
2983 * 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 +01002984 * never called by the profile or device owner, the name will be set to default values.
2985 *
2986 * @see #isProfileOwnerApp
2987 * @see #isDeviceOwnerApp
2988 *
2989 * @param profileName The name of the profile.
2990 */
2991 public void setProfileName(ComponentName who, String profileName) {
2992 if (mService != null) {
2993 try {
2994 mService.setProfileName(who, profileName);
2995 } catch (RemoteException e) {
2996 Log.w(TAG, "Failed talking with device policy service", e);
2997 }
2998 }
2999}
3000
3001 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003002 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003003 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003004 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003005 *
3006 * @param packageName The package name of the app to compare with the registered profile owner.
3007 * @return Whether or not the package is registered as the profile owner.
3008 */
3009 public boolean isProfileOwnerApp(String packageName) {
3010 if (mService != null) {
3011 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003012 ComponentName profileOwner = mService.getProfileOwner(
3013 Process.myUserHandle().getIdentifier());
3014 return profileOwner != null
3015 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003016 } catch (RemoteException re) {
3017 Log.w(TAG, "Failed to check profile owner");
3018 }
3019 }
3020 return false;
3021 }
3022
3023 /**
3024 * @hide
3025 * @return the packageName of the owner of the given user profile or null if no profile
3026 * owner has been set for that user.
3027 * @throws IllegalArgumentException if the userId is invalid.
3028 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003029 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003030 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003031 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3032 }
3033
3034 /**
3035 * @see #getProfileOwner()
3036 * @hide
3037 */
3038 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003039 if (mService != null) {
3040 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003041 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003042 } catch (RemoteException re) {
3043 Log.w(TAG, "Failed to get profile owner");
3044 throw new IllegalArgumentException(
3045 "Requested profile owner for invalid userId", re);
3046 }
3047 }
3048 return null;
3049 }
3050
3051 /**
3052 * @hide
3053 * @return the human readable name of the organisation associated with this DPM or null if
3054 * one is not set.
3055 * @throws IllegalArgumentException if the userId is invalid.
3056 */
3057 public String getProfileOwnerName() throws IllegalArgumentException {
3058 if (mService != null) {
3059 try {
3060 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3061 } catch (RemoteException re) {
3062 Log.w(TAG, "Failed to get profile owner");
3063 throw new IllegalArgumentException(
3064 "Requested profile owner for invalid userId", re);
3065 }
3066 }
3067 return null;
3068 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003069
3070 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003071 * @hide
3072 * @param user The user for whom to fetch the profile owner name, if any.
3073 * @return the human readable name of the organisation associated with this profile owner or
3074 * null if one is not set.
3075 * @throws IllegalArgumentException if the userId is invalid.
3076 */
3077 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003078 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003079 if (mService != null) {
3080 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003081 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003082 } catch (RemoteException re) {
3083 Log.w(TAG, "Failed to get profile owner");
3084 throw new IllegalArgumentException(
3085 "Requested profile owner for invalid userId", re);
3086 }
3087 }
3088 return null;
3089 }
3090
3091 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003092 * Called by a profile owner or device owner to add a default intent handler activity for
3093 * intents that match a certain intent filter. This activity will remain the default intent
3094 * handler even if the set of potential event handlers for the intent filter changes and if
3095 * the intent preferences are reset.
3096 *
3097 * <p>The default disambiguation mechanism takes over if the activity is not installed
3098 * (anymore). When the activity is (re)installed, it is automatically reset as default
3099 * intent handler for the filter.
3100 *
3101 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3102 * security exception will be thrown.
3103 *
3104 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3105 * @param filter The IntentFilter for which a default handler is added.
3106 * @param activity The Activity that is added as default intent handler.
3107 */
3108 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
3109 ComponentName activity) {
3110 if (mService != null) {
3111 try {
3112 mService.addPersistentPreferredActivity(admin, filter, activity);
3113 } catch (RemoteException e) {
3114 Log.w(TAG, "Failed talking with device policy service", e);
3115 }
3116 }
3117 }
3118
3119 /**
3120 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003121 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003122 *
3123 * <p>The calling device admin must be a profile owner. If it is not, a security
3124 * exception will be thrown.
3125 *
3126 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3127 * @param packageName The name of the package for which preferences are removed.
3128 */
3129 public void clearPackagePersistentPreferredActivities(ComponentName admin,
3130 String packageName) {
3131 if (mService != null) {
3132 try {
3133 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3134 } catch (RemoteException e) {
3135 Log.w(TAG, "Failed talking with device policy service", e);
3136 }
3137 }
3138 }
Robin Lee66e5d962014-04-09 16:44:21 +01003139
3140 /**
3141 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003142 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003143 *
3144 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003145 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003146 *
3147 * <p>The application restrictions are only made visible to the target application and the
3148 * profile or device owner.
3149 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003150 * <p>If the restrictions are not available yet, but may be applied in the near future,
3151 * the admin can notify the target application of that by adding
3152 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3153 *
Robin Lee66e5d962014-04-09 16:44:21 +01003154 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3155 * exception will be thrown.
3156 *
3157 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3158 * @param packageName The name of the package to update restricted settings for.
3159 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3160 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003161 *
3162 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003163 */
3164 public void setApplicationRestrictions(ComponentName admin, String packageName,
3165 Bundle settings) {
3166 if (mService != null) {
3167 try {
3168 mService.setApplicationRestrictions(admin, packageName, settings);
3169 } catch (RemoteException e) {
3170 Log.w(TAG, "Failed talking with device policy service", e);
3171 }
3172 }
3173 }
3174
3175 /**
Jim Millere303bf42014-08-26 17:12:29 -07003176 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3177 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3178 * trust agents but those enabled by this function call. If flag
3179 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003180 *
3181 * <p>The calling device admin must have requested
3182 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003183 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003184 *
3185 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003186 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003187 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003188 * will be strictly disabled according to the state of the
3189 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3190 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3191 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3192 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003193 */
Jim Millere303bf42014-08-26 17:12:29 -07003194 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08003195 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003196 if (mService != null) {
3197 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003198 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003199 } catch (RemoteException e) {
3200 Log.w(TAG, "Failed talking with device policy service", e);
3201 }
3202 }
3203 }
3204
3205 /**
Jim Millere303bf42014-08-26 17:12:29 -07003206 * Gets configuration for the given trust agent based on aggregating all calls to
3207 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3208 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003209 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003210 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3211 * this function returns a list of configurations for all admins that declare
3212 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3213 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3214 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3215 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003216 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003217 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003218 */
Jim Millere303bf42014-08-26 17:12:29 -07003219 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3220 ComponentName agent) {
3221 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3222 }
3223
3224 /** @hide per-user version */
3225 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3226 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003227 if (mService != null) {
3228 try {
Jim Millere303bf42014-08-26 17:12:29 -07003229 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003230 } catch (RemoteException e) {
3231 Log.w(TAG, "Failed talking with device policy service", e);
3232 }
3233 }
Jim Millere303bf42014-08-26 17:12:29 -07003234 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003235 }
3236
3237 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003238 * Called by a profile owner of a managed profile to set whether caller-Id information from
3239 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003240 *
3241 * <p>The calling device admin must be a profile owner. If it is not, a
3242 * security exception will be thrown.
3243 *
3244 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3245 * @param disabled If true caller-Id information in the managed profile is not displayed.
3246 */
3247 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
3248 if (mService != null) {
3249 try {
3250 mService.setCrossProfileCallerIdDisabled(who, disabled);
3251 } catch (RemoteException e) {
3252 Log.w(TAG, "Failed talking with device policy service", e);
3253 }
3254 }
3255 }
3256
3257 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003258 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3259 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003260 *
3261 * <p>The calling device admin must be a profile owner. If it is not, a
3262 * security exception will be thrown.
3263 *
3264 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3265 */
3266 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3267 if (mService != null) {
3268 try {
3269 return mService.getCrossProfileCallerIdDisabled(who);
3270 } catch (RemoteException e) {
3271 Log.w(TAG, "Failed talking with device policy service", e);
3272 }
3273 }
3274 return false;
3275 }
3276
3277 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003278 * Determine whether or not caller-Id information has been disabled.
3279 *
3280 * @param userHandle The user for whom to check the caller-id permission
3281 * @hide
3282 */
3283 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3284 if (mService != null) {
3285 try {
3286 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3287 } catch (RemoteException e) {
3288 Log.w(TAG, "Failed talking with device policy service", e);
3289 }
3290 }
3291 return false;
3292 }
3293
3294 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003295 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3296 * @hide
3297 */
3298 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3299 Intent originalIntent) {
3300 if (mService != null) {
3301 try {
3302 mService.startManagedQuickContact(
3303 actualLookupKey, actualContactId, originalIntent);
3304 } catch (RemoteException e) {
3305 Log.w(TAG, "Failed talking with device policy service", e);
3306 }
3307 }
3308 }
3309
3310 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003311 * Called by a profile owner of a managed profile to set whether bluetooth
3312 * devices can access enterprise contacts.
3313 * <p>
3314 * The calling device admin must be a profile owner. If it is not, a
3315 * security exception will be thrown.
3316 * <p>
3317 * This API works on managed profile only.
3318 *
3319 * @param who Which {@link DeviceAdminReceiver} this request is associated
3320 * with.
3321 * @param disabled If true, bluetooth devices cannot access enterprise
3322 * contacts.
3323 */
3324 public void setBluetoothContactSharingDisabled(ComponentName who, boolean disabled) {
3325 if (mService != null) {
3326 try {
3327 mService.setBluetoothContactSharingDisabled(who, disabled);
3328 } catch (RemoteException e) {
3329 Log.w(TAG, "Failed talking with device policy service", e);
3330 }
3331 }
3332 }
3333
3334 /**
3335 * Called by a profile owner of a managed profile to determine whether or
3336 * not Bluetooth devices cannot access enterprise contacts.
3337 * <p>
3338 * The calling device admin must be a profile owner. If it is not, a
3339 * security exception will be thrown.
3340 * <p>
3341 * This API works on managed profile only.
3342 *
3343 * @param who Which {@link DeviceAdminReceiver} this request is associated
3344 * with.
3345 */
3346 public boolean getBluetoothContactSharingDisabled(ComponentName who) {
3347 if (mService != null) {
3348 try {
3349 return mService.getBluetoothContactSharingDisabled(who);
3350 } catch (RemoteException e) {
3351 Log.w(TAG, "Failed talking with device policy service", e);
3352 }
3353 }
3354 return true;
3355 }
3356
3357 /**
3358 * Determine whether or not Bluetooth devices cannot access contacts.
3359 * <p>
3360 * This API works on managed profile UserHandle only.
3361 *
3362 * @param userHandle The user for whom to check the caller-id permission
3363 * @hide
3364 */
3365 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3366 if (mService != null) {
3367 try {
3368 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3369 .getIdentifier());
3370 } catch (RemoteException e) {
3371 Log.w(TAG, "Failed talking with device policy service", e);
3372 }
3373 }
3374 return true;
3375 }
3376
3377 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003378 * Called by the profile owner of a managed profile so that some intents sent in the managed
3379 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003380 * Only activity intents are supported.
3381 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003382 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003383 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3384 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003385 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3386 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003387 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003388 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003389 if (mService != null) {
3390 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003391 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003392 } catch (RemoteException e) {
3393 Log.w(TAG, "Failed talking with device policy service", e);
3394 }
3395 }
3396 }
3397
3398 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003399 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3400 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003401 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003402 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3403 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003404 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003405 if (mService != null) {
3406 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003407 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003408 } catch (RemoteException e) {
3409 Log.w(TAG, "Failed talking with device policy service", e);
3410 }
3411 }
3412 }
3413
3414 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003415 * Called by a profile or device owner to set the permitted accessibility services. When
3416 * set by a device owner or profile owner the restriction applies to all profiles of the
3417 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003418 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003419 * By default the user can use any accessiblity service. When zero or more packages have
3420 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003421 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003422 *
3423 * <p> Calling with a null value for the list disables the restriction so that all services
3424 * can be used, calling with an empty list only allows the builtin system's services.
3425 *
3426 * <p> System accesibility services are always available to the user the list can't modify
3427 * this.
3428 *
3429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3430 * @param packageNames List of accessibility service package names.
3431 *
3432 * @return true if setting the restriction succeeded. It fail if there is
3433 * one or more non-system accessibility services enabled, that are not in the list.
3434 */
3435 public boolean setPermittedAccessibilityServices(ComponentName admin,
3436 List<String> packageNames) {
3437 if (mService != null) {
3438 try {
3439 return mService.setPermittedAccessibilityServices(admin, packageNames);
3440 } catch (RemoteException e) {
3441 Log.w(TAG, "Failed talking with device policy service", e);
3442 }
3443 }
3444 return false;
3445 }
3446
3447 /**
3448 * Returns the list of permitted accessibility services set by this device or profile owner.
3449 *
3450 * <p>An empty list means no accessibility services except system services are allowed.
3451 * Null means all accessibility services are allowed.
3452 *
3453 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3454 * @return List of accessiblity service package names.
3455 */
3456 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3457 if (mService != null) {
3458 try {
3459 return mService.getPermittedAccessibilityServices(admin);
3460 } catch (RemoteException e) {
3461 Log.w(TAG, "Failed talking with device policy service", e);
3462 }
3463 }
3464 return null;
3465 }
3466
3467 /**
3468 * Returns the list of accessibility services permitted by the device or profiles
3469 * owners of this user.
3470 *
3471 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3472 * it will contain the intersection of the permitted lists for any device or profile
3473 * owners that apply to this user. It will also include any system accessibility services.
3474 *
3475 * @param userId which user to check for.
3476 * @return List of accessiblity service package names.
3477 * @hide
3478 */
3479 @SystemApi
3480 public List<String> getPermittedAccessibilityServices(int userId) {
3481 if (mService != null) {
3482 try {
3483 return mService.getPermittedAccessibilityServicesForUser(userId);
3484 } catch (RemoteException e) {
3485 Log.w(TAG, "Failed talking with device policy service", e);
3486 }
3487 }
3488 return null;
3489 }
3490
3491 /**
3492 * Called by a profile or device owner to set the permitted input methods services. When
3493 * set by a device owner or profile owner the restriction applies to all profiles of the
3494 * user the device owner or profile owner is an admin for.
3495 *
3496 * By default the user can use any input method. When zero or more packages have
3497 * been added, input method that are not in the list and not part of the system
3498 * can not be enabled by the user.
3499 *
3500 * This method will fail if it is called for a admin that is not for the foreground user
3501 * or a profile of the foreground user.
3502 *
3503 * <p> Calling with a null value for the list disables the restriction so that all input methods
3504 * can be used, calling with an empty list disables all but the system's own input methods.
3505 *
3506 * <p> System input methods are always available to the user this method can't modify this.
3507 *
3508 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3509 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003510 * @return true if setting the restriction succeeded. It will fail if there are
3511 * one or more non-system input methods currently enabled that are not in
3512 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003513 */
3514 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3515 if (mService != null) {
3516 try {
3517 return mService.setPermittedInputMethods(admin, packageNames);
3518 } catch (RemoteException e) {
3519 Log.w(TAG, "Failed talking with device policy service", e);
3520 }
3521 }
3522 return false;
3523 }
3524
3525
3526 /**
3527 * Returns the list of permitted input methods set by this device or profile owner.
3528 *
3529 * <p>An empty list means no input methods except system input methods are allowed.
3530 * Null means all input methods are allowed.
3531 *
3532 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3533 * @return List of input method package names.
3534 */
3535 public List<String> getPermittedInputMethods(ComponentName admin) {
3536 if (mService != null) {
3537 try {
3538 return mService.getPermittedInputMethods(admin);
3539 } catch (RemoteException e) {
3540 Log.w(TAG, "Failed talking with device policy service", e);
3541 }
3542 }
3543 return null;
3544 }
3545
3546 /**
3547 * Returns the list of input methods permitted by the device or profiles
3548 * owners of the current user.
3549 *
3550 * <p>Null means all input methods are allowed, if a non-null list is returned
3551 * it will contain the intersection of the permitted lists for any device or profile
3552 * owners that apply to this user. It will also include any system input methods.
3553 *
3554 * @return List of input method package names.
3555 * @hide
3556 */
3557 @SystemApi
3558 public List<String> getPermittedInputMethodsForCurrentUser() {
3559 if (mService != null) {
3560 try {
3561 return mService.getPermittedInputMethodsForCurrentUser();
3562 } catch (RemoteException e) {
3563 Log.w(TAG, "Failed talking with device policy service", e);
3564 }
3565 }
3566 return null;
3567 }
3568
3569 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003570 * Called by a device owner to create a user with the specified name. The UserHandle returned
3571 * by this method should not be persisted as user handles are recycled as users are removed and
3572 * created. If you need to persist an identifier for this user, use
3573 * {@link UserManager#getSerialNumberForUser}.
3574 *
3575 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3576 * @param name the user's name
3577 * @see UserHandle
3578 * @return the UserHandle object for the created user, or null if the user could not be created.
3579 */
3580 public UserHandle createUser(ComponentName admin, String name) {
3581 try {
3582 return mService.createUser(admin, name);
3583 } catch (RemoteException re) {
3584 Log.w(TAG, "Could not create a user", re);
3585 }
3586 return null;
3587 }
3588
3589 /**
Jason Monk03978a42014-06-10 15:05:30 -04003590 * Called by a device owner to create a user with the specified name. The UserHandle returned
3591 * by this method should not be persisted as user handles are recycled as users are removed and
3592 * created. If you need to persist an identifier for this user, use
3593 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3594 * immediately.
3595 *
3596 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3597 * as registered as an active admin on the new user. The profile owner package will be
3598 * installed on the new user if it already is installed on the device.
3599 *
3600 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3601 * profileOwnerComponent when onEnable is called.
3602 *
3603 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3604 * @param name the user's name
3605 * @param ownerName the human readable name of the organisation associated with this DPM.
3606 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3607 * the user.
3608 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3609 * on the new user.
3610 * @see UserHandle
3611 * @return the UserHandle object for the created user, or null if the user could not be created.
3612 */
3613 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3614 ComponentName profileOwnerComponent, Bundle adminExtras) {
3615 try {
3616 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3617 adminExtras);
3618 } catch (RemoteException re) {
3619 Log.w(TAG, "Could not create a user", re);
3620 }
3621 return null;
3622 }
3623
3624 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003625 * Called by a device owner to remove a user and all associated data. The primary user can
3626 * not be removed.
3627 *
3628 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3629 * @param userHandle the user to remove.
3630 * @return {@code true} if the user was removed, {@code false} otherwise.
3631 */
3632 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3633 try {
3634 return mService.removeUser(admin, userHandle);
3635 } catch (RemoteException re) {
3636 Log.w(TAG, "Could not remove user ", re);
3637 return false;
3638 }
3639 }
3640
3641 /**
Jason Monk582d9112014-07-09 19:57:08 -04003642 * Called by a device owner to switch the specified user to the foreground.
3643 *
3644 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3645 * @param userHandle the user to switch to; null will switch to primary.
3646 * @return {@code true} if the switch was successful, {@code false} otherwise.
3647 *
3648 * @see Intent#ACTION_USER_FOREGROUND
3649 */
3650 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3651 try {
3652 return mService.switchUser(admin, userHandle);
3653 } catch (RemoteException re) {
3654 Log.w(TAG, "Could not switch user ", re);
3655 return false;
3656 }
3657 }
3658
3659 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003660 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003661 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003662 *
3663 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3664 * exception will be thrown.
3665 *
3666 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3667 * @param packageName The name of the package to fetch restricted settings of.
3668 * @return {@link Bundle} of settings corresponding to what was set last time
3669 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3670 * if no restrictions have been set.
3671 */
3672 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3673 if (mService != null) {
3674 try {
3675 return mService.getApplicationRestrictions(admin, packageName);
3676 } catch (RemoteException e) {
3677 Log.w(TAG, "Failed talking with device policy service", e);
3678 }
3679 }
3680 return null;
3681 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003682
3683 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003684 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003685 * <p>
3686 * The calling device admin must be a profile or device owner; if it is not,
3687 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003688 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003689 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3690 * with.
3691 * @param key The key of the restriction. See the constants in
3692 * {@link android.os.UserManager} for the list of keys.
3693 */
3694 public void addUserRestriction(ComponentName admin, String key) {
3695 if (mService != null) {
3696 try {
3697 mService.setUserRestriction(admin, key, true);
3698 } catch (RemoteException e) {
3699 Log.w(TAG, "Failed talking with device policy service", e);
3700 }
3701 }
3702 }
3703
3704 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003705 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003706 * <p>
3707 * The calling device admin must be a profile or device owner; if it is not,
3708 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003709 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003710 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3711 * with.
3712 * @param key The key of the restriction. See the constants in
3713 * {@link android.os.UserManager} for the list of keys.
3714 */
3715 public void clearUserRestriction(ComponentName admin, String key) {
3716 if (mService != null) {
3717 try {
3718 mService.setUserRestriction(admin, key, false);
3719 } catch (RemoteException e) {
3720 Log.w(TAG, "Failed talking with device policy service", e);
3721 }
3722 }
3723 }
Adam Connors010cfd42014-04-16 12:48:13 +01003724
3725 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003726 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003727 * is unavailable for use, but the data and actual package file remain.
3728 *
3729 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003730 * @param packageName The name of the package to hide or unhide.
3731 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3732 * unhidden.
3733 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003734 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003735 public boolean setApplicationHidden(ComponentName admin, String packageName,
3736 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003737 if (mService != null) {
3738 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003739 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003740 } catch (RemoteException e) {
3741 Log.w(TAG, "Failed talking with device policy service", e);
3742 }
3743 }
3744 return false;
3745 }
3746
3747 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003748 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003749 *
3750 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003751 * @param packageName The name of the package to retrieve the hidden status of.
3752 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003753 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003754 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003755 if (mService != null) {
3756 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003757 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003758 } catch (RemoteException e) {
3759 Log.w(TAG, "Failed talking with device policy service", e);
3760 }
3761 }
3762 return false;
3763 }
3764
3765 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003766 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003767 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003768 *
3769 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3770 * @param packageName The package to be re-enabled in the current profile.
3771 */
3772 public void enableSystemApp(ComponentName admin, String packageName) {
3773 if (mService != null) {
3774 try {
3775 mService.enableSystemApp(admin, packageName);
3776 } catch (RemoteException e) {
3777 Log.w(TAG, "Failed to install package: " + packageName);
3778 }
3779 }
3780 }
3781
3782 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003783 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003784 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003785 *
3786 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3787 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3788 * intent will be re-enabled in the current profile.
3789 * @return int The number of activities that matched the intent and were installed.
3790 */
3791 public int enableSystemApp(ComponentName admin, Intent intent) {
3792 if (mService != null) {
3793 try {
3794 return mService.enableSystemAppWithIntent(admin, intent);
3795 } catch (RemoteException e) {
3796 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3797 }
3798 }
3799 return 0;
3800 }
3801
3802 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003803 * Called by a device owner or profile owner to disable account management for a specific type
3804 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003805 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003806 * <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 +01003807 * security exception will be thrown.
3808 *
3809 * <p>When account management is disabled for an account type, adding or removing an account
3810 * of that type will not be possible.
3811 *
3812 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3813 * @param accountType For which account management is disabled or enabled.
3814 * @param disabled The boolean indicating that account management will be disabled (true) or
3815 * enabled (false).
3816 */
3817 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3818 boolean disabled) {
3819 if (mService != null) {
3820 try {
3821 mService.setAccountManagementDisabled(admin, accountType, disabled);
3822 } catch (RemoteException e) {
3823 Log.w(TAG, "Failed talking with device policy service", e);
3824 }
3825 }
3826 }
3827
3828 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003829 * Gets the array of accounts for which account management is disabled by the profile owner.
3830 *
3831 * <p> Account management can be disabled/enabled by calling
3832 * {@link #setAccountManagementDisabled}.
3833 *
3834 * @return a list of account types for which account management has been disabled.
3835 *
3836 * @see #setAccountManagementDisabled
3837 */
3838 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003839 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003840 }
3841
3842 /**
3843 * @see #getAccountTypesWithManagementDisabled()
3844 * @hide
3845 */
3846 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003847 if (mService != null) {
3848 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003849 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003850 } catch (RemoteException e) {
3851 Log.w(TAG, "Failed talking with device policy service", e);
3852 }
3853 }
3854
3855 return null;
3856 }
justinzhang511e0d82014-03-24 16:09:24 -04003857
3858 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003859 * Sets which packages may enter lock task mode.
3860 *
3861 * <p>Any packages that shares uid with an allowed package will also be allowed
3862 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003863 *
Jason Monkc5185f22014-06-24 11:12:42 -04003864 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003865 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003867 *
3868 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003869 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3870 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003871 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003872 */
Jason Monk48aacba2014-08-13 16:29:08 -04003873 public void setLockTaskPackages(ComponentName admin, String[] packages)
3874 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003875 if (mService != null) {
3876 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003877 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003878 } catch (RemoteException e) {
3879 Log.w(TAG, "Failed talking with device policy service", e);
3880 }
3881 }
3882 }
3883
3884 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003885 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003886 *
3887 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003888 * @hide
3889 */
Jason Monk48aacba2014-08-13 16:29:08 -04003890 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003891 if (mService != null) {
3892 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003893 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003894 } catch (RemoteException e) {
3895 Log.w(TAG, "Failed talking with device policy service", e);
3896 }
3897 }
3898 return null;
3899 }
3900
3901 /**
3902 * This function lets the caller know whether the given component is allowed to start the
3903 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003904 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003905 */
Jason Monkd7b86212014-06-16 13:15:38 -04003906 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003907 if (mService != null) {
3908 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003909 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003910 } catch (RemoteException e) {
3911 Log.w(TAG, "Failed talking with device policy service", e);
3912 }
3913 }
3914 return false;
3915 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003916
3917 /**
3918 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3919 * 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 -04003920 * <p>The settings that can be updated with this method are:
3921 * <ul>
3922 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3923 * <li>{@link Settings.Global#AUTO_TIME}</li>
3924 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003925 * <li>{@link Settings.Global#BLUETOOTH_ON}
3926 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3927 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3928 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003929 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3930 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3931 * <li>{@link Settings.Global#MODE_RINGER}</li>
3932 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3933 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003934 * <li>{@link Settings.Global#WIFI_ON}
3935 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3936 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003937 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003938 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3939 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3940 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003941 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003942 *
3943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3944 * @param setting The name of the setting to update.
3945 * @param value The value to update the setting to.
3946 */
3947 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3948 if (mService != null) {
3949 try {
3950 mService.setGlobalSetting(admin, setting, value);
3951 } catch (RemoteException e) {
3952 Log.w(TAG, "Failed talking with device policy service", e);
3953 }
3954 }
3955 }
3956
3957 /**
3958 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3959 * that the value of the setting is in the correct form for the setting type should be performed
3960 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003961 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003962 * <ul>
3963 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003964 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003965 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3966 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003967 * <p>A device owner can additionally update the following settings:
3968 * <ul>
3969 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3970 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003971 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3972 * @param setting The name of the setting to update.
3973 * @param value The value to update the setting to.
3974 */
3975 public void setSecureSetting(ComponentName admin, String setting, String value) {
3976 if (mService != null) {
3977 try {
3978 mService.setSecureSetting(admin, setting, value);
3979 } catch (RemoteException e) {
3980 Log.w(TAG, "Failed talking with device policy service", e);
3981 }
3982 }
3983 }
3984
Amith Yamasanif20d6402014-05-24 15:34:37 -07003985 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003986 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003987 * making permission requests of a local or remote administrator of the user.
3988 * <p/>
3989 * Only a profile owner can designate the restrictions provider.
3990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003991 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003992 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003993 * it removes the restrictions provider previously assigned.
3994 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003995 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003996 if (mService != null) {
3997 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003998 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003999 } catch (RemoteException re) {
4000 Log.w(TAG, "Failed to set permission provider on device policy service");
4001 }
4002 }
4003 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004004
4005 /**
4006 * Called by profile or device owners to set the master volume mute on or off.
4007 *
4008 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4009 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4010 */
4011 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
4012 if (mService != null) {
4013 try {
4014 mService.setMasterVolumeMuted(admin, on);
4015 } catch (RemoteException re) {
4016 Log.w(TAG, "Failed to setMasterMute on device policy service");
4017 }
4018 }
4019 }
4020
4021 /**
4022 * Called by profile or device owners to check whether the master volume mute is on or off.
4023 *
4024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4025 * @return {@code true} if master volume is muted, {@code false} if it's not.
4026 */
4027 public boolean isMasterVolumeMuted(ComponentName admin) {
4028 if (mService != null) {
4029 try {
4030 return mService.isMasterVolumeMuted(admin);
4031 } catch (RemoteException re) {
4032 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4033 }
4034 }
4035 return false;
4036 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004037
4038 /**
4039 * Called by profile or device owners to change whether a user can uninstall
4040 * a package.
4041 *
4042 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4043 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004044 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004045 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004046 public void setUninstallBlocked(ComponentName admin, String packageName,
4047 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004048 if (mService != null) {
4049 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004050 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004051 } catch (RemoteException re) {
4052 Log.w(TAG, "Failed to call block uninstall on device policy service");
4053 }
4054 }
4055 }
4056
4057 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004058 * Check whether the current user has been blocked by device policy from uninstalling a package.
4059 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004060 * <p>
4061 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
4062 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
4063 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
4064 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004065 *
Rubin Xua97855b2014-11-07 05:41:00 +00004066 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00004067 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004068 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004069 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004070 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01004071 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004072 if (mService != null) {
4073 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004074 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004075 } catch (RemoteException re) {
4076 Log.w(TAG, "Failed to call block uninstall on device policy service");
4077 }
4078 }
4079 return false;
4080 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004081
4082 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004083 * Called by the profile owner of a managed profile to enable widget providers from a
4084 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004085 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004086 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004087 * a package may have zero or more provider components, where each component
4088 * provides a different widget type.
4089 * <p>
4090 * <strong>Note:</strong> By default no widget provider package is white-listed.
4091 * </p>
4092 *
4093 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4094 * @param packageName The package from which widget providers are white-listed.
4095 * @return Whether the package was added.
4096 *
4097 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4098 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4099 */
4100 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4101 if (mService != null) {
4102 try {
4103 return mService.addCrossProfileWidgetProvider(admin, packageName);
4104 } catch (RemoteException re) {
4105 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4106 }
4107 }
4108 return false;
4109 }
4110
4111 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004112 * Called by the profile owner of a managed profile to disable widget providers from a given
4113 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004114 * package should have been added via {@link #addCrossProfileWidgetProvider(
4115 * android.content.ComponentName, String)}.
4116 * <p>
4117 * <strong>Note:</strong> By default no widget provider package is white-listed.
4118 * </p>
4119 *
4120 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4121 * @param packageName The package from which widget providers are no longer
4122 * white-listed.
4123 * @return Whether the package was removed.
4124 *
4125 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4126 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4127 */
4128 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4129 if (mService != null) {
4130 try {
4131 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4132 } catch (RemoteException re) {
4133 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4134 }
4135 }
4136 return false;
4137 }
4138
4139 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004140 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004141 * available in the parent profile.
4142 *
4143 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4144 * @return The white-listed package list.
4145 *
4146 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4147 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4148 */
4149 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
4150 if (mService != null) {
4151 try {
4152 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4153 if (providers != null) {
4154 return providers;
4155 }
4156 } catch (RemoteException re) {
4157 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4158 }
4159 }
4160 return Collections.emptyList();
4161 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004162
4163 /**
4164 * Called by profile or device owners to set the current user's photo.
4165 *
4166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4167 * @param icon the bitmap to set as the photo.
4168 */
4169 public void setUserIcon(ComponentName admin, Bitmap icon) {
4170 try {
4171 mService.setUserIcon(admin, icon);
4172 } catch (RemoteException re) {
4173 Log.w(TAG, "Could not set the user icon ", re);
4174 }
4175 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004176
4177 /**
4178 * Called by device initializer to send a provisioning status update to the remote setup device.
4179 *
4180 * @param statusCode a custom status code value as defined by
4181 * {@link DeviceInitializerStatus#isCustomStatus(int)}.
4182 * @param description custom description of the status code sent
4183 */
4184 public void sendDeviceInitializerStatus(int statusCode, String description) {
4185 try {
4186 mService.sendDeviceInitializerStatus(statusCode, description);
4187 } catch (RemoteException re) {
4188 Log.w(TAG, "Could not send device initializer status", re);
4189 }
4190 }
Rubin Xu8027a4f2015-03-10 17:52:37 +00004191
4192 /*
4193 * Called by device owners to set a local OTA update policy. When a new OTA policy is set,
4194 * {@link #ACTION_OTA_POLICY_CHANGED} is broadcasted.
4195 *
4196 * @param who Which {@link DeviceAdminReceiver} this request is associated with. All components
4197 * in the device owner package can set OTA policies and the most recent policy takes effect.
4198 * @param policy the new OTA policy, or null to clear the current policy.
4199 * @see OtaPolicy
4200 */
4201 public void setOtaPolicy(ComponentName who, OtaPolicy policy) {
4202 if (mService != null) {
4203 try {
4204 if (policy != null) {
4205 mService.setOtaPolicy(who, policy.getPolicyBundle());
4206 } else {
4207 mService.setOtaPolicy(who, null);
4208 }
4209 } catch (RemoteException re) {
4210 Log.w(TAG, "Error calling setOtaPolicy", re);
4211 }
4212 }
4213 }
4214
4215 /**
4216 * Retrieve a local OTA update policy set previously by {@link #setOtaPolicy}.
4217 *
4218 * @return The current OTA policy object, or null if no policy is set or the system does not
4219 * support managed OTA.
4220 */
4221 public OtaPolicy getOtaPolicy() {
4222 if (mService != null) {
4223 try {
4224 PersistableBundle bundle = mService.getOtaPolicy();
4225 if (bundle != null) {
4226 return new OtaPolicy(bundle);
4227 } else {
4228 return null;
4229 }
4230 } catch (RemoteException re) {
4231 Log.w(TAG, "Error calling getOtaPolicy", re);
4232 }
4233 }
4234 return null;
4235 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004236
4237 /**
4238 * Called by a device owner to disable the keyguard altogether.
4239 *
4240 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4241 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4242 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4243 * being disabled.
4244 *
4245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4246 * @param enabled New state of the keyguard.
4247 *
4248 * @return {@code false} if attempting to disable the keyguard while a lock password was in
4249 * place. {@code true} otherwise."
4250 */
4251 public boolean setKeyguardEnabledState(ComponentName admin, boolean enabled) {
4252 try {
4253 return mService.setKeyguardEnabledState(admin, enabled);
4254 } catch (RemoteException re) {
4255 Log.w(TAG, "Failed talking with device policy service", re);
4256 return false;
4257 }
4258 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004259}