blob: a0b95b6a53c4cd47f36ae057590252bb682ed8c9 [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
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010034import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080035import android.os.Handler;
Jim Millere303bf42014-08-26 17:12:29 -070036import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000037import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080038import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070041import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040042import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040043import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010044import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070045import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import android.util.Log;
47
Maggie Benthallda51e682013-08-08 22:35:44 -040048import com.android.org.conscrypt.TrustedCertificateStore;
49
Jessica Hummel91da58d2014-04-10 17:39:43 +010050import org.xmlpull.v1.XmlPullParserException;
51
Maggie Benthallda51e682013-08-08 22:35:44 -040052import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080053import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070054import java.net.InetSocketAddress;
55import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010056import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010057import java.security.PrivateKey;
58import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040059import java.security.cert.CertificateException;
60import java.security.cert.CertificateFactory;
61import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010062import java.security.spec.PKCS8EncodedKeySpec;
63import java.security.spec.InvalidKeySpecException;
64import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070065import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070066import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080067import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080068
69/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000070 * Public interface for managing policies enforced on a device. Most clients of this class must be
71 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000072 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000073 * a device administrator may be registered as either a profile or device owner. A given method is
74 * accessible to all device administrators unless the documentation for that method specifies that
75 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080076 *
77 * <div class="special reference">
78 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000079 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080080 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070081 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080083 */
84public class DevicePolicyManager {
85 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080086
87 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080088 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070089
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080090 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080091 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080092 mService = IDevicePolicyManager.Stub.asInterface(
93 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
94 }
95
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080096 /** @hide */
97 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080098 DevicePolicyManager me = new DevicePolicyManager(context, handler);
99 return me.mService != null ? me : null;
100 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700101
Dianne Hackbornd6847842010-01-12 18:14:19 -0800102 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000103 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000104 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100105 * <p>A managed profile allows data separation for example for the usage of a
106 * device as a personal and corporate device. The user which provisioning is started from and
107 * the managed profile share a launcher.
108 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800109 * <p>This intent will typically be sent by a mobile device management application (MDM).
110 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
111 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100112 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000113 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
114 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
115 * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain the extra
116 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
117 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000118 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000119 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
120 * in the provisioning intent. The
121 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
122 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
123 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100124 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100125 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
126 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127 */
128 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
129 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100130 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000131
132 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700133 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
134 * a mobile device management application that starts managed profile provisioning to pass data
135 * to itself on the managed profile when provisioning completes. The mobile device management
136 * application sends this extra in an intent with the action
137 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
138 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
139 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
140 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100141 */
142 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100143 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100144
145 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100146 * A String extra holding the package name of the mobile device management application that
147 * will be set as the profile owner or device owner.
148 *
149 * <p>If an application starts provisioning directly via an intent with action
150 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
151 * application that started provisioning. The package will be set as profile owner in that case.
152 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000153 * <p>This package is set as device owner when device owner provisioning is started by an NFC
154 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000155 *
156 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700157 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000158
159 * @see DeviceAdminReceiver
160 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
161 * supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000162 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000163 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000164 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100165 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000166
167 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000168 * A ComponentName extra indicating the device admin receiver of the mobile device management
169 * application that will be set as the profile owner or device owner and active admin.
170 *
171 * <p>If an application starts provisioning directly via an intent with action
172 * {@link #ACTION_PROVISION_MANAGED_PROFILE} the package name of this component has to match the
173 * package name of the application that started provisioning.
174 *
175 * <p>This component is set as device owner and active admin when device owner provisioning is
176 * started by an NFC message containing an NFC record with MIME type
Rubin Xu44ef750b2015-03-23 16:51:33 +0000177 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}. For the NFC record, the component name should be
178 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000179 *
180 * @see DeviceAdminReceiver
181 */
182 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
183 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
184
185 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000186 * An {@link android.accounts.Account} extra holding the account to migrate during managed
187 * profile provisioning. If the account supplied is present in the primary user, it will be
188 * copied, along with its credentials to the managed profile and removed from the primary user.
189 *
190 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
191 */
192
193 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
194 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
195
196 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100197 * A String extra that, holds the email address of the account which a managed profile is
198 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
199 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100200 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100201 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
202 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100203 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
204 * contains this extra, it is forwarded in the
205 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
206 * device management application that was set as the profile owner during provisioning.
207 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100208 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100209 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
210 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100211
212 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000213 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700214 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000215 *
216 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
217 * provisioning via an NFC bump.
218 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000219 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
220 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000221
222 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100223 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
224 * will be set to.
225 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000226 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
227 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100228 */
229 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100230 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100231
232 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100233 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
234 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100235 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000236 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
237 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100238 */
239 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100240 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100241
242 /**
243 * A String extra holding the {@link java.util.Locale} that the device will be set to.
244 * Format: xx_yy, where xx is the language code, and yy the country code.
245 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000246 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
247 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100248 */
249 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100250 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100251
252 /**
253 * A String extra holding the ssid of the wifi network that should be used during nfc device
254 * owner provisioning for downloading the mobile device management application.
255 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000256 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
257 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100258 */
259 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100260 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100261
262 /**
263 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
264 * is hidden or not.
265 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000266 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
267 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100268 */
269 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100270 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100271
272 /**
273 * A String extra indicating the security type of the wifi network in
274 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
275 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000276 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
277 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100278 */
279 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100280 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100281
282 /**
283 * A String extra holding the password of the wifi network in
284 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
285 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000286 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
287 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100288 */
289 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100290 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100291
292 /**
293 * A String extra holding the proxy host for the wifi network in
294 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
295 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000296 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
297 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100298 */
299 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100300 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100301
302 /**
303 * An int extra holding the proxy port for the wifi network in
304 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
305 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000306 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
307 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100308 */
309 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100310 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100311
312 /**
313 * A String extra holding the proxy bypass for the wifi network in
314 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
315 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000316 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
317 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100318 */
319 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100320 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100321
322 /**
323 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
324 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
325 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000326 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
327 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100328 */
329 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100330 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100331
332 /**
333 * A String extra holding a url that specifies the download location of the device admin
334 * package. When not provided it is assumed that the device admin package is already installed.
335 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000336 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
337 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100338 */
339 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100340 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100341
342 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400343 * An int extra holding a minimum required version code for the device admin package. If the
344 * device admin is already installed on the device, it will only be re-downloaded from
345 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
346 * installed package is less than this version code.
347 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400348 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400349 * provisioning via an NFC bump.
350 */
351 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
352 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
353
354 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100355 * A String extra holding a http cookie header which should be used in the http request to the
356 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
357 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000358 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
359 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100360 */
361 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100362 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100363
364 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000365 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100366 * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
367 *
368 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM} should be
369 * present. The provided checksum should match the checksum of the file at the download
370 * location. If the checksum doesn't match an error will be shown to the user and the user will
371 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100372 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000373 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
374 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100375 */
376 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100377 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100378
379 /**
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100380 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any certificate of the
381 * android package archive at the download location specified in {@link
382 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
383 *
384 * <p>The certificates of an android package archive can be obtained using
385 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
386 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
387 *
388 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
389 * present. The provided checksum should match the checksum of any certificate of the file at
390 * the download location. If the checksum does not match an error will be shown to the user and
391 * the user will be asked to factory reset the device.
392 *
393 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
394 * provisioning via an NFC bump.
395 */
396 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM
397 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM";
398
399 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000400 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
401 * has completed successfully.
402 *
403 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700404 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000405 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800406 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000407 * corresponds to the account requested to be migrated at provisioning time, if any.
408 */
409 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
410 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
411 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
412
413 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400414 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500415 * provisioning.
416 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400417 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500418 * provisioning via an NFC bump.
419 */
420 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
421 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
422
423 /**
Rubin Xu44ef750b2015-03-23 16:51:33 +0000424 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
425 * component of the application that is temporarily granted device owner privileges during
426 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500427 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000428 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000429 * 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 +0000430 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
431 * string first.
432 *
433 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500434 */
435 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
436 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
437
438 /**
439 * A String extra holding an http url that specifies the download location of the device
440 * initializer package. When not provided it is assumed that the device initializer package is
441 * already installed.
442 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400443 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500444 * provisioning via an NFC bump.
445 */
446 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
447 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
448
449 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400450 * An int extra holding a minimum required version code for the device initializer package.
451 * If the initializer is already installed on the device, it will only be re-downloaded from
452 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
453 * the installed package is less than this version code.
454 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400455 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400456 * provisioning via an NFC bump.
457 */
458 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
459 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
460
461 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500462 * A String extra holding a http cookie header which should be used in the http request to the
463 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
464 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400465 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500466 * provisioning via an NFC bump.
467 */
468 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
469 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
470
471 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000472 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
473 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100474 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
475 *
476 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM}
477 * should be present. The provided checksum should match the checksum of the file at the
478 * download location. If the checksum doesn't match an error will be shown to the user and the
479 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500480 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400481 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500482 * provisioning via an NFC bump.
483 */
484 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
485 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
486
487 /**
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100488 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any certificate of the
489 * android package archive at the download location specified in {@link
490 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
491 *
492 * <p>The certificates of an android package archive can be obtained using
493 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
494 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
495 *
496 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
497 * should be present. The provided checksum should match the checksum of any certificate of the
498 * file at the download location. If the checksum doesn't match an error will be shown to the
499 * user and the user will be asked to factory reset the device.
500 *
501 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
502 * provisioning via an NFC bump.
503 */
504 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM
505 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM";
506
507 /**
Craig Lafayette97e473e2015-03-19 10:19:38 -0400508 * A String extra holding the MAC address of the Bluetooth device to connect to with status
509 * updates during provisioning.
510 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400511 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400512 * provisioning via an NFC bump.
513 */
514 public static final String EXTRA_PROVISIONING_BT_MAC_ADDRESS
515 = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS";
516
517 /**
518 * A String extra holding the Bluetooth service UUID on the device to connect to with status
519 * updates during provisioning.
520 *
521 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
522 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400523 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400524 * provisioning via an NFC bump.
525 */
526 public static final String EXTRA_PROVISIONING_BT_UUID
527 = "android.app.extra.PROVISIONING_BT_UUID";
528
529 /**
530 * A String extra holding a unique identifier used to identify the device connecting over
531 * Bluetooth. This identifier will be part of every status message sent to the remote device.
532 *
533 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
534 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400535 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400536 * provisioning via an NFC bump.
537 */
538 public static final String EXTRA_PROVISIONING_BT_DEVICE_ID
539 = "android.app.extra.PROVISIONING_BT_DEVICE_ID";
540
541 /**
542 * A Boolean extra that that will cause a provisioned device to temporarily proxy network
543 * traffic over Bluetooth. When a Wi-Fi network is available, the network proxy will stop.
544 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400546 * provisioning via an NFC bump.
547 */
548 public static final String EXTRA_PROVISIONING_BT_USE_PROXY
549 = "android.app.extra.PROVISIONING_BT_USE_PROXY";
Craig Lafayette8e27c4d2015-03-19 08:36:38 -0400550
551 /**
552 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
553 * holds data needed by the system to wipe factory reset protection. The data needed to wipe
554 * the device depend on the installed factory reset protection implementation. For example,
555 * if an account is needed to unlock a device, this extra may contain data used to
556 * authenticate that account.
557 *
558 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
559 * provisioning via an NFC bump.
560 */
561 public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS
562 = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
563
Craig Lafayette97e473e2015-03-19 10:19:38 -0400564 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400565 * This MIME type is used for starting the Device Owner provisioning that does not require
566 * provisioning features introduced in Android API level
567 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100568 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400569 * <p>For more information about the provisioning process see
570 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100571 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000572 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100573 * contains the following properties:
574 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400575 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
576 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100577 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400578 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
580 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
581 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
582 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
583 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
584 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
585 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
586 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
587 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
588 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400589 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000591 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400592 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
593 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
594 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
595 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
596 *
597 * @see #MIME_TYPE_PROVISIONING_NFC_V2
598 *
599 */
600 public static final String MIME_TYPE_PROVISIONING_NFC
601 = "application/com.android.managedprovisioning";
602
603
604 /**
605 * This MIME type is used for starting the Device Owner provisioning that requires
606 * new provisioning features introduced in API version
607 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
608 * versions.
609 *
610 * <p>During device owner provisioning a device admin app is set as the owner of the device.
611 * A device owner has full control over the device. The device owner can not be modified by the
612 * user and the only way of resetting the device is if the device owner app calls a factory
613 * reset.
614 *
615 * <p> A typical use case would be a device that is owned by a company, but used by either an
616 * employee or client.
617 *
618 * <p> The NFC message should be sent to an unprovisioned device.
619 *
620 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
621 * contains the following properties in addition to properties listed at
622 * {@link #MIME_TYPE_PROVISIONING_NFC}:
623 * <ul>
624 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
625 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
626 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
627 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
628 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
629 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
630 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
631 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
632 * should be converted to a String via
633 * {@link android.content.ComponentName#flattenToString()}</li>
634 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li>
635 * <li>{@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, optional</li>
636 * <li>{@link #EXTRA_PROVISIONING_BT_UUID}, optional</li>
637 * <li>{@link #EXTRA_PROVISIONING_BT_DEVICE_ID}, optional</li>
638 * <li>{@link #EXTRA_PROVISIONING_BT_USE_PROXY}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000639 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100640 * <p> When device owner provisioning has completed, an intent of the type
641 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
642 * device owner.
643 *
644 * <p>
645 * If provisioning fails, the device is factory reset.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100646 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400647 public static final String MIME_TYPE_PROVISIONING_NFC_V2
648 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100649
650 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800651 * Activity action: ask the user to add a new device administrator to the system.
652 * The desired policy is the ComponentName of the policy in the
653 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
654 * bring the user through adding the device administrator to the system (or
655 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700656 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800657 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
658 * field to provide the user with additional explanation (in addition
659 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800660 *
661 * <p>If your administrator is already active, this will ordinarily return immediately (without
662 * user intervention). However, if your administrator has been updated and is requesting
663 * additional uses-policy flags, the user will be presented with the new list. New policies
664 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800665 */
666 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
667 public static final String ACTION_ADD_DEVICE_ADMIN
668 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700669
Dianne Hackbornd6847842010-01-12 18:14:19 -0800670 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700671 * @hide
672 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700673 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700674 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700675 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
676 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700677 * to remotely control restrictions on the user.
678 *
679 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
680 * result of whether or not the user approved the action. If approved, the result will
681 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
682 * as a profile owner.
683 *
684 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
685 * field to provide the user with additional explanation (in addition
686 * to your component's description) about what is being added.
687 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700688 * <p>If there is already a profile owner active or the caller is not a system app, the
689 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700690 */
691 @SystemApi
692 public static final String ACTION_SET_PROFILE_OWNER
693 = "android.app.action.SET_PROFILE_OWNER";
694
695 /**
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400696 * Protected broadcast action that will be sent to managed provisioning to notify it that a
697 * status update has been reported by the device initializer. The status update will be
698 * reported to the remote setup device over Bluetooth.
699 *
700 * <p>Broadcasts with this action must supply a
Craig Lafayette9ef04bf2015-05-06 16:57:01 -0400701 * {@linkplain DeviceInitializerStatus#FLAG_STATUS_CUSTOM custom} status code in the
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400702 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_CODE} extra.
703 *
704 * <p>Broadcasts may optionally contain a description in the
705 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION} extra.
706 * @hide
707 */
708 @SystemApi
709 public static final String ACTION_SEND_DEVICE_INITIALIZER_STATUS
710 = "android.app.action.SEND_DEVICE_INITIALIZER_STATUS";
711
712 /**
713 * An integer extra that contains the status code that defines a status update. This extra must
714 * sent as part of a broadcast with an action of {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
715 *
716 * <p>The status code sent with this extra must be a custom status code as defined by
Craig Lafayette9ef04bf2015-05-06 16:57:01 -0400717 * {@link DeviceInitializerStatus#FLAG_STATUS_CUSTOM}.
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400718 * @hide
719 */
720 @SystemApi
721 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_CODE
722 = "android.app.extra.DEVICE_INITIALIZER_STATUS_CODE";
723
724 /**
725 * A {@code String} extra that contains an optional description accompanying a status update.
726 * This extra my be sent as part of a broadcast with an action of
727 * {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
728 * @hide
729 */
730 @SystemApi
731 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION
732 = "android.app.extra.DEVICE_INITIALIZER_STATUS_DESCRIPTION";
733
734 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700735 * @hide
736 * Name of the profile owner admin that controls the user.
737 */
738 @SystemApi
739 public static final String EXTRA_PROFILE_OWNER_NAME
740 = "android.app.extra.PROFILE_OWNER_NAME";
741
742 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700743 * Activity action: send when any policy admin changes a policy.
744 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700745 *
Jim Miller284b62e2010-06-08 14:27:42 -0700746 * @hide
747 */
748 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
749 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
750
751 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800752 * The ComponentName of the administrator component.
753 *
754 * @see #ACTION_ADD_DEVICE_ADMIN
755 */
756 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700757
Dianne Hackbornd6847842010-01-12 18:14:19 -0800758 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800759 * An optional CharSequence providing additional explanation for why the
760 * admin is being added.
761 *
762 * @see #ACTION_ADD_DEVICE_ADMIN
763 */
764 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700765
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800766 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700767 * Activity action: have the user enter a new password. This activity should
768 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
769 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
770 * enter a new password that meets the current requirements. You can use
771 * {@link #isActivePasswordSufficient()} to determine whether you need to
772 * have the user select a new password in order to meet the current
773 * constraints. Upon being resumed from this activity, you can check the new
774 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800775 */
776 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
777 public static final String ACTION_SET_NEW_PASSWORD
778 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700779
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000780 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000781 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
782 * the parent profile to access intents sent from the managed profile.
783 * That is, when an app in the managed profile calls
784 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
785 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000786 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100787 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000788
789 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000790 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
791 * the managed profile to access intents sent from the parent profile.
792 * That is, when an app in the parent profile calls
793 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
794 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000795 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100796 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700797
Dianne Hackbornd6847842010-01-12 18:14:19 -0800798 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100799 * Broadcast action: notify that a new local system update policy has been set by the device
800 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000801 */
802 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100803 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
804 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000805
Amith Yamasanid49489b2015-04-28 14:00:26 -0700806 /**
807 * Permission policy to prompt user for new permission requests for runtime permissions.
808 * Already granted or denied permissions are not affected by this.
809 */
810 public static final int PERMISSION_POLICY_PROMPT = 0;
811
812 /**
813 * Permission policy to always grant new permission requests for runtime permissions.
814 * Already granted or denied permissions are not affected by this.
815 */
816 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
817
818 /**
819 * Permission policy to always deny new permission requests for runtime permissions.
820 * Already granted or denied permissions are not affected by this.
821 */
822 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
823
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700824 /**
825 * Runtime permission state: The user can manage the permission
826 * through the UI.
827 */
828 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
829
830 /**
831 * Runtime permission state: The permission is granted to the app
832 * and the user cannot manage the permission through the UI.
833 */
834 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
835
836 /**
837 * Runtime permission state: The permission is denied to the app
838 * and the user cannot manage the permission through the UI.
839 */
840 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000841
842 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800843 * Return true if the given administrator component is currently
844 * active (enabled) in the system.
845 */
Robin Lee25e26452015-06-02 09:56:29 -0700846 public boolean isAdminActive(@NonNull ComponentName admin) {
847 return isAdminActiveAsUser(admin, UserHandle.myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100848 }
849
850 /**
851 * @see #isAdminActive(ComponentName)
852 * @hide
853 */
Robin Lee25e26452015-06-02 09:56:29 -0700854 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800855 if (mService != null) {
856 try {
Robin Lee25e26452015-06-02 09:56:29 -0700857 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800858 } catch (RemoteException e) {
859 Log.w(TAG, "Failed talking with device policy service", e);
860 }
861 }
862 return false;
863 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800864 /**
865 * Return true if the given administrator component is currently being removed
866 * for the user.
867 * @hide
868 */
Robin Lee25e26452015-06-02 09:56:29 -0700869 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800870 if (mService != null) {
871 try {
Robin Lee25e26452015-06-02 09:56:29 -0700872 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800873 } catch (RemoteException e) {
874 Log.w(TAG, "Failed talking with device policy service", e);
875 }
876 }
877 return false;
878 }
879
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700880
Dianne Hackbornd6847842010-01-12 18:14:19 -0800881 /**
Robin Lee25e26452015-06-02 09:56:29 -0700882 * Return a list of all currently active device administrators' component
883 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800884 * returned.
885 */
886 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100887 return getActiveAdminsAsUser(UserHandle.myUserId());
888 }
889
890 /**
891 * @see #getActiveAdmins()
892 * @hide
893 */
894 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800895 if (mService != null) {
896 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100897 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800898 } catch (RemoteException e) {
899 Log.w(TAG, "Failed talking with device policy service", e);
900 }
901 }
902 return null;
903 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700904
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800905 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700906 * Used by package administration code to determine if a package can be stopped
907 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800908 * @hide
909 */
910 public boolean packageHasActiveAdmins(String packageName) {
911 if (mService != null) {
912 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700913 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800914 } catch (RemoteException e) {
915 Log.w(TAG, "Failed talking with device policy service", e);
916 }
917 }
918 return false;
919 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700920
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800921 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800922 * Remove a current administration component. This can only be called
923 * by the application that owns the administration component; if you
924 * try to remove someone else's component, a security exception will be
925 * thrown.
926 */
Robin Lee25e26452015-06-02 09:56:29 -0700927 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800928 if (mService != null) {
929 try {
Robin Lee25e26452015-06-02 09:56:29 -0700930 mService.removeActiveAdmin(admin, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800931 } catch (RemoteException e) {
932 Log.w(TAG, "Failed talking with device policy service", e);
933 }
934 }
935 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700936
Dianne Hackbornd6847842010-01-12 18:14:19 -0800937 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800938 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700939 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800940 * but requires additional policies after an upgrade.
941 *
942 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
943 * an active administrator, or an exception will be thrown.
944 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
945 */
Robin Lee25e26452015-06-02 09:56:29 -0700946 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800947 if (mService != null) {
948 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700949 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800950 } catch (RemoteException e) {
951 Log.w(TAG, "Failed talking with device policy service", e);
952 }
953 }
954 return false;
955 }
956
957 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800958 * Constant for {@link #setPasswordQuality}: the policy has no requirements
959 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800960 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800961 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800962 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700963
Dianne Hackbornd6847842010-01-12 18:14:19 -0800964 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700965 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
966 * recognition technology. This implies technologies that can recognize the identity of
967 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
968 * Note that quality constants are ordered so that higher values are more restrictive.
969 */
970 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
971
972 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800973 * Constant for {@link #setPasswordQuality}: the policy requires some kind
974 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800975 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800976 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800977 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700978
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800979 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800980 * Constant for {@link #setPasswordQuality}: the user must have entered a
981 * password containing at least numeric characters. Note that quality
982 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800983 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800984 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700985
Dianne Hackbornd6847842010-01-12 18:14:19 -0800986 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800987 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800988 * password containing at least numeric characters with no repeating (4444)
989 * or ordered (1234, 4321, 2468) sequences. Note that quality
990 * constants are ordered so that higher values are more restrictive.
991 */
992 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
993
994 /**
995 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700996 * password containing at least alphabetic (or other symbol) characters.
997 * Note that quality constants are ordered so that higher values are more
998 * restrictive.
999 */
1000 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001001
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001002 /**
1003 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001004 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001005 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001006 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001007 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001008 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001009
Dianne Hackbornd6847842010-01-12 18:14:19 -08001010 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001011 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001012 * password containing at least a letter, a numerical digit and a special
1013 * symbol, by default. With this password quality, passwords can be
1014 * restricted to contain various sets of characters, like at least an
1015 * uppercase letter, etc. These are specified using various methods,
1016 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1017 * that quality constants are ordered so that higher values are more
1018 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001019 */
1020 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1021
1022 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001023 * Called by an application that is administering the device to set the
1024 * password restrictions it is imposing. After setting this, the user
1025 * will not be able to enter a new password that is not at least as
1026 * restrictive as what has been set. Note that the current password
1027 * will remain until the user has set a new one, so the change does not
1028 * take place immediately. To prompt the user for a new password, use
1029 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001030 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001031 * <p>Quality constants are ordered so that higher values are more restrictive;
1032 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001033 * the user's preference, and any other considerations) is the one that
1034 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001035 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001036 * <p>The calling device admin must have requested
1037 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1038 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001039 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001040 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001041 * @param quality The new desired quality. One of
1042 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001043 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1044 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1045 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001046 */
Robin Lee25e26452015-06-02 09:56:29 -07001047 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 if (mService != null) {
1049 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001050 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001051 } catch (RemoteException e) {
1052 Log.w(TAG, "Failed talking with device policy service", e);
1053 }
1054 }
1055 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001056
Dianne Hackbornd6847842010-01-12 18:14:19 -08001057 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001058 * Retrieve the current minimum password quality for all admins of this user
1059 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001060 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001061 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001062 */
Robin Lee25e26452015-06-02 09:56:29 -07001063 public int getPasswordQuality(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001064 return getPasswordQuality(admin, UserHandle.myUserId());
1065 }
1066
1067 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001068 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 if (mService != null) {
1070 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001071 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001072 } catch (RemoteException e) {
1073 Log.w(TAG, "Failed talking with device policy service", e);
1074 }
1075 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001076 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001077 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001080 * Called by an application that is administering the device to set the
1081 * minimum allowed password length. After setting this, the user
1082 * will not be able to enter a new password that is not at least as
1083 * restrictive as what has been set. Note that the current password
1084 * will remain until the user has set a new one, so the change does not
1085 * take place immediately. To prompt the user for a new password, use
1086 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1087 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001088 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1089 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1090 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001091 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001092 * <p>The calling device admin must have requested
1093 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1094 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001095 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001096 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001097 * @param length The new desired minimum password length. A value of 0
1098 * means there is no restriction.
1099 */
Robin Lee25e26452015-06-02 09:56:29 -07001100 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001101 if (mService != null) {
1102 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001103 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001104 } catch (RemoteException e) {
1105 Log.w(TAG, "Failed talking with device policy service", e);
1106 }
1107 }
1108 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001109
Dianne Hackbornd6847842010-01-12 18:14:19 -08001110 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001111 * Retrieve the current minimum password length for all admins of this
1112 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001113 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001114 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001115 */
Robin Lee25e26452015-06-02 09:56:29 -07001116 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001117 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1118 }
1119
1120 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001121 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001122 if (mService != null) {
1123 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001124 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001125 } catch (RemoteException e) {
1126 Log.w(TAG, "Failed talking with device policy service", e);
1127 }
1128 }
1129 return 0;
1130 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001131
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001132 /**
1133 * Called by an application that is administering the device to set the
1134 * minimum number of upper case letters required in the password. After
1135 * setting this, the user will not be able to enter a new password that is
1136 * not at least as restrictive as what has been set. Note that the current
1137 * password will remain until the user has set a new one, so the change does
1138 * not take place immediately. To prompt the user for a new password, use
1139 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1140 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001141 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1142 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001143 * <p>
1144 * The calling device admin must have requested
1145 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1146 * this method; if it has not, a security exception will be thrown.
1147 *
1148 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1149 * with.
1150 * @param length The new desired minimum number of upper case letters
1151 * required in the password. A value of 0 means there is no
1152 * restriction.
1153 */
Robin Lee25e26452015-06-02 09:56:29 -07001154 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001155 if (mService != null) {
1156 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001157 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001158 } catch (RemoteException e) {
1159 Log.w(TAG, "Failed talking with device policy service", e);
1160 }
1161 }
1162 }
1163
1164 /**
1165 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001166 * password for all admins of this user and its profiles or a particular one.
1167 * This is the same value as set by
1168 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001169 * and only applies when the password quality is
1170 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001171 *
Robin Lee25e26452015-06-02 09:56:29 -07001172 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001173 * aggregate all admins.
1174 * @return The minimum number of upper case letters required in the
1175 * password.
1176 */
Robin Lee25e26452015-06-02 09:56:29 -07001177 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001178 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1179 }
1180
1181 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001182 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001183 if (mService != null) {
1184 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001185 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001186 } catch (RemoteException e) {
1187 Log.w(TAG, "Failed talking with device policy service", e);
1188 }
1189 }
1190 return 0;
1191 }
1192
1193 /**
1194 * Called by an application that is administering the device to set the
1195 * minimum number of lower case letters required in the password. After
1196 * setting this, the user will not be able to enter a new password that is
1197 * not at least as restrictive as what has been set. Note that the current
1198 * password will remain until the user has set a new one, so the change does
1199 * not take place immediately. To prompt the user for a new password, use
1200 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1201 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001202 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1203 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001204 * <p>
1205 * The calling device admin must have requested
1206 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1207 * this method; if it has not, a security exception will be thrown.
1208 *
1209 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1210 * with.
1211 * @param length The new desired minimum number of lower case letters
1212 * required in the password. A value of 0 means there is no
1213 * restriction.
1214 */
Robin Lee25e26452015-06-02 09:56:29 -07001215 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001216 if (mService != null) {
1217 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001218 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001219 } catch (RemoteException e) {
1220 Log.w(TAG, "Failed talking with device policy service", e);
1221 }
1222 }
1223 }
1224
1225 /**
1226 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001227 * password for all admins of this user and its profiles or a particular one.
1228 * This is the same value as set by
1229 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001230 * and only applies when the password quality is
1231 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001232 *
Robin Lee25e26452015-06-02 09:56:29 -07001233 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001234 * aggregate all admins.
1235 * @return The minimum number of lower case letters required in the
1236 * password.
1237 */
Robin Lee25e26452015-06-02 09:56:29 -07001238 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001239 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1240 }
1241
1242 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001243 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001244 if (mService != null) {
1245 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001246 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001247 } catch (RemoteException e) {
1248 Log.w(TAG, "Failed talking with device policy service", e);
1249 }
1250 }
1251 return 0;
1252 }
1253
1254 /**
1255 * Called by an application that is administering the device to set the
1256 * minimum number of letters required in the password. After setting this,
1257 * the user will not be able to enter a new password that is not at least as
1258 * restrictive as what has been set. Note that the current password will
1259 * remain until the user has set a new one, so the change does not take
1260 * place immediately. To prompt the user for a new password, use
1261 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1262 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001263 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1264 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001265 * <p>
1266 * The calling device admin must have requested
1267 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1268 * this method; if it has not, a security exception will be thrown.
1269 *
1270 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1271 * with.
1272 * @param length The new desired minimum number of letters required in the
1273 * password. A value of 0 means there is no restriction.
1274 */
Robin Lee25e26452015-06-02 09:56:29 -07001275 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001276 if (mService != null) {
1277 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001278 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001279 } catch (RemoteException e) {
1280 Log.w(TAG, "Failed talking with device policy service", e);
1281 }
1282 }
1283 }
1284
1285 /**
1286 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001287 * admins or a particular one. This is the same value as
1288 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1289 * and only applies when the password quality is
1290 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001291 *
Robin Lee25e26452015-06-02 09:56:29 -07001292 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001293 * aggregate all admins.
1294 * @return The minimum number of letters required in the password.
1295 */
Robin Lee25e26452015-06-02 09:56:29 -07001296 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001297 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1298 }
1299
1300 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001301 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001302 if (mService != null) {
1303 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001304 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001305 } catch (RemoteException e) {
1306 Log.w(TAG, "Failed talking with device policy service", e);
1307 }
1308 }
1309 return 0;
1310 }
1311
1312 /**
1313 * Called by an application that is administering the device to set the
1314 * minimum number of numerical digits required in the password. After
1315 * setting this, the user will not be able to enter a new password that is
1316 * not at least as restrictive as what has been set. Note that the current
1317 * password will remain until the user has set a new one, so the change does
1318 * not take place immediately. To prompt the user for a new password, use
1319 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1320 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001321 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1322 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001323 * <p>
1324 * The calling device admin must have requested
1325 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1326 * this method; if it has not, a security exception will be thrown.
1327 *
1328 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1329 * with.
1330 * @param length The new desired minimum number of numerical digits required
1331 * in the password. A value of 0 means there is no restriction.
1332 */
Robin Lee25e26452015-06-02 09:56:29 -07001333 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001334 if (mService != null) {
1335 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001336 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001337 } catch (RemoteException e) {
1338 Log.w(TAG, "Failed talking with device policy service", e);
1339 }
1340 }
1341 }
1342
1343 /**
1344 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001345 * for all admins of this user and its profiles or a particular one.
1346 * This is the same value as set by
1347 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001348 * and only applies when the password quality is
1349 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001350 *
Robin Lee25e26452015-06-02 09:56:29 -07001351 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001352 * aggregate all admins.
1353 * @return The minimum number of numerical digits required in the password.
1354 */
Robin Lee25e26452015-06-02 09:56:29 -07001355 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001356 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1357 }
1358
1359 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001360 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001361 if (mService != null) {
1362 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001363 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001364 } catch (RemoteException e) {
1365 Log.w(TAG, "Failed talking with device policy service", e);
1366 }
1367 }
1368 return 0;
1369 }
1370
1371 /**
1372 * Called by an application that is administering the device to set the
1373 * minimum number of symbols required in the password. After setting this,
1374 * the user will not be able to enter a new password that is not at least as
1375 * restrictive as what has been set. Note that the current password will
1376 * remain until the user has set a new one, so the change does not take
1377 * place immediately. To prompt the user for a new password, use
1378 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1379 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001380 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1381 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001382 * <p>
1383 * The calling device admin must have requested
1384 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1385 * this method; if it has not, a security exception will be thrown.
1386 *
1387 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1388 * with.
1389 * @param length The new desired minimum number of symbols required in the
1390 * password. A value of 0 means there is no restriction.
1391 */
Robin Lee25e26452015-06-02 09:56:29 -07001392 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001393 if (mService != null) {
1394 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001395 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001396 } catch (RemoteException e) {
1397 Log.w(TAG, "Failed talking with device policy service", e);
1398 }
1399 }
1400 }
1401
1402 /**
1403 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001404 * admins or a particular one. This is the same value as
1405 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1406 * and only applies when the password quality is
1407 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001408 *
Robin Lee25e26452015-06-02 09:56:29 -07001409 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001410 * aggregate all admins.
1411 * @return The minimum number of symbols required in the password.
1412 */
Robin Lee25e26452015-06-02 09:56:29 -07001413 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001414 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1415 }
1416
1417 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001418 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001419 if (mService != null) {
1420 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001421 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001422 } catch (RemoteException e) {
1423 Log.w(TAG, "Failed talking with device policy service", e);
1424 }
1425 }
1426 return 0;
1427 }
1428
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001429 /**
1430 * Called by an application that is administering the device to set the
1431 * minimum number of non-letter characters (numerical digits or symbols)
1432 * required in the password. After setting this, the user will not be able
1433 * to enter a new password that is not at least as restrictive as what has
1434 * been set. Note that the current password will remain until the user has
1435 * set a new one, so the change does not take place immediately. To prompt
1436 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1437 * setting this value. This constraint is only imposed if the administrator
1438 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1439 * {@link #setPasswordQuality}. The default value is 0.
1440 * <p>
1441 * The calling device admin must have requested
1442 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1443 * this method; if it has not, a security exception will be thrown.
1444 *
1445 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1446 * with.
1447 * @param length The new desired minimum number of letters required in the
1448 * password. A value of 0 means there is no restriction.
1449 */
Robin Lee25e26452015-06-02 09:56:29 -07001450 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001451 if (mService != null) {
1452 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001453 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001454 } catch (RemoteException e) {
1455 Log.w(TAG, "Failed talking with device policy service", e);
1456 }
1457 }
1458 }
1459
1460 /**
1461 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001462 * password for all admins of this user and its profiles or a particular one.
1463 * This is the same value as set by
1464 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001465 * and only applies when the password quality is
1466 * {@link #PASSWORD_QUALITY_COMPLEX}.
1467 *
Robin Lee25e26452015-06-02 09:56:29 -07001468 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001469 * aggregate all admins.
1470 * @return The minimum number of letters required in the password.
1471 */
Robin Lee25e26452015-06-02 09:56:29 -07001472 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001473 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1474 }
1475
1476 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001477 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001478 if (mService != null) {
1479 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001480 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001481 } catch (RemoteException e) {
1482 Log.w(TAG, "Failed talking with device policy service", e);
1483 }
1484 }
1485 return 0;
1486 }
1487
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001488 /**
1489 * Called by an application that is administering the device to set the length
1490 * of the password history. After setting this, the user will not be able to
1491 * enter a new password that is the same as any password in the history. Note
1492 * that the current password will remain until the user has set a new one, so
1493 * the change does not take place immediately. To prompt the user for a new
1494 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1495 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001496 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1497 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1498 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001499 *
1500 * <p>
1501 * The calling device admin must have requested
1502 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1503 * method; if it has not, a security exception will be thrown.
1504 *
1505 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1506 * with.
1507 * @param length The new desired length of password history. A value of 0
1508 * means there is no restriction.
1509 */
Robin Lee25e26452015-06-02 09:56:29 -07001510 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001511 if (mService != null) {
1512 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001513 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001514 } catch (RemoteException e) {
1515 Log.w(TAG, "Failed talking with device policy service", e);
1516 }
1517 }
1518 }
1519
1520 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001521 * Called by a device admin to set the password expiration timeout. Calling this method
1522 * will restart the countdown for password expiration for the given admin, as will changing
1523 * the device password (for all admins).
1524 *
1525 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1526 * For example, to have the password expire 5 days from now, timeout would be
1527 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1528 *
1529 * <p>To disable password expiration, a value of 0 may be used for timeout.
1530 *
Jim Millera4e28d12010-11-08 16:15:47 -08001531 * <p>The calling device admin must have requested
1532 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1533 * method; if it has not, a security exception will be thrown.
1534 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001535 * <p> Note that setting the password will automatically reset the expiration time for all
1536 * active admins. Active admins do not need to explicitly call this method in that case.
1537 *
Jim Millera4e28d12010-11-08 16:15:47 -08001538 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1539 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1540 * means there is no restriction (unlimited).
1541 */
Robin Lee25e26452015-06-02 09:56:29 -07001542 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001543 if (mService != null) {
1544 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001545 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001546 } catch (RemoteException e) {
1547 Log.w(TAG, "Failed talking with device policy service", e);
1548 }
1549 }
1550 }
1551
1552 /**
Jim Miller6b857682011-02-16 16:27:41 -08001553 * Get the password expiration timeout for the given admin. The expiration timeout is the
1554 * recurring expiration timeout provided in the call to
1555 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001556 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001557 *
Robin Lee25e26452015-06-02 09:56:29 -07001558 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001559 * @return The timeout for the given admin or the minimum of all timeouts
1560 */
Robin Lee25e26452015-06-02 09:56:29 -07001561 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001562 if (mService != null) {
1563 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001564 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001565 } catch (RemoteException e) {
1566 Log.w(TAG, "Failed talking with device policy service", e);
1567 }
1568 }
1569 return 0;
1570 }
1571
1572 /**
1573 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001574 * all admins of this user and its profiles if admin is null. If the password is
1575 * expired, this will return the time since the password expired as a negative number.
1576 * If admin is null, then a composite of all expiration timeouts is returned
1577 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001578 *
Robin Lee25e26452015-06-02 09:56:29 -07001579 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001580 * @return The password expiration time, in ms.
1581 */
Robin Lee25e26452015-06-02 09:56:29 -07001582 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001583 if (mService != null) {
1584 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001585 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001586 } catch (RemoteException e) {
1587 Log.w(TAG, "Failed talking with device policy service", e);
1588 }
1589 }
1590 return 0;
1591 }
1592
1593 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001594 * Retrieve the current password history length for all admins of this
1595 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001596 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001597 * all admins.
1598 * @return The length of the password history
1599 */
Robin Lee25e26452015-06-02 09:56:29 -07001600 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001601 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1602 }
1603
1604 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001605 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001606 if (mService != null) {
1607 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001608 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001609 } catch (RemoteException e) {
1610 Log.w(TAG, "Failed talking with device policy service", e);
1611 }
1612 }
1613 return 0;
1614 }
1615
Dianne Hackbornd6847842010-01-12 18:14:19 -08001616 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001617 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001618 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001619 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001620 * @return Returns the maximum length that the user can enter.
1621 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001622 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001623 // Kind-of arbitrary.
1624 return 16;
1625 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001626
Dianne Hackborn254cb442010-01-27 19:23:59 -08001627 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001628 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001629 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001630 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001631 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001632 * <p>The calling device admin must have requested
1633 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1634 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001635 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001636 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001637 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001638 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001639 if (mService != null) {
1640 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001641 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001642 } catch (RemoteException e) {
1643 Log.w(TAG, "Failed talking with device policy service", e);
1644 }
1645 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001646 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001647 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001648
Dianne Hackbornd6847842010-01-12 18:14:19 -08001649 /**
1650 * Retrieve the number of times the user has failed at entering a
1651 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001652 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001653 * <p>The calling device admin must have requested
1654 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1655 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001656 */
1657 public int getCurrentFailedPasswordAttempts() {
1658 if (mService != null) {
1659 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001660 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001661 } catch (RemoteException e) {
1662 Log.w(TAG, "Failed talking with device policy service", e);
1663 }
1664 }
1665 return -1;
1666 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001667
1668 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001669 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001670 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001671 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001672 * @hide
1673 */
1674 public boolean getDoNotAskCredentialsOnBoot() {
1675 if (mService != null) {
1676 try {
1677 return mService.getDoNotAskCredentialsOnBoot();
1678 } catch (RemoteException e) {
1679 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1680 }
1681 }
1682 return false;
1683 }
1684
1685 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001686 * Setting this to a value greater than zero enables a built-in policy
1687 * that will perform a device wipe after too many incorrect
1688 * device-unlock passwords have been entered. This built-in policy combines
1689 * watching for failed passwords and wiping the device, and requires
1690 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001691 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001692 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001693 * <p>To implement any other policy (e.g. wiping data for a particular
1694 * application only, erasing or revoking credentials, or reporting the
1695 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001696 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001697 * instead. Do not use this API, because if the maximum count is reached,
1698 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001699 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001701 * @param num The number of failed password attempts at which point the
1702 * device will wipe its data.
1703 */
Robin Lee25e26452015-06-02 09:56:29 -07001704 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001705 if (mService != null) {
1706 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001707 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001708 } catch (RemoteException e) {
1709 Log.w(TAG, "Failed talking with device policy service", e);
1710 }
1711 }
1712 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001713
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001714 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001715 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001716 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001717 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001718 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001719 * all admins.
1720 */
Robin Lee25e26452015-06-02 09:56:29 -07001721 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001722 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1723 }
1724
1725 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001726 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001727 if (mService != null) {
1728 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001729 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001730 } catch (RemoteException e) {
1731 Log.w(TAG, "Failed talking with device policy service", e);
1732 }
1733 }
1734 return 0;
1735 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001736
Dianne Hackborn254cb442010-01-27 19:23:59 -08001737 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001738 * Returns the profile with the smallest maximum failed passwords for wipe,
1739 * for the given user. So for primary user, it might return the primary or
1740 * a managed profile. For a secondary user, it would be the same as the
1741 * user passed in.
1742 * @hide Used only by Keyguard
1743 */
1744 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1745 if (mService != null) {
1746 try {
1747 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1748 } catch (RemoteException e) {
1749 Log.w(TAG, "Failed talking with device policy service", e);
1750 }
1751 }
1752 return UserHandle.USER_NULL;
1753 }
1754
1755 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001756 * Flag for {@link #resetPassword}: don't allow other admins to change
1757 * the password again until the user has entered it.
1758 */
1759 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001760
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001761 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001762 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1763 * If the flag is set, the device can be booted without asking for user password.
1764 * The absence of this flag does not change the current boot requirements. This flag
1765 * can be set by the device owner only. If the app is not the device owner, the flag
1766 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1767 * device to factory defaults.
1768 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001769 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001770
1771 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001772 * Force a new device unlock password (the password needed to access the
1773 * entire device, not for individual accounts) on the user. This takes
1774 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001775 * The given password must be sufficient for the
1776 * current password quality and length constraints as returned by
1777 * {@link #getPasswordQuality(ComponentName)} and
1778 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1779 * these constraints, then it will be rejected and false returned. Note
1780 * that the password may be a stronger quality (containing alphanumeric
1781 * characters when the requested quality is only numeric), in which case
1782 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001783 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001784 * <p>Calling with a null or empty password will clear any existing PIN,
1785 * pattern or password if the current password constraints allow it.
1786 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001787 * <p>The calling device admin must have requested
1788 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1789 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001790 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001791 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001792 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001793 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001794 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001795 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001796 * @return Returns true if the password was applied, or false if it is
1797 * not acceptable for the current constraints.
1798 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001799 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001800 if (mService != null) {
1801 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001802 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001803 } catch (RemoteException e) {
1804 Log.w(TAG, "Failed talking with device policy service", e);
1805 }
1806 }
1807 return false;
1808 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001809
Dianne Hackbornd6847842010-01-12 18:14:19 -08001810 /**
1811 * Called by an application that is administering the device to set the
1812 * maximum time for user activity until the device will lock. This limits
1813 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001814 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001815 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001816 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001817 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001818 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001819 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001820 * @param timeMs The new desired maximum time to lock in milliseconds.
1821 * A value of 0 means there is no restriction.
1822 */
Robin Lee25e26452015-06-02 09:56:29 -07001823 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 if (mService != null) {
1825 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001826 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001827 } catch (RemoteException e) {
1828 Log.w(TAG, "Failed talking with device policy service", e);
1829 }
1830 }
1831 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001832
Dianne Hackbornd6847842010-01-12 18:14:19 -08001833 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001834 * Retrieve the current maximum time to unlock for all admins of this user
1835 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001836 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001837 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001838 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001839 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001840 */
Robin Lee25e26452015-06-02 09:56:29 -07001841 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001842 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1843 }
1844
1845 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001846 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001847 if (mService != null) {
1848 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001849 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001850 } catch (RemoteException e) {
1851 Log.w(TAG, "Failed talking with device policy service", e);
1852 }
1853 }
1854 return 0;
1855 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001856
Dianne Hackbornd6847842010-01-12 18:14:19 -08001857 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001858 * Make the device lock immediately, as if the lock screen timeout has
1859 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001860 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001861 * <p>The calling device admin must have requested
1862 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1863 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001864 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001865 public void lockNow() {
1866 if (mService != null) {
1867 try {
1868 mService.lockNow();
1869 } catch (RemoteException e) {
1870 Log.w(TAG, "Failed talking with device policy service", e);
1871 }
1872 }
1873 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001874
Dianne Hackbornd6847842010-01-12 18:14:19 -08001875 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001876 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001877 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001878 */
1879 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1880
1881 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001882 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1883 * data.
1884 *
Paul Crowley2934b262014-12-02 11:21:13 +00001885 * <p>This flag may only be set by device owner admins; if it is set by
1886 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001887 */
1888 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1889
1890 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001891 * Ask the user data be wiped. Wiping the primary user will cause the
1892 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001893 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001894 * <p>The calling device admin must have requested
1895 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1896 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001897 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001898 * @param flags Bit mask of additional options: currently supported flags
1899 * are {@link #WIPE_EXTERNAL_STORAGE} and
1900 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001901 */
1902 public void wipeData(int flags) {
1903 if (mService != null) {
1904 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001905 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001906 } catch (RemoteException e) {
1907 Log.w(TAG, "Failed talking with device policy service", e);
1908 }
1909 }
1910 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001911
Dianne Hackbornd6847842010-01-12 18:14:19 -08001912 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001913 * Called by an application that is administering the device to set the
1914 * global proxy and exclusion list.
1915 * <p>
1916 * The calling device admin must have requested
1917 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1918 * this method; if it has not, a security exception will be thrown.
1919 * Only the first device admin can set the proxy. If a second admin attempts
1920 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001921 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001922 * be returned.
1923 * The method can be called repeatedly by the device admin alrady setting the
1924 * proxy to update the proxy and exclusion list.
1925 *
Robin Lee25e26452015-06-02 09:56:29 -07001926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001927 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1928 * Pass Proxy.NO_PROXY to reset the proxy.
1929 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001930 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1931 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001932 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001933 */
Robin Lee25e26452015-06-02 09:56:29 -07001934 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001935 List<String> exclusionList ) {
1936 if (proxySpec == null) {
1937 throw new NullPointerException();
1938 }
1939 if (mService != null) {
1940 try {
1941 String hostSpec;
1942 String exclSpec;
1943 if (proxySpec.equals(Proxy.NO_PROXY)) {
1944 hostSpec = null;
1945 exclSpec = null;
1946 } else {
1947 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1948 throw new IllegalArgumentException();
1949 }
1950 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1951 String hostName = sa.getHostName();
1952 int port = sa.getPort();
1953 StringBuilder hostBuilder = new StringBuilder();
1954 hostSpec = hostBuilder.append(hostName)
1955 .append(":").append(Integer.toString(port)).toString();
1956 if (exclusionList == null) {
1957 exclSpec = "";
1958 } else {
1959 StringBuilder listBuilder = new StringBuilder();
1960 boolean firstDomain = true;
1961 for (String exclDomain : exclusionList) {
1962 if (!firstDomain) {
1963 listBuilder = listBuilder.append(",");
1964 } else {
1965 firstDomain = false;
1966 }
1967 listBuilder = listBuilder.append(exclDomain.trim());
1968 }
1969 exclSpec = listBuilder.toString();
1970 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001971 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1972 != android.net.Proxy.PROXY_VALID)
1973 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001974 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001975 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001976 } catch (RemoteException e) {
1977 Log.w(TAG, "Failed talking with device policy service", e);
1978 }
1979 }
1980 return null;
1981 }
1982
1983 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001984 * Set a network-independent global HTTP proxy. This is not normally what you want
1985 * for typical HTTP proxies - they are generally network dependent. However if you're
1986 * doing something unusual like general internal filtering this may be useful. On
1987 * a private network where the proxy is not accessible, you may break HTTP using this.
1988 *
1989 * <p>This method requires the caller to be the device owner.
1990 *
1991 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1992 * @see ProxyInfo
1993 *
1994 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1995 * with.
1996 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1997 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1998 */
Robin Lee25e26452015-06-02 09:56:29 -07001999 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2000 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002001 if (mService != null) {
2002 try {
2003 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2004 } catch (RemoteException e) {
2005 Log.w(TAG, "Failed talking with device policy service", e);
2006 }
2007 }
2008 }
2009
2010 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002011 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002012 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2013 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002014 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002015 */
2016 public ComponentName getGlobalProxyAdmin() {
2017 if (mService != null) {
2018 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002019 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002020 } catch (RemoteException e) {
2021 Log.w(TAG, "Failed talking with device policy service", e);
2022 }
2023 }
2024 return null;
2025 }
2026
2027 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002028 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002029 * indicating that encryption is not supported.
2030 */
2031 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2032
2033 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002034 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002035 * indicating that encryption is supported, but is not currently active.
2036 */
2037 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2038
2039 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002040 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002041 * indicating that encryption is not currently active, but is currently
2042 * being activated. This is only reported by devices that support
2043 * encryption of data and only when the storage is currently
2044 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2045 * to become encrypted will never return this value.
2046 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002047 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002048
2049 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002050 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002051 * indicating that encryption is active.
2052 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002053 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002054
2055 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002056 * Result code for {@link #getStorageEncryptionStatus}:
2057 * indicating that encryption is active, but an encryption key has not
2058 * been set by the user.
2059 */
2060 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2061
2062 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002063 * Activity action: begin the process of encrypting data on the device. This activity should
2064 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2065 * After resuming from this activity, use {@link #getStorageEncryption}
2066 * to check encryption status. However, on some devices this activity may never return, as
2067 * it may trigger a reboot and in some cases a complete data wipe of the device.
2068 */
2069 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2070 public static final String ACTION_START_ENCRYPTION
2071 = "android.app.action.START_ENCRYPTION";
2072
2073 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002074 * Widgets are enabled in keyguard
2075 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002076 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002077
2078 /**
Jim Miller50e62182014-04-23 17:25:00 -07002079 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002080 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002081 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2082
2083 /**
2084 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2085 */
2086 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2087
2088 /**
Jim Miller50e62182014-04-23 17:25:00 -07002089 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2090 */
2091 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2092
2093 /**
2094 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2095 */
2096 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2097
2098 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002099 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002100 * (e.g. PIN/Pattern/Password).
2101 */
2102 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2103
2104 /**
Jim Miller06e34502014-07-17 14:46:05 -07002105 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2106 */
2107 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2108
2109 /**
Jim Miller35207742012-11-02 15:33:20 -07002110 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002111 */
2112 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002113
2114 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002115 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002116 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002117 *
2118 * <p>When multiple device administrators attempt to control device
2119 * encryption, the most secure, supported setting will always be
2120 * used. If any device administrator requests device encryption,
2121 * it will be enabled; Conversely, if a device administrator
2122 * attempts to disable device encryption while another
2123 * device administrator has enabled it, the call to disable will
2124 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2125 *
2126 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002127 * written to other storage areas may or may not be encrypted, and this policy does not require
2128 * or control the encryption of any other storage areas.
2129 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2130 * {@code true}, then the directory returned by
2131 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2132 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002133 *
2134 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2135 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2136 * the encryption key may not be fully secured. For maximum security, the administrator should
2137 * also require (and check for) a pattern, PIN, or password.
2138 *
2139 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2140 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002141 * @return the new request status (for all active admins) - will be one of
2142 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2143 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2144 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002145 */
Robin Lee25e26452015-06-02 09:56:29 -07002146 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002147 if (mService != null) {
2148 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002149 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002150 } catch (RemoteException e) {
2151 Log.w(TAG, "Failed talking with device policy service", e);
2152 }
2153 }
2154 return ENCRYPTION_STATUS_UNSUPPORTED;
2155 }
2156
2157 /**
2158 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002159 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002160 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002161 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2162 * this will return the requested encryption setting as an aggregate of all active
2163 * administrators.
2164 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002165 */
Robin Lee25e26452015-06-02 09:56:29 -07002166 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002167 if (mService != null) {
2168 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002169 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002170 } catch (RemoteException e) {
2171 Log.w(TAG, "Failed talking with device policy service", e);
2172 }
2173 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002174 return false;
2175 }
2176
2177 /**
2178 * Called by an application that is administering the device to
2179 * determine the current encryption status of the device.
2180 *
2181 * Depending on the returned status code, the caller may proceed in different
2182 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2183 * storage system does not support encryption. If the
2184 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2185 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002186 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2187 * storage system has enabled encryption but no password is set so further action
2188 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002189 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2190 *
Robin Lee7e678712014-07-24 16:41:31 +01002191 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002192 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002193 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2194 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002195 */
2196 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002197 return getStorageEncryptionStatus(UserHandle.myUserId());
2198 }
2199
2200 /** @hide per-user version */
2201 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002202 if (mService != null) {
2203 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002204 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002205 } catch (RemoteException e) {
2206 Log.w(TAG, "Failed talking with device policy service", e);
2207 }
2208 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002209 return ENCRYPTION_STATUS_UNSUPPORTED;
2210 }
2211
2212 /**
Robin Lee7e678712014-07-24 16:41:31 +01002213 * Installs the given certificate as a user CA.
2214 *
Robin Lee25e26452015-06-02 09:56:29 -07002215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2216 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002217 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002218 *
2219 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002220 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002221 */
Robin Lee25e26452015-06-02 09:56:29 -07002222 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002223 if (mService != null) {
2224 try {
Robin Lee7e678712014-07-24 16:41:31 +01002225 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002226 } catch (RemoteException e) {
2227 Log.w(TAG, "Failed talking with device policy service", e);
2228 }
2229 }
2230 return false;
2231 }
2232
2233 /**
Robin Lee7e678712014-07-24 16:41:31 +01002234 * Uninstalls the given certificate from trusted user CAs, if present.
2235 *
Robin Lee25e26452015-06-02 09:56:29 -07002236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2237 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002238 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002239 */
Robin Lee25e26452015-06-02 09:56:29 -07002240 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002241 if (mService != null) {
2242 try {
Robin Lee306fe082014-06-19 14:04:24 +00002243 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002244 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002245 } catch (CertificateException e) {
2246 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002247 } catch (RemoteException e) {
2248 Log.w(TAG, "Failed talking with device policy service", e);
2249 }
2250 }
2251 }
2252
2253 /**
Robin Lee7e678712014-07-24 16:41:31 +01002254 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2255 * If a user has installed any certificates by other means than device policy these will be
2256 * included too.
2257 *
Robin Lee25e26452015-06-02 09:56:29 -07002258 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2259 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002260 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002261 */
Robin Lee25e26452015-06-02 09:56:29 -07002262 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002263 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002264 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002265 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002266 mService.enforceCanManageCaCerts(admin);
2267 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2268 for (String alias : certStore.userAliases()) {
2269 try {
2270 certs.add(certStore.getCertificate(alias).getEncoded());
2271 } catch (CertificateException ce) {
2272 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2273 }
2274 }
2275 } catch (RemoteException re) {
2276 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002277 }
2278 }
2279 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002280 }
2281
2282 /**
Robin Lee7e678712014-07-24 16:41:31 +01002283 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2284 * means other than device policy will also be removed, except for system CA certificates.
2285 *
Robin Lee25e26452015-06-02 09:56:29 -07002286 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2287 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002288 */
Robin Lee25e26452015-06-02 09:56:29 -07002289 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002290 if (mService != null) {
2291 for (String alias : new TrustedCertificateStore().userAliases()) {
2292 try {
2293 mService.uninstallCaCert(admin, alias);
2294 } catch (RemoteException re) {
2295 Log.w(TAG, "Failed talking with device policy service", re);
2296 }
2297 }
2298 }
2299 }
2300
2301 /**
2302 * Returns whether this certificate is installed as a trusted CA.
2303 *
Robin Lee25e26452015-06-02 09:56:29 -07002304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2305 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002306 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002307 */
Robin Lee25e26452015-06-02 09:56:29 -07002308 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002309 if (mService != null) {
2310 try {
2311 mService.enforceCanManageCaCerts(admin);
2312 return getCaCertAlias(certBuffer) != null;
2313 } catch (RemoteException re) {
2314 Log.w(TAG, "Failed talking with device policy service", re);
2315 } catch (CertificateException ce) {
2316 Log.w(TAG, "Could not parse certificate", ce);
2317 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002318 }
2319 return false;
2320 }
2321
2322 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002323 * Called by a device or profile owner to install a certificate and private key pair. The
2324 * keypair will be visible to all apps within the profile.
2325 *
Robin Lee25e26452015-06-02 09:56:29 -07002326 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2327 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002328 * @param privKey The private key to install.
2329 * @param cert The certificate to install.
2330 * @param alias The private key alias under which to install the certificate. If a certificate
2331 * with that alias already exists, it will be overwritten.
2332 * @return {@code true} if the keys were installed, {@code false} otherwise.
2333 */
Robin Lee25e26452015-06-02 09:56:29 -07002334 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002335 String alias) {
2336 try {
2337 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002338 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2339 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002340 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002341 } catch (RemoteException e) {
2342 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002343 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2344 Log.w(TAG, "Failed to obtain private key material", e);
2345 } catch (CertificateException | IOException e) {
2346 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002347 }
2348 return false;
2349 }
2350
2351 /**
Robin Lee25e26452015-06-02 09:56:29 -07002352 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002353 * doesn't exist.
2354 */
2355 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2356 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2357 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2358 new ByteArrayInputStream(certBuffer));
2359 return new TrustedCertificateStore().getCertificateAlias(cert);
2360 }
2361
2362 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002363 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002364 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002365 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002366 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002367 * <p>
2368 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2369 * it is later cleared by calling this method with a null value or uninstallling the certificate
2370 * installer.
2371 *
Robin Lee25e26452015-06-02 09:56:29 -07002372 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002373 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002374 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002375 */
Robin Lee25e26452015-06-02 09:56:29 -07002376 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2377 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002378 if (mService != null) {
2379 try {
Robin Lee25e26452015-06-02 09:56:29 -07002380 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002381 } catch (RemoteException e) {
2382 Log.w(TAG, "Failed talking with device policy service", e);
2383 }
2384 }
2385 }
2386
2387 /**
2388 * Called by a profile owner or device owner to retrieve the certificate installer for the
2389 * current user. null if none is set.
2390 *
Robin Lee25e26452015-06-02 09:56:29 -07002391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2392 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002393 * if none is set.
2394 */
Robin Lee25e26452015-06-02 09:56:29 -07002395 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002396 if (mService != null) {
2397 try {
Robin Lee25e26452015-06-02 09:56:29 -07002398 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002399 } catch (RemoteException e) {
2400 Log.w(TAG, "Failed talking with device policy service", e);
2401 }
2402 }
2403 return null;
2404 }
2405
2406 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002407 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002408 * on the device, for this user. After setting this, no applications running as this user
2409 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002410 *
2411 * <p>The calling device admin must have requested
2412 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2413 * this method; if it has not, a security exception will be thrown.
2414 *
2415 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2416 * @param disabled Whether or not the camera should be disabled.
2417 */
Robin Lee25e26452015-06-02 09:56:29 -07002418 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002419 if (mService != null) {
2420 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002421 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002422 } catch (RemoteException e) {
2423 Log.w(TAG, "Failed talking with device policy service", e);
2424 }
2425 }
2426 }
2427
2428 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002429 * Determine whether or not the device's cameras have been disabled for this user,
2430 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002431 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Ben Komalo2447edd2011-05-09 16:05:33 -07002432 * have disabled the camera
2433 */
Robin Lee25e26452015-06-02 09:56:29 -07002434 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002435 return getCameraDisabled(admin, UserHandle.myUserId());
2436 }
2437
2438 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002439 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002440 if (mService != null) {
2441 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002442 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002443 } catch (RemoteException e) {
2444 Log.w(TAG, "Failed talking with device policy service", e);
2445 }
2446 }
2447 return false;
2448 }
2449
2450 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002451 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2452 * screen capture also prevents the content from being shown on display devices that do not have
2453 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2454 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002455 *
2456 * <p>The calling device admin must be a device or profile owner. If it is not, a
2457 * security exception will be thrown.
2458 *
2459 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002460 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002461 */
Robin Lee25e26452015-06-02 09:56:29 -07002462 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002463 if (mService != null) {
2464 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002465 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002466 } catch (RemoteException e) {
2467 Log.w(TAG, "Failed talking with device policy service", e);
2468 }
2469 }
2470 }
2471
2472 /**
2473 * Determine whether or not screen capture has been disabled by the current
2474 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002475 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002476 * have disabled screen capture.
2477 */
Robin Lee25e26452015-06-02 09:56:29 -07002478 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002479 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2480 }
2481
2482 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002483 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002484 if (mService != null) {
2485 try {
2486 return mService.getScreenCaptureDisabled(admin, userHandle);
2487 } catch (RemoteException e) {
2488 Log.w(TAG, "Failed talking with device policy service", e);
2489 }
2490 }
2491 return false;
2492 }
2493
2494 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002495 * Called by a device owner to set whether auto time is required. If auto time is
2496 * required the user cannot set the date and time, but has to use network date and time.
2497 *
2498 * <p>Note: if auto time is required the user can still manually set the time zone.
2499 *
2500 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2501 * be thrown.
2502 *
2503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2504 * @param required Whether auto time is set required or not.
2505 */
Robin Lee25e26452015-06-02 09:56:29 -07002506 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002507 if (mService != null) {
2508 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002509 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002510 } catch (RemoteException e) {
2511 Log.w(TAG, "Failed talking with device policy service", e);
2512 }
2513 }
2514 }
2515
2516 /**
2517 * @return true if auto time is required.
2518 */
2519 public boolean getAutoTimeRequired() {
2520 if (mService != null) {
2521 try {
2522 return mService.getAutoTimeRequired();
2523 } catch (RemoteException e) {
2524 Log.w(TAG, "Failed talking with device policy service", e);
2525 }
2526 }
2527 return false;
2528 }
2529
2530 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002531 * Called by an application that is administering the device to disable keyguard customizations,
2532 * such as widgets. After setting this, keyguard features will be disabled according to the
2533 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002534 *
2535 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002536 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002537 * this method; if it has not, a security exception will be thrown.
2538 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002539 * <p>Calling this from a managed profile before version
2540 * {@link android.os.Build.VERSION_CODES#MNC} will throw a security exception.
2541 *
2542 * <p>From version {@link android.os.Build.VERSION_CODES#MNC} a profile owner can set:
2543 * <ul>
2544 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2545 * these will affect the profile's parent user.
2546 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2547 * generated by applications in the managed profile.
2548 * </ul>
2549 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2550 * can check which features have been disabled by calling
2551 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002552 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002553 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002554 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2555 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002556 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002557 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2558 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002559 */
Robin Lee25e26452015-06-02 09:56:29 -07002560 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002561 if (mService != null) {
2562 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002563 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002564 } catch (RemoteException e) {
2565 Log.w(TAG, "Failed talking with device policy service", e);
2566 }
2567 }
2568 }
2569
2570 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002571 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002572 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002573 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002574 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002575 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2576 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002577 */
Robin Lee25e26452015-06-02 09:56:29 -07002578 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002579 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002580 }
2581
2582 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002583 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002584 if (mService != null) {
2585 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002586 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002587 } catch (RemoteException e) {
2588 Log.w(TAG, "Failed talking with device policy service", e);
2589 }
2590 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002591 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002592 }
2593
2594 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002595 * @hide
2596 */
Robin Lee25e26452015-06-02 09:56:29 -07002597 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2598 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002599 if (mService != null) {
2600 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002601 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002602 } catch (RemoteException e) {
2603 Log.w(TAG, "Failed talking with device policy service", e);
2604 }
2605 }
2606 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002607
Dianne Hackbornd6847842010-01-12 18:14:19 -08002608 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002609 * @hide
2610 */
Robin Lee25e26452015-06-02 09:56:29 -07002611 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002612 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2613 }
2614
2615 /**
Robin Lee25e26452015-06-02 09:56:29 -07002616 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002617 * @hide
2618 */
Robin Lee25e26452015-06-02 09:56:29 -07002619 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002620 ActivityInfo ai;
2621 try {
2622 ai = mContext.getPackageManager().getReceiverInfo(cn,
2623 PackageManager.GET_META_DATA);
2624 } catch (PackageManager.NameNotFoundException e) {
2625 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2626 return null;
2627 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002628
Dianne Hackbornd6847842010-01-12 18:14:19 -08002629 ResolveInfo ri = new ResolveInfo();
2630 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002631
Dianne Hackbornd6847842010-01-12 18:14:19 -08002632 try {
2633 return new DeviceAdminInfo(mContext, ri);
2634 } catch (XmlPullParserException e) {
2635 Log.w(TAG, "Unable to parse device policy " + cn, e);
2636 return null;
2637 } catch (IOException e) {
2638 Log.w(TAG, "Unable to parse device policy " + cn, e);
2639 return null;
2640 }
2641 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002642
Dianne Hackbornd6847842010-01-12 18:14:19 -08002643 /**
2644 * @hide
2645 */
Robin Lee25e26452015-06-02 09:56:29 -07002646 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002647 if (mService != null) {
2648 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002649 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002650 } catch (RemoteException e) {
2651 Log.w(TAG, "Failed talking with device policy service", e);
2652 }
2653 }
2654 }
2655
2656 /**
2657 * @hide
2658 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002659 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002660 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002661 if (mService != null) {
2662 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002663 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002664 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002665 } catch (RemoteException e) {
2666 Log.w(TAG, "Failed talking with device policy service", e);
2667 }
2668 }
2669 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002670
Dianne Hackbornd6847842010-01-12 18:14:19 -08002671 /**
2672 * @hide
2673 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002674 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002675 if (mService != null) {
2676 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002677 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002678 } catch (RemoteException e) {
2679 Log.w(TAG, "Failed talking with device policy service", e);
2680 }
2681 }
2682 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002683
Dianne Hackbornd6847842010-01-12 18:14:19 -08002684 /**
2685 * @hide
2686 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002687 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002688 if (mService != null) {
2689 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002690 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002691 } catch (RemoteException e) {
2692 Log.w(TAG, "Failed talking with device policy service", e);
2693 }
2694 }
2695 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002696
2697 /**
2698 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002699 * Sets the given package as the device owner.
2700 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002701 * @param packageName the package name of the application to be registered as the device owner.
2702 * @return whether the package was successfully registered as the device owner.
2703 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002704 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002705 */
2706 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2707 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002708 return setDeviceOwner(packageName, null);
2709 }
2710
2711 /**
2712 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002713 * Sets the given package as the device owner. The package must already be installed. There
2714 * must not already be a device owner.
2715 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2716 * this method.
2717 * Calling this after the setup phase of the primary user has completed is allowed only if
2718 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002719 * @param packageName the package name of the application to be registered as the device owner.
2720 * @param ownerName the human readable name of the institution that owns this device.
2721 * @return whether the package was successfully registered as the device owner.
2722 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002723 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002724 */
2725 public boolean setDeviceOwner(String packageName, String ownerName)
2726 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002727 if (mService != null) {
2728 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002729 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002730 } catch (RemoteException re) {
2731 Log.w(TAG, "Failed to set device owner");
2732 }
2733 }
2734 return false;
2735 }
2736
2737 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002738 * Used to determine if a particular package has been registered as a Device Owner app.
2739 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002740 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002741 * package is currently registered as the device owner app, pass in the package name from
2742 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002743 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002744 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2745 * the setup process.
2746 * @param packageName the package name of the app, to compare with the registered device owner
2747 * app, if any.
2748 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002749 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002750 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002751 if (mService != null) {
2752 try {
2753 return mService.isDeviceOwner(packageName);
2754 } catch (RemoteException re) {
2755 Log.w(TAG, "Failed to check device owner");
2756 }
2757 }
2758 return false;
2759 }
2760
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002761 /**
2762 * @hide
2763 * Redirect to isDeviceOwnerApp.
2764 */
2765 public boolean isDeviceOwner(String packageName) {
2766 return isDeviceOwnerApp(packageName);
2767 }
2768
Jason Monkb0dced82014-06-06 14:36:20 -04002769 /**
2770 * Clears the current device owner. The caller must be the device owner.
2771 *
2772 * This function should be used cautiously as once it is called it cannot
2773 * be undone. The device owner can only be set as a part of device setup
2774 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002775 *
2776 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002777 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002778 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002779 if (mService != null) {
2780 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002781 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002782 } catch (RemoteException re) {
2783 Log.w(TAG, "Failed to clear device owner");
2784 }
2785 }
2786 }
2787
Amith Yamasani71e6c692013-03-24 17:39:28 -07002788 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002789 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002790 public String getDeviceOwner() {
2791 if (mService != null) {
2792 try {
2793 return mService.getDeviceOwner();
2794 } catch (RemoteException re) {
2795 Log.w(TAG, "Failed to get device owner");
2796 }
2797 }
2798 return null;
2799 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002800
2801 /** @hide */
2802 public String getDeviceOwnerName() {
2803 if (mService != null) {
2804 try {
2805 return mService.getDeviceOwnerName();
2806 } catch (RemoteException re) {
2807 Log.w(TAG, "Failed to get device owner");
2808 }
2809 }
2810 return null;
2811 }
Adam Connors776c5552014-01-09 10:42:56 +00002812
2813 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002814 * Sets the given component as the device initializer. The package must already be installed and
2815 * set as an active device administrator, and there must not be an existing device initializer,
2816 * for this call to succeed. This method can only be called by an app holding the
2817 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2818 * device initializer app is granted device owner privileges during device initialization and
2819 * profile owner privileges during secondary user initialization.
Robin Lee25e26452015-06-02 09:56:29 -07002820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2821 * {@code null} if not called by the device owner.
Julia Reynolds20118f12015-02-11 12:34:08 -05002822 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002823 * @return whether the component was successfully registered as the device initializer.
2824 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002825 * @throws IllegalStateException if the caller is not device owner or the device has
2826 * already been provisioned or a device initializer already exists.
2827 */
Robin Lee25e26452015-06-02 09:56:29 -07002828 public boolean setDeviceInitializer(@Nullable ComponentName admin,
2829 @NonNull ComponentName initializer)
Julia Reynolds731051e2015-05-11 15:52:08 -04002830 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002831 if (mService != null) {
2832 try {
Robin Lee25e26452015-06-02 09:56:29 -07002833 return mService.setDeviceInitializer(admin, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002834 } catch (RemoteException re) {
2835 Log.w(TAG, "Failed to set device initializer");
2836 }
2837 }
2838 return false;
2839 }
2840
2841 /**
2842 * Used to determine if a particular package has been registered as the device initializer.
2843 *
2844 * @param packageName the package name of the app, to compare with the registered device
2845 * initializer app, if any.
2846 * @return whether or not the caller is registered as the device initializer app.
2847 */
2848 public boolean isDeviceInitializerApp(String packageName) {
2849 if (mService != null) {
2850 try {
2851 return mService.isDeviceInitializer(packageName);
2852 } catch (RemoteException re) {
2853 Log.w(TAG, "Failed to check device initializer");
2854 }
2855 }
2856 return false;
2857 }
2858
2859 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002860 * Removes the device initializer, so that it will not be invoked on user initialization for any
2861 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002862 * initializer itself. The caller must be an active administrator.
2863 *
Robin Lee25e26452015-06-02 09:56:29 -07002864 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002865 */
Robin Lee25e26452015-06-02 09:56:29 -07002866 public void clearDeviceInitializerApp(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002867 if (mService != null) {
2868 try {
Robin Lee25e26452015-06-02 09:56:29 -07002869 mService.clearDeviceInitializer(admin);
Julia Reynolds20118f12015-02-11 12:34:08 -05002870 } catch (RemoteException re) {
2871 Log.w(TAG, "Failed to clear device initializer");
2872 }
2873 }
2874 }
2875
2876 /**
2877 * @hide
2878 * Gets the device initializer of the system.
2879 *
2880 * @return the package name of the device initializer.
2881 */
2882 @SystemApi
2883 public String getDeviceInitializerApp() {
2884 if (mService != null) {
2885 try {
2886 return mService.getDeviceInitializer();
2887 } catch (RemoteException re) {
2888 Log.w(TAG, "Failed to get device initializer");
2889 }
2890 }
2891 return null;
2892 }
2893
2894 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002895 * @hide
2896 * Gets the device initializer component of the system.
2897 *
2898 * @return the component name of the device initializer.
2899 */
2900 @SystemApi
2901 public ComponentName getDeviceInitializerComponent() {
2902 if (mService != null) {
2903 try {
2904 return mService.getDeviceInitializerComponent();
2905 } catch (RemoteException re) {
2906 Log.w(TAG, "Failed to get device initializer");
2907 }
2908 }
2909 return null;
2910 }
2911
2912
2913 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002914 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2915 * be used.
2916 *
2917 * <p>Device initializer must call this method to mark the user as functional.
2918 * Only the device initializer agent can call this.
2919 *
2920 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2921 * device initializer will no longer have elevated permissions to call methods in this class.
2922 * Additionally, it will be removed as an active administrator and its
2923 * {@link DeviceAdminReceiver} will be disabled.
2924 *
2925 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2926 * @return whether the user is now enabled.
2927 */
Robin Lee25e26452015-06-02 09:56:29 -07002928 public boolean setUserEnabled(@NonNull ComponentName admin) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002929 if (mService != null) {
2930 try {
2931 return mService.setUserEnabled(admin);
2932 } catch (RemoteException e) {
2933 Log.w(TAG, "Failed talking with device policy service", e);
2934 }
2935 }
2936 return false;
2937 }
2938
2939 /**
Adam Connors776c5552014-01-09 10:42:56 +00002940 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002941 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302942 * Sets the given component as an active admin and registers the package as the profile
2943 * owner for this user. The package must already be installed and there shouldn't be
2944 * an existing profile owner registered for this user. Also, this method must be called
2945 * before the user setup has been completed.
2946 * <p>
2947 * This method can only be called by system apps that hold MANAGE_USERS permission and
2948 * MANAGE_DEVICE_ADMINS permission.
2949 * @param admin The component to register as an active admin and profile owner.
2950 * @param ownerName The user-visible name of the entity that is managing this user.
2951 * @return whether the admin was successfully registered as the profile owner.
2952 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2953 * the user has already been set up.
2954 */
Justin Morey80440cc2014-07-24 09:16:35 -05002955 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002956 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302957 throws IllegalArgumentException {
2958 if (mService != null) {
2959 try {
2960 final int myUserId = UserHandle.myUserId();
2961 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002962 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302963 } catch (RemoteException re) {
2964 Log.w(TAG, "Failed to set profile owner " + re);
2965 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2966 }
2967 }
2968 return false;
2969 }
2970
2971 /**
2972 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002973 * Clears the active profile owner and removes all user restrictions. The caller must
2974 * be from the same package as the active profile owner for this user, otherwise a
2975 * SecurityException will be thrown.
2976 *
2977 * @param admin The component to remove as the profile owner.
2978 * @return
2979 */
2980 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002981 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002982 if (mService != null) {
2983 try {
2984 mService.clearProfileOwner(admin);
2985 } catch (RemoteException re) {
2986 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2987 }
2988 }
2989 }
2990
2991 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002992 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002993 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002994 */
2995 public boolean hasUserSetupCompleted() {
2996 if (mService != null) {
2997 try {
2998 return mService.hasUserSetupCompleted();
2999 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07003000 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003001 }
3002 }
3003 return true;
3004 }
3005
3006 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003007 * @hide
3008 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003009 * already be installed. There must not already be a profile owner for this user.
3010 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3011 * this method.
3012 * Calling this after the setup phase of the specified user has completed is allowed only if:
3013 * - the caller is SYSTEM_UID.
3014 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003015 * @param admin the component name to be registered as profile owner.
3016 * @param ownerName the human readable name of the organisation associated with this DPM.
3017 * @param userHandle the userId to set the profile owner for.
3018 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003019 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3020 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003021 */
Robin Lee25e26452015-06-02 09:56:29 -07003022 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003023 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003024 if (admin == null) {
3025 throw new NullPointerException("admin cannot be null");
3026 }
Adam Connors776c5552014-01-09 10:42:56 +00003027 if (mService != null) {
3028 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003029 if (ownerName == null) {
3030 ownerName = "";
3031 }
3032 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003033 } catch (RemoteException re) {
3034 Log.w(TAG, "Failed to set profile owner", re);
3035 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3036 }
3037 }
3038 return false;
3039 }
3040
3041 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003042 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3043 * be used. Only the profile owner can call this.
3044 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003045 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003046 *
3047 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3048 */
Robin Lee25e26452015-06-02 09:56:29 -07003049 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003050 if (mService != null) {
3051 try {
3052 mService.setProfileEnabled(admin);
3053 } catch (RemoteException e) {
3054 Log.w(TAG, "Failed talking with device policy service", e);
3055 }
3056 }
3057 }
3058
3059 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003060 * Sets the name of the profile. In the device owner case it sets the name of the user
3061 * 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 +01003062 * never called by the profile or device owner, the name will be set to default values.
3063 *
3064 * @see #isProfileOwnerApp
3065 * @see #isDeviceOwnerApp
3066 *
Robin Lee25e26452015-06-02 09:56:29 -07003067 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003068 * @param profileName The name of the profile.
3069 */
Robin Lee25e26452015-06-02 09:56:29 -07003070 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003071 if (mService != null) {
3072 try {
Robin Lee25e26452015-06-02 09:56:29 -07003073 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003074 } catch (RemoteException e) {
3075 Log.w(TAG, "Failed talking with device policy service", e);
3076 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003077 }
3078 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003079
3080 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003081 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003082 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003083 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003084 *
3085 * @param packageName The package name of the app to compare with the registered profile owner.
3086 * @return Whether or not the package is registered as the profile owner.
3087 */
3088 public boolean isProfileOwnerApp(String packageName) {
3089 if (mService != null) {
3090 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003091 ComponentName profileOwner = mService.getProfileOwner(
3092 Process.myUserHandle().getIdentifier());
3093 return profileOwner != null
3094 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003095 } catch (RemoteException re) {
3096 Log.w(TAG, "Failed to check profile owner");
3097 }
3098 }
3099 return false;
3100 }
3101
3102 /**
3103 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003104 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003105 * owner has been set for that user.
3106 * @throws IllegalArgumentException if the userId is invalid.
3107 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003108 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003109 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003110 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3111 }
3112
3113 /**
3114 * @see #getProfileOwner()
3115 * @hide
3116 */
3117 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003118 if (mService != null) {
3119 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003120 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003121 } catch (RemoteException re) {
3122 Log.w(TAG, "Failed to get profile owner");
3123 throw new IllegalArgumentException(
3124 "Requested profile owner for invalid userId", re);
3125 }
3126 }
3127 return null;
3128 }
3129
3130 /**
3131 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003132 * @return the human readable name of the organisation associated with this DPM or {@code null}
3133 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003134 * @throws IllegalArgumentException if the userId is invalid.
3135 */
3136 public String getProfileOwnerName() throws IllegalArgumentException {
3137 if (mService != null) {
3138 try {
3139 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3140 } catch (RemoteException re) {
3141 Log.w(TAG, "Failed to get profile owner");
3142 throw new IllegalArgumentException(
3143 "Requested profile owner for invalid userId", re);
3144 }
3145 }
3146 return null;
3147 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003148
3149 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003150 * @hide
3151 * @param user The user for whom to fetch the profile owner name, if any.
3152 * @return the human readable name of the organisation associated with this profile owner or
3153 * null if one is not set.
3154 * @throws IllegalArgumentException if the userId is invalid.
3155 */
3156 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003157 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003158 if (mService != null) {
3159 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003160 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003161 } catch (RemoteException re) {
3162 Log.w(TAG, "Failed to get profile owner");
3163 throw new IllegalArgumentException(
3164 "Requested profile owner for invalid userId", re);
3165 }
3166 }
3167 return null;
3168 }
3169
3170 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003171 * Called by a profile owner or device owner to add a default intent handler activity for
3172 * intents that match a certain intent filter. This activity will remain the default intent
3173 * handler even if the set of potential event handlers for the intent filter changes and if
3174 * the intent preferences are reset.
3175 *
3176 * <p>The default disambiguation mechanism takes over if the activity is not installed
3177 * (anymore). When the activity is (re)installed, it is automatically reset as default
3178 * intent handler for the filter.
3179 *
3180 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3181 * security exception will be thrown.
3182 *
3183 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3184 * @param filter The IntentFilter for which a default handler is added.
3185 * @param activity The Activity that is added as default intent handler.
3186 */
Robin Lee25e26452015-06-02 09:56:29 -07003187 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3188 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003189 if (mService != null) {
3190 try {
3191 mService.addPersistentPreferredActivity(admin, filter, activity);
3192 } catch (RemoteException e) {
3193 Log.w(TAG, "Failed talking with device policy service", e);
3194 }
3195 }
3196 }
3197
3198 /**
3199 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003200 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003201 *
3202 * <p>The calling device admin must be a profile owner. If it is not, a security
3203 * exception will be thrown.
3204 *
3205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3206 * @param packageName The name of the package for which preferences are removed.
3207 */
Robin Lee25e26452015-06-02 09:56:29 -07003208 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003209 String packageName) {
3210 if (mService != null) {
3211 try {
3212 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3213 } catch (RemoteException e) {
3214 Log.w(TAG, "Failed talking with device policy service", e);
3215 }
3216 }
3217 }
Robin Lee66e5d962014-04-09 16:44:21 +01003218
3219 /**
3220 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003221 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003222 *
3223 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003224 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003225 *
3226 * <p>The application restrictions are only made visible to the target application and the
3227 * profile or device owner.
3228 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003229 * <p>If the restrictions are not available yet, but may be applied in the near future,
3230 * the admin can notify the target application of that by adding
3231 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3232 *
Robin Lee66e5d962014-04-09 16:44:21 +01003233 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3234 * exception will be thrown.
3235 *
3236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3237 * @param packageName The name of the package to update restricted settings for.
3238 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3239 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003240 *
3241 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003242 */
Robin Lee25e26452015-06-02 09:56:29 -07003243 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003244 Bundle settings) {
3245 if (mService != null) {
3246 try {
3247 mService.setApplicationRestrictions(admin, packageName, settings);
3248 } catch (RemoteException e) {
3249 Log.w(TAG, "Failed talking with device policy service", e);
3250 }
3251 }
3252 }
3253
3254 /**
Jim Millere303bf42014-08-26 17:12:29 -07003255 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3256 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3257 * trust agents but those enabled by this function call. If flag
3258 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003259 *
3260 * <p>The calling device admin must have requested
3261 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003262 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003263 *
3264 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003265 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003266 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003267 * will be strictly disabled according to the state of the
3268 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3269 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3270 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3271 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003272 */
Robin Lee25e26452015-06-02 09:56:29 -07003273 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3274 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003275 if (mService != null) {
3276 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003277 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003278 } catch (RemoteException e) {
3279 Log.w(TAG, "Failed talking with device policy service", e);
3280 }
3281 }
3282 }
3283
3284 /**
Jim Millere303bf42014-08-26 17:12:29 -07003285 * Gets configuration for the given trust agent based on aggregating all calls to
3286 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3287 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003288 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3290 * this function returns a list of configurations for all admins that declare
3291 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3292 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3293 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3294 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003295 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003296 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003297 */
Robin Lee25e26452015-06-02 09:56:29 -07003298 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3299 @NonNull ComponentName agent) {
Jim Millere303bf42014-08-26 17:12:29 -07003300 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3301 }
3302
3303 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003304 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3305 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003306 if (mService != null) {
3307 try {
Jim Millere303bf42014-08-26 17:12:29 -07003308 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003309 } catch (RemoteException e) {
3310 Log.w(TAG, "Failed talking with device policy service", e);
3311 }
3312 }
Jim Millere303bf42014-08-26 17:12:29 -07003313 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003314 }
3315
3316 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003317 * Called by a profile owner of a managed profile to set whether caller-Id information from
3318 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003319 *
3320 * <p>The calling device admin must be a profile owner. If it is not, a
3321 * security exception will be thrown.
3322 *
Robin Lee25e26452015-06-02 09:56:29 -07003323 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003324 * @param disabled If true caller-Id information in the managed profile is not displayed.
3325 */
Robin Lee25e26452015-06-02 09:56:29 -07003326 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003327 if (mService != null) {
3328 try {
Robin Lee25e26452015-06-02 09:56:29 -07003329 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003330 } catch (RemoteException e) {
3331 Log.w(TAG, "Failed talking with device policy service", e);
3332 }
3333 }
3334 }
3335
3336 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003337 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3338 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003339 *
3340 * <p>The calling device admin must be a profile owner. If it is not, a
3341 * security exception will be thrown.
3342 *
Robin Lee25e26452015-06-02 09:56:29 -07003343 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003344 */
Robin Lee25e26452015-06-02 09:56:29 -07003345 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003346 if (mService != null) {
3347 try {
Robin Lee25e26452015-06-02 09:56:29 -07003348 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003349 } catch (RemoteException e) {
3350 Log.w(TAG, "Failed talking with device policy service", e);
3351 }
3352 }
3353 return false;
3354 }
3355
3356 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003357 * Determine whether or not caller-Id information has been disabled.
3358 *
3359 * @param userHandle The user for whom to check the caller-id permission
3360 * @hide
3361 */
3362 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3363 if (mService != null) {
3364 try {
3365 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3366 } catch (RemoteException e) {
3367 Log.w(TAG, "Failed talking with device policy service", e);
3368 }
3369 }
3370 return false;
3371 }
3372
3373 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003374 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3375 * @hide
3376 */
3377 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3378 Intent originalIntent) {
3379 if (mService != null) {
3380 try {
3381 mService.startManagedQuickContact(
3382 actualLookupKey, actualContactId, originalIntent);
3383 } catch (RemoteException e) {
3384 Log.w(TAG, "Failed talking with device policy service", e);
3385 }
3386 }
3387 }
3388
3389 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003390 * Called by a profile owner of a managed profile to set whether bluetooth
3391 * devices can access enterprise contacts.
3392 * <p>
3393 * The calling device admin must be a profile owner. If it is not, a
3394 * security exception will be thrown.
3395 * <p>
3396 * This API works on managed profile only.
3397 *
Robin Lee25e26452015-06-02 09:56:29 -07003398 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003399 * with.
3400 * @param disabled If true, bluetooth devices cannot access enterprise
3401 * contacts.
3402 */
Robin Lee25e26452015-06-02 09:56:29 -07003403 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003404 if (mService != null) {
3405 try {
Robin Lee25e26452015-06-02 09:56:29 -07003406 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003407 } catch (RemoteException e) {
3408 Log.w(TAG, "Failed talking with device policy service", e);
3409 }
3410 }
3411 }
3412
3413 /**
3414 * Called by a profile owner of a managed profile to determine whether or
3415 * not Bluetooth devices cannot access enterprise contacts.
3416 * <p>
3417 * The calling device admin must be a profile owner. If it is not, a
3418 * security exception will be thrown.
3419 * <p>
3420 * This API works on managed profile only.
3421 *
Robin Lee25e26452015-06-02 09:56:29 -07003422 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003423 * with.
3424 */
Robin Lee25e26452015-06-02 09:56:29 -07003425 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003426 if (mService != null) {
3427 try {
Robin Lee25e26452015-06-02 09:56:29 -07003428 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003429 } catch (RemoteException e) {
3430 Log.w(TAG, "Failed talking with device policy service", e);
3431 }
3432 }
3433 return true;
3434 }
3435
3436 /**
3437 * Determine whether or not Bluetooth devices cannot access contacts.
3438 * <p>
3439 * This API works on managed profile UserHandle only.
3440 *
3441 * @param userHandle The user for whom to check the caller-id permission
3442 * @hide
3443 */
3444 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3445 if (mService != null) {
3446 try {
3447 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3448 .getIdentifier());
3449 } catch (RemoteException e) {
3450 Log.w(TAG, "Failed talking with device policy service", e);
3451 }
3452 }
3453 return true;
3454 }
3455
3456 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003457 * Called by the profile owner of a managed profile so that some intents sent in the managed
3458 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003459 * Only activity intents are supported.
3460 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003461 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003462 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3463 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003464 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3465 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003466 */
Robin Lee25e26452015-06-02 09:56:29 -07003467 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003468 if (mService != null) {
3469 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003470 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003471 } catch (RemoteException e) {
3472 Log.w(TAG, "Failed talking with device policy service", e);
3473 }
3474 }
3475 }
3476
3477 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003478 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3479 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003480 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003481 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3482 */
Robin Lee25e26452015-06-02 09:56:29 -07003483 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003484 if (mService != null) {
3485 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003486 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003487 } catch (RemoteException e) {
3488 Log.w(TAG, "Failed talking with device policy service", e);
3489 }
3490 }
3491 }
3492
3493 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003494 * Called by a profile or device owner to set the permitted accessibility services. When
3495 * set by a device owner or profile owner the restriction applies to all profiles of the
3496 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003497 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003498 * By default the user can use any accessiblity service. When zero or more packages have
3499 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003500 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003501 *
3502 * <p> Calling with a null value for the list disables the restriction so that all services
3503 * can be used, calling with an empty list only allows the builtin system's services.
3504 *
3505 * <p> System accesibility services are always available to the user the list can't modify
3506 * this.
3507 *
3508 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3509 * @param packageNames List of accessibility service package names.
3510 *
3511 * @return true if setting the restriction succeeded. It fail if there is
3512 * one or more non-system accessibility services enabled, that are not in the list.
3513 */
Robin Lee25e26452015-06-02 09:56:29 -07003514 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003515 List<String> packageNames) {
3516 if (mService != null) {
3517 try {
3518 return mService.setPermittedAccessibilityServices(admin, packageNames);
3519 } catch (RemoteException e) {
3520 Log.w(TAG, "Failed talking with device policy service", e);
3521 }
3522 }
3523 return false;
3524 }
3525
3526 /**
3527 * Returns the list of permitted accessibility services set by this device or profile owner.
3528 *
3529 * <p>An empty list means no accessibility services except system services are allowed.
3530 * Null means all accessibility services are allowed.
3531 *
3532 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3533 * @return List of accessiblity service package names.
3534 */
Robin Lee25e26452015-06-02 09:56:29 -07003535 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003536 if (mService != null) {
3537 try {
3538 return mService.getPermittedAccessibilityServices(admin);
3539 } catch (RemoteException e) {
3540 Log.w(TAG, "Failed talking with device policy service", e);
3541 }
3542 }
3543 return null;
3544 }
3545
3546 /**
3547 * Returns the list of accessibility services permitted by the device or profiles
3548 * owners of this user.
3549 *
3550 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3551 * it will contain the intersection of the permitted lists for any device or profile
3552 * owners that apply to this user. It will also include any system accessibility services.
3553 *
3554 * @param userId which user to check for.
3555 * @return List of accessiblity service package names.
3556 * @hide
3557 */
3558 @SystemApi
3559 public List<String> getPermittedAccessibilityServices(int userId) {
3560 if (mService != null) {
3561 try {
3562 return mService.getPermittedAccessibilityServicesForUser(userId);
3563 } catch (RemoteException e) {
3564 Log.w(TAG, "Failed talking with device policy service", e);
3565 }
3566 }
3567 return null;
3568 }
3569
3570 /**
3571 * Called by a profile or device owner to set the permitted input methods services. When
3572 * set by a device owner or profile owner the restriction applies to all profiles of the
3573 * user the device owner or profile owner is an admin for.
3574 *
3575 * By default the user can use any input method. When zero or more packages have
3576 * been added, input method that are not in the list and not part of the system
3577 * can not be enabled by the user.
3578 *
3579 * This method will fail if it is called for a admin that is not for the foreground user
3580 * or a profile of the foreground user.
3581 *
3582 * <p> Calling with a null value for the list disables the restriction so that all input methods
3583 * can be used, calling with an empty list disables all but the system's own input methods.
3584 *
3585 * <p> System input methods are always available to the user this method can't modify this.
3586 *
3587 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3588 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003589 * @return true if setting the restriction succeeded. It will fail if there are
3590 * one or more non-system input methods currently enabled that are not in
3591 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003592 */
Robin Lee25e26452015-06-02 09:56:29 -07003593 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003594 if (mService != null) {
3595 try {
3596 return mService.setPermittedInputMethods(admin, packageNames);
3597 } catch (RemoteException e) {
3598 Log.w(TAG, "Failed talking with device policy service", e);
3599 }
3600 }
3601 return false;
3602 }
3603
3604
3605 /**
3606 * Returns the list of permitted input methods set by this device or profile owner.
3607 *
3608 * <p>An empty list means no input methods except system input methods are allowed.
3609 * Null means all input methods are allowed.
3610 *
3611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3612 * @return List of input method package names.
3613 */
Robin Lee25e26452015-06-02 09:56:29 -07003614 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003615 if (mService != null) {
3616 try {
3617 return mService.getPermittedInputMethods(admin);
3618 } catch (RemoteException e) {
3619 Log.w(TAG, "Failed talking with device policy service", e);
3620 }
3621 }
3622 return null;
3623 }
3624
3625 /**
3626 * Returns the list of input methods permitted by the device or profiles
3627 * owners of the current user.
3628 *
3629 * <p>Null means all input methods are allowed, if a non-null list is returned
3630 * it will contain the intersection of the permitted lists for any device or profile
3631 * owners that apply to this user. It will also include any system input methods.
3632 *
3633 * @return List of input method package names.
3634 * @hide
3635 */
3636 @SystemApi
3637 public List<String> getPermittedInputMethodsForCurrentUser() {
3638 if (mService != null) {
3639 try {
3640 return mService.getPermittedInputMethodsForCurrentUser();
3641 } catch (RemoteException e) {
3642 Log.w(TAG, "Failed talking with device policy service", e);
3643 }
3644 }
3645 return null;
3646 }
3647
3648 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003649 * Called by a device owner to create a user with the specified name. The UserHandle returned
3650 * by this method should not be persisted as user handles are recycled as users are removed and
3651 * created. If you need to persist an identifier for this user, use
3652 * {@link UserManager#getSerialNumberForUser}.
3653 *
3654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3655 * @param name the user's name
3656 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003657 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3658 * user could not be created.
Julia Reynolds1e958392014-05-16 14:25:21 -04003659 */
Robin Lee25e26452015-06-02 09:56:29 -07003660 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003661 try {
3662 return mService.createUser(admin, name);
3663 } catch (RemoteException re) {
3664 Log.w(TAG, "Could not create a user", re);
3665 }
3666 return null;
3667 }
3668
3669 /**
Jason Monk03978a42014-06-10 15:05:30 -04003670 * Called by a device owner to create a user with the specified name. The UserHandle returned
3671 * by this method should not be persisted as user handles are recycled as users are removed and
3672 * created. If you need to persist an identifier for this user, use
3673 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3674 * immediately.
3675 *
3676 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3677 * as registered as an active admin on the new user. The profile owner package will be
3678 * installed on the new user if it already is installed on the device.
3679 *
3680 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3681 * profileOwnerComponent when onEnable is called.
3682 *
3683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3684 * @param name the user's name
3685 * @param ownerName the human readable name of the organisation associated with this DPM.
3686 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3687 * the user.
3688 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3689 * on the new user.
3690 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003691 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3692 * user could not be created.
Jason Monk03978a42014-06-10 15:05:30 -04003693 */
Robin Lee25e26452015-06-02 09:56:29 -07003694 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3695 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003696 try {
3697 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3698 adminExtras);
3699 } catch (RemoteException re) {
3700 Log.w(TAG, "Could not create a user", re);
3701 }
3702 return null;
3703 }
3704
3705 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003706 * Called by a device owner to remove a user and all associated data. The primary user can
3707 * not be removed.
3708 *
3709 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3710 * @param userHandle the user to remove.
3711 * @return {@code true} if the user was removed, {@code false} otherwise.
3712 */
Robin Lee25e26452015-06-02 09:56:29 -07003713 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003714 try {
3715 return mService.removeUser(admin, userHandle);
3716 } catch (RemoteException re) {
3717 Log.w(TAG, "Could not remove user ", re);
3718 return false;
3719 }
3720 }
3721
3722 /**
Jason Monk582d9112014-07-09 19:57:08 -04003723 * Called by a device owner to switch the specified user to the foreground.
3724 *
3725 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3726 * @param userHandle the user to switch to; null will switch to primary.
3727 * @return {@code true} if the switch was successful, {@code false} otherwise.
3728 *
3729 * @see Intent#ACTION_USER_FOREGROUND
3730 */
Robin Lee25e26452015-06-02 09:56:29 -07003731 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003732 try {
3733 return mService.switchUser(admin, userHandle);
3734 } catch (RemoteException re) {
3735 Log.w(TAG, "Could not switch user ", re);
3736 return false;
3737 }
3738 }
3739
3740 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003741 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003742 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003743 *
3744 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3745 * exception will be thrown.
3746 *
3747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3748 * @param packageName The name of the package to fetch restricted settings of.
3749 * @return {@link Bundle} of settings corresponding to what was set last time
3750 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3751 * if no restrictions have been set.
3752 */
Robin Lee25e26452015-06-02 09:56:29 -07003753 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003754 if (mService != null) {
3755 try {
3756 return mService.getApplicationRestrictions(admin, packageName);
3757 } catch (RemoteException e) {
3758 Log.w(TAG, "Failed talking with device policy service", e);
3759 }
3760 }
3761 return null;
3762 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003763
3764 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003765 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003766 * <p>
3767 * The calling device admin must be a profile or device owner; if it is not,
3768 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003769 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003770 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3771 * with.
3772 * @param key The key of the restriction. See the constants in
3773 * {@link android.os.UserManager} for the list of keys.
3774 */
Robin Lee25e26452015-06-02 09:56:29 -07003775 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003776 if (mService != null) {
3777 try {
3778 mService.setUserRestriction(admin, key, true);
3779 } catch (RemoteException e) {
3780 Log.w(TAG, "Failed talking with device policy service", e);
3781 }
3782 }
3783 }
3784
3785 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003786 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003787 * <p>
3788 * The calling device admin must be a profile or device owner; if it is not,
3789 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003790 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003791 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3792 * with.
3793 * @param key The key of the restriction. See the constants in
3794 * {@link android.os.UserManager} for the list of keys.
3795 */
Robin Lee25e26452015-06-02 09:56:29 -07003796 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003797 if (mService != null) {
3798 try {
3799 mService.setUserRestriction(admin, key, false);
3800 } catch (RemoteException e) {
3801 Log.w(TAG, "Failed talking with device policy service", e);
3802 }
3803 }
3804 }
Adam Connors010cfd42014-04-16 12:48:13 +01003805
3806 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003807 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003808 * is unavailable for use, but the data and actual package file remain.
3809 *
3810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003811 * @param packageName The name of the package to hide or unhide.
3812 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3813 * unhidden.
3814 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003815 */
Robin Lee25e26452015-06-02 09:56:29 -07003816 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003817 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003818 if (mService != null) {
3819 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003820 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003821 } catch (RemoteException e) {
3822 Log.w(TAG, "Failed talking with device policy service", e);
3823 }
3824 }
3825 return false;
3826 }
3827
3828 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003829 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003830 *
3831 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003832 * @param packageName The name of the package to retrieve the hidden status of.
3833 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003834 */
Robin Lee25e26452015-06-02 09:56:29 -07003835 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003836 if (mService != null) {
3837 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003838 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003839 } catch (RemoteException e) {
3840 Log.w(TAG, "Failed talking with device policy service", e);
3841 }
3842 }
3843 return false;
3844 }
3845
3846 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003847 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003848 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003849 *
3850 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3851 * @param packageName The package to be re-enabled in the current profile.
3852 */
Robin Lee25e26452015-06-02 09:56:29 -07003853 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003854 if (mService != null) {
3855 try {
3856 mService.enableSystemApp(admin, packageName);
3857 } catch (RemoteException e) {
3858 Log.w(TAG, "Failed to install package: " + packageName);
3859 }
3860 }
3861 }
3862
3863 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003864 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003865 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003866 *
3867 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3868 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3869 * intent will be re-enabled in the current profile.
3870 * @return int The number of activities that matched the intent and were installed.
3871 */
Robin Lee25e26452015-06-02 09:56:29 -07003872 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003873 if (mService != null) {
3874 try {
3875 return mService.enableSystemAppWithIntent(admin, intent);
3876 } catch (RemoteException e) {
3877 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3878 }
3879 }
3880 return 0;
3881 }
3882
3883 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003884 * Called by a device owner or profile owner to disable account management for a specific type
3885 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003886 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003887 * <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 +01003888 * security exception will be thrown.
3889 *
3890 * <p>When account management is disabled for an account type, adding or removing an account
3891 * of that type will not be possible.
3892 *
3893 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3894 * @param accountType For which account management is disabled or enabled.
3895 * @param disabled The boolean indicating that account management will be disabled (true) or
3896 * enabled (false).
3897 */
Robin Lee25e26452015-06-02 09:56:29 -07003898 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003899 boolean disabled) {
3900 if (mService != null) {
3901 try {
3902 mService.setAccountManagementDisabled(admin, accountType, disabled);
3903 } catch (RemoteException e) {
3904 Log.w(TAG, "Failed talking with device policy service", e);
3905 }
3906 }
3907 }
3908
3909 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003910 * Gets the array of accounts for which account management is disabled by the profile owner.
3911 *
3912 * <p> Account management can be disabled/enabled by calling
3913 * {@link #setAccountManagementDisabled}.
3914 *
3915 * @return a list of account types for which account management has been disabled.
3916 *
3917 * @see #setAccountManagementDisabled
3918 */
3919 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003920 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003921 }
3922
3923 /**
3924 * @see #getAccountTypesWithManagementDisabled()
3925 * @hide
3926 */
3927 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003928 if (mService != null) {
3929 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003930 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003931 } catch (RemoteException e) {
3932 Log.w(TAG, "Failed talking with device policy service", e);
3933 }
3934 }
3935
3936 return null;
3937 }
justinzhang511e0d82014-03-24 16:09:24 -04003938
3939 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003940 * Sets which packages may enter lock task mode.
3941 *
3942 * <p>Any packages that shares uid with an allowed package will also be allowed
3943 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003944 *
Jason Monkc5185f22014-06-24 11:12:42 -04003945 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003946 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003947 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003948 *
3949 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003950 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3951 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003952 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003953 */
Robin Lee25e26452015-06-02 09:56:29 -07003954 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003955 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003956 if (mService != null) {
3957 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003958 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003959 } catch (RemoteException e) {
3960 Log.w(TAG, "Failed talking with device policy service", e);
3961 }
3962 }
3963 }
3964
3965 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003966 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003967 *
3968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003969 * @hide
3970 */
Robin Lee25e26452015-06-02 09:56:29 -07003971 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003972 if (mService != null) {
3973 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003974 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003975 } catch (RemoteException e) {
3976 Log.w(TAG, "Failed talking with device policy service", e);
3977 }
3978 }
3979 return null;
3980 }
3981
3982 /**
3983 * This function lets the caller know whether the given component is allowed to start the
3984 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003985 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003986 */
Jason Monkd7b86212014-06-16 13:15:38 -04003987 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003988 if (mService != null) {
3989 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003990 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003991 } catch (RemoteException e) {
3992 Log.w(TAG, "Failed talking with device policy service", e);
3993 }
3994 }
3995 return false;
3996 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003997
3998 /**
3999 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4000 * 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 -04004001 * <p>The settings that can be updated with this method are:
4002 * <ul>
4003 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4004 * <li>{@link Settings.Global#AUTO_TIME}</li>
4005 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00004006 * <li>{@link Settings.Global#BLUETOOTH_ON}
4007 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
4008 * {@link android.bluetooth.BluetoothAdapter#enable()} and
4009 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004010 * <li>{@link Settings.Global#DATA_ROAMING}</li>
4011 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4012 * <li>{@link Settings.Global#MODE_RINGER}</li>
4013 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4014 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00004015 * <li>{@link Settings.Global#WIFI_ON}
4016 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
4017 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004018 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004019 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
4020 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
4021 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004022 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004023 *
4024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4025 * @param setting The name of the setting to update.
4026 * @param value The value to update the setting to.
4027 */
Robin Lee25e26452015-06-02 09:56:29 -07004028 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004029 if (mService != null) {
4030 try {
4031 mService.setGlobalSetting(admin, setting, value);
4032 } catch (RemoteException e) {
4033 Log.w(TAG, "Failed talking with device policy service", e);
4034 }
4035 }
4036 }
4037
4038 /**
4039 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4040 * that the value of the setting is in the correct form for the setting type should be performed
4041 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004042 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004043 * <ul>
4044 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004045 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004046 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4047 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004048 * <p>A device owner can additionally update the following settings:
4049 * <ul>
4050 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4051 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004052 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4053 * @param setting The name of the setting to update.
4054 * @param value The value to update the setting to.
4055 */
Robin Lee25e26452015-06-02 09:56:29 -07004056 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004057 if (mService != null) {
4058 try {
4059 mService.setSecureSetting(admin, setting, value);
4060 } catch (RemoteException e) {
4061 Log.w(TAG, "Failed talking with device policy service", e);
4062 }
4063 }
4064 }
4065
Amith Yamasanif20d6402014-05-24 15:34:37 -07004066 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004067 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004068 * making permission requests of a local or remote administrator of the user.
4069 * <p/>
4070 * Only a profile owner can designate the restrictions provider.
4071 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004072 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004073 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004074 * it removes the restrictions provider previously assigned.
4075 */
Robin Lee25e26452015-06-02 09:56:29 -07004076 public void setRestrictionsProvider(@NonNull ComponentName admin,
4077 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004078 if (mService != null) {
4079 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004080 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004081 } catch (RemoteException re) {
4082 Log.w(TAG, "Failed to set permission provider on device policy service");
4083 }
4084 }
4085 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004086
4087 /**
4088 * Called by profile or device owners to set the master volume mute on or off.
4089 *
4090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4091 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4092 */
Robin Lee25e26452015-06-02 09:56:29 -07004093 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004094 if (mService != null) {
4095 try {
4096 mService.setMasterVolumeMuted(admin, on);
4097 } catch (RemoteException re) {
4098 Log.w(TAG, "Failed to setMasterMute on device policy service");
4099 }
4100 }
4101 }
4102
4103 /**
4104 * Called by profile or device owners to check whether the master volume mute is on or off.
4105 *
4106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4107 * @return {@code true} if master volume is muted, {@code false} if it's not.
4108 */
Robin Lee25e26452015-06-02 09:56:29 -07004109 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004110 if (mService != null) {
4111 try {
4112 return mService.isMasterVolumeMuted(admin);
4113 } catch (RemoteException re) {
4114 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4115 }
4116 }
4117 return false;
4118 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004119
4120 /**
4121 * Called by profile or device owners to change whether a user can uninstall
4122 * a package.
4123 *
4124 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4125 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004126 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004127 */
Robin Lee25e26452015-06-02 09:56:29 -07004128 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004129 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004130 if (mService != null) {
4131 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004132 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004133 } catch (RemoteException re) {
4134 Log.w(TAG, "Failed to call block uninstall on device policy service");
4135 }
4136 }
4137 }
4138
4139 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004140 * Check whether the current user has been blocked by device policy from uninstalling a package.
4141 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004142 * <p>
4143 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004144 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004145 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004146 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004147 *
Robin Lee25e26452015-06-02 09:56:29 -07004148 * @param admin The name of the admin component whose blocking policy will be checked, or
4149 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004150 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004151 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004152 */
Robin Lee25e26452015-06-02 09:56:29 -07004153 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004154 if (mService != null) {
4155 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004156 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004157 } catch (RemoteException re) {
4158 Log.w(TAG, "Failed to call block uninstall on device policy service");
4159 }
4160 }
4161 return false;
4162 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004163
4164 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004165 * Called by the profile owner of a managed profile to enable widget providers from a
4166 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004167 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004168 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004169 * a package may have zero or more provider components, where each component
4170 * provides a different widget type.
4171 * <p>
4172 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004173 *
4174 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4175 * @param packageName The package from which widget providers are white-listed.
4176 * @return Whether the package was added.
4177 *
4178 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4179 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4180 */
Robin Lee25e26452015-06-02 09:56:29 -07004181 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004182 if (mService != null) {
4183 try {
4184 return mService.addCrossProfileWidgetProvider(admin, packageName);
4185 } catch (RemoteException re) {
4186 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4187 }
4188 }
4189 return false;
4190 }
4191
4192 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004193 * Called by the profile owner of a managed profile to disable widget providers from a given
4194 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004195 * package should have been added via {@link #addCrossProfileWidgetProvider(
4196 * android.content.ComponentName, String)}.
4197 * <p>
4198 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004199 *
4200 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4201 * @param packageName The package from which widget providers are no longer
4202 * white-listed.
4203 * @return Whether the package was removed.
4204 *
4205 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4206 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4207 */
Robin Lee25e26452015-06-02 09:56:29 -07004208 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004209 if (mService != null) {
4210 try {
4211 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4212 } catch (RemoteException re) {
4213 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4214 }
4215 }
4216 return false;
4217 }
4218
4219 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004220 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004221 * available in the parent profile.
4222 *
4223 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4224 * @return The white-listed package list.
4225 *
4226 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4227 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4228 */
Robin Lee25e26452015-06-02 09:56:29 -07004229 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004230 if (mService != null) {
4231 try {
4232 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4233 if (providers != null) {
4234 return providers;
4235 }
4236 } catch (RemoteException re) {
4237 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4238 }
4239 }
4240 return Collections.emptyList();
4241 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004242
4243 /**
4244 * Called by profile or device owners to set the current user's photo.
4245 *
4246 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4247 * @param icon the bitmap to set as the photo.
4248 */
Robin Lee25e26452015-06-02 09:56:29 -07004249 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004250 try {
4251 mService.setUserIcon(admin, icon);
4252 } catch (RemoteException re) {
4253 Log.w(TAG, "Could not set the user icon ", re);
4254 }
4255 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004256
4257 /**
4258 * Called by device initializer to send a provisioning status update to the remote setup device.
4259 *
4260 * @param statusCode a custom status code value as defined by
Craig Lafayette9ef04bf2015-05-06 16:57:01 -04004261 * {@link DeviceInitializerStatus#FLAG_STATUS_CUSTOM}.
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004262 * @param description custom description of the status code sent
4263 */
4264 public void sendDeviceInitializerStatus(int statusCode, String description) {
4265 try {
4266 mService.sendDeviceInitializerStatus(statusCode, description);
4267 } catch (RemoteException re) {
4268 Log.w(TAG, "Could not send device initializer status", re);
4269 }
4270 }
Rubin Xu8027a4f2015-03-10 17:52:37 +00004271
Rubin Xu5faad8e2015-04-20 17:43:48 +01004272 /**
4273 * Called by device owners to set a local system update policy. When a new policy is set,
4274 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004275 *
Robin Lee25e26452015-06-02 09:56:29 -07004276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4277 * components in the device owner package can set system update policies and the
4278 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004279 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004280 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004281 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004282 */
Robin Lee25e26452015-06-02 09:56:29 -07004283 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004284 if (mService != null) {
4285 try {
Robin Lee25e26452015-06-02 09:56:29 -07004286 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004287 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004288 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004289 }
4290 }
4291 }
4292
4293 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004294 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004295 *
Robin Lee25e26452015-06-02 09:56:29 -07004296 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004297 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004298 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004299 if (mService != null) {
4300 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004301 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004302 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004303 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004304 }
4305 }
4306 return null;
4307 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004308
4309 /**
4310 * Called by a device owner to disable the keyguard altogether.
4311 *
4312 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4313 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4314 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4315 * being disabled.
4316 *
4317 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004318 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004319 *
4320 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004321 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004322 */
Robin Lee25e26452015-06-02 09:56:29 -07004323 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004324 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004325 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004326 } catch (RemoteException re) {
4327 Log.w(TAG, "Failed talking with device policy service", re);
4328 return false;
4329 }
4330 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004331
4332 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004333 * Called by device owner to disable the status bar. Disabling the status bar blocks
4334 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004335 * a single use device.
4336 *
4337 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004338 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4339 *
4340 * @return {@code false} if attempting to disable the status bar failed.
4341 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004342 */
Robin Lee25e26452015-06-02 09:56:29 -07004343 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004344 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004345 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004346 } catch (RemoteException re) {
4347 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004348 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004349 }
4350 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004351
4352 /**
4353 * Callable by the system update service to notify device owners about pending updates.
4354 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4355 * permission.
4356 *
4357 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4358 * when the current pending update was first available. -1 if no update is available.
4359 * @hide
4360 */
4361 @SystemApi
4362 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4363 if (mService != null) {
4364 try {
4365 mService.notifyPendingSystemUpdate(updateReceivedTime);
4366 } catch (RemoteException re) {
4367 Log.w(TAG, "Could not notify device owner about pending system update", re);
4368 }
4369 }
4370 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004371
4372 /**
4373 * Called by a device initializer to set the activity to be launched on device boot or after a
4374 * user switch during user setup. This activity will be started regardless of the priority of
4375 * other 'home' activities. Once user setup is complete, the preferred setup activity will be
4376 * ignored.
4377 *
4378 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4379 * @param activity The Activity to be started by default during user setup.
4380 */
Robin Lee25e26452015-06-02 09:56:29 -07004381 public void setPreferredSetupActivity(@NonNull ComponentName admin,
4382 @NonNull ComponentName activity) {
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004383 try {
4384 mService.setPreferredSetupActivity(admin, activity);
4385 } catch (RemoteException re) {
4386 Log.w(TAG, "Failed talking with device policy service", re);
4387 }
4388 }
Amith Yamasanid49489b2015-04-28 14:00:26 -07004389
4390 /**
4391 * Called by profile or device owners to set the default response for future runtime permission
4392 * requests by applications. The policy can allow for normal operation which prompts the
4393 * user to grant a permission, or can allow automatic granting or denying of runtime
4394 * permission requests by an application. This also applies to new permissions declared by app
4395 * updates.
4396 * @param admin Which profile or device owner this request is associated with.
4397 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4398 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
4399 */
Robin Lee25e26452015-06-02 09:56:29 -07004400 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004401 try {
4402 mService.setPermissionPolicy(admin, policy);
4403 } catch (RemoteException re) {
4404 Log.w(TAG, "Failed talking with device policy service", re);
4405 }
4406 }
4407
4408 /**
4409 * Returns the current runtime permission policy set by the device or profile owner. The
4410 * default is {@link #PERMISSION_POLICY_PROMPT}.
4411 * @param admin Which profile or device owner this request is associated with.
4412 * @return the current policy for future permission requests.
4413 */
Robin Lee25e26452015-06-02 09:56:29 -07004414 public int getPermissionPolicy(@NonNull ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004415 try {
4416 return mService.getPermissionPolicy(admin);
4417 } catch (RemoteException re) {
4418 return PERMISSION_POLICY_PROMPT;
4419 }
4420 }
4421
4422 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004423 * Sets the grant state of a runtime permission for a specific application. The state
4424 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4425 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4426 * is denied and the user cannot manage it through the UI, and {@link
4427 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4428 * user cannot manage it through the UI. This might affect all permissions in a
4429 * group that the runtime permission belongs to. This method can only be called
4430 * by a profile or device owner.
4431 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004432 * @param admin Which profile or device owner this request is associated with.
4433 * @param packageName The application to grant or revoke a permission to.
4434 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004435 * @param grantState The permission grant state which is one of {@link
4436 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4437 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4438 * @return whether the permission was successfully granted or revoked.
4439 *
4440 * @see #PERMISSION_GRANT_STATE_DENIED
4441 * @see #PERMISSION_GRANT_STATE_DEFAULT
4442 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004443 */
Robin Lee25e26452015-06-02 09:56:29 -07004444 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004445 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004446 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004447 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004448 } catch (RemoteException re) {
4449 Log.w(TAG, "Failed talking with device policy service", re);
4450 return false;
4451 }
4452 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004453
4454 /**
4455 * Returns the current grant state of a runtime permission for a specific application.
4456 *
4457 * @param admin Which profile or device owner this request is associated with.
4458 * @param packageName The application to check the grant state for.
4459 * @param permission The permission to check for.
4460 * @return the current grant state specified by device policy. If the profile or device owner
4461 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4462 * This does not indicate whether or not the permission is currently granted for the package.
4463 *
4464 * <p/>If a grant state was set by the profile or device owner, then the return value will
4465 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4466 * which indicates if the permission is currently denied or granted.
4467 *
4468 * @see #setPermissionGrantState(ComponentName, String, String, int)
4469 * @see PackageManager#checkPermission(String, String)
4470 */
Robin Lee25e26452015-06-02 09:56:29 -07004471 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004472 String permission) {
4473 try {
4474 return mService.getPermissionGrantState(admin, packageName, permission);
4475 } catch (RemoteException re) {
4476 Log.w(TAG, "Failed talking with device policy service", re);
4477 return PERMISSION_GRANT_STATE_DEFAULT;
4478 }
4479 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004480}