blob: 9e2da61c70f3190c592521c0cf792cd3b815882d [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 Xu5faad8e2015-04-20 17:43:48 +0100803 * Broadcast action: notify that a new local system update policy has been set by the device
804 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000805 */
806 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100807 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
808 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000809
810
811 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800812 * Return true if the given administrator component is currently
813 * active (enabled) in the system.
814 */
815 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100816 return isAdminActiveAsUser(who, UserHandle.myUserId());
817 }
818
819 /**
820 * @see #isAdminActive(ComponentName)
821 * @hide
822 */
823 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800824 if (mService != null) {
825 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100826 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 } catch (RemoteException e) {
828 Log.w(TAG, "Failed talking with device policy service", e);
829 }
830 }
831 return false;
832 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800833 /**
834 * Return true if the given administrator component is currently being removed
835 * for the user.
836 * @hide
837 */
838 public boolean isRemovingAdmin(ComponentName who, int userId) {
839 if (mService != null) {
840 try {
841 return mService.isRemovingAdmin(who, userId);
842 } catch (RemoteException e) {
843 Log.w(TAG, "Failed talking with device policy service", e);
844 }
845 }
846 return false;
847 }
848
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700849
Dianne Hackbornd6847842010-01-12 18:14:19 -0800850 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800851 * Return a list of all currently active device administrator's component
852 * names. Note that if there are no administrators than null may be
853 * returned.
854 */
855 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100856 return getActiveAdminsAsUser(UserHandle.myUserId());
857 }
858
859 /**
860 * @see #getActiveAdmins()
861 * @hide
862 */
863 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800864 if (mService != null) {
865 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100866 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800867 } catch (RemoteException e) {
868 Log.w(TAG, "Failed talking with device policy service", e);
869 }
870 }
871 return null;
872 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700873
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800874 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700875 * Used by package administration code to determine if a package can be stopped
876 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800877 * @hide
878 */
879 public boolean packageHasActiveAdmins(String packageName) {
880 if (mService != null) {
881 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700882 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800883 } catch (RemoteException e) {
884 Log.w(TAG, "Failed talking with device policy service", e);
885 }
886 }
887 return false;
888 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700889
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800890 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800891 * Remove a current administration component. This can only be called
892 * by the application that owns the administration component; if you
893 * try to remove someone else's component, a security exception will be
894 * thrown.
895 */
896 public void removeActiveAdmin(ComponentName who) {
897 if (mService != null) {
898 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700899 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800900 } catch (RemoteException e) {
901 Log.w(TAG, "Failed talking with device policy service", e);
902 }
903 }
904 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700905
Dianne Hackbornd6847842010-01-12 18:14:19 -0800906 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800907 * Returns true if an administrator has been granted a particular device policy. This can
908 * be used to check if the administrator was activated under an earlier set of policies,
909 * but requires additional policies after an upgrade.
910 *
911 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
912 * an active administrator, or an exception will be thrown.
913 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
914 */
915 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
916 if (mService != null) {
917 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700918 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800919 } catch (RemoteException e) {
920 Log.w(TAG, "Failed talking with device policy service", e);
921 }
922 }
923 return false;
924 }
925
926 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800927 * Constant for {@link #setPasswordQuality}: the policy has no requirements
928 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800929 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800930 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800931 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700932
Dianne Hackbornd6847842010-01-12 18:14:19 -0800933 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700934 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
935 * recognition technology. This implies technologies that can recognize the identity of
936 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
937 * Note that quality constants are ordered so that higher values are more restrictive.
938 */
939 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
940
941 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800942 * Constant for {@link #setPasswordQuality}: the policy requires some kind
943 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800944 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800945 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800946 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700947
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800948 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800949 * Constant for {@link #setPasswordQuality}: the user must have entered a
950 * password containing at least numeric characters. Note that quality
951 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800952 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800953 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700954
Dianne Hackbornd6847842010-01-12 18:14:19 -0800955 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800956 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800957 * password containing at least numeric characters with no repeating (4444)
958 * or ordered (1234, 4321, 2468) sequences. Note that quality
959 * constants are ordered so that higher values are more restrictive.
960 */
961 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
962
963 /**
964 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700965 * password containing at least alphabetic (or other symbol) characters.
966 * Note that quality constants are ordered so that higher values are more
967 * restrictive.
968 */
969 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700970
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700971 /**
972 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800973 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700974 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800975 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800976 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700977 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700978
Dianne Hackbornd6847842010-01-12 18:14:19 -0800979 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700980 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700981 * password containing at least a letter, a numerical digit and a special
982 * symbol, by default. With this password quality, passwords can be
983 * restricted to contain various sets of characters, like at least an
984 * uppercase letter, etc. These are specified using various methods,
985 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
986 * that quality constants are ordered so that higher values are more
987 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700988 */
989 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
990
991 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800992 * Called by an application that is administering the device to set the
993 * password restrictions it is imposing. After setting this, the user
994 * will not be able to enter a new password that is not at least as
995 * restrictive as what has been set. Note that the current password
996 * will remain until the user has set a new one, so the change does not
997 * take place immediately. To prompt the user for a new password, use
998 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700999 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001000 * <p>Quality constants are ordered so that higher values are more restrictive;
1001 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001002 * the user's preference, and any other considerations) is the one that
1003 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001004 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001005 * <p>The calling device admin must have requested
1006 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1007 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001008 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001009 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001010 * @param quality The new desired quality. One of
1011 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001012 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1013 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1014 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001015 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001016 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001017 if (mService != null) {
1018 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001019 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001020 } catch (RemoteException e) {
1021 Log.w(TAG, "Failed talking with device policy service", e);
1022 }
1023 }
1024 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001025
Dianne Hackbornd6847842010-01-12 18:14:19 -08001026 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001027 * Retrieve the current minimum password quality for all admins of this user
1028 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001029 * @param admin The name of the admin component to check, or null to aggregate
1030 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001031 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001032 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001033 return getPasswordQuality(admin, UserHandle.myUserId());
1034 }
1035
1036 /** @hide per-user version */
1037 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001038 if (mService != null) {
1039 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001040 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001041 } catch (RemoteException e) {
1042 Log.w(TAG, "Failed talking with device policy service", e);
1043 }
1044 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001045 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001046 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001047
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001049 * Called by an application that is administering the device to set the
1050 * minimum allowed password length. After setting this, the user
1051 * will not be able to enter a new password that is not at least as
1052 * restrictive as what has been set. Note that the current password
1053 * will remain until the user has set a new one, so the change does not
1054 * take place immediately. To prompt the user for a new password, use
1055 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1056 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001057 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1058 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1059 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001060 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001061 * <p>The calling device admin must have requested
1062 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1063 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001064 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001065 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001066 * @param length The new desired minimum password length. A value of 0
1067 * means there is no restriction.
1068 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001069 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001070 if (mService != null) {
1071 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001072 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 } catch (RemoteException e) {
1074 Log.w(TAG, "Failed talking with device policy service", e);
1075 }
1076 }
1077 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001080 * Retrieve the current minimum password length for all admins of this
1081 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001082 * @param admin The name of the admin component to check, or null to aggregate
1083 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001084 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001085 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001086 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1087 }
1088
1089 /** @hide per-user version */
1090 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001091 if (mService != null) {
1092 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001093 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001094 } catch (RemoteException e) {
1095 Log.w(TAG, "Failed talking with device policy service", e);
1096 }
1097 }
1098 return 0;
1099 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001100
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001101 /**
1102 * Called by an application that is administering the device to set the
1103 * minimum number of upper case letters required in the password. After
1104 * setting this, the user will not be able to enter a new password that is
1105 * not at least as restrictive as what has been set. Note that the current
1106 * password will remain until the user has set a new one, so the change does
1107 * not take place immediately. To prompt the user for a new password, use
1108 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1109 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001110 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1111 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001112 * <p>
1113 * The calling device admin must have requested
1114 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1115 * this method; if it has not, a security exception will be thrown.
1116 *
1117 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1118 * with.
1119 * @param length The new desired minimum number of upper case letters
1120 * required in the password. A value of 0 means there is no
1121 * restriction.
1122 */
1123 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
1124 if (mService != null) {
1125 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001126 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001127 } catch (RemoteException e) {
1128 Log.w(TAG, "Failed talking with device policy service", e);
1129 }
1130 }
1131 }
1132
1133 /**
1134 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001135 * password for all admins of this user and its profiles or a particular one.
1136 * This is the same value as set by
1137 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001138 * and only applies when the password quality is
1139 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001140 *
1141 * @param admin The name of the admin component to check, or null to
1142 * aggregate all admins.
1143 * @return The minimum number of upper case letters required in the
1144 * password.
1145 */
1146 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001147 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1148 }
1149
1150 /** @hide per-user version */
1151 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001152 if (mService != null) {
1153 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001154 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001155 } catch (RemoteException e) {
1156 Log.w(TAG, "Failed talking with device policy service", e);
1157 }
1158 }
1159 return 0;
1160 }
1161
1162 /**
1163 * Called by an application that is administering the device to set the
1164 * minimum number of lower case letters required in the password. After
1165 * setting this, the user will not be able to enter a new password that is
1166 * not at least as restrictive as what has been set. Note that the current
1167 * password will remain until the user has set a new one, so the change does
1168 * not take place immediately. To prompt the user for a new password, use
1169 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1170 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001171 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1172 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001173 * <p>
1174 * The calling device admin must have requested
1175 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1176 * this method; if it has not, a security exception will be thrown.
1177 *
1178 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1179 * with.
1180 * @param length The new desired minimum number of lower case letters
1181 * required in the password. A value of 0 means there is no
1182 * restriction.
1183 */
1184 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
1185 if (mService != null) {
1186 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001187 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 } catch (RemoteException e) {
1189 Log.w(TAG, "Failed talking with device policy service", e);
1190 }
1191 }
1192 }
1193
1194 /**
1195 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001196 * password for all admins of this user and its profiles or a particular one.
1197 * This is the same value as set by
1198 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001199 * and only applies when the password quality is
1200 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001201 *
1202 * @param admin The name of the admin component to check, or null to
1203 * aggregate all admins.
1204 * @return The minimum number of lower case letters required in the
1205 * password.
1206 */
1207 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001208 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1209 }
1210
1211 /** @hide per-user version */
1212 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001213 if (mService != null) {
1214 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001215 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001216 } catch (RemoteException e) {
1217 Log.w(TAG, "Failed talking with device policy service", e);
1218 }
1219 }
1220 return 0;
1221 }
1222
1223 /**
1224 * Called by an application that is administering the device to set the
1225 * minimum number of letters required in the password. After setting this,
1226 * the user will not be able to enter a new password that is not at least as
1227 * restrictive as what has been set. Note that the current password will
1228 * remain until the user has set a new one, so the change does not take
1229 * place immediately. To prompt the user for a new password, use
1230 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1231 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001232 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1233 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001234 * <p>
1235 * The calling device admin must have requested
1236 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1237 * this method; if it has not, a security exception will be thrown.
1238 *
1239 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1240 * with.
1241 * @param length The new desired minimum number of letters required in the
1242 * password. A value of 0 means there is no restriction.
1243 */
1244 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1245 if (mService != null) {
1246 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001247 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001248 } catch (RemoteException e) {
1249 Log.w(TAG, "Failed talking with device policy service", e);
1250 }
1251 }
1252 }
1253
1254 /**
1255 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001256 * admins or a particular one. This is the same value as
1257 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1258 * and only applies when the password quality is
1259 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001260 *
1261 * @param admin The name of the admin component to check, or null to
1262 * aggregate all admins.
1263 * @return The minimum number of letters required in the password.
1264 */
1265 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001266 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1267 }
1268
1269 /** @hide per-user version */
1270 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001271 if (mService != null) {
1272 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001273 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001274 } catch (RemoteException e) {
1275 Log.w(TAG, "Failed talking with device policy service", e);
1276 }
1277 }
1278 return 0;
1279 }
1280
1281 /**
1282 * Called by an application that is administering the device to set the
1283 * minimum number of numerical digits required in the password. After
1284 * setting this, the user will not be able to enter a new password that is
1285 * not at least as restrictive as what has been set. Note that the current
1286 * password will remain until the user has set a new one, so the change does
1287 * not take place immediately. To prompt the user for a new password, use
1288 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1289 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001290 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1291 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001292 * <p>
1293 * The calling device admin must have requested
1294 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1295 * this method; if it has not, a security exception will be thrown.
1296 *
1297 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1298 * with.
1299 * @param length The new desired minimum number of numerical digits required
1300 * in the password. A value of 0 means there is no restriction.
1301 */
1302 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1303 if (mService != null) {
1304 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001305 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001306 } catch (RemoteException e) {
1307 Log.w(TAG, "Failed talking with device policy service", e);
1308 }
1309 }
1310 }
1311
1312 /**
1313 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001314 * for all admins of this user and its profiles or a particular one.
1315 * This is the same value as set by
1316 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001317 * and only applies when the password quality is
1318 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001319 *
1320 * @param admin The name of the admin component to check, or null to
1321 * aggregate all admins.
1322 * @return The minimum number of numerical digits required in the password.
1323 */
1324 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001325 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1326 }
1327
1328 /** @hide per-user version */
1329 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001330 if (mService != null) {
1331 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001332 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001333 } catch (RemoteException e) {
1334 Log.w(TAG, "Failed talking with device policy service", e);
1335 }
1336 }
1337 return 0;
1338 }
1339
1340 /**
1341 * Called by an application that is administering the device to set the
1342 * minimum number of symbols required in the password. After setting this,
1343 * the user will not be able to enter a new password that is not at least as
1344 * restrictive as what has been set. Note that the current password will
1345 * remain until the user has set a new one, so the change does not take
1346 * place immediately. To prompt the user for a new password, use
1347 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1348 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001349 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1350 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001351 * <p>
1352 * The calling device admin must have requested
1353 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1354 * this method; if it has not, a security exception will be thrown.
1355 *
1356 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1357 * with.
1358 * @param length The new desired minimum number of symbols required in the
1359 * password. A value of 0 means there is no restriction.
1360 */
1361 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1362 if (mService != null) {
1363 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001364 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001365 } catch (RemoteException e) {
1366 Log.w(TAG, "Failed talking with device policy service", e);
1367 }
1368 }
1369 }
1370
1371 /**
1372 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001373 * admins or a particular one. This is the same value as
1374 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1375 * and only applies when the password quality is
1376 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001377 *
1378 * @param admin The name of the admin component to check, or null to
1379 * aggregate all admins.
1380 * @return The minimum number of symbols required in the password.
1381 */
1382 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001383 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1384 }
1385
1386 /** @hide per-user version */
1387 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001388 if (mService != null) {
1389 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001390 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001391 } catch (RemoteException e) {
1392 Log.w(TAG, "Failed talking with device policy service", e);
1393 }
1394 }
1395 return 0;
1396 }
1397
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001398 /**
1399 * Called by an application that is administering the device to set the
1400 * minimum number of non-letter characters (numerical digits or symbols)
1401 * required in the password. After setting this, the user will not be able
1402 * to enter a new password that is not at least as restrictive as what has
1403 * been set. Note that the current password will remain until the user has
1404 * set a new one, so the change does not take place immediately. To prompt
1405 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1406 * setting this value. This constraint is only imposed if the administrator
1407 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1408 * {@link #setPasswordQuality}. The default value is 0.
1409 * <p>
1410 * The calling device admin must have requested
1411 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1412 * this method; if it has not, a security exception will be thrown.
1413 *
1414 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1415 * with.
1416 * @param length The new desired minimum number of letters required in the
1417 * password. A value of 0 means there is no restriction.
1418 */
1419 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1420 if (mService != null) {
1421 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001422 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001423 } catch (RemoteException e) {
1424 Log.w(TAG, "Failed talking with device policy service", e);
1425 }
1426 }
1427 }
1428
1429 /**
1430 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001431 * password for all admins of this user and its profiles or a particular one.
1432 * This is the same value as set by
1433 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001434 * and only applies when the password quality is
1435 * {@link #PASSWORD_QUALITY_COMPLEX}.
1436 *
1437 * @param admin The name of the admin component to check, or null to
1438 * aggregate all admins.
1439 * @return The minimum number of letters required in the password.
1440 */
1441 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001442 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1443 }
1444
1445 /** @hide per-user version */
1446 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001447 if (mService != null) {
1448 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001449 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001450 } catch (RemoteException e) {
1451 Log.w(TAG, "Failed talking with device policy service", e);
1452 }
1453 }
1454 return 0;
1455 }
1456
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001457 /**
1458 * Called by an application that is administering the device to set the length
1459 * of the password history. After setting this, the user will not be able to
1460 * enter a new password that is the same as any password in the history. Note
1461 * that the current password will remain until the user has set a new one, so
1462 * the change does not take place immediately. To prompt the user for a new
1463 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1464 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001465 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1466 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1467 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001468 *
1469 * <p>
1470 * The calling device admin must have requested
1471 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1472 * method; if it has not, a security exception will be thrown.
1473 *
1474 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1475 * with.
1476 * @param length The new desired length of password history. A value of 0
1477 * means there is no restriction.
1478 */
1479 public void setPasswordHistoryLength(ComponentName admin, int length) {
1480 if (mService != null) {
1481 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001482 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001483 } catch (RemoteException e) {
1484 Log.w(TAG, "Failed talking with device policy service", e);
1485 }
1486 }
1487 }
1488
1489 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001490 * Called by a device admin to set the password expiration timeout. Calling this method
1491 * will restart the countdown for password expiration for the given admin, as will changing
1492 * the device password (for all admins).
1493 *
1494 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1495 * For example, to have the password expire 5 days from now, timeout would be
1496 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1497 *
1498 * <p>To disable password expiration, a value of 0 may be used for timeout.
1499 *
Jim Millera4e28d12010-11-08 16:15:47 -08001500 * <p>The calling device admin must have requested
1501 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1502 * method; if it has not, a security exception will be thrown.
1503 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001504 * <p> Note that setting the password will automatically reset the expiration time for all
1505 * active admins. Active admins do not need to explicitly call this method in that case.
1506 *
Jim Millera4e28d12010-11-08 16:15:47 -08001507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1508 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1509 * means there is no restriction (unlimited).
1510 */
1511 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1512 if (mService != null) {
1513 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001514 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001515 } catch (RemoteException e) {
1516 Log.w(TAG, "Failed talking with device policy service", e);
1517 }
1518 }
1519 }
1520
1521 /**
Jim Miller6b857682011-02-16 16:27:41 -08001522 * Get the password expiration timeout for the given admin. The expiration timeout is the
1523 * recurring expiration timeout provided in the call to
1524 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1525 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001526 *
1527 * @param admin The name of the admin component to check, or null to aggregate all admins.
1528 * @return The timeout for the given admin or the minimum of all timeouts
1529 */
1530 public long getPasswordExpirationTimeout(ComponentName admin) {
1531 if (mService != null) {
1532 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001533 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001534 } catch (RemoteException e) {
1535 Log.w(TAG, "Failed talking with device policy service", e);
1536 }
1537 }
1538 return 0;
1539 }
1540
1541 /**
1542 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001543 * all admins of this user and its profiles if admin is null. If the password is
1544 * expired, this will return the time since the password expired as a negative number.
1545 * If admin is null, then a composite of all expiration timeouts is returned
1546 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001547 *
1548 * @param admin The name of the admin component to check, or null to aggregate all admins.
1549 * @return The password expiration time, in ms.
1550 */
1551 public long getPasswordExpiration(ComponentName admin) {
1552 if (mService != null) {
1553 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001554 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001555 } catch (RemoteException e) {
1556 Log.w(TAG, "Failed talking with device policy service", e);
1557 }
1558 }
1559 return 0;
1560 }
1561
1562 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001563 * Retrieve the current password history length for all admins of this
1564 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001565 * @param admin The name of the admin component to check, or null to aggregate
1566 * all admins.
1567 * @return The length of the password history
1568 */
1569 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001570 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1571 }
1572
1573 /** @hide per-user version */
1574 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001575 if (mService != null) {
1576 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001577 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001578 } catch (RemoteException e) {
1579 Log.w(TAG, "Failed talking with device policy service", e);
1580 }
1581 }
1582 return 0;
1583 }
1584
Dianne Hackbornd6847842010-01-12 18:14:19 -08001585 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001586 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001587 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001588 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001589 * @return Returns the maximum length that the user can enter.
1590 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001591 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001592 // Kind-of arbitrary.
1593 return 16;
1594 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001595
Dianne Hackborn254cb442010-01-27 19:23:59 -08001596 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001597 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001598 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001599 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001600 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001601 * <p>The calling device admin must have requested
1602 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1603 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001604 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001605 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001606 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001607 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001608 if (mService != null) {
1609 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001610 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001611 } catch (RemoteException e) {
1612 Log.w(TAG, "Failed talking with device policy service", e);
1613 }
1614 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001615 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001616 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001617
Dianne Hackbornd6847842010-01-12 18:14:19 -08001618 /**
1619 * Retrieve the number of times the user has failed at entering a
1620 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001621 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001622 * <p>The calling device admin must have requested
1623 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1624 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001625 */
1626 public int getCurrentFailedPasswordAttempts() {
1627 if (mService != null) {
1628 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001629 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001630 } catch (RemoteException e) {
1631 Log.w(TAG, "Failed talking with device policy service", e);
1632 }
1633 }
1634 return -1;
1635 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001636
1637 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001638 * Queries whether {@link #DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
1639 *
1640 * @return true if DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
1641 * @hide
1642 */
1643 public boolean getDoNotAskCredentialsOnBoot() {
1644 if (mService != null) {
1645 try {
1646 return mService.getDoNotAskCredentialsOnBoot();
1647 } catch (RemoteException e) {
1648 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1649 }
1650 }
1651 return false;
1652 }
1653
1654 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001655 * Setting this to a value greater than zero enables a built-in policy
1656 * that will perform a device wipe after too many incorrect
1657 * device-unlock passwords have been entered. This built-in policy combines
1658 * watching for failed passwords and wiping the device, and requires
1659 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001660 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001661 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001662 * <p>To implement any other policy (e.g. wiping data for a particular
1663 * application only, erasing or revoking credentials, or reporting the
1664 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001665 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001666 * instead. Do not use this API, because if the maximum count is reached,
1667 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001668 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001669 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001670 * @param num The number of failed password attempts at which point the
1671 * device will wipe its data.
1672 */
1673 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1674 if (mService != null) {
1675 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001676 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001677 } catch (RemoteException e) {
1678 Log.w(TAG, "Failed talking with device policy service", e);
1679 }
1680 }
1681 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001682
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001683 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001684 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001685 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001686 * or a particular one.
1687 * @param admin The name of the admin component to check, or null to aggregate
1688 * all admins.
1689 */
1690 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001691 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1692 }
1693
1694 /** @hide per-user version */
1695 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001696 if (mService != null) {
1697 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001698 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001699 } catch (RemoteException e) {
1700 Log.w(TAG, "Failed talking with device policy service", e);
1701 }
1702 }
1703 return 0;
1704 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001705
Dianne Hackborn254cb442010-01-27 19:23:59 -08001706 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001707 * Returns the profile with the smallest maximum failed passwords for wipe,
1708 * for the given user. So for primary user, it might return the primary or
1709 * a managed profile. For a secondary user, it would be the same as the
1710 * user passed in.
1711 * @hide Used only by Keyguard
1712 */
1713 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1714 if (mService != null) {
1715 try {
1716 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1717 } catch (RemoteException e) {
1718 Log.w(TAG, "Failed talking with device policy service", e);
1719 }
1720 }
1721 return UserHandle.USER_NULL;
1722 }
1723
1724 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001725 * Flag for {@link #resetPassword}: don't allow other admins to change
1726 * the password again until the user has entered it.
1727 */
1728 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001729
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001730 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001731 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1732 * If the flag is set, the device can be booted without asking for user password.
1733 * The absence of this flag does not change the current boot requirements. This flag
1734 * can be set by the device owner only. If the app is not the device owner, the flag
1735 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1736 * device to factory defaults.
1737 */
1738 public static final int DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
1739
1740 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001741 * Force a new device unlock password (the password needed to access the
1742 * entire device, not for individual accounts) on the user. This takes
1743 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001744 * The given password must be sufficient for the
1745 * current password quality and length constraints as returned by
1746 * {@link #getPasswordQuality(ComponentName)} and
1747 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1748 * these constraints, then it will be rejected and false returned. Note
1749 * that the password may be a stronger quality (containing alphanumeric
1750 * characters when the requested quality is only numeric), in which case
1751 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001752 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001753 * <p>Calling with a null or empty password will clear any existing PIN,
1754 * pattern or password if the current password constraints allow it.
1755 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001756 * <p>The calling device admin must have requested
1757 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1758 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001759 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001760 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001761 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001762 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001763 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
1764 * {@link #DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001765 * @return Returns true if the password was applied, or false if it is
1766 * not acceptable for the current constraints.
1767 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001768 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001769 if (mService != null) {
1770 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001771 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001772 } catch (RemoteException e) {
1773 Log.w(TAG, "Failed talking with device policy service", e);
1774 }
1775 }
1776 return false;
1777 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001778
Dianne Hackbornd6847842010-01-12 18:14:19 -08001779 /**
1780 * Called by an application that is administering the device to set the
1781 * maximum time for user activity until the device will lock. This limits
1782 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001783 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001784 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001785 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001786 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001787 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001788 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001789 * @param timeMs The new desired maximum time to lock in milliseconds.
1790 * A value of 0 means there is no restriction.
1791 */
1792 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1793 if (mService != null) {
1794 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001795 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001796 } catch (RemoteException e) {
1797 Log.w(TAG, "Failed talking with device policy service", e);
1798 }
1799 }
1800 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001801
Dianne Hackbornd6847842010-01-12 18:14:19 -08001802 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001803 * Retrieve the current maximum time to unlock for all admins of this user
1804 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001805 * @param admin The name of the admin component to check, or null to aggregate
1806 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001807 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001808 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001809 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001810 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001811 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1812 }
1813
1814 /** @hide per-user version */
1815 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001816 if (mService != null) {
1817 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001818 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001819 } catch (RemoteException e) {
1820 Log.w(TAG, "Failed talking with device policy service", e);
1821 }
1822 }
1823 return 0;
1824 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001825
Dianne Hackbornd6847842010-01-12 18:14:19 -08001826 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001827 * Make the device lock immediately, as if the lock screen timeout has
1828 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001829 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001830 * <p>The calling device admin must have requested
1831 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1832 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001833 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001834 public void lockNow() {
1835 if (mService != null) {
1836 try {
1837 mService.lockNow();
1838 } catch (RemoteException e) {
1839 Log.w(TAG, "Failed talking with device policy service", e);
1840 }
1841 }
1842 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001843
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001845 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001846 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001847 */
1848 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1849
1850 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001851 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1852 * data.
1853 *
Paul Crowley2934b262014-12-02 11:21:13 +00001854 * <p>This flag may only be set by device owner admins; if it is set by
1855 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001856 */
1857 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1858
1859 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001860 * Ask the user data be wiped. Wiping the primary user will cause the
1861 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001862 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001863 * <p>The calling device admin must have requested
1864 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1865 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001866 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001867 * @param flags Bit mask of additional options: currently supported flags
1868 * are {@link #WIPE_EXTERNAL_STORAGE} and
1869 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001870 */
1871 public void wipeData(int flags) {
1872 if (mService != null) {
1873 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001874 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001875 } catch (RemoteException e) {
1876 Log.w(TAG, "Failed talking with device policy service", e);
1877 }
1878 }
1879 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001880
Dianne Hackbornd6847842010-01-12 18:14:19 -08001881 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001882 * Called by an application that is administering the device to set the
1883 * global proxy and exclusion list.
1884 * <p>
1885 * The calling device admin must have requested
1886 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1887 * this method; if it has not, a security exception will be thrown.
1888 * Only the first device admin can set the proxy. If a second admin attempts
1889 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1890 * proxy will be returned. If successful in setting the proxy, null will
1891 * be returned.
1892 * The method can be called repeatedly by the device admin alrady setting the
1893 * proxy to update the proxy and exclusion list.
1894 *
1895 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1896 * with.
1897 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1898 * Pass Proxy.NO_PROXY to reset the proxy.
1899 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001900 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1901 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001902 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001903 */
1904 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1905 List<String> exclusionList ) {
1906 if (proxySpec == null) {
1907 throw new NullPointerException();
1908 }
1909 if (mService != null) {
1910 try {
1911 String hostSpec;
1912 String exclSpec;
1913 if (proxySpec.equals(Proxy.NO_PROXY)) {
1914 hostSpec = null;
1915 exclSpec = null;
1916 } else {
1917 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1918 throw new IllegalArgumentException();
1919 }
1920 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1921 String hostName = sa.getHostName();
1922 int port = sa.getPort();
1923 StringBuilder hostBuilder = new StringBuilder();
1924 hostSpec = hostBuilder.append(hostName)
1925 .append(":").append(Integer.toString(port)).toString();
1926 if (exclusionList == null) {
1927 exclSpec = "";
1928 } else {
1929 StringBuilder listBuilder = new StringBuilder();
1930 boolean firstDomain = true;
1931 for (String exclDomain : exclusionList) {
1932 if (!firstDomain) {
1933 listBuilder = listBuilder.append(",");
1934 } else {
1935 firstDomain = false;
1936 }
1937 listBuilder = listBuilder.append(exclDomain.trim());
1938 }
1939 exclSpec = listBuilder.toString();
1940 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001941 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1942 != android.net.Proxy.PROXY_VALID)
1943 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001944 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001945 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001946 } catch (RemoteException e) {
1947 Log.w(TAG, "Failed talking with device policy service", e);
1948 }
1949 }
1950 return null;
1951 }
1952
1953 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001954 * Set a network-independent global HTTP proxy. This is not normally what you want
1955 * for typical HTTP proxies - they are generally network dependent. However if you're
1956 * doing something unusual like general internal filtering this may be useful. On
1957 * a private network where the proxy is not accessible, you may break HTTP using this.
1958 *
1959 * <p>This method requires the caller to be the device owner.
1960 *
1961 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1962 * @see ProxyInfo
1963 *
1964 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1965 * with.
1966 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1967 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1968 */
1969 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1970 if (mService != null) {
1971 try {
1972 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1973 } catch (RemoteException e) {
1974 Log.w(TAG, "Failed talking with device policy service", e);
1975 }
1976 }
1977 }
1978
1979 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001980 * Returns the component name setting the global proxy.
1981 * @return ComponentName object of the device admin that set the global proxy, or
1982 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001983 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001984 */
1985 public ComponentName getGlobalProxyAdmin() {
1986 if (mService != null) {
1987 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001988 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001989 } catch (RemoteException e) {
1990 Log.w(TAG, "Failed talking with device policy service", e);
1991 }
1992 }
1993 return null;
1994 }
1995
1996 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001997 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001998 * indicating that encryption is not supported.
1999 */
2000 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2001
2002 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002003 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002004 * indicating that encryption is supported, but is not currently active.
2005 */
2006 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2007
2008 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002009 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002010 * indicating that encryption is not currently active, but is currently
2011 * being activated. This is only reported by devices that support
2012 * encryption of data and only when the storage is currently
2013 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2014 * to become encrypted will never return this value.
2015 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002016 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002017
2018 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002019 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002020 * indicating that encryption is active.
2021 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002022 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002023
2024 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002025 * Result code for {@link #getStorageEncryptionStatus}:
2026 * indicating that encryption is active, but an encryption key has not
2027 * been set by the user.
2028 */
2029 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2030
2031 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002032 * Activity action: begin the process of encrypting data on the device. This activity should
2033 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2034 * After resuming from this activity, use {@link #getStorageEncryption}
2035 * to check encryption status. However, on some devices this activity may never return, as
2036 * it may trigger a reboot and in some cases a complete data wipe of the device.
2037 */
2038 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2039 public static final String ACTION_START_ENCRYPTION
2040 = "android.app.action.START_ENCRYPTION";
2041
2042 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002043 * Widgets are enabled in keyguard
2044 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002045 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002046
2047 /**
Jim Miller50e62182014-04-23 17:25:00 -07002048 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002049 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002050 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2051
2052 /**
2053 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2054 */
2055 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2056
2057 /**
Jim Miller50e62182014-04-23 17:25:00 -07002058 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2059 */
2060 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2061
2062 /**
2063 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2064 */
2065 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2066
2067 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002068 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002069 * (e.g. PIN/Pattern/Password).
2070 */
2071 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2072
2073 /**
Jim Miller06e34502014-07-17 14:46:05 -07002074 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2075 */
2076 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2077
2078 /**
Jim Miller35207742012-11-02 15:33:20 -07002079 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002080 */
2081 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002082
2083 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002084 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002085 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002086 *
2087 * <p>When multiple device administrators attempt to control device
2088 * encryption, the most secure, supported setting will always be
2089 * used. If any device administrator requests device encryption,
2090 * it will be enabled; Conversely, if a device administrator
2091 * attempts to disable device encryption while another
2092 * device administrator has enabled it, the call to disable will
2093 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2094 *
2095 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002096 * written to other storage areas may or may not be encrypted, and this policy does not require
2097 * or control the encryption of any other storage areas.
2098 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2099 * {@code true}, then the directory returned by
2100 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2101 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002102 *
2103 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2104 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2105 * the encryption key may not be fully secured. For maximum security, the administrator should
2106 * also require (and check for) a pattern, PIN, or password.
2107 *
2108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2109 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002110 * @return the new request status (for all active admins) - will be one of
2111 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2112 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2113 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002114 */
2115 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
2116 if (mService != null) {
2117 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002118 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002119 } catch (RemoteException e) {
2120 Log.w(TAG, "Failed talking with device policy service", e);
2121 }
2122 }
2123 return ENCRYPTION_STATUS_UNSUPPORTED;
2124 }
2125
2126 /**
2127 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002128 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002129 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002130 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2131 * this will return the requested encryption setting as an aggregate of all active
2132 * administrators.
2133 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002134 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002135 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002136 if (mService != null) {
2137 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002138 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002139 } catch (RemoteException e) {
2140 Log.w(TAG, "Failed talking with device policy service", e);
2141 }
2142 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002143 return false;
2144 }
2145
2146 /**
2147 * Called by an application that is administering the device to
2148 * determine the current encryption status of the device.
2149 *
2150 * Depending on the returned status code, the caller may proceed in different
2151 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2152 * storage system does not support encryption. If the
2153 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2154 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002155 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2156 * storage system has enabled encryption but no password is set so further action
2157 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002158 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2159 *
Robin Lee7e678712014-07-24 16:41:31 +01002160 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002161 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002162 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2163 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002164 */
2165 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002166 return getStorageEncryptionStatus(UserHandle.myUserId());
2167 }
2168
2169 /** @hide per-user version */
2170 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002171 if (mService != null) {
2172 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002173 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002174 } catch (RemoteException e) {
2175 Log.w(TAG, "Failed talking with device policy service", e);
2176 }
2177 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002178 return ENCRYPTION_STATUS_UNSUPPORTED;
2179 }
2180
2181 /**
Robin Lee7e678712014-07-24 16:41:31 +01002182 * Installs the given certificate as a user CA.
2183 *
Rubin Xuec32b562015-03-03 17:34:05 +00002184 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2185 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002186 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002187 *
2188 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002189 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002190 */
Robin Lee7e678712014-07-24 16:41:31 +01002191 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002192 if (mService != null) {
2193 try {
Robin Lee7e678712014-07-24 16:41:31 +01002194 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002195 } catch (RemoteException e) {
2196 Log.w(TAG, "Failed talking with device policy service", e);
2197 }
2198 }
2199 return false;
2200 }
2201
2202 /**
Robin Lee7e678712014-07-24 16:41:31 +01002203 * Uninstalls the given certificate from trusted user CAs, if present.
2204 *
Rubin Xuec32b562015-03-03 17:34:05 +00002205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2206 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002207 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002208 */
Robin Lee7e678712014-07-24 16:41:31 +01002209 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002210 if (mService != null) {
2211 try {
Robin Lee306fe082014-06-19 14:04:24 +00002212 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002213 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002214 } catch (CertificateException e) {
2215 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002216 } catch (RemoteException e) {
2217 Log.w(TAG, "Failed talking with device policy service", e);
2218 }
2219 }
2220 }
2221
2222 /**
Robin Lee7e678712014-07-24 16:41:31 +01002223 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2224 * If a user has installed any certificates by other means than device policy these will be
2225 * included too.
2226 *
Rubin Xuec32b562015-03-03 17:34:05 +00002227 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2228 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002229 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002230 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002231 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002232 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002233 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002234 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002235 mService.enforceCanManageCaCerts(admin);
2236 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2237 for (String alias : certStore.userAliases()) {
2238 try {
2239 certs.add(certStore.getCertificate(alias).getEncoded());
2240 } catch (CertificateException ce) {
2241 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2242 }
2243 }
2244 } catch (RemoteException re) {
2245 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002246 }
2247 }
2248 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002249 }
2250
2251 /**
Robin Lee7e678712014-07-24 16:41:31 +01002252 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2253 * means other than device policy will also be removed, except for system CA certificates.
2254 *
Rubin Xuec32b562015-03-03 17:34:05 +00002255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2256 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002257 */
2258 public void uninstallAllUserCaCerts(ComponentName admin) {
2259 if (mService != null) {
2260 for (String alias : new TrustedCertificateStore().userAliases()) {
2261 try {
2262 mService.uninstallCaCert(admin, alias);
2263 } catch (RemoteException re) {
2264 Log.w(TAG, "Failed talking with device policy service", re);
2265 }
2266 }
2267 }
2268 }
2269
2270 /**
2271 * Returns whether this certificate is installed as a trusted CA.
2272 *
Rubin Xuec32b562015-03-03 17:34:05 +00002273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2274 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002275 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002276 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002277 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2278 if (mService != null) {
2279 try {
2280 mService.enforceCanManageCaCerts(admin);
2281 return getCaCertAlias(certBuffer) != null;
2282 } catch (RemoteException re) {
2283 Log.w(TAG, "Failed talking with device policy service", re);
2284 } catch (CertificateException ce) {
2285 Log.w(TAG, "Could not parse certificate", ce);
2286 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002287 }
2288 return false;
2289 }
2290
2291 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002292 * Called by a device or profile owner to install a certificate and private key pair. The
2293 * keypair will be visible to all apps within the profile.
2294 *
Rubin Xuacdc1832015-04-02 12:40:20 +01002295 * @param who Which {@link DeviceAdminReceiver} this request is associated with. Use
2296 * <code>null</code> if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002297 * @param privKey The private key to install.
2298 * @param cert The certificate to install.
2299 * @param alias The private key alias under which to install the certificate. If a certificate
2300 * with that alias already exists, it will be overwritten.
2301 * @return {@code true} if the keys were installed, {@code false} otherwise.
2302 */
2303 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2304 String alias) {
2305 try {
2306 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002307 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2308 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2309 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002310 } catch (RemoteException e) {
2311 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002312 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2313 Log.w(TAG, "Failed to obtain private key material", e);
2314 } catch (CertificateException | IOException e) {
2315 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002316 }
2317 return false;
2318 }
2319
2320 /**
Robin Lee306fe082014-06-19 14:04:24 +00002321 * Returns the alias of a given CA certificate in the certificate store, or null if it
2322 * doesn't exist.
2323 */
2324 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2325 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2326 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2327 new ByteArrayInputStream(certBuffer));
2328 return new TrustedCertificateStore().getCertificateAlias(cert);
2329 }
2330
2331 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002332 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002333 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002334 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002335 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002336 * <p>
2337 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2338 * it is later cleared by calling this method with a null value or uninstallling the certificate
2339 * installer.
2340 *
2341 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2342 * @param installerPackage The package name of the certificate installer which will be given
2343 * access. If <code>null</code> is given the current package will be cleared.
2344 */
2345 public void setCertInstallerPackage(ComponentName who, String installerPackage)
2346 throws SecurityException {
2347 if (mService != null) {
2348 try {
2349 mService.setCertInstallerPackage(who, installerPackage);
2350 } catch (RemoteException e) {
2351 Log.w(TAG, "Failed talking with device policy service", e);
2352 }
2353 }
2354 }
2355
2356 /**
2357 * Called by a profile owner or device owner to retrieve the certificate installer for the
2358 * current user. null if none is set.
2359 *
2360 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2361 * @return The package name of the current delegated certificate installer. <code>null</code>
2362 * if none is set.
2363 */
2364 public String getCertInstallerPackage(ComponentName who) throws SecurityException {
2365 if (mService != null) {
2366 try {
2367 return mService.getCertInstallerPackage(who);
2368 } catch (RemoteException e) {
2369 Log.w(TAG, "Failed talking with device policy service", e);
2370 }
2371 }
2372 return null;
2373 }
2374
2375 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002376 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002377 * on the device, for this user. After setting this, no applications running as this user
2378 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002379 *
2380 * <p>The calling device admin must have requested
2381 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2382 * this method; if it has not, a security exception will be thrown.
2383 *
2384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2385 * @param disabled Whether or not the camera should be disabled.
2386 */
2387 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2388 if (mService != null) {
2389 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002390 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002391 } catch (RemoteException e) {
2392 Log.w(TAG, "Failed talking with device policy service", e);
2393 }
2394 }
2395 }
2396
2397 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002398 * Determine whether or not the device's cameras have been disabled for this user,
2399 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002400 * @param admin The name of the admin component to check, or null to check if any admins
2401 * have disabled the camera
2402 */
2403 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002404 return getCameraDisabled(admin, UserHandle.myUserId());
2405 }
2406
2407 /** @hide per-user version */
2408 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002409 if (mService != null) {
2410 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002411 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002412 } catch (RemoteException e) {
2413 Log.w(TAG, "Failed talking with device policy service", e);
2414 }
2415 }
2416 return false;
2417 }
2418
2419 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002420 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2421 * screen capture also prevents the content from being shown on display devices that do not have
2422 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2423 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002424 *
2425 * <p>The calling device admin must be a device or profile owner. If it is not, a
2426 * security exception will be thrown.
2427 *
2428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002429 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002430 */
2431 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2432 if (mService != null) {
2433 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002434 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002435 } catch (RemoteException e) {
2436 Log.w(TAG, "Failed talking with device policy service", e);
2437 }
2438 }
2439 }
2440
2441 /**
2442 * Determine whether or not screen capture has been disabled by the current
2443 * admin, if specified, or all admins.
2444 * @param admin The name of the admin component to check, or null to check if any admins
2445 * have disabled screen capture.
2446 */
2447 public boolean getScreenCaptureDisabled(ComponentName admin) {
2448 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2449 }
2450
2451 /** @hide per-user version */
2452 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2453 if (mService != null) {
2454 try {
2455 return mService.getScreenCaptureDisabled(admin, userHandle);
2456 } catch (RemoteException e) {
2457 Log.w(TAG, "Failed talking with device policy service", e);
2458 }
2459 }
2460 return false;
2461 }
2462
2463 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002464 * Called by a device owner to set whether auto time is required. If auto time is
2465 * required the user cannot set the date and time, but has to use network date and time.
2466 *
2467 * <p>Note: if auto time is required the user can still manually set the time zone.
2468 *
2469 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2470 * be thrown.
2471 *
2472 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2473 * @param required Whether auto time is set required or not.
2474 */
2475 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2476 if (mService != null) {
2477 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002478 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002479 } catch (RemoteException e) {
2480 Log.w(TAG, "Failed talking with device policy service", e);
2481 }
2482 }
2483 }
2484
2485 /**
2486 * @return true if auto time is required.
2487 */
2488 public boolean getAutoTimeRequired() {
2489 if (mService != null) {
2490 try {
2491 return mService.getAutoTimeRequired();
2492 } catch (RemoteException e) {
2493 Log.w(TAG, "Failed talking with device policy service", e);
2494 }
2495 }
2496 return false;
2497 }
2498
2499 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002500 * Called by an application that is administering the device to disable keyguard customizations,
2501 * such as widgets. After setting this, keyguard features will be disabled according to the
2502 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002503 *
2504 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002505 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002506 * this method; if it has not, a security exception will be thrown.
2507 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002508 * <p>Calling this from a managed profile will throw a security exception.
2509 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002511 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2512 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002513 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2514 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002515 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002516 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002517 if (mService != null) {
2518 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002519 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002520 } catch (RemoteException e) {
2521 Log.w(TAG, "Failed talking with device policy service", e);
2522 }
2523 }
2524 }
2525
2526 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002527 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002528 * admin, if specified, or all admins.
2529 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002530 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002531 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2532 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002533 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002534 public int getKeyguardDisabledFeatures(ComponentName admin) {
2535 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002536 }
2537
2538 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002539 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002540 if (mService != null) {
2541 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002542 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002543 } catch (RemoteException e) {
2544 Log.w(TAG, "Failed talking with device policy service", e);
2545 }
2546 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002547 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002548 }
2549
2550 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002551 * @hide
2552 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002553 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002554 if (mService != null) {
2555 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002556 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002557 } catch (RemoteException e) {
2558 Log.w(TAG, "Failed talking with device policy service", e);
2559 }
2560 }
2561 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002562
Dianne Hackbornd6847842010-01-12 18:14:19 -08002563 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002564 * @hide
2565 */
2566 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2567 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2568 }
2569
2570 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002571 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002572 * @hide
2573 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002574 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002575 ActivityInfo ai;
2576 try {
2577 ai = mContext.getPackageManager().getReceiverInfo(cn,
2578 PackageManager.GET_META_DATA);
2579 } catch (PackageManager.NameNotFoundException e) {
2580 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2581 return null;
2582 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002583
Dianne Hackbornd6847842010-01-12 18:14:19 -08002584 ResolveInfo ri = new ResolveInfo();
2585 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002586
Dianne Hackbornd6847842010-01-12 18:14:19 -08002587 try {
2588 return new DeviceAdminInfo(mContext, ri);
2589 } catch (XmlPullParserException e) {
2590 Log.w(TAG, "Unable to parse device policy " + cn, e);
2591 return null;
2592 } catch (IOException e) {
2593 Log.w(TAG, "Unable to parse device policy " + cn, e);
2594 return null;
2595 }
2596 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002597
Dianne Hackbornd6847842010-01-12 18:14:19 -08002598 /**
2599 * @hide
2600 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002601 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2602 if (mService != null) {
2603 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002604 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002605 } catch (RemoteException e) {
2606 Log.w(TAG, "Failed talking with device policy service", e);
2607 }
2608 }
2609 }
2610
2611 /**
2612 * @hide
2613 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002614 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002615 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002616 if (mService != null) {
2617 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002618 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002619 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002620 } catch (RemoteException e) {
2621 Log.w(TAG, "Failed talking with device policy service", e);
2622 }
2623 }
2624 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002625
Dianne Hackbornd6847842010-01-12 18:14:19 -08002626 /**
2627 * @hide
2628 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002629 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002630 if (mService != null) {
2631 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002632 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002633 } catch (RemoteException e) {
2634 Log.w(TAG, "Failed talking with device policy service", e);
2635 }
2636 }
2637 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002638
Dianne Hackbornd6847842010-01-12 18:14:19 -08002639 /**
2640 * @hide
2641 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002642 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002643 if (mService != null) {
2644 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002645 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002646 } catch (RemoteException e) {
2647 Log.w(TAG, "Failed talking with device policy service", e);
2648 }
2649 }
2650 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002651
2652 /**
2653 * @hide
2654 * Sets the given package as the device owner. The package must already be installed and there
2655 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2656 * method must be called before the device is provisioned.
2657 * @param packageName the package name of the application to be registered as the device owner.
2658 * @return whether the package was successfully registered as the device owner.
2659 * @throws IllegalArgumentException if the package name is null or invalid
2660 * @throws IllegalStateException if a device owner is already registered or the device has
2661 * already been provisioned.
2662 */
2663 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2664 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002665 return setDeviceOwner(packageName, null);
2666 }
2667
2668 /**
2669 * @hide
2670 * Sets the given package as the device owner. The package must already be installed and there
2671 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2672 * method must be called before the device is provisioned.
2673 * @param packageName the package name of the application to be registered as the device owner.
2674 * @param ownerName the human readable name of the institution that owns this device.
2675 * @return whether the package was successfully registered as the device owner.
2676 * @throws IllegalArgumentException if the package name is null or invalid
2677 * @throws IllegalStateException if a device owner is already registered or the device has
2678 * already been provisioned.
2679 */
2680 public boolean setDeviceOwner(String packageName, String ownerName)
2681 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002682 if (mService != null) {
2683 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002684 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002685 } catch (RemoteException re) {
2686 Log.w(TAG, "Failed to set device owner");
2687 }
2688 }
2689 return false;
2690 }
2691
2692 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002693 * Used to determine if a particular package has been registered as a Device Owner app.
2694 * A device owner app is a special device admin that cannot be deactivated by the user, once
2695 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2696 * package is currently registered as the device owner app, pass in the package name from
2697 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2698 * admin apps that want to check if they are also registered as the device owner app. The
2699 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2700 * the setup process.
2701 * @param packageName the package name of the app, to compare with the registered device owner
2702 * app, if any.
2703 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002704 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002705 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002706 if (mService != null) {
2707 try {
2708 return mService.isDeviceOwner(packageName);
2709 } catch (RemoteException re) {
2710 Log.w(TAG, "Failed to check device owner");
2711 }
2712 }
2713 return false;
2714 }
2715
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002716 /**
2717 * @hide
2718 * Redirect to isDeviceOwnerApp.
2719 */
2720 public boolean isDeviceOwner(String packageName) {
2721 return isDeviceOwnerApp(packageName);
2722 }
2723
Jason Monkb0dced82014-06-06 14:36:20 -04002724 /**
2725 * Clears the current device owner. The caller must be the device owner.
2726 *
2727 * This function should be used cautiously as once it is called it cannot
2728 * be undone. The device owner can only be set as a part of device setup
2729 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002730 *
2731 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002732 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002733 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002734 if (mService != null) {
2735 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002736 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002737 } catch (RemoteException re) {
2738 Log.w(TAG, "Failed to clear device owner");
2739 }
2740 }
2741 }
2742
Amith Yamasani71e6c692013-03-24 17:39:28 -07002743 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002744 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002745 public String getDeviceOwner() {
2746 if (mService != null) {
2747 try {
2748 return mService.getDeviceOwner();
2749 } catch (RemoteException re) {
2750 Log.w(TAG, "Failed to get device owner");
2751 }
2752 }
2753 return null;
2754 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002755
2756 /** @hide */
2757 public String getDeviceOwnerName() {
2758 if (mService != null) {
2759 try {
2760 return mService.getDeviceOwnerName();
2761 } catch (RemoteException re) {
2762 Log.w(TAG, "Failed to get device owner");
2763 }
2764 }
2765 return null;
2766 }
Adam Connors776c5552014-01-09 10:42:56 +00002767
2768 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002769 * Sets the given component as the device initializer. The package must already be installed and
2770 * set as an active device administrator, and there must not be an existing device initializer,
2771 * for this call to succeed. This method can only be called by an app holding the
2772 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2773 * device initializer app is granted device owner privileges during device initialization and
2774 * profile owner privileges during secondary user initialization.
2775 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2776 * called by the device owner.
2777 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2778 * @param initializerName The user-visible name of the device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002779 * @return whether the component was successfully registered as the device initializer.
2780 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002781 * @throws IllegalStateException if the caller is not device owner or the device has
2782 * already been provisioned or a device initializer already exists.
2783 */
2784 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2785 String initializerName) throws IllegalArgumentException, IllegalStateException {
2786 if (mService != null) {
2787 try {
2788 return mService.setDeviceInitializer(who, initializer, initializerName);
2789 } catch (RemoteException re) {
2790 Log.w(TAG, "Failed to set device initializer");
2791 }
2792 }
2793 return false;
2794 }
2795
2796 /**
2797 * Used to determine if a particular package has been registered as the device initializer.
2798 *
2799 * @param packageName the package name of the app, to compare with the registered device
2800 * initializer app, if any.
2801 * @return whether or not the caller is registered as the device initializer app.
2802 */
2803 public boolean isDeviceInitializerApp(String packageName) {
2804 if (mService != null) {
2805 try {
2806 return mService.isDeviceInitializer(packageName);
2807 } catch (RemoteException re) {
2808 Log.w(TAG, "Failed to check device initializer");
2809 }
2810 }
2811 return false;
2812 }
2813
2814 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002815 * Removes the device initializer, so that it will not be invoked on user initialization for any
2816 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002817 * initializer itself. The caller must be an active administrator.
2818 *
2819 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002820 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002821 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002822 if (mService != null) {
2823 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002824 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002825 } catch (RemoteException re) {
2826 Log.w(TAG, "Failed to clear device initializer");
2827 }
2828 }
2829 }
2830
2831 /**
2832 * @hide
2833 * Gets the device initializer of the system.
2834 *
2835 * @return the package name of the device initializer.
2836 */
2837 @SystemApi
2838 public String getDeviceInitializerApp() {
2839 if (mService != null) {
2840 try {
2841 return mService.getDeviceInitializer();
2842 } catch (RemoteException re) {
2843 Log.w(TAG, "Failed to get device initializer");
2844 }
2845 }
2846 return null;
2847 }
2848
2849 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002850 * @hide
2851 * Gets the device initializer component of the system.
2852 *
2853 * @return the component name of the device initializer.
2854 */
2855 @SystemApi
2856 public ComponentName getDeviceInitializerComponent() {
2857 if (mService != null) {
2858 try {
2859 return mService.getDeviceInitializerComponent();
2860 } catch (RemoteException re) {
2861 Log.w(TAG, "Failed to get device initializer");
2862 }
2863 }
2864 return null;
2865 }
2866
2867
2868 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002869 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2870 * be used.
2871 *
2872 * <p>Device initializer must call this method to mark the user as functional.
2873 * Only the device initializer agent can call this.
2874 *
2875 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2876 * device initializer will no longer have elevated permissions to call methods in this class.
2877 * Additionally, it will be removed as an active administrator and its
2878 * {@link DeviceAdminReceiver} will be disabled.
2879 *
2880 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2881 * @return whether the user is now enabled.
2882 */
2883 public boolean setUserEnabled(ComponentName admin) {
2884 if (mService != null) {
2885 try {
2886 return mService.setUserEnabled(admin);
2887 } catch (RemoteException e) {
2888 Log.w(TAG, "Failed talking with device policy service", e);
2889 }
2890 }
2891 return false;
2892 }
2893
2894 /**
Adam Connors776c5552014-01-09 10:42:56 +00002895 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002896 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302897 * Sets the given component as an active admin and registers the package as the profile
2898 * owner for this user. The package must already be installed and there shouldn't be
2899 * an existing profile owner registered for this user. Also, this method must be called
2900 * before the user setup has been completed.
2901 * <p>
2902 * This method can only be called by system apps that hold MANAGE_USERS permission and
2903 * MANAGE_DEVICE_ADMINS permission.
2904 * @param admin The component to register as an active admin and profile owner.
2905 * @param ownerName The user-visible name of the entity that is managing this user.
2906 * @return whether the admin was successfully registered as the profile owner.
2907 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2908 * the user has already been set up.
2909 */
Justin Morey80440cc2014-07-24 09:16:35 -05002910 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302911 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2912 throws IllegalArgumentException {
2913 if (mService != null) {
2914 try {
2915 final int myUserId = UserHandle.myUserId();
2916 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002917 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302918 } catch (RemoteException re) {
2919 Log.w(TAG, "Failed to set profile owner " + re);
2920 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2921 }
2922 }
2923 return false;
2924 }
2925
2926 /**
2927 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002928 * Clears the active profile owner and removes all user restrictions. The caller must
2929 * be from the same package as the active profile owner for this user, otherwise a
2930 * SecurityException will be thrown.
2931 *
2932 * @param admin The component to remove as the profile owner.
2933 * @return
2934 */
2935 @SystemApi
2936 public void clearProfileOwner(ComponentName admin) {
2937 if (mService != null) {
2938 try {
2939 mService.clearProfileOwner(admin);
2940 } catch (RemoteException re) {
2941 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2942 }
2943 }
2944 }
2945
2946 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002947 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002948 * Checks if the user was already setup.
2949 */
2950 public boolean hasUserSetupCompleted() {
2951 if (mService != null) {
2952 try {
2953 return mService.hasUserSetupCompleted();
2954 } catch (RemoteException re) {
2955 Log.w(TAG, "Failed to check if user setup has completed");
2956 }
2957 }
2958 return true;
2959 }
2960
2961 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002962 * @hide
2963 * Sets the given component as the profile owner of the given user profile. The package must
2964 * already be installed and there shouldn't be an existing profile owner registered for this
2965 * user. Only the system can call this API if the user has already completed setup.
2966 * @param admin the component name to be registered as profile owner.
2967 * @param ownerName the human readable name of the organisation associated with this DPM.
2968 * @param userHandle the userId to set the profile owner for.
2969 * @return whether the component was successfully registered as the profile owner.
2970 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2971 * the user has already been set up.
2972 */
2973 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2974 throws IllegalArgumentException {
2975 if (admin == null) {
2976 throw new NullPointerException("admin cannot be null");
2977 }
Adam Connors776c5552014-01-09 10:42:56 +00002978 if (mService != null) {
2979 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002980 if (ownerName == null) {
2981 ownerName = "";
2982 }
2983 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002984 } catch (RemoteException re) {
2985 Log.w(TAG, "Failed to set profile owner", re);
2986 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2987 }
2988 }
2989 return false;
2990 }
2991
2992 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002993 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2994 * be used. Only the profile owner can call this.
2995 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002996 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002997 *
2998 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2999 */
3000 public void setProfileEnabled(ComponentName admin) {
3001 if (mService != null) {
3002 try {
3003 mService.setProfileEnabled(admin);
3004 } catch (RemoteException e) {
3005 Log.w(TAG, "Failed talking with device policy service", e);
3006 }
3007 }
3008 }
3009
3010 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003011 * Sets the name of the profile. In the device owner case it sets the name of the user
3012 * 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 +01003013 * never called by the profile or device owner, the name will be set to default values.
3014 *
3015 * @see #isProfileOwnerApp
3016 * @see #isDeviceOwnerApp
3017 *
3018 * @param profileName The name of the profile.
3019 */
3020 public void setProfileName(ComponentName who, String profileName) {
3021 if (mService != null) {
3022 try {
3023 mService.setProfileName(who, profileName);
3024 } catch (RemoteException e) {
3025 Log.w(TAG, "Failed talking with device policy service", e);
3026 }
3027 }
3028}
3029
3030 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003031 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003032 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003033 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003034 *
3035 * @param packageName The package name of the app to compare with the registered profile owner.
3036 * @return Whether or not the package is registered as the profile owner.
3037 */
3038 public boolean isProfileOwnerApp(String packageName) {
3039 if (mService != null) {
3040 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003041 ComponentName profileOwner = mService.getProfileOwner(
3042 Process.myUserHandle().getIdentifier());
3043 return profileOwner != null
3044 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003045 } catch (RemoteException re) {
3046 Log.w(TAG, "Failed to check profile owner");
3047 }
3048 }
3049 return false;
3050 }
3051
3052 /**
3053 * @hide
3054 * @return the packageName of the owner of the given user profile or null if no profile
3055 * owner has been set for that user.
3056 * @throws IllegalArgumentException if the userId is invalid.
3057 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003058 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003059 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003060 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3061 }
3062
3063 /**
3064 * @see #getProfileOwner()
3065 * @hide
3066 */
3067 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003068 if (mService != null) {
3069 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003070 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003071 } catch (RemoteException re) {
3072 Log.w(TAG, "Failed to get profile owner");
3073 throw new IllegalArgumentException(
3074 "Requested profile owner for invalid userId", re);
3075 }
3076 }
3077 return null;
3078 }
3079
3080 /**
3081 * @hide
3082 * @return the human readable name of the organisation associated with this DPM or null if
3083 * one is not set.
3084 * @throws IllegalArgumentException if the userId is invalid.
3085 */
3086 public String getProfileOwnerName() throws IllegalArgumentException {
3087 if (mService != null) {
3088 try {
3089 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3090 } catch (RemoteException re) {
3091 Log.w(TAG, "Failed to get profile owner");
3092 throw new IllegalArgumentException(
3093 "Requested profile owner for invalid userId", re);
3094 }
3095 }
3096 return null;
3097 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003098
3099 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003100 * @hide
3101 * @param user The user for whom to fetch the profile owner name, if any.
3102 * @return the human readable name of the organisation associated with this profile owner or
3103 * null if one is not set.
3104 * @throws IllegalArgumentException if the userId is invalid.
3105 */
3106 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003107 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003108 if (mService != null) {
3109 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003110 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003111 } catch (RemoteException re) {
3112 Log.w(TAG, "Failed to get profile owner");
3113 throw new IllegalArgumentException(
3114 "Requested profile owner for invalid userId", re);
3115 }
3116 }
3117 return null;
3118 }
3119
3120 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003121 * Called by a profile owner or device owner to add a default intent handler activity for
3122 * intents that match a certain intent filter. This activity will remain the default intent
3123 * handler even if the set of potential event handlers for the intent filter changes and if
3124 * the intent preferences are reset.
3125 *
3126 * <p>The default disambiguation mechanism takes over if the activity is not installed
3127 * (anymore). When the activity is (re)installed, it is automatically reset as default
3128 * intent handler for the filter.
3129 *
3130 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3131 * security exception will be thrown.
3132 *
3133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3134 * @param filter The IntentFilter for which a default handler is added.
3135 * @param activity The Activity that is added as default intent handler.
3136 */
3137 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
3138 ComponentName activity) {
3139 if (mService != null) {
3140 try {
3141 mService.addPersistentPreferredActivity(admin, filter, activity);
3142 } catch (RemoteException e) {
3143 Log.w(TAG, "Failed talking with device policy service", e);
3144 }
3145 }
3146 }
3147
3148 /**
3149 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003150 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003151 *
3152 * <p>The calling device admin must be a profile owner. If it is not, a security
3153 * exception will be thrown.
3154 *
3155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3156 * @param packageName The name of the package for which preferences are removed.
3157 */
3158 public void clearPackagePersistentPreferredActivities(ComponentName admin,
3159 String packageName) {
3160 if (mService != null) {
3161 try {
3162 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3163 } catch (RemoteException e) {
3164 Log.w(TAG, "Failed talking with device policy service", e);
3165 }
3166 }
3167 }
Robin Lee66e5d962014-04-09 16:44:21 +01003168
3169 /**
3170 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003171 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003172 *
3173 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003174 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003175 *
3176 * <p>The application restrictions are only made visible to the target application and the
3177 * profile or device owner.
3178 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003179 * <p>If the restrictions are not available yet, but may be applied in the near future,
3180 * the admin can notify the target application of that by adding
3181 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3182 *
Robin Lee66e5d962014-04-09 16:44:21 +01003183 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3184 * exception will be thrown.
3185 *
3186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3187 * @param packageName The name of the package to update restricted settings for.
3188 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3189 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003190 *
3191 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003192 */
3193 public void setApplicationRestrictions(ComponentName admin, String packageName,
3194 Bundle settings) {
3195 if (mService != null) {
3196 try {
3197 mService.setApplicationRestrictions(admin, packageName, settings);
3198 } catch (RemoteException e) {
3199 Log.w(TAG, "Failed talking with device policy service", e);
3200 }
3201 }
3202 }
3203
3204 /**
Jim Millere303bf42014-08-26 17:12:29 -07003205 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3206 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3207 * trust agents but those enabled by this function call. If flag
3208 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003209 *
3210 * <p>The calling device admin must have requested
3211 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003212 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003213 *
3214 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003215 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003216 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003217 * will be strictly disabled according to the state of the
3218 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3219 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3220 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3221 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003222 */
Jim Millere303bf42014-08-26 17:12:29 -07003223 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08003224 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003225 if (mService != null) {
3226 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003227 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003228 } catch (RemoteException e) {
3229 Log.w(TAG, "Failed talking with device policy service", e);
3230 }
3231 }
3232 }
3233
3234 /**
Jim Millere303bf42014-08-26 17:12:29 -07003235 * Gets configuration for the given trust agent based on aggregating all calls to
3236 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3237 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003238 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003239 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3240 * this function returns a list of configurations for all admins that declare
3241 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3242 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3243 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3244 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003245 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003246 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003247 */
Jim Millere303bf42014-08-26 17:12:29 -07003248 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3249 ComponentName agent) {
3250 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3251 }
3252
3253 /** @hide per-user version */
3254 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3255 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003256 if (mService != null) {
3257 try {
Jim Millere303bf42014-08-26 17:12:29 -07003258 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003259 } catch (RemoteException e) {
3260 Log.w(TAG, "Failed talking with device policy service", e);
3261 }
3262 }
Jim Millere303bf42014-08-26 17:12:29 -07003263 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003264 }
3265
3266 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003267 * Called by a profile owner of a managed profile to set whether caller-Id information from
3268 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003269 *
3270 * <p>The calling device admin must be a profile owner. If it is not, a
3271 * security exception will be thrown.
3272 *
3273 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3274 * @param disabled If true caller-Id information in the managed profile is not displayed.
3275 */
3276 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
3277 if (mService != null) {
3278 try {
3279 mService.setCrossProfileCallerIdDisabled(who, disabled);
3280 } catch (RemoteException e) {
3281 Log.w(TAG, "Failed talking with device policy service", e);
3282 }
3283 }
3284 }
3285
3286 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003287 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3288 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003289 *
3290 * <p>The calling device admin must be a profile owner. If it is not, a
3291 * security exception will be thrown.
3292 *
3293 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3294 */
3295 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3296 if (mService != null) {
3297 try {
3298 return mService.getCrossProfileCallerIdDisabled(who);
3299 } catch (RemoteException e) {
3300 Log.w(TAG, "Failed talking with device policy service", e);
3301 }
3302 }
3303 return false;
3304 }
3305
3306 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003307 * Determine whether or not caller-Id information has been disabled.
3308 *
3309 * @param userHandle The user for whom to check the caller-id permission
3310 * @hide
3311 */
3312 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3313 if (mService != null) {
3314 try {
3315 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3316 } catch (RemoteException e) {
3317 Log.w(TAG, "Failed talking with device policy service", e);
3318 }
3319 }
3320 return false;
3321 }
3322
3323 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003324 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3325 * @hide
3326 */
3327 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3328 Intent originalIntent) {
3329 if (mService != null) {
3330 try {
3331 mService.startManagedQuickContact(
3332 actualLookupKey, actualContactId, originalIntent);
3333 } catch (RemoteException e) {
3334 Log.w(TAG, "Failed talking with device policy service", e);
3335 }
3336 }
3337 }
3338
3339 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003340 * Called by a profile owner of a managed profile to set whether bluetooth
3341 * devices can access enterprise contacts.
3342 * <p>
3343 * The calling device admin must be a profile owner. If it is not, a
3344 * security exception will be thrown.
3345 * <p>
3346 * This API works on managed profile only.
3347 *
3348 * @param who Which {@link DeviceAdminReceiver} this request is associated
3349 * with.
3350 * @param disabled If true, bluetooth devices cannot access enterprise
3351 * contacts.
3352 */
3353 public void setBluetoothContactSharingDisabled(ComponentName who, boolean disabled) {
3354 if (mService != null) {
3355 try {
3356 mService.setBluetoothContactSharingDisabled(who, disabled);
3357 } catch (RemoteException e) {
3358 Log.w(TAG, "Failed talking with device policy service", e);
3359 }
3360 }
3361 }
3362
3363 /**
3364 * Called by a profile owner of a managed profile to determine whether or
3365 * not Bluetooth devices cannot access enterprise contacts.
3366 * <p>
3367 * The calling device admin must be a profile owner. If it is not, a
3368 * security exception will be thrown.
3369 * <p>
3370 * This API works on managed profile only.
3371 *
3372 * @param who Which {@link DeviceAdminReceiver} this request is associated
3373 * with.
3374 */
3375 public boolean getBluetoothContactSharingDisabled(ComponentName who) {
3376 if (mService != null) {
3377 try {
3378 return mService.getBluetoothContactSharingDisabled(who);
3379 } catch (RemoteException e) {
3380 Log.w(TAG, "Failed talking with device policy service", e);
3381 }
3382 }
3383 return true;
3384 }
3385
3386 /**
3387 * Determine whether or not Bluetooth devices cannot access contacts.
3388 * <p>
3389 * This API works on managed profile UserHandle only.
3390 *
3391 * @param userHandle The user for whom to check the caller-id permission
3392 * @hide
3393 */
3394 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3395 if (mService != null) {
3396 try {
3397 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3398 .getIdentifier());
3399 } catch (RemoteException e) {
3400 Log.w(TAG, "Failed talking with device policy service", e);
3401 }
3402 }
3403 return true;
3404 }
3405
3406 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003407 * Called by the profile owner of a managed profile so that some intents sent in the managed
3408 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003409 * Only activity intents are supported.
3410 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003411 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003412 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3413 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003414 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3415 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003416 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003417 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003418 if (mService != null) {
3419 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003420 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003421 } catch (RemoteException e) {
3422 Log.w(TAG, "Failed talking with device policy service", e);
3423 }
3424 }
3425 }
3426
3427 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003428 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3429 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003430 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003431 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3432 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003433 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003434 if (mService != null) {
3435 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003436 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003437 } catch (RemoteException e) {
3438 Log.w(TAG, "Failed talking with device policy service", e);
3439 }
3440 }
3441 }
3442
3443 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003444 * Called by a profile or device owner to set the permitted accessibility services. When
3445 * set by a device owner or profile owner the restriction applies to all profiles of the
3446 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003447 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003448 * By default the user can use any accessiblity service. When zero or more packages have
3449 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003450 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003451 *
3452 * <p> Calling with a null value for the list disables the restriction so that all services
3453 * can be used, calling with an empty list only allows the builtin system's services.
3454 *
3455 * <p> System accesibility services are always available to the user the list can't modify
3456 * this.
3457 *
3458 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3459 * @param packageNames List of accessibility service package names.
3460 *
3461 * @return true if setting the restriction succeeded. It fail if there is
3462 * one or more non-system accessibility services enabled, that are not in the list.
3463 */
3464 public boolean setPermittedAccessibilityServices(ComponentName admin,
3465 List<String> packageNames) {
3466 if (mService != null) {
3467 try {
3468 return mService.setPermittedAccessibilityServices(admin, packageNames);
3469 } catch (RemoteException e) {
3470 Log.w(TAG, "Failed talking with device policy service", e);
3471 }
3472 }
3473 return false;
3474 }
3475
3476 /**
3477 * Returns the list of permitted accessibility services set by this device or profile owner.
3478 *
3479 * <p>An empty list means no accessibility services except system services are allowed.
3480 * Null means all accessibility services are allowed.
3481 *
3482 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3483 * @return List of accessiblity service package names.
3484 */
3485 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3486 if (mService != null) {
3487 try {
3488 return mService.getPermittedAccessibilityServices(admin);
3489 } catch (RemoteException e) {
3490 Log.w(TAG, "Failed talking with device policy service", e);
3491 }
3492 }
3493 return null;
3494 }
3495
3496 /**
3497 * Returns the list of accessibility services permitted by the device or profiles
3498 * owners of this user.
3499 *
3500 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3501 * it will contain the intersection of the permitted lists for any device or profile
3502 * owners that apply to this user. It will also include any system accessibility services.
3503 *
3504 * @param userId which user to check for.
3505 * @return List of accessiblity service package names.
3506 * @hide
3507 */
3508 @SystemApi
3509 public List<String> getPermittedAccessibilityServices(int userId) {
3510 if (mService != null) {
3511 try {
3512 return mService.getPermittedAccessibilityServicesForUser(userId);
3513 } catch (RemoteException e) {
3514 Log.w(TAG, "Failed talking with device policy service", e);
3515 }
3516 }
3517 return null;
3518 }
3519
3520 /**
3521 * Called by a profile or device owner to set the permitted input methods services. When
3522 * set by a device owner or profile owner the restriction applies to all profiles of the
3523 * user the device owner or profile owner is an admin for.
3524 *
3525 * By default the user can use any input method. When zero or more packages have
3526 * been added, input method that are not in the list and not part of the system
3527 * can not be enabled by the user.
3528 *
3529 * This method will fail if it is called for a admin that is not for the foreground user
3530 * or a profile of the foreground user.
3531 *
3532 * <p> Calling with a null value for the list disables the restriction so that all input methods
3533 * can be used, calling with an empty list disables all but the system's own input methods.
3534 *
3535 * <p> System input methods are always available to the user this method can't modify this.
3536 *
3537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3538 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003539 * @return true if setting the restriction succeeded. It will fail if there are
3540 * one or more non-system input methods currently enabled that are not in
3541 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003542 */
3543 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3544 if (mService != null) {
3545 try {
3546 return mService.setPermittedInputMethods(admin, packageNames);
3547 } catch (RemoteException e) {
3548 Log.w(TAG, "Failed talking with device policy service", e);
3549 }
3550 }
3551 return false;
3552 }
3553
3554
3555 /**
3556 * Returns the list of permitted input methods set by this device or profile owner.
3557 *
3558 * <p>An empty list means no input methods except system input methods are allowed.
3559 * Null means all input methods are allowed.
3560 *
3561 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3562 * @return List of input method package names.
3563 */
3564 public List<String> getPermittedInputMethods(ComponentName admin) {
3565 if (mService != null) {
3566 try {
3567 return mService.getPermittedInputMethods(admin);
3568 } catch (RemoteException e) {
3569 Log.w(TAG, "Failed talking with device policy service", e);
3570 }
3571 }
3572 return null;
3573 }
3574
3575 /**
3576 * Returns the list of input methods permitted by the device or profiles
3577 * owners of the current user.
3578 *
3579 * <p>Null means all input methods are allowed, if a non-null list is returned
3580 * it will contain the intersection of the permitted lists for any device or profile
3581 * owners that apply to this user. It will also include any system input methods.
3582 *
3583 * @return List of input method package names.
3584 * @hide
3585 */
3586 @SystemApi
3587 public List<String> getPermittedInputMethodsForCurrentUser() {
3588 if (mService != null) {
3589 try {
3590 return mService.getPermittedInputMethodsForCurrentUser();
3591 } catch (RemoteException e) {
3592 Log.w(TAG, "Failed talking with device policy service", e);
3593 }
3594 }
3595 return null;
3596 }
3597
3598 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003599 * Called by a device owner to create a user with the specified name. The UserHandle returned
3600 * by this method should not be persisted as user handles are recycled as users are removed and
3601 * created. If you need to persist an identifier for this user, use
3602 * {@link UserManager#getSerialNumberForUser}.
3603 *
3604 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3605 * @param name the user's name
3606 * @see UserHandle
3607 * @return the UserHandle object for the created user, or null if the user could not be created.
3608 */
3609 public UserHandle createUser(ComponentName admin, String name) {
3610 try {
3611 return mService.createUser(admin, name);
3612 } catch (RemoteException re) {
3613 Log.w(TAG, "Could not create a user", re);
3614 }
3615 return null;
3616 }
3617
3618 /**
Jason Monk03978a42014-06-10 15:05:30 -04003619 * Called by a device owner to create a user with the specified name. The UserHandle returned
3620 * by this method should not be persisted as user handles are recycled as users are removed and
3621 * created. If you need to persist an identifier for this user, use
3622 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3623 * immediately.
3624 *
3625 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3626 * as registered as an active admin on the new user. The profile owner package will be
3627 * installed on the new user if it already is installed on the device.
3628 *
3629 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3630 * profileOwnerComponent when onEnable is called.
3631 *
3632 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3633 * @param name the user's name
3634 * @param ownerName the human readable name of the organisation associated with this DPM.
3635 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3636 * the user.
3637 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3638 * on the new user.
3639 * @see UserHandle
3640 * @return the UserHandle object for the created user, or null if the user could not be created.
3641 */
3642 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3643 ComponentName profileOwnerComponent, Bundle adminExtras) {
3644 try {
3645 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3646 adminExtras);
3647 } catch (RemoteException re) {
3648 Log.w(TAG, "Could not create a user", re);
3649 }
3650 return null;
3651 }
3652
3653 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003654 * Called by a device owner to remove a user and all associated data. The primary user can
3655 * not be removed.
3656 *
3657 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3658 * @param userHandle the user to remove.
3659 * @return {@code true} if the user was removed, {@code false} otherwise.
3660 */
3661 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3662 try {
3663 return mService.removeUser(admin, userHandle);
3664 } catch (RemoteException re) {
3665 Log.w(TAG, "Could not remove user ", re);
3666 return false;
3667 }
3668 }
3669
3670 /**
Jason Monk582d9112014-07-09 19:57:08 -04003671 * Called by a device owner to switch the specified user to the foreground.
3672 *
3673 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3674 * @param userHandle the user to switch to; null will switch to primary.
3675 * @return {@code true} if the switch was successful, {@code false} otherwise.
3676 *
3677 * @see Intent#ACTION_USER_FOREGROUND
3678 */
3679 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3680 try {
3681 return mService.switchUser(admin, userHandle);
3682 } catch (RemoteException re) {
3683 Log.w(TAG, "Could not switch user ", re);
3684 return false;
3685 }
3686 }
3687
3688 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003689 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003690 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003691 *
3692 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3693 * exception will be thrown.
3694 *
3695 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3696 * @param packageName The name of the package to fetch restricted settings of.
3697 * @return {@link Bundle} of settings corresponding to what was set last time
3698 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3699 * if no restrictions have been set.
3700 */
3701 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3702 if (mService != null) {
3703 try {
3704 return mService.getApplicationRestrictions(admin, packageName);
3705 } catch (RemoteException e) {
3706 Log.w(TAG, "Failed talking with device policy service", e);
3707 }
3708 }
3709 return null;
3710 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003711
3712 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003713 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003714 * <p>
3715 * The calling device admin must be a profile or device owner; if it is not,
3716 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003717 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003718 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3719 * with.
3720 * @param key The key of the restriction. See the constants in
3721 * {@link android.os.UserManager} for the list of keys.
3722 */
3723 public void addUserRestriction(ComponentName admin, String key) {
3724 if (mService != null) {
3725 try {
3726 mService.setUserRestriction(admin, key, true);
3727 } catch (RemoteException e) {
3728 Log.w(TAG, "Failed talking with device policy service", e);
3729 }
3730 }
3731 }
3732
3733 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003734 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003735 * <p>
3736 * The calling device admin must be a profile or device owner; if it is not,
3737 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003738 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003739 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3740 * with.
3741 * @param key The key of the restriction. See the constants in
3742 * {@link android.os.UserManager} for the list of keys.
3743 */
3744 public void clearUserRestriction(ComponentName admin, String key) {
3745 if (mService != null) {
3746 try {
3747 mService.setUserRestriction(admin, key, false);
3748 } catch (RemoteException e) {
3749 Log.w(TAG, "Failed talking with device policy service", e);
3750 }
3751 }
3752 }
Adam Connors010cfd42014-04-16 12:48:13 +01003753
3754 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003755 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003756 * is unavailable for use, but the data and actual package file remain.
3757 *
3758 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003759 * @param packageName The name of the package to hide or unhide.
3760 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3761 * unhidden.
3762 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003763 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003764 public boolean setApplicationHidden(ComponentName admin, String packageName,
3765 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003766 if (mService != null) {
3767 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003768 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003769 } catch (RemoteException e) {
3770 Log.w(TAG, "Failed talking with device policy service", e);
3771 }
3772 }
3773 return false;
3774 }
3775
3776 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003777 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003778 *
3779 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003780 * @param packageName The name of the package to retrieve the hidden status of.
3781 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003782 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003783 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003784 if (mService != null) {
3785 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003786 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003787 } catch (RemoteException e) {
3788 Log.w(TAG, "Failed talking with device policy service", e);
3789 }
3790 }
3791 return false;
3792 }
3793
3794 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003795 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003796 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003797 *
3798 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3799 * @param packageName The package to be re-enabled in the current profile.
3800 */
3801 public void enableSystemApp(ComponentName admin, String packageName) {
3802 if (mService != null) {
3803 try {
3804 mService.enableSystemApp(admin, packageName);
3805 } catch (RemoteException e) {
3806 Log.w(TAG, "Failed to install package: " + packageName);
3807 }
3808 }
3809 }
3810
3811 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003812 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003813 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003814 *
3815 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3816 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3817 * intent will be re-enabled in the current profile.
3818 * @return int The number of activities that matched the intent and were installed.
3819 */
3820 public int enableSystemApp(ComponentName admin, Intent intent) {
3821 if (mService != null) {
3822 try {
3823 return mService.enableSystemAppWithIntent(admin, intent);
3824 } catch (RemoteException e) {
3825 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3826 }
3827 }
3828 return 0;
3829 }
3830
3831 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003832 * Called by a device owner or profile owner to disable account management for a specific type
3833 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003834 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003835 * <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 +01003836 * security exception will be thrown.
3837 *
3838 * <p>When account management is disabled for an account type, adding or removing an account
3839 * of that type will not be possible.
3840 *
3841 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3842 * @param accountType For which account management is disabled or enabled.
3843 * @param disabled The boolean indicating that account management will be disabled (true) or
3844 * enabled (false).
3845 */
3846 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3847 boolean disabled) {
3848 if (mService != null) {
3849 try {
3850 mService.setAccountManagementDisabled(admin, accountType, disabled);
3851 } catch (RemoteException e) {
3852 Log.w(TAG, "Failed talking with device policy service", e);
3853 }
3854 }
3855 }
3856
3857 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003858 * Gets the array of accounts for which account management is disabled by the profile owner.
3859 *
3860 * <p> Account management can be disabled/enabled by calling
3861 * {@link #setAccountManagementDisabled}.
3862 *
3863 * @return a list of account types for which account management has been disabled.
3864 *
3865 * @see #setAccountManagementDisabled
3866 */
3867 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003868 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003869 }
3870
3871 /**
3872 * @see #getAccountTypesWithManagementDisabled()
3873 * @hide
3874 */
3875 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003876 if (mService != null) {
3877 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003878 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003879 } catch (RemoteException e) {
3880 Log.w(TAG, "Failed talking with device policy service", e);
3881 }
3882 }
3883
3884 return null;
3885 }
justinzhang511e0d82014-03-24 16:09:24 -04003886
3887 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003888 * Sets which packages may enter lock task mode.
3889 *
3890 * <p>Any packages that shares uid with an allowed package will also be allowed
3891 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003892 *
Jason Monkc5185f22014-06-24 11:12:42 -04003893 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003894 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003895 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003896 *
3897 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003898 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3899 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003900 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003901 */
Jason Monk48aacba2014-08-13 16:29:08 -04003902 public void setLockTaskPackages(ComponentName admin, String[] packages)
3903 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003904 if (mService != null) {
3905 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003906 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003907 } catch (RemoteException e) {
3908 Log.w(TAG, "Failed talking with device policy service", e);
3909 }
3910 }
3911 }
3912
3913 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003914 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003915 *
3916 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003917 * @hide
3918 */
Jason Monk48aacba2014-08-13 16:29:08 -04003919 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003920 if (mService != null) {
3921 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003922 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003923 } catch (RemoteException e) {
3924 Log.w(TAG, "Failed talking with device policy service", e);
3925 }
3926 }
3927 return null;
3928 }
3929
3930 /**
3931 * This function lets the caller know whether the given component is allowed to start the
3932 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003933 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003934 */
Jason Monkd7b86212014-06-16 13:15:38 -04003935 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003936 if (mService != null) {
3937 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003938 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003939 } catch (RemoteException e) {
3940 Log.w(TAG, "Failed talking with device policy service", e);
3941 }
3942 }
3943 return false;
3944 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003945
3946 /**
3947 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3948 * 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 -04003949 * <p>The settings that can be updated with this method are:
3950 * <ul>
3951 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3952 * <li>{@link Settings.Global#AUTO_TIME}</li>
3953 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003954 * <li>{@link Settings.Global#BLUETOOTH_ON}
3955 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3956 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3957 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003958 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3959 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3960 * <li>{@link Settings.Global#MODE_RINGER}</li>
3961 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3962 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003963 * <li>{@link Settings.Global#WIFI_ON}
3964 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3965 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003966 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003967 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3968 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3969 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003970 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003971 *
3972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3973 * @param setting The name of the setting to update.
3974 * @param value The value to update the setting to.
3975 */
3976 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3977 if (mService != null) {
3978 try {
3979 mService.setGlobalSetting(admin, setting, value);
3980 } catch (RemoteException e) {
3981 Log.w(TAG, "Failed talking with device policy service", e);
3982 }
3983 }
3984 }
3985
3986 /**
3987 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3988 * that the value of the setting is in the correct form for the setting type should be performed
3989 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003990 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003991 * <ul>
3992 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003993 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003994 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3995 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003996 * <p>A device owner can additionally update the following settings:
3997 * <ul>
3998 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3999 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004000 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4001 * @param setting The name of the setting to update.
4002 * @param value The value to update the setting to.
4003 */
4004 public void setSecureSetting(ComponentName admin, String setting, String value) {
4005 if (mService != null) {
4006 try {
4007 mService.setSecureSetting(admin, setting, value);
4008 } catch (RemoteException e) {
4009 Log.w(TAG, "Failed talking with device policy service", e);
4010 }
4011 }
4012 }
4013
Amith Yamasanif20d6402014-05-24 15:34:37 -07004014 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004015 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004016 * making permission requests of a local or remote administrator of the user.
4017 * <p/>
4018 * Only a profile owner can designate the restrictions provider.
4019 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004020 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004021 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004022 * it removes the restrictions provider previously assigned.
4023 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004024 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004025 if (mService != null) {
4026 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004027 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004028 } catch (RemoteException re) {
4029 Log.w(TAG, "Failed to set permission provider on device policy service");
4030 }
4031 }
4032 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004033
4034 /**
4035 * Called by profile or device owners to set the master volume mute on or off.
4036 *
4037 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4038 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4039 */
4040 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
4041 if (mService != null) {
4042 try {
4043 mService.setMasterVolumeMuted(admin, on);
4044 } catch (RemoteException re) {
4045 Log.w(TAG, "Failed to setMasterMute on device policy service");
4046 }
4047 }
4048 }
4049
4050 /**
4051 * Called by profile or device owners to check whether the master volume mute is on or off.
4052 *
4053 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4054 * @return {@code true} if master volume is muted, {@code false} if it's not.
4055 */
4056 public boolean isMasterVolumeMuted(ComponentName admin) {
4057 if (mService != null) {
4058 try {
4059 return mService.isMasterVolumeMuted(admin);
4060 } catch (RemoteException re) {
4061 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4062 }
4063 }
4064 return false;
4065 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004066
4067 /**
4068 * Called by profile or device owners to change whether a user can uninstall
4069 * a package.
4070 *
4071 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4072 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004073 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004074 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004075 public void setUninstallBlocked(ComponentName admin, String packageName,
4076 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004077 if (mService != null) {
4078 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004079 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004080 } catch (RemoteException re) {
4081 Log.w(TAG, "Failed to call block uninstall on device policy service");
4082 }
4083 }
4084 }
4085
4086 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004087 * Check whether the current user has been blocked by device policy from uninstalling a package.
4088 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004089 * <p>
4090 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
4091 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
4092 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
4093 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004094 *
Rubin Xua97855b2014-11-07 05:41:00 +00004095 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00004096 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004097 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004098 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004099 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01004100 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004101 if (mService != null) {
4102 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004103 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004104 } catch (RemoteException re) {
4105 Log.w(TAG, "Failed to call block uninstall on device policy service");
4106 }
4107 }
4108 return false;
4109 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004110
4111 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004112 * Called by the profile owner of a managed profile to enable widget providers from a
4113 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004114 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004115 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004116 * a package may have zero or more provider components, where each component
4117 * provides a different widget type.
4118 * <p>
4119 * <strong>Note:</strong> By default no widget provider package is white-listed.
4120 * </p>
4121 *
4122 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4123 * @param packageName The package from which widget providers are white-listed.
4124 * @return Whether the package was added.
4125 *
4126 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4127 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4128 */
4129 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4130 if (mService != null) {
4131 try {
4132 return mService.addCrossProfileWidgetProvider(admin, packageName);
4133 } catch (RemoteException re) {
4134 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4135 }
4136 }
4137 return false;
4138 }
4139
4140 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004141 * Called by the profile owner of a managed profile to disable widget providers from a given
4142 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004143 * package should have been added via {@link #addCrossProfileWidgetProvider(
4144 * android.content.ComponentName, String)}.
4145 * <p>
4146 * <strong>Note:</strong> By default no widget provider package is white-listed.
4147 * </p>
4148 *
4149 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4150 * @param packageName The package from which widget providers are no longer
4151 * white-listed.
4152 * @return Whether the package was removed.
4153 *
4154 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4155 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4156 */
4157 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4158 if (mService != null) {
4159 try {
4160 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4161 } catch (RemoteException re) {
4162 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4163 }
4164 }
4165 return false;
4166 }
4167
4168 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004169 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004170 * available in the parent profile.
4171 *
4172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4173 * @return The white-listed package list.
4174 *
4175 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4176 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4177 */
4178 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
4179 if (mService != null) {
4180 try {
4181 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4182 if (providers != null) {
4183 return providers;
4184 }
4185 } catch (RemoteException re) {
4186 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4187 }
4188 }
4189 return Collections.emptyList();
4190 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004191
4192 /**
4193 * Called by profile or device owners to set the current user's photo.
4194 *
4195 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4196 * @param icon the bitmap to set as the photo.
4197 */
4198 public void setUserIcon(ComponentName admin, Bitmap icon) {
4199 try {
4200 mService.setUserIcon(admin, icon);
4201 } catch (RemoteException re) {
4202 Log.w(TAG, "Could not set the user icon ", re);
4203 }
4204 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004205
4206 /**
4207 * Called by device initializer to send a provisioning status update to the remote setup device.
4208 *
4209 * @param statusCode a custom status code value as defined by
4210 * {@link DeviceInitializerStatus#isCustomStatus(int)}.
4211 * @param description custom description of the status code sent
4212 */
4213 public void sendDeviceInitializerStatus(int statusCode, String description) {
4214 try {
4215 mService.sendDeviceInitializerStatus(statusCode, description);
4216 } catch (RemoteException re) {
4217 Log.w(TAG, "Could not send device initializer status", re);
4218 }
4219 }
Rubin Xu8027a4f2015-03-10 17:52:37 +00004220
Rubin Xu5faad8e2015-04-20 17:43:48 +01004221 /**
4222 * Called by device owners to set a local system update policy. When a new policy is set,
4223 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004224 *
4225 * @param who Which {@link DeviceAdminReceiver} this request is associated with. All components
Rubin Xu5faad8e2015-04-20 17:43:48 +01004226 * in the device owner package can set system update policies and the most recent policy takes
4227 * effect.
4228 * @param policy the new policy, or null to clear the current policy.
4229 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004230 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004231 public void setSystemUpdatePolicy(ComponentName who, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004232 if (mService != null) {
4233 try {
4234 if (policy != null) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004235 mService.setSystemUpdatePolicy(who, policy.getPolicyBundle());
Rubin Xu8027a4f2015-03-10 17:52:37 +00004236 } else {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004237 mService.setSystemUpdatePolicy(who, null);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004238 }
4239 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004240 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004241 }
4242 }
4243 }
4244
4245 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004246 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004247 *
Rubin Xu5faad8e2015-04-20 17:43:48 +01004248 * @return The current policy object, or null if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004249 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004250 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004251 if (mService != null) {
4252 try {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004253 PersistableBundle bundle = mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004254 if (bundle != null) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004255 return new SystemUpdatePolicy(bundle);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004256 } else {
4257 return null;
4258 }
4259 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004260 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004261 }
4262 }
4263 return null;
4264 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004265
4266 /**
4267 * Called by a device owner to disable the keyguard altogether.
4268 *
4269 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4270 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4271 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4272 * being disabled.
4273 *
4274 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4275 * @param enabled New state of the keyguard.
4276 *
4277 * @return {@code false} if attempting to disable the keyguard while a lock password was in
4278 * place. {@code true} otherwise."
4279 */
4280 public boolean setKeyguardEnabledState(ComponentName admin, boolean enabled) {
4281 try {
4282 return mService.setKeyguardEnabledState(admin, enabled);
4283 } catch (RemoteException re) {
4284 Log.w(TAG, "Failed talking with device policy service", re);
4285 return false;
4286 }
4287 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004288
4289 /**
4290 * Called by device owner to set the enabled state of the status bar. Disabling the status
4291 * bar blocks notifications, quick settings and other screen overlays that allow escaping from
4292 * a single use device.
4293 *
4294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4295 * @param enabled New state of the status bar.
4296 */
4297 public void setStatusBarEnabledState(ComponentName admin, boolean enabled) {
4298 try {
4299 mService.setStatusBarEnabledState(admin, enabled);
4300 } catch (RemoteException re) {
4301 Log.w(TAG, "Failed talking with device policy service", re);
4302 }
4303 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004304}