blob: 52ccd7b24b6b29e2beb9dae43202a3384561666f [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Dianne Hackbornd6847842010-01-12 18:14:19 -080019import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050021import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040022import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.content.ComponentName;
24import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010025import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000026import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080027import android.content.pm.ActivityInfo;
28import android.content.pm.PackageManager;
29import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050030import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040031import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010032import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.os.Handler;
Jim Millere303bf42014-08-26 17:12:29 -070034import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000035import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080036import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.os.RemoteException;
38import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070039import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040040import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040041import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010042import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070043import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080044import android.util.Log;
45
Maggie Benthallda51e682013-08-08 22:35:44 -040046import com.android.org.conscrypt.TrustedCertificateStore;
47
Jessica Hummel91da58d2014-04-10 17:39:43 +010048import org.xmlpull.v1.XmlPullParserException;
49
Maggie Benthallda51e682013-08-08 22:35:44 -040050import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070052import java.net.InetSocketAddress;
53import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010054import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010055import java.security.PrivateKey;
56import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040057import java.security.cert.CertificateException;
58import java.security.cert.CertificateFactory;
59import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010060import java.security.spec.PKCS8EncodedKeySpec;
61import java.security.spec.InvalidKeySpecException;
62import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070063import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070064import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080065import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080066
67/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000068 * Public interface for managing policies enforced on a device. Most clients of this class must be
69 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000070 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000071 * a device administrator may be registered as either a profile or device owner. A given method is
72 * accessible to all device administrators unless the documentation for that method specifies that
73 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080074 *
75 * <div class="special reference">
76 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000077 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080078 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
79 * developer guide.</p>
80 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080081 */
82public class DevicePolicyManager {
83 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080084
85 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080086 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070087
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080088 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080089 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 mService = IDevicePolicyManager.Stub.asInterface(
91 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
92 }
93
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080094 /** @hide */
95 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080096 DevicePolicyManager me = new DevicePolicyManager(context, handler);
97 return me.mService != null ? me : null;
98 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070099
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000101 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000102 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100103 * <p>A managed profile allows data separation for example for the usage of a
104 * device as a personal and corporate device. The user which provisioning is started from and
105 * the managed profile share a launcher.
106 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800107 * <p>This intent will typically be sent by a mobile device management application (MDM).
108 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
109 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100110 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000111 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
112 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
113 * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain the extra
114 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
115 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000117 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
118 * in the provisioning intent. The
119 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
120 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
121 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100122 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100123 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
124 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000125 *
126 * <p>Input: Nothing.</p>
127 * <p>Output: Nothing</p>
128 */
129 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
130 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100131 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000132
133 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700134 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
135 * a mobile device management application that starts managed profile provisioning to pass data
136 * to itself on the managed profile when provisioning completes. The mobile device management
137 * application sends this extra in an intent with the action
138 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
139 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
140 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
141 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100142 */
143 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100144 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100145
146 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100147 * A String extra holding the package name of the mobile device management application that
148 * will be set as the profile owner or device owner.
149 *
150 * <p>If an application starts provisioning directly via an intent with action
151 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
152 * application that started provisioning. The package will be set as profile owner in that case.
153 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000154 * <p>This package is set as device owner when device owner provisioning is started by an NFC
155 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000156 *
157 * <p> When this extra is set, the application must have exactly one device admin receiver.
158 * This receiver will be set as the profile or device owner and active admin.</p>
159
160 * @see DeviceAdminReceiver
161 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
162 * supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000163 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000164 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000165 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100166 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000167
168 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000169 * A ComponentName extra indicating the device admin receiver of the mobile device management
170 * application that will be set as the profile owner or device owner and active admin.
171 *
172 * <p>If an application starts provisioning directly via an intent with action
173 * {@link #ACTION_PROVISION_MANAGED_PROFILE} the package name of this component has to match the
174 * package name of the application that started provisioning.
175 *
176 * <p>This component is set as device owner and active admin when device owner provisioning is
177 * started by an NFC message containing an NFC record with MIME type
Rubin Xu44ef750b2015-03-23 16:51:33 +0000178 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}. For the NFC record, the component name should be
179 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000180 *
181 * @see DeviceAdminReceiver
182 */
183 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
184 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
185
186 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000187 * An {@link android.accounts.Account} extra holding the account to migrate during managed
188 * profile provisioning. If the account supplied is present in the primary user, it will be
189 * copied, along with its credentials to the managed profile and removed from the primary user.
190 *
191 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
192 */
193
194 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
195 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
196
197 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100198 * A String extra that, holds the email address of the account which a managed profile is
199 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
200 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100201 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100202 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
203 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100204 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
205 * contains this extra, it is forwarded in the
206 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
207 * device management application that was set as the profile owner during provisioning.
208 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100209 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100210 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
211 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100212
213 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000214 * A Boolean extra that can be used by the mobile device management application to skip the
215 * disabling of system apps during provisioning when set to <code>true</code>.
216 *
217 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
218 * provisioning via an NFC bump.
219 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000220 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
221 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000222
223 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100224 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
225 * will be set to.
226 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000227 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
228 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100229 */
230 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100231 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100232
233 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100234 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
235 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100236 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000237 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
238 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100239 */
240 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100241 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100242
243 /**
244 * A String extra holding the {@link java.util.Locale} that the device will be set to.
245 * Format: xx_yy, where xx is the language code, and yy the country code.
246 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000247 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
248 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100249 */
250 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100251 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100252
253 /**
254 * A String extra holding the ssid of the wifi network that should be used during nfc device
255 * owner provisioning for downloading the mobile device management application.
256 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000257 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
258 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100259 */
260 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100261 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100262
263 /**
264 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
265 * is hidden or not.
266 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000267 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
268 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100269 */
270 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100271 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100272
273 /**
274 * A String extra indicating the security type of the wifi network in
275 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
276 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000277 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
278 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100279 */
280 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100281 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100282
283 /**
284 * A String extra holding the password of the wifi network in
285 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
286 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000287 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
288 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100289 */
290 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100291 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100292
293 /**
294 * A String extra holding the proxy host for the wifi network in
295 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
296 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000297 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
298 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100299 */
300 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100301 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100302
303 /**
304 * An int extra holding the proxy port for the wifi network in
305 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
306 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000307 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
308 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100309 */
310 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100311 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100312
313 /**
314 * A String extra holding the proxy bypass for the wifi network in
315 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
316 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000317 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
318 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319 */
320 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100321 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100322
323 /**
324 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
325 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
326 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000327 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
328 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329 */
330 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100331 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100332
333 /**
334 * A String extra holding a url that specifies the download location of the device admin
335 * package. When not provided it is assumed that the device admin package is already installed.
336 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000337 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
338 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100339 */
340 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100341 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100342
343 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400344 * An int extra holding a minimum required version code for the device admin package. If the
345 * device admin is already installed on the device, it will only be re-downloaded from
346 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
347 * installed package is less than this version code.
348 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400349 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400350 * provisioning via an NFC bump.
351 */
352 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
353 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
354
355 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100356 * A String extra holding a http cookie header which should be used in the http request to the
357 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
358 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000359 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
360 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100361 */
362 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100363 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100364
365 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000366 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100367 * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
368 *
369 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM} should be
370 * present. The provided checksum should match the checksum of the file at the download
371 * location. If the checksum doesn't match an error will be shown to the user and the user will
372 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000374 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
375 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100376 */
377 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100378 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100379
380 /**
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100381 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any certificate of the
382 * android package archive at the download location specified in {@link
383 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
384 *
385 * <p>The certificates of an android package archive can be obtained using
386 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
387 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
388 *
389 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
390 * present. The provided checksum should match the checksum of any certificate of the file at
391 * the download location. If the checksum does not match an error will be shown to the user and
392 * the user will be asked to factory reset the device.
393 *
394 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
395 * provisioning via an NFC bump.
396 */
397 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM
398 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM";
399
400 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000401 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
402 * has completed successfully.
403 *
404 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700405 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000406 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800407 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000408 * corresponds to the account requested to be migrated at provisioning time, if any.
409 */
410 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
411 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
412 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
413
414 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400415 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500416 * provisioning.
417 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400418 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500419 * provisioning via an NFC bump.
420 */
421 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
422 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
423
424 /**
Rubin Xu44ef750b2015-03-23 16:51:33 +0000425 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
426 * component of the application that is temporarily granted device owner privileges during
427 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500428 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000429 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000430 * It can also be used in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts
Rubin Xu44ef750b2015-03-23 16:51:33 +0000431 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
432 * string first.
433 *
434 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500435 */
436 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
437 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
438
439 /**
440 * A String extra holding an http url that specifies the download location of the device
441 * initializer package. When not provided it is assumed that the device initializer package is
442 * already installed.
443 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400444 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500445 * provisioning via an NFC bump.
446 */
447 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
448 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
449
450 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400451 * An int extra holding a minimum required version code for the device initializer package.
452 * If the initializer is already installed on the device, it will only be re-downloaded from
453 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
454 * the installed package is less than this version code.
455 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400456 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400457 * provisioning via an NFC bump.
458 */
459 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
460 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
461
462 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500463 * A String extra holding a http cookie header which should be used in the http request to the
464 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
465 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400466 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500467 * provisioning via an NFC bump.
468 */
469 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
470 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
471
472 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000473 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
474 * location specified in
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100475 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
476 *
477 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM}
478 * should be present. The provided checksum should match the checksum of the file at the
479 * download location. If the checksum doesn't match an error will be shown to the user and the
480 * user will be asked to factory reset the device.
Julia Reynolds20118f12015-02-11 12:34:08 -0500481 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400482 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500483 * provisioning via an NFC bump.
484 */
485 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
486 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
487
488 /**
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100489 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any certificate of the
490 * android package archive at the download location specified in {@link
491 * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
492 *
493 * <p>The certificates of an android package archive can be obtained using
494 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
495 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
496 *
497 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}
498 * should be present. The provided checksum should match the checksum of any certificate of the
499 * file at the download location. If the checksum doesn't match an error will be shown to the
500 * user and the user will be asked to factory reset the device.
501 *
502 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
503 * provisioning via an NFC bump.
504 */
505 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM
506 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM";
507
508 /**
Craig Lafayette97e473e2015-03-19 10:19:38 -0400509 * A String extra holding the MAC address of the Bluetooth device to connect to with status
510 * updates during provisioning.
511 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400512 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400513 * provisioning via an NFC bump.
514 */
515 public static final String EXTRA_PROVISIONING_BT_MAC_ADDRESS
516 = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS";
517
518 /**
519 * A String extra holding the Bluetooth service UUID on the device to connect to with status
520 * updates during provisioning.
521 *
522 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
523 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400524 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400525 * provisioning via an NFC bump.
526 */
527 public static final String EXTRA_PROVISIONING_BT_UUID
528 = "android.app.extra.PROVISIONING_BT_UUID";
529
530 /**
531 * A String extra holding a unique identifier used to identify the device connecting over
532 * Bluetooth. This identifier will be part of every status message sent to the remote device.
533 *
534 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
535 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400536 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400537 * provisioning via an NFC bump.
538 */
539 public static final String EXTRA_PROVISIONING_BT_DEVICE_ID
540 = "android.app.extra.PROVISIONING_BT_DEVICE_ID";
541
542 /**
543 * A Boolean extra that that will cause a provisioned device to temporarily proxy network
544 * traffic over Bluetooth. When a Wi-Fi network is available, the network proxy will stop.
545 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400546 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400547 * provisioning via an NFC bump.
548 */
549 public static final String EXTRA_PROVISIONING_BT_USE_PROXY
550 = "android.app.extra.PROVISIONING_BT_USE_PROXY";
Craig Lafayette8e27c4d2015-03-19 08:36:38 -0400551
552 /**
553 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
554 * holds data needed by the system to wipe factory reset protection. The data needed to wipe
555 * the device depend on the installed factory reset protection implementation. For example,
556 * if an account is needed to unlock a device, this extra may contain data used to
557 * authenticate that account.
558 *
559 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
560 * provisioning via an NFC bump.
561 */
562 public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS
563 = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
564
Craig Lafayette97e473e2015-03-19 10:19:38 -0400565 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400566 * This MIME type is used for starting the Device Owner provisioning that does not require
567 * provisioning features introduced in Android API level
568 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100569 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400570 * <p>For more information about the provisioning process see
571 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000573 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574 * contains the following properties:
575 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400576 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
577 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100578 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400579 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
581 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
582 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
583 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
584 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
585 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
586 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
587 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
588 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
589 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400590 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100591 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000592 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400593 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
594 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
595 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
596 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
597 *
598 * @see #MIME_TYPE_PROVISIONING_NFC_V2
599 *
600 */
601 public static final String MIME_TYPE_PROVISIONING_NFC
602 = "application/com.android.managedprovisioning";
603
604
605 /**
606 * This MIME type is used for starting the Device Owner provisioning that requires
607 * new provisioning features introduced in API version
608 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
609 * versions.
610 *
611 * <p>During device owner provisioning a device admin app is set as the owner of the device.
612 * A device owner has full control over the device. The device owner can not be modified by the
613 * user and the only way of resetting the device is if the device owner app calls a factory
614 * reset.
615 *
616 * <p> A typical use case would be a device that is owned by a company, but used by either an
617 * employee or client.
618 *
619 * <p> The NFC message should be sent to an unprovisioned device.
620 *
621 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
622 * contains the following properties in addition to properties listed at
623 * {@link #MIME_TYPE_PROVISIONING_NFC}:
624 * <ul>
625 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
626 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
627 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
628 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
629 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
630 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
631 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
632 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
633 * should be converted to a String via
634 * {@link android.content.ComponentName#flattenToString()}</li>
635 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li>
636 * <li>{@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, optional</li>
637 * <li>{@link #EXTRA_PROVISIONING_BT_UUID}, optional</li>
638 * <li>{@link #EXTRA_PROVISIONING_BT_DEVICE_ID}, optional</li>
639 * <li>{@link #EXTRA_PROVISIONING_BT_USE_PROXY}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000640 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100641 * <p> When device owner provisioning has completed, an intent of the type
642 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
643 * device owner.
644 *
645 * <p>
646 * If provisioning fails, the device is factory reset.
647 *
648 * <p>Input: Nothing.</p>
649 * <p>Output: Nothing</p>
650 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400651 public static final String MIME_TYPE_PROVISIONING_NFC_V2
652 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653
654 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800655 * Activity action: ask the user to add a new device administrator to the system.
656 * The desired policy is the ComponentName of the policy in the
657 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
658 * bring the user through adding the device administrator to the system (or
659 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700660 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800661 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
662 * field to provide the user with additional explanation (in addition
663 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800664 *
665 * <p>If your administrator is already active, this will ordinarily return immediately (without
666 * user intervention). However, if your administrator has been updated and is requesting
667 * additional uses-policy flags, the user will be presented with the new list. New policies
668 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800669 */
670 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
671 public static final String ACTION_ADD_DEVICE_ADMIN
672 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700673
Dianne Hackbornd6847842010-01-12 18:14:19 -0800674 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700675 * @hide
676 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700677 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700678 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700679 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
680 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700681 * to remotely control restrictions on the user.
682 *
683 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
684 * result of whether or not the user approved the action. If approved, the result will
685 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
686 * as a profile owner.
687 *
688 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
689 * field to provide the user with additional explanation (in addition
690 * to your component's description) about what is being added.
691 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700692 * <p>If there is already a profile owner active or the caller is not a system app, the
693 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700694 */
695 @SystemApi
696 public static final String ACTION_SET_PROFILE_OWNER
697 = "android.app.action.SET_PROFILE_OWNER";
698
699 /**
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400700 * Protected broadcast action that will be sent to managed provisioning to notify it that a
701 * status update has been reported by the device initializer. The status update will be
702 * reported to the remote setup device over Bluetooth.
703 *
704 * <p>Broadcasts with this action must supply a
Craig Lafayette9ef04bf2015-05-06 16:57:01 -0400705 * {@linkplain DeviceInitializerStatus#FLAG_STATUS_CUSTOM custom} status code in the
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400706 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_CODE} extra.
707 *
708 * <p>Broadcasts may optionally contain a description in the
709 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION} extra.
710 * @hide
711 */
712 @SystemApi
713 public static final String ACTION_SEND_DEVICE_INITIALIZER_STATUS
714 = "android.app.action.SEND_DEVICE_INITIALIZER_STATUS";
715
716 /**
717 * An integer extra that contains the status code that defines a status update. This extra must
718 * sent as part of a broadcast with an action of {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
719 *
720 * <p>The status code sent with this extra must be a custom status code as defined by
Craig Lafayette9ef04bf2015-05-06 16:57:01 -0400721 * {@link DeviceInitializerStatus#FLAG_STATUS_CUSTOM}.
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400722 * @hide
723 */
724 @SystemApi
725 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_CODE
726 = "android.app.extra.DEVICE_INITIALIZER_STATUS_CODE";
727
728 /**
729 * A {@code String} extra that contains an optional description accompanying a status update.
730 * This extra my be sent as part of a broadcast with an action of
731 * {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
732 * @hide
733 */
734 @SystemApi
735 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION
736 = "android.app.extra.DEVICE_INITIALIZER_STATUS_DESCRIPTION";
737
738 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700739 * @hide
740 * Name of the profile owner admin that controls the user.
741 */
742 @SystemApi
743 public static final String EXTRA_PROFILE_OWNER_NAME
744 = "android.app.extra.PROFILE_OWNER_NAME";
745
746 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700747 * Activity action: send when any policy admin changes a policy.
748 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700749 *
Jim Miller284b62e2010-06-08 14:27:42 -0700750 * @hide
751 */
752 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
753 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
754
755 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800756 * The ComponentName of the administrator component.
757 *
758 * @see #ACTION_ADD_DEVICE_ADMIN
759 */
760 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700761
Dianne Hackbornd6847842010-01-12 18:14:19 -0800762 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800763 * An optional CharSequence providing additional explanation for why the
764 * admin is being added.
765 *
766 * @see #ACTION_ADD_DEVICE_ADMIN
767 */
768 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700769
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800770 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700771 * Activity action: have the user enter a new password. This activity should
772 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
773 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
774 * enter a new password that meets the current requirements. You can use
775 * {@link #isActivePasswordSufficient()} to determine whether you need to
776 * have the user select a new password in order to meet the current
777 * constraints. Upon being resumed from this activity, you can check the new
778 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800779 */
780 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
781 public static final String ACTION_SET_NEW_PASSWORD
782 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700783
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000784 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000785 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
786 * the parent profile to access intents sent from the managed profile.
787 * That is, when an app in the managed profile calls
788 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
789 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000790 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100791 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000792
793 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000794 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
795 * the managed profile to access intents sent from the parent profile.
796 * That is, when an app in the parent profile calls
797 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
798 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000799 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100800 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700801
Dianne Hackbornd6847842010-01-12 18:14:19 -0800802 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100803 * Broadcast action: notify that a new local system update policy has been set by the device
804 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000805 */
806 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100807 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
808 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000809
Amith Yamasanid49489b2015-04-28 14:00:26 -0700810 /**
811 * Permission policy to prompt user for new permission requests for runtime permissions.
812 * Already granted or denied permissions are not affected by this.
813 */
814 public static final int PERMISSION_POLICY_PROMPT = 0;
815
816 /**
817 * Permission policy to always grant new permission requests for runtime permissions.
818 * Already granted or denied permissions are not affected by this.
819 */
820 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
821
822 /**
823 * Permission policy to always deny new permission requests for runtime permissions.
824 * Already granted or denied permissions are not affected by this.
825 */
826 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
827
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700828 /**
829 * Runtime permission state: The user can manage the permission
830 * through the UI.
831 */
832 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
833
834 /**
835 * Runtime permission state: The permission is granted to the app
836 * and the user cannot manage the permission through the UI.
837 */
838 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
839
840 /**
841 * Runtime permission state: The permission is denied to the app
842 * and the user cannot manage the permission through the UI.
843 */
844 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000845
846 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800847 * Return true if the given administrator component is currently
848 * active (enabled) in the system.
849 */
850 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100851 return isAdminActiveAsUser(who, UserHandle.myUserId());
852 }
853
854 /**
855 * @see #isAdminActive(ComponentName)
856 * @hide
857 */
858 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800859 if (mService != null) {
860 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100861 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800862 } catch (RemoteException e) {
863 Log.w(TAG, "Failed talking with device policy service", e);
864 }
865 }
866 return false;
867 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800868 /**
869 * Return true if the given administrator component is currently being removed
870 * for the user.
871 * @hide
872 */
873 public boolean isRemovingAdmin(ComponentName who, int userId) {
874 if (mService != null) {
875 try {
876 return mService.isRemovingAdmin(who, userId);
877 } catch (RemoteException e) {
878 Log.w(TAG, "Failed talking with device policy service", e);
879 }
880 }
881 return false;
882 }
883
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700884
Dianne Hackbornd6847842010-01-12 18:14:19 -0800885 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800886 * Return a list of all currently active device administrator's component
887 * names. Note that if there are no administrators than null may be
888 * returned.
889 */
890 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100891 return getActiveAdminsAsUser(UserHandle.myUserId());
892 }
893
894 /**
895 * @see #getActiveAdmins()
896 * @hide
897 */
898 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800899 if (mService != null) {
900 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100901 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800902 } catch (RemoteException e) {
903 Log.w(TAG, "Failed talking with device policy service", e);
904 }
905 }
906 return null;
907 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700908
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800909 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700910 * Used by package administration code to determine if a package can be stopped
911 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800912 * @hide
913 */
914 public boolean packageHasActiveAdmins(String packageName) {
915 if (mService != null) {
916 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700917 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800918 } catch (RemoteException e) {
919 Log.w(TAG, "Failed talking with device policy service", e);
920 }
921 }
922 return false;
923 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700924
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800925 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800926 * Remove a current administration component. This can only be called
927 * by the application that owns the administration component; if you
928 * try to remove someone else's component, a security exception will be
929 * thrown.
930 */
931 public void removeActiveAdmin(ComponentName who) {
932 if (mService != null) {
933 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700934 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800935 } catch (RemoteException e) {
936 Log.w(TAG, "Failed talking with device policy service", e);
937 }
938 }
939 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700940
Dianne Hackbornd6847842010-01-12 18:14:19 -0800941 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800942 * Returns true if an administrator has been granted a particular device policy. This can
943 * be used to check if the administrator was activated under an earlier set of policies,
944 * but requires additional policies after an upgrade.
945 *
946 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
947 * an active administrator, or an exception will be thrown.
948 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
949 */
950 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
951 if (mService != null) {
952 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700953 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800954 } catch (RemoteException e) {
955 Log.w(TAG, "Failed talking with device policy service", e);
956 }
957 }
958 return false;
959 }
960
961 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800962 * Constant for {@link #setPasswordQuality}: the policy has no requirements
963 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800964 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800965 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800966 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700967
Dianne Hackbornd6847842010-01-12 18:14:19 -0800968 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700969 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
970 * recognition technology. This implies technologies that can recognize the identity of
971 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
972 * Note that quality constants are ordered so that higher values are more restrictive.
973 */
974 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
975
976 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800977 * Constant for {@link #setPasswordQuality}: the policy requires some kind
978 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800979 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800980 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800981 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700982
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800983 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800984 * Constant for {@link #setPasswordQuality}: the user must have entered a
985 * password containing at least numeric characters. Note that quality
986 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800987 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800988 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700989
Dianne Hackbornd6847842010-01-12 18:14:19 -0800990 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800991 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800992 * password containing at least numeric characters with no repeating (4444)
993 * or ordered (1234, 4321, 2468) sequences. Note that quality
994 * constants are ordered so that higher values are more restrictive.
995 */
996 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
997
998 /**
999 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001000 * password containing at least alphabetic (or other symbol) characters.
1001 * Note that quality constants are ordered so that higher values are more
1002 * restrictive.
1003 */
1004 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001005
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001006 /**
1007 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001008 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001009 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001010 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001011 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001012 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001013
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001015 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001016 * password containing at least a letter, a numerical digit and a special
1017 * symbol, by default. With this password quality, passwords can be
1018 * restricted to contain various sets of characters, like at least an
1019 * uppercase letter, etc. These are specified using various methods,
1020 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1021 * that quality constants are ordered so that higher values are more
1022 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001023 */
1024 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1025
1026 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 * Called by an application that is administering the device to set the
1028 * password restrictions it is imposing. After setting this, the user
1029 * will not be able to enter a new password that is not at least as
1030 * restrictive as what has been set. Note that the current password
1031 * will remain until the user has set a new one, so the change does not
1032 * take place immediately. To prompt the user for a new password, use
1033 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001034 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001035 * <p>Quality constants are ordered so that higher values are more restrictive;
1036 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001037 * the user's preference, and any other considerations) is the one that
1038 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001039 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001040 * <p>The calling device admin must have requested
1041 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1042 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001043 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001045 * @param quality The new desired quality. One of
1046 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001047 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1048 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1049 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001050 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001051 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001052 if (mService != null) {
1053 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001054 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001055 } catch (RemoteException e) {
1056 Log.w(TAG, "Failed talking with device policy service", e);
1057 }
1058 }
1059 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001060
Dianne Hackbornd6847842010-01-12 18:14:19 -08001061 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001062 * Retrieve the current minimum password quality for all admins of this user
1063 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001064 * @param admin The name of the admin component to check, or null to aggregate
1065 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001066 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001067 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001068 return getPasswordQuality(admin, UserHandle.myUserId());
1069 }
1070
1071 /** @hide per-user version */
1072 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 if (mService != null) {
1074 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001075 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001076 } catch (RemoteException e) {
1077 Log.w(TAG, "Failed talking with device policy service", e);
1078 }
1079 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001080 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001081 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001082
Dianne Hackbornd6847842010-01-12 18:14:19 -08001083 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001084 * Called by an application that is administering the device to set the
1085 * minimum allowed password length. After setting this, the user
1086 * will not be able to enter a new password that is not at least as
1087 * restrictive as what has been set. Note that the current password
1088 * will remain until the user has set a new one, so the change does not
1089 * take place immediately. To prompt the user for a new password, use
1090 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1091 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001092 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1093 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1094 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001095 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001096 * <p>The calling device admin must have requested
1097 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1098 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001099 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001101 * @param length The new desired minimum password length. A value of 0
1102 * means there is no restriction.
1103 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001104 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001105 if (mService != null) {
1106 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001107 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001108 } catch (RemoteException e) {
1109 Log.w(TAG, "Failed talking with device policy service", e);
1110 }
1111 }
1112 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001113
Dianne Hackbornd6847842010-01-12 18:14:19 -08001114 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001115 * Retrieve the current minimum password length for all admins of this
1116 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001117 * @param admin The name of the admin component to check, or null to aggregate
1118 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001119 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001120 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001121 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1122 }
1123
1124 /** @hide per-user version */
1125 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001126 if (mService != null) {
1127 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001128 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001129 } catch (RemoteException e) {
1130 Log.w(TAG, "Failed talking with device policy service", e);
1131 }
1132 }
1133 return 0;
1134 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001135
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001136 /**
1137 * Called by an application that is administering the device to set the
1138 * minimum number of upper case letters required in the password. After
1139 * setting this, the user will not be able to enter a new password that is
1140 * not at least as restrictive as what has been set. Note that the current
1141 * password will remain until the user has set a new one, so the change does
1142 * not take place immediately. To prompt the user for a new password, use
1143 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1144 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001145 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1146 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001147 * <p>
1148 * The calling device admin must have requested
1149 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1150 * this method; if it has not, a security exception will be thrown.
1151 *
1152 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1153 * with.
1154 * @param length The new desired minimum number of upper case letters
1155 * required in the password. A value of 0 means there is no
1156 * restriction.
1157 */
1158 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
1159 if (mService != null) {
1160 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001161 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001162 } catch (RemoteException e) {
1163 Log.w(TAG, "Failed talking with device policy service", e);
1164 }
1165 }
1166 }
1167
1168 /**
1169 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001170 * password for all admins of this user and its profiles or a particular one.
1171 * This is the same value as set by
1172 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001173 * and only applies when the password quality is
1174 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001175 *
1176 * @param admin The name of the admin component to check, or null to
1177 * aggregate all admins.
1178 * @return The minimum number of upper case letters required in the
1179 * password.
1180 */
1181 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001182 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1183 }
1184
1185 /** @hide per-user version */
1186 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001187 if (mService != null) {
1188 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001189 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001190 } catch (RemoteException e) {
1191 Log.w(TAG, "Failed talking with device policy service", e);
1192 }
1193 }
1194 return 0;
1195 }
1196
1197 /**
1198 * Called by an application that is administering the device to set the
1199 * minimum number of lower case letters required in the password. After
1200 * setting this, the user will not be able to enter a new password that is
1201 * not at least as restrictive as what has been set. Note that the current
1202 * password will remain until the user has set a new one, so the change does
1203 * not take place immediately. To prompt the user for a new password, use
1204 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1205 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001206 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1207 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001208 * <p>
1209 * The calling device admin must have requested
1210 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1211 * this method; if it has not, a security exception will be thrown.
1212 *
1213 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1214 * with.
1215 * @param length The new desired minimum number of lower case letters
1216 * required in the password. A value of 0 means there is no
1217 * restriction.
1218 */
1219 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
1220 if (mService != null) {
1221 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001222 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001223 } catch (RemoteException e) {
1224 Log.w(TAG, "Failed talking with device policy service", e);
1225 }
1226 }
1227 }
1228
1229 /**
1230 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001231 * password for all admins of this user and its profiles or a particular one.
1232 * This is the same value as set by
1233 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001234 * and only applies when the password quality is
1235 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001236 *
1237 * @param admin The name of the admin component to check, or null to
1238 * aggregate all admins.
1239 * @return The minimum number of lower case letters required in the
1240 * password.
1241 */
1242 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001243 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1244 }
1245
1246 /** @hide per-user version */
1247 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001248 if (mService != null) {
1249 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001250 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001251 } catch (RemoteException e) {
1252 Log.w(TAG, "Failed talking with device policy service", e);
1253 }
1254 }
1255 return 0;
1256 }
1257
1258 /**
1259 * Called by an application that is administering the device to set the
1260 * minimum number of letters required in the password. After setting this,
1261 * the user will not be able to enter a new password that is not at least as
1262 * restrictive as what has been set. Note that the current password will
1263 * remain until the user has set a new one, so the change does not take
1264 * place immediately. To prompt the user for a new password, use
1265 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1266 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001267 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1268 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001269 * <p>
1270 * The calling device admin must have requested
1271 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1272 * this method; if it has not, a security exception will be thrown.
1273 *
1274 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1275 * with.
1276 * @param length The new desired minimum number of letters required in the
1277 * password. A value of 0 means there is no restriction.
1278 */
1279 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1280 if (mService != null) {
1281 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001282 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001283 } catch (RemoteException e) {
1284 Log.w(TAG, "Failed talking with device policy service", e);
1285 }
1286 }
1287 }
1288
1289 /**
1290 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001291 * admins or a particular one. This is the same value as
1292 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1293 * and only applies when the password quality is
1294 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001295 *
1296 * @param admin The name of the admin component to check, or null to
1297 * aggregate all admins.
1298 * @return The minimum number of letters required in the password.
1299 */
1300 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001301 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1302 }
1303
1304 /** @hide per-user version */
1305 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001306 if (mService != null) {
1307 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001308 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001309 } catch (RemoteException e) {
1310 Log.w(TAG, "Failed talking with device policy service", e);
1311 }
1312 }
1313 return 0;
1314 }
1315
1316 /**
1317 * Called by an application that is administering the device to set the
1318 * minimum number of numerical digits required in the password. After
1319 * setting this, the user will not be able to enter a new password that is
1320 * not at least as restrictive as what has been set. Note that the current
1321 * password will remain until the user has set a new one, so the change does
1322 * not take place immediately. To prompt the user for a new password, use
1323 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1324 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001325 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1326 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001327 * <p>
1328 * The calling device admin must have requested
1329 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1330 * this method; if it has not, a security exception will be thrown.
1331 *
1332 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1333 * with.
1334 * @param length The new desired minimum number of numerical digits required
1335 * in the password. A value of 0 means there is no restriction.
1336 */
1337 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1338 if (mService != null) {
1339 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001340 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001341 } catch (RemoteException e) {
1342 Log.w(TAG, "Failed talking with device policy service", e);
1343 }
1344 }
1345 }
1346
1347 /**
1348 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001349 * for all admins of this user and its profiles or a particular one.
1350 * This is the same value as set by
1351 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001352 * and only applies when the password quality is
1353 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001354 *
1355 * @param admin The name of the admin component to check, or null to
1356 * aggregate all admins.
1357 * @return The minimum number of numerical digits required in the password.
1358 */
1359 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001360 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1361 }
1362
1363 /** @hide per-user version */
1364 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001365 if (mService != null) {
1366 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001367 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001368 } catch (RemoteException e) {
1369 Log.w(TAG, "Failed talking with device policy service", e);
1370 }
1371 }
1372 return 0;
1373 }
1374
1375 /**
1376 * Called by an application that is administering the device to set the
1377 * minimum number of symbols required in the password. After setting this,
1378 * the user will not be able to enter a new password that is not at least as
1379 * restrictive as what has been set. Note that the current password will
1380 * remain until the user has set a new one, so the change does not take
1381 * place immediately. To prompt the user for a new password, use
1382 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1383 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001384 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1385 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001386 * <p>
1387 * The calling device admin must have requested
1388 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1389 * this method; if it has not, a security exception will be thrown.
1390 *
1391 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1392 * with.
1393 * @param length The new desired minimum number of symbols required in the
1394 * password. A value of 0 means there is no restriction.
1395 */
1396 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1397 if (mService != null) {
1398 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001399 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001400 } catch (RemoteException e) {
1401 Log.w(TAG, "Failed talking with device policy service", e);
1402 }
1403 }
1404 }
1405
1406 /**
1407 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001408 * admins or a particular one. This is the same value as
1409 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1410 * and only applies when the password quality is
1411 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001412 *
1413 * @param admin The name of the admin component to check, or null to
1414 * aggregate all admins.
1415 * @return The minimum number of symbols required in the password.
1416 */
1417 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001418 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1419 }
1420
1421 /** @hide per-user version */
1422 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001423 if (mService != null) {
1424 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001425 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001426 } catch (RemoteException e) {
1427 Log.w(TAG, "Failed talking with device policy service", e);
1428 }
1429 }
1430 return 0;
1431 }
1432
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001433 /**
1434 * Called by an application that is administering the device to set the
1435 * minimum number of non-letter characters (numerical digits or symbols)
1436 * required in the password. After setting this, the user will not be able
1437 * to enter a new password that is not at least as restrictive as what has
1438 * been set. Note that the current password will remain until the user has
1439 * set a new one, so the change does not take place immediately. To prompt
1440 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1441 * setting this value. This constraint is only imposed if the administrator
1442 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1443 * {@link #setPasswordQuality}. The default value is 0.
1444 * <p>
1445 * The calling device admin must have requested
1446 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1447 * this method; if it has not, a security exception will be thrown.
1448 *
1449 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1450 * with.
1451 * @param length The new desired minimum number of letters required in the
1452 * password. A value of 0 means there is no restriction.
1453 */
1454 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1455 if (mService != null) {
1456 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001457 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001458 } catch (RemoteException e) {
1459 Log.w(TAG, "Failed talking with device policy service", e);
1460 }
1461 }
1462 }
1463
1464 /**
1465 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001466 * password for all admins of this user and its profiles or a particular one.
1467 * This is the same value as set by
1468 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001469 * and only applies when the password quality is
1470 * {@link #PASSWORD_QUALITY_COMPLEX}.
1471 *
1472 * @param admin The name of the admin component to check, or null to
1473 * aggregate all admins.
1474 * @return The minimum number of letters required in the password.
1475 */
1476 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001477 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1478 }
1479
1480 /** @hide per-user version */
1481 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001482 if (mService != null) {
1483 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001484 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001485 } catch (RemoteException e) {
1486 Log.w(TAG, "Failed talking with device policy service", e);
1487 }
1488 }
1489 return 0;
1490 }
1491
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001492 /**
1493 * Called by an application that is administering the device to set the length
1494 * of the password history. After setting this, the user will not be able to
1495 * enter a new password that is the same as any password in the history. Note
1496 * that the current password will remain until the user has set a new one, so
1497 * the change does not take place immediately. To prompt the user for a new
1498 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1499 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001500 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1501 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1502 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001503 *
1504 * <p>
1505 * The calling device admin must have requested
1506 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1507 * method; if it has not, a security exception will be thrown.
1508 *
1509 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1510 * with.
1511 * @param length The new desired length of password history. A value of 0
1512 * means there is no restriction.
1513 */
1514 public void setPasswordHistoryLength(ComponentName admin, int length) {
1515 if (mService != null) {
1516 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001517 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001518 } catch (RemoteException e) {
1519 Log.w(TAG, "Failed talking with device policy service", e);
1520 }
1521 }
1522 }
1523
1524 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001525 * Called by a device admin to set the password expiration timeout. Calling this method
1526 * will restart the countdown for password expiration for the given admin, as will changing
1527 * the device password (for all admins).
1528 *
1529 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1530 * For example, to have the password expire 5 days from now, timeout would be
1531 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1532 *
1533 * <p>To disable password expiration, a value of 0 may be used for timeout.
1534 *
Jim Millera4e28d12010-11-08 16:15:47 -08001535 * <p>The calling device admin must have requested
1536 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1537 * method; if it has not, a security exception will be thrown.
1538 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001539 * <p> Note that setting the password will automatically reset the expiration time for all
1540 * active admins. Active admins do not need to explicitly call this method in that case.
1541 *
Jim Millera4e28d12010-11-08 16:15:47 -08001542 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1543 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1544 * means there is no restriction (unlimited).
1545 */
1546 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1547 if (mService != null) {
1548 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001549 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001550 } catch (RemoteException e) {
1551 Log.w(TAG, "Failed talking with device policy service", e);
1552 }
1553 }
1554 }
1555
1556 /**
Jim Miller6b857682011-02-16 16:27:41 -08001557 * Get the password expiration timeout for the given admin. The expiration timeout is the
1558 * recurring expiration timeout provided in the call to
1559 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1560 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001561 *
1562 * @param admin The name of the admin component to check, or null to aggregate all admins.
1563 * @return The timeout for the given admin or the minimum of all timeouts
1564 */
1565 public long getPasswordExpirationTimeout(ComponentName admin) {
1566 if (mService != null) {
1567 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001568 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001569 } catch (RemoteException e) {
1570 Log.w(TAG, "Failed talking with device policy service", e);
1571 }
1572 }
1573 return 0;
1574 }
1575
1576 /**
1577 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001578 * all admins of this user and its profiles if admin is null. If the password is
1579 * expired, this will return the time since the password expired as a negative number.
1580 * If admin is null, then a composite of all expiration timeouts is returned
1581 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001582 *
1583 * @param admin The name of the admin component to check, or null to aggregate all admins.
1584 * @return The password expiration time, in ms.
1585 */
1586 public long getPasswordExpiration(ComponentName admin) {
1587 if (mService != null) {
1588 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001589 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001590 } catch (RemoteException e) {
1591 Log.w(TAG, "Failed talking with device policy service", e);
1592 }
1593 }
1594 return 0;
1595 }
1596
1597 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001598 * Retrieve the current password history length for all admins of this
1599 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001600 * @param admin The name of the admin component to check, or null to aggregate
1601 * all admins.
1602 * @return The length of the password history
1603 */
1604 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001605 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1606 }
1607
1608 /** @hide per-user version */
1609 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001610 if (mService != null) {
1611 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001612 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001613 } catch (RemoteException e) {
1614 Log.w(TAG, "Failed talking with device policy service", e);
1615 }
1616 }
1617 return 0;
1618 }
1619
Dianne Hackbornd6847842010-01-12 18:14:19 -08001620 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001621 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001622 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001623 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001624 * @return Returns the maximum length that the user can enter.
1625 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001626 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001627 // Kind-of arbitrary.
1628 return 16;
1629 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001630
Dianne Hackborn254cb442010-01-27 19:23:59 -08001631 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001632 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001633 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001634 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001635 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001636 * <p>The calling device admin must have requested
1637 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1638 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001639 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001640 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001641 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001642 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001643 if (mService != null) {
1644 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001645 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001646 } catch (RemoteException e) {
1647 Log.w(TAG, "Failed talking with device policy service", e);
1648 }
1649 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001650 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001651 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001652
Dianne Hackbornd6847842010-01-12 18:14:19 -08001653 /**
1654 * Retrieve the number of times the user has failed at entering a
1655 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001656 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001657 * <p>The calling device admin must have requested
1658 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1659 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001660 */
1661 public int getCurrentFailedPasswordAttempts() {
1662 if (mService != null) {
1663 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001664 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001665 } catch (RemoteException e) {
1666 Log.w(TAG, "Failed talking with device policy service", e);
1667 }
1668 }
1669 return -1;
1670 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001671
1672 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001673 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001674 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001675 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001676 * @hide
1677 */
1678 public boolean getDoNotAskCredentialsOnBoot() {
1679 if (mService != null) {
1680 try {
1681 return mService.getDoNotAskCredentialsOnBoot();
1682 } catch (RemoteException e) {
1683 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1684 }
1685 }
1686 return false;
1687 }
1688
1689 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001690 * Setting this to a value greater than zero enables a built-in policy
1691 * that will perform a device wipe after too many incorrect
1692 * device-unlock passwords have been entered. This built-in policy combines
1693 * watching for failed passwords and wiping the device, and requires
1694 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001695 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001696 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001697 * <p>To implement any other policy (e.g. wiping data for a particular
1698 * application only, erasing or revoking credentials, or reporting the
1699 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001700 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001701 * instead. Do not use this API, because if the maximum count is reached,
1702 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001703 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001704 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001705 * @param num The number of failed password attempts at which point the
1706 * device will wipe its data.
1707 */
1708 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1709 if (mService != null) {
1710 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001711 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001712 } catch (RemoteException e) {
1713 Log.w(TAG, "Failed talking with device policy service", e);
1714 }
1715 }
1716 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001717
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001718 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001719 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001720 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001721 * or a particular one.
1722 * @param admin The name of the admin component to check, or null to aggregate
1723 * all admins.
1724 */
1725 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001726 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1727 }
1728
1729 /** @hide per-user version */
1730 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001731 if (mService != null) {
1732 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001733 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001734 } catch (RemoteException e) {
1735 Log.w(TAG, "Failed talking with device policy service", e);
1736 }
1737 }
1738 return 0;
1739 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001740
Dianne Hackborn254cb442010-01-27 19:23:59 -08001741 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001742 * Returns the profile with the smallest maximum failed passwords for wipe,
1743 * for the given user. So for primary user, it might return the primary or
1744 * a managed profile. For a secondary user, it would be the same as the
1745 * user passed in.
1746 * @hide Used only by Keyguard
1747 */
1748 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1749 if (mService != null) {
1750 try {
1751 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1752 } catch (RemoteException e) {
1753 Log.w(TAG, "Failed talking with device policy service", e);
1754 }
1755 }
1756 return UserHandle.USER_NULL;
1757 }
1758
1759 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001760 * Flag for {@link #resetPassword}: don't allow other admins to change
1761 * the password again until the user has entered it.
1762 */
1763 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001764
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001765 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001766 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1767 * If the flag is set, the device can be booted without asking for user password.
1768 * The absence of this flag does not change the current boot requirements. This flag
1769 * can be set by the device owner only. If the app is not the device owner, the flag
1770 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1771 * device to factory defaults.
1772 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001773 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001774
1775 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001776 * Force a new device unlock password (the password needed to access the
1777 * entire device, not for individual accounts) on the user. This takes
1778 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001779 * The given password must be sufficient for the
1780 * current password quality and length constraints as returned by
1781 * {@link #getPasswordQuality(ComponentName)} and
1782 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1783 * these constraints, then it will be rejected and false returned. Note
1784 * that the password may be a stronger quality (containing alphanumeric
1785 * characters when the requested quality is only numeric), in which case
1786 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001787 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001788 * <p>Calling with a null or empty password will clear any existing PIN,
1789 * pattern or password if the current password constraints allow it.
1790 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001791 * <p>The calling device admin must have requested
1792 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1793 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001794 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001795 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001796 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001797 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001798 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001799 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001800 * @return Returns true if the password was applied, or false if it is
1801 * not acceptable for the current constraints.
1802 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001803 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001804 if (mService != null) {
1805 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001806 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001807 } catch (RemoteException e) {
1808 Log.w(TAG, "Failed talking with device policy service", e);
1809 }
1810 }
1811 return false;
1812 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001813
Dianne Hackbornd6847842010-01-12 18:14:19 -08001814 /**
1815 * Called by an application that is administering the device to set the
1816 * maximum time for user activity until the device will lock. This limits
1817 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001818 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001819 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001820 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001821 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001822 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001823 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 * @param timeMs The new desired maximum time to lock in milliseconds.
1825 * A value of 0 means there is no restriction.
1826 */
1827 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1828 if (mService != null) {
1829 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001830 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001831 } catch (RemoteException e) {
1832 Log.w(TAG, "Failed talking with device policy service", e);
1833 }
1834 }
1835 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001836
Dianne Hackbornd6847842010-01-12 18:14:19 -08001837 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001838 * Retrieve the current maximum time to unlock for all admins of this user
1839 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001840 * @param admin The name of the admin component to check, or null to aggregate
1841 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001842 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001843 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001845 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001846 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1847 }
1848
1849 /** @hide per-user version */
1850 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001851 if (mService != null) {
1852 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001853 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001854 } catch (RemoteException e) {
1855 Log.w(TAG, "Failed talking with device policy service", e);
1856 }
1857 }
1858 return 0;
1859 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001860
Dianne Hackbornd6847842010-01-12 18:14:19 -08001861 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001862 * Make the device lock immediately, as if the lock screen timeout has
1863 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001864 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001865 * <p>The calling device admin must have requested
1866 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1867 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001868 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001869 public void lockNow() {
1870 if (mService != null) {
1871 try {
1872 mService.lockNow();
1873 } catch (RemoteException e) {
1874 Log.w(TAG, "Failed talking with device policy service", e);
1875 }
1876 }
1877 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001878
Dianne Hackbornd6847842010-01-12 18:14:19 -08001879 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001880 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001881 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001882 */
1883 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1884
1885 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001886 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1887 * data.
1888 *
Paul Crowley2934b262014-12-02 11:21:13 +00001889 * <p>This flag may only be set by device owner admins; if it is set by
1890 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001891 */
1892 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1893
1894 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001895 * Ask the user data be wiped. Wiping the primary user will cause the
1896 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001897 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001898 * <p>The calling device admin must have requested
1899 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1900 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001901 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001902 * @param flags Bit mask of additional options: currently supported flags
1903 * are {@link #WIPE_EXTERNAL_STORAGE} and
1904 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001905 */
1906 public void wipeData(int flags) {
1907 if (mService != null) {
1908 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001909 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001910 } catch (RemoteException e) {
1911 Log.w(TAG, "Failed talking with device policy service", e);
1912 }
1913 }
1914 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001915
Dianne Hackbornd6847842010-01-12 18:14:19 -08001916 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001917 * Called by an application that is administering the device to set the
1918 * global proxy and exclusion list.
1919 * <p>
1920 * The calling device admin must have requested
1921 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1922 * this method; if it has not, a security exception will be thrown.
1923 * Only the first device admin can set the proxy. If a second admin attempts
1924 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1925 * proxy will be returned. If successful in setting the proxy, null will
1926 * be returned.
1927 * The method can be called repeatedly by the device admin alrady setting the
1928 * proxy to update the proxy and exclusion list.
1929 *
1930 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1931 * with.
1932 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1933 * Pass Proxy.NO_PROXY to reset the proxy.
1934 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001935 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1936 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001937 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001938 */
1939 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1940 List<String> exclusionList ) {
1941 if (proxySpec == null) {
1942 throw new NullPointerException();
1943 }
1944 if (mService != null) {
1945 try {
1946 String hostSpec;
1947 String exclSpec;
1948 if (proxySpec.equals(Proxy.NO_PROXY)) {
1949 hostSpec = null;
1950 exclSpec = null;
1951 } else {
1952 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1953 throw new IllegalArgumentException();
1954 }
1955 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1956 String hostName = sa.getHostName();
1957 int port = sa.getPort();
1958 StringBuilder hostBuilder = new StringBuilder();
1959 hostSpec = hostBuilder.append(hostName)
1960 .append(":").append(Integer.toString(port)).toString();
1961 if (exclusionList == null) {
1962 exclSpec = "";
1963 } else {
1964 StringBuilder listBuilder = new StringBuilder();
1965 boolean firstDomain = true;
1966 for (String exclDomain : exclusionList) {
1967 if (!firstDomain) {
1968 listBuilder = listBuilder.append(",");
1969 } else {
1970 firstDomain = false;
1971 }
1972 listBuilder = listBuilder.append(exclDomain.trim());
1973 }
1974 exclSpec = listBuilder.toString();
1975 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001976 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1977 != android.net.Proxy.PROXY_VALID)
1978 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001979 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001980 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001981 } catch (RemoteException e) {
1982 Log.w(TAG, "Failed talking with device policy service", e);
1983 }
1984 }
1985 return null;
1986 }
1987
1988 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001989 * Set a network-independent global HTTP proxy. This is not normally what you want
1990 * for typical HTTP proxies - they are generally network dependent. However if you're
1991 * doing something unusual like general internal filtering this may be useful. On
1992 * a private network where the proxy is not accessible, you may break HTTP using this.
1993 *
1994 * <p>This method requires the caller to be the device owner.
1995 *
1996 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1997 * @see ProxyInfo
1998 *
1999 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2000 * with.
2001 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2002 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2003 */
2004 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
2005 if (mService != null) {
2006 try {
2007 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2008 } catch (RemoteException e) {
2009 Log.w(TAG, "Failed talking with device policy service", e);
2010 }
2011 }
2012 }
2013
2014 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002015 * Returns the component name setting the global proxy.
2016 * @return ComponentName object of the device admin that set the global proxy, or
2017 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002018 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002019 */
2020 public ComponentName getGlobalProxyAdmin() {
2021 if (mService != null) {
2022 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002023 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002024 } catch (RemoteException e) {
2025 Log.w(TAG, "Failed talking with device policy service", e);
2026 }
2027 }
2028 return null;
2029 }
2030
2031 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002032 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002033 * indicating that encryption is not supported.
2034 */
2035 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2036
2037 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002038 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002039 * indicating that encryption is supported, but is not currently active.
2040 */
2041 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2042
2043 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002044 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002045 * indicating that encryption is not currently active, but is currently
2046 * being activated. This is only reported by devices that support
2047 * encryption of data and only when the storage is currently
2048 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2049 * to become encrypted will never return this value.
2050 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002051 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002052
2053 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002054 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002055 * indicating that encryption is active.
2056 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002057 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002058
2059 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002060 * Result code for {@link #getStorageEncryptionStatus}:
2061 * indicating that encryption is active, but an encryption key has not
2062 * been set by the user.
2063 */
2064 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2065
2066 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002067 * Activity action: begin the process of encrypting data on the device. This activity should
2068 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2069 * After resuming from this activity, use {@link #getStorageEncryption}
2070 * to check encryption status. However, on some devices this activity may never return, as
2071 * it may trigger a reboot and in some cases a complete data wipe of the device.
2072 */
2073 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2074 public static final String ACTION_START_ENCRYPTION
2075 = "android.app.action.START_ENCRYPTION";
2076
2077 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002078 * Widgets are enabled in keyguard
2079 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002080 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002081
2082 /**
Jim Miller50e62182014-04-23 17:25:00 -07002083 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002084 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002085 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2086
2087 /**
2088 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2089 */
2090 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2091
2092 /**
Jim Miller50e62182014-04-23 17:25:00 -07002093 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2094 */
2095 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2096
2097 /**
2098 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2099 */
2100 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2101
2102 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002103 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002104 * (e.g. PIN/Pattern/Password).
2105 */
2106 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2107
2108 /**
Jim Miller06e34502014-07-17 14:46:05 -07002109 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2110 */
2111 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2112
2113 /**
Jim Miller35207742012-11-02 15:33:20 -07002114 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002115 */
2116 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002117
2118 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002119 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002120 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002121 *
2122 * <p>When multiple device administrators attempt to control device
2123 * encryption, the most secure, supported setting will always be
2124 * used. If any device administrator requests device encryption,
2125 * it will be enabled; Conversely, if a device administrator
2126 * attempts to disable device encryption while another
2127 * device administrator has enabled it, the call to disable will
2128 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2129 *
2130 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002131 * written to other storage areas may or may not be encrypted, and this policy does not require
2132 * or control the encryption of any other storage areas.
2133 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2134 * {@code true}, then the directory returned by
2135 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2136 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002137 *
2138 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2139 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2140 * the encryption key may not be fully secured. For maximum security, the administrator should
2141 * also require (and check for) a pattern, PIN, or password.
2142 *
2143 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2144 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002145 * @return the new request status (for all active admins) - will be one of
2146 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2147 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2148 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002149 */
2150 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
2151 if (mService != null) {
2152 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002153 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002154 } catch (RemoteException e) {
2155 Log.w(TAG, "Failed talking with device policy service", e);
2156 }
2157 }
2158 return ENCRYPTION_STATUS_UNSUPPORTED;
2159 }
2160
2161 /**
2162 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002163 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002164 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2166 * this will return the requested encryption setting as an aggregate of all active
2167 * administrators.
2168 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002169 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002170 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002171 if (mService != null) {
2172 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002173 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002174 } catch (RemoteException e) {
2175 Log.w(TAG, "Failed talking with device policy service", e);
2176 }
2177 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002178 return false;
2179 }
2180
2181 /**
2182 * Called by an application that is administering the device to
2183 * determine the current encryption status of the device.
2184 *
2185 * Depending on the returned status code, the caller may proceed in different
2186 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2187 * storage system does not support encryption. If the
2188 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2189 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002190 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2191 * storage system has enabled encryption but no password is set so further action
2192 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002193 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2194 *
Robin Lee7e678712014-07-24 16:41:31 +01002195 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002196 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002197 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2198 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002199 */
2200 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002201 return getStorageEncryptionStatus(UserHandle.myUserId());
2202 }
2203
2204 /** @hide per-user version */
2205 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002206 if (mService != null) {
2207 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002208 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002209 } catch (RemoteException e) {
2210 Log.w(TAG, "Failed talking with device policy service", e);
2211 }
2212 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002213 return ENCRYPTION_STATUS_UNSUPPORTED;
2214 }
2215
2216 /**
Robin Lee7e678712014-07-24 16:41:31 +01002217 * Installs the given certificate as a user CA.
2218 *
Rubin Xuec32b562015-03-03 17:34:05 +00002219 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2220 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002221 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002222 *
2223 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002224 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002225 */
Robin Lee7e678712014-07-24 16:41:31 +01002226 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002227 if (mService != null) {
2228 try {
Robin Lee7e678712014-07-24 16:41:31 +01002229 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002230 } catch (RemoteException e) {
2231 Log.w(TAG, "Failed talking with device policy service", e);
2232 }
2233 }
2234 return false;
2235 }
2236
2237 /**
Robin Lee7e678712014-07-24 16:41:31 +01002238 * Uninstalls the given certificate from trusted user CAs, if present.
2239 *
Rubin Xuec32b562015-03-03 17:34:05 +00002240 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2241 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002242 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002243 */
Robin Lee7e678712014-07-24 16:41:31 +01002244 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002245 if (mService != null) {
2246 try {
Robin Lee306fe082014-06-19 14:04:24 +00002247 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002248 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002249 } catch (CertificateException e) {
2250 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002251 } catch (RemoteException e) {
2252 Log.w(TAG, "Failed talking with device policy service", e);
2253 }
2254 }
2255 }
2256
2257 /**
Robin Lee7e678712014-07-24 16:41:31 +01002258 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2259 * If a user has installed any certificates by other means than device policy these will be
2260 * included too.
2261 *
Rubin Xuec32b562015-03-03 17:34:05 +00002262 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2263 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002264 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002265 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002266 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002267 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002268 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002269 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002270 mService.enforceCanManageCaCerts(admin);
2271 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2272 for (String alias : certStore.userAliases()) {
2273 try {
2274 certs.add(certStore.getCertificate(alias).getEncoded());
2275 } catch (CertificateException ce) {
2276 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2277 }
2278 }
2279 } catch (RemoteException re) {
2280 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002281 }
2282 }
2283 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002284 }
2285
2286 /**
Robin Lee7e678712014-07-24 16:41:31 +01002287 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2288 * means other than device policy will also be removed, except for system CA certificates.
2289 *
Rubin Xuec32b562015-03-03 17:34:05 +00002290 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2291 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002292 */
2293 public void uninstallAllUserCaCerts(ComponentName admin) {
2294 if (mService != null) {
2295 for (String alias : new TrustedCertificateStore().userAliases()) {
2296 try {
2297 mService.uninstallCaCert(admin, alias);
2298 } catch (RemoteException re) {
2299 Log.w(TAG, "Failed talking with device policy service", re);
2300 }
2301 }
2302 }
2303 }
2304
2305 /**
2306 * Returns whether this certificate is installed as a trusted CA.
2307 *
Rubin Xuec32b562015-03-03 17:34:05 +00002308 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2309 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002310 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002311 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002312 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2313 if (mService != null) {
2314 try {
2315 mService.enforceCanManageCaCerts(admin);
2316 return getCaCertAlias(certBuffer) != null;
2317 } catch (RemoteException re) {
2318 Log.w(TAG, "Failed talking with device policy service", re);
2319 } catch (CertificateException ce) {
2320 Log.w(TAG, "Could not parse certificate", ce);
2321 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002322 }
2323 return false;
2324 }
2325
2326 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002327 * Called by a device or profile owner to install a certificate and private key pair. The
2328 * keypair will be visible to all apps within the profile.
2329 *
Rubin Xuacdc1832015-04-02 12:40:20 +01002330 * @param who Which {@link DeviceAdminReceiver} this request is associated with. Use
2331 * <code>null</code> if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002332 * @param privKey The private key to install.
2333 * @param cert The certificate to install.
2334 * @param alias The private key alias under which to install the certificate. If a certificate
2335 * with that alias already exists, it will be overwritten.
2336 * @return {@code true} if the keys were installed, {@code false} otherwise.
2337 */
2338 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2339 String alias) {
2340 try {
2341 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002342 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2343 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2344 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002345 } catch (RemoteException e) {
2346 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002347 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2348 Log.w(TAG, "Failed to obtain private key material", e);
2349 } catch (CertificateException | IOException e) {
2350 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002351 }
2352 return false;
2353 }
2354
2355 /**
Robin Lee306fe082014-06-19 14:04:24 +00002356 * Returns the alias of a given CA certificate in the certificate store, or null if it
2357 * doesn't exist.
2358 */
2359 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2360 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2361 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2362 new ByteArrayInputStream(certBuffer));
2363 return new TrustedCertificateStore().getCertificateAlias(cert);
2364 }
2365
2366 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002367 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002368 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002369 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002370 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002371 * <p>
2372 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2373 * it is later cleared by calling this method with a null value or uninstallling the certificate
2374 * installer.
2375 *
2376 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2377 * @param installerPackage The package name of the certificate installer which will be given
2378 * access. If <code>null</code> is given the current package will be cleared.
2379 */
2380 public void setCertInstallerPackage(ComponentName who, String installerPackage)
2381 throws SecurityException {
2382 if (mService != null) {
2383 try {
2384 mService.setCertInstallerPackage(who, installerPackage);
2385 } catch (RemoteException e) {
2386 Log.w(TAG, "Failed talking with device policy service", e);
2387 }
2388 }
2389 }
2390
2391 /**
2392 * Called by a profile owner or device owner to retrieve the certificate installer for the
2393 * current user. null if none is set.
2394 *
2395 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2396 * @return The package name of the current delegated certificate installer. <code>null</code>
2397 * if none is set.
2398 */
2399 public String getCertInstallerPackage(ComponentName who) throws SecurityException {
2400 if (mService != null) {
2401 try {
2402 return mService.getCertInstallerPackage(who);
2403 } catch (RemoteException e) {
2404 Log.w(TAG, "Failed talking with device policy service", e);
2405 }
2406 }
2407 return null;
2408 }
2409
2410 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002411 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002412 * on the device, for this user. After setting this, no applications running as this user
2413 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002414 *
2415 * <p>The calling device admin must have requested
2416 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2417 * this method; if it has not, a security exception will be thrown.
2418 *
2419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2420 * @param disabled Whether or not the camera should be disabled.
2421 */
2422 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2423 if (mService != null) {
2424 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002425 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002426 } catch (RemoteException e) {
2427 Log.w(TAG, "Failed talking with device policy service", e);
2428 }
2429 }
2430 }
2431
2432 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002433 * Determine whether or not the device's cameras have been disabled for this user,
2434 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002435 * @param admin The name of the admin component to check, or null to check if any admins
2436 * have disabled the camera
2437 */
2438 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002439 return getCameraDisabled(admin, UserHandle.myUserId());
2440 }
2441
2442 /** @hide per-user version */
2443 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002444 if (mService != null) {
2445 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002446 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002447 } catch (RemoteException e) {
2448 Log.w(TAG, "Failed talking with device policy service", e);
2449 }
2450 }
2451 return false;
2452 }
2453
2454 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002455 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2456 * screen capture also prevents the content from being shown on display devices that do not have
2457 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2458 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002459 *
2460 * <p>The calling device admin must be a device or profile owner. If it is not, a
2461 * security exception will be thrown.
2462 *
2463 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002464 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002465 */
2466 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2467 if (mService != null) {
2468 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002469 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002470 } catch (RemoteException e) {
2471 Log.w(TAG, "Failed talking with device policy service", e);
2472 }
2473 }
2474 }
2475
2476 /**
2477 * Determine whether or not screen capture has been disabled by the current
2478 * admin, if specified, or all admins.
2479 * @param admin The name of the admin component to check, or null to check if any admins
2480 * have disabled screen capture.
2481 */
2482 public boolean getScreenCaptureDisabled(ComponentName admin) {
2483 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2484 }
2485
2486 /** @hide per-user version */
2487 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2488 if (mService != null) {
2489 try {
2490 return mService.getScreenCaptureDisabled(admin, userHandle);
2491 } catch (RemoteException e) {
2492 Log.w(TAG, "Failed talking with device policy service", e);
2493 }
2494 }
2495 return false;
2496 }
2497
2498 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002499 * Called by a device owner to set whether auto time is required. If auto time is
2500 * required the user cannot set the date and time, but has to use network date and time.
2501 *
2502 * <p>Note: if auto time is required the user can still manually set the time zone.
2503 *
2504 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2505 * be thrown.
2506 *
2507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2508 * @param required Whether auto time is set required or not.
2509 */
2510 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2511 if (mService != null) {
2512 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002513 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002514 } catch (RemoteException e) {
2515 Log.w(TAG, "Failed talking with device policy service", e);
2516 }
2517 }
2518 }
2519
2520 /**
2521 * @return true if auto time is required.
2522 */
2523 public boolean getAutoTimeRequired() {
2524 if (mService != null) {
2525 try {
2526 return mService.getAutoTimeRequired();
2527 } catch (RemoteException e) {
2528 Log.w(TAG, "Failed talking with device policy service", e);
2529 }
2530 }
2531 return false;
2532 }
2533
2534 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002535 * Called by an application that is administering the device to disable keyguard customizations,
2536 * such as widgets. After setting this, keyguard features will be disabled according to the
2537 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002538 *
2539 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002540 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002541 * this method; if it has not, a security exception will be thrown.
2542 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002543 * <p>Calling this from a managed profile before version
2544 * {@link android.os.Build.VERSION_CODES#MNC} will throw a security exception.
2545 *
2546 * <p>From version {@link android.os.Build.VERSION_CODES#MNC} a profile owner can set:
2547 * <ul>
2548 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2549 * these will affect the profile's parent user.
2550 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2551 * generated by applications in the managed profile.
2552 * </ul>
2553 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2554 * can check which features have been disabled by calling
2555 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002556 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002558 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2559 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002560 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002561 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2562 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002563 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002564 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002565 if (mService != null) {
2566 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002567 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002568 } catch (RemoteException e) {
2569 Log.w(TAG, "Failed talking with device policy service", e);
2570 }
2571 }
2572 }
2573
2574 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002575 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002576 * admin, if specified, or all admins.
2577 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002578 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002579 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2580 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002581 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002582 public int getKeyguardDisabledFeatures(ComponentName admin) {
2583 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002584 }
2585
2586 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002587 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002588 if (mService != null) {
2589 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002590 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002591 } catch (RemoteException e) {
2592 Log.w(TAG, "Failed talking with device policy service", e);
2593 }
2594 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002595 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002596 }
2597
2598 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002599 * @hide
2600 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002601 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002602 if (mService != null) {
2603 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002604 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002605 } catch (RemoteException e) {
2606 Log.w(TAG, "Failed talking with device policy service", e);
2607 }
2608 }
2609 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002610
Dianne Hackbornd6847842010-01-12 18:14:19 -08002611 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002612 * @hide
2613 */
2614 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2615 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2616 }
2617
2618 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002619 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002620 * @hide
2621 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002622 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002623 ActivityInfo ai;
2624 try {
2625 ai = mContext.getPackageManager().getReceiverInfo(cn,
2626 PackageManager.GET_META_DATA);
2627 } catch (PackageManager.NameNotFoundException e) {
2628 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2629 return null;
2630 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002631
Dianne Hackbornd6847842010-01-12 18:14:19 -08002632 ResolveInfo ri = new ResolveInfo();
2633 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002634
Dianne Hackbornd6847842010-01-12 18:14:19 -08002635 try {
2636 return new DeviceAdminInfo(mContext, ri);
2637 } catch (XmlPullParserException e) {
2638 Log.w(TAG, "Unable to parse device policy " + cn, e);
2639 return null;
2640 } catch (IOException e) {
2641 Log.w(TAG, "Unable to parse device policy " + cn, e);
2642 return null;
2643 }
2644 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002645
Dianne Hackbornd6847842010-01-12 18:14:19 -08002646 /**
2647 * @hide
2648 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002649 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2650 if (mService != null) {
2651 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002652 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002653 } catch (RemoteException e) {
2654 Log.w(TAG, "Failed talking with device policy service", e);
2655 }
2656 }
2657 }
2658
2659 /**
2660 * @hide
2661 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002662 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002663 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002664 if (mService != null) {
2665 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002666 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002667 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002668 } catch (RemoteException e) {
2669 Log.w(TAG, "Failed talking with device policy service", e);
2670 }
2671 }
2672 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002673
Dianne Hackbornd6847842010-01-12 18:14:19 -08002674 /**
2675 * @hide
2676 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002677 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002678 if (mService != null) {
2679 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002680 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002681 } catch (RemoteException e) {
2682 Log.w(TAG, "Failed talking with device policy service", e);
2683 }
2684 }
2685 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002686
Dianne Hackbornd6847842010-01-12 18:14:19 -08002687 /**
2688 * @hide
2689 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002690 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002691 if (mService != null) {
2692 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002693 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002694 } catch (RemoteException e) {
2695 Log.w(TAG, "Failed talking with device policy service", e);
2696 }
2697 }
2698 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002699
2700 /**
2701 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002702 * Sets the given package as the device owner.
2703 * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002704 * @param packageName the package name of the application to be registered as the device owner.
2705 * @return whether the package was successfully registered as the device owner.
2706 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002707 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002708 */
2709 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2710 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002711 return setDeviceOwner(packageName, null);
2712 }
2713
2714 /**
2715 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002716 * Sets the given package as the device owner. The package must already be installed. There
2717 * must not already be a device owner.
2718 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2719 * this method.
2720 * Calling this after the setup phase of the primary user has completed is allowed only if
2721 * the caller is the shell uid, and there are no additional users and no accounts.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002722 * @param packageName the package name of the application to be registered as the device owner.
2723 * @param ownerName the human readable name of the institution that owns this device.
2724 * @return whether the package was successfully registered as the device owner.
2725 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002726 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002727 */
2728 public boolean setDeviceOwner(String packageName, String ownerName)
2729 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002730 if (mService != null) {
2731 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002732 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002733 } catch (RemoteException re) {
2734 Log.w(TAG, "Failed to set device owner");
2735 }
2736 }
2737 return false;
2738 }
2739
2740 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002741 * Used to determine if a particular package has been registered as a Device Owner app.
2742 * A device owner app is a special device admin that cannot be deactivated by the user, once
2743 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2744 * package is currently registered as the device owner app, pass in the package name from
2745 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2746 * admin apps that want to check if they are also registered as the device owner app. The
2747 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2748 * the setup process.
2749 * @param packageName the package name of the app, to compare with the registered device owner
2750 * app, if any.
2751 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002752 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002753 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002754 if (mService != null) {
2755 try {
2756 return mService.isDeviceOwner(packageName);
2757 } catch (RemoteException re) {
2758 Log.w(TAG, "Failed to check device owner");
2759 }
2760 }
2761 return false;
2762 }
2763
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002764 /**
2765 * @hide
2766 * Redirect to isDeviceOwnerApp.
2767 */
2768 public boolean isDeviceOwner(String packageName) {
2769 return isDeviceOwnerApp(packageName);
2770 }
2771
Jason Monkb0dced82014-06-06 14:36:20 -04002772 /**
2773 * Clears the current device owner. The caller must be the device owner.
2774 *
2775 * This function should be used cautiously as once it is called it cannot
2776 * be undone. The device owner can only be set as a part of device setup
2777 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002778 *
2779 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002780 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002781 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002782 if (mService != null) {
2783 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002784 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002785 } catch (RemoteException re) {
2786 Log.w(TAG, "Failed to clear device owner");
2787 }
2788 }
2789 }
2790
Amith Yamasani71e6c692013-03-24 17:39:28 -07002791 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002792 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002793 public String getDeviceOwner() {
2794 if (mService != null) {
2795 try {
2796 return mService.getDeviceOwner();
2797 } catch (RemoteException re) {
2798 Log.w(TAG, "Failed to get device owner");
2799 }
2800 }
2801 return null;
2802 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002803
2804 /** @hide */
2805 public String getDeviceOwnerName() {
2806 if (mService != null) {
2807 try {
2808 return mService.getDeviceOwnerName();
2809 } catch (RemoteException re) {
2810 Log.w(TAG, "Failed to get device owner");
2811 }
2812 }
2813 return null;
2814 }
Adam Connors776c5552014-01-09 10:42:56 +00002815
2816 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002817 * Sets the given component as the device initializer. The package must already be installed and
2818 * set as an active device administrator, and there must not be an existing device initializer,
2819 * for this call to succeed. This method can only be called by an app holding the
2820 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2821 * device initializer app is granted device owner privileges during device initialization and
2822 * profile owner privileges during secondary user initialization.
2823 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2824 * called by the device owner.
2825 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002826 * @return whether the component was successfully registered as the device initializer.
2827 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002828 * @throws IllegalStateException if the caller is not device owner or the device has
2829 * already been provisioned or a device initializer already exists.
2830 */
Julia Reynolds731051e2015-05-11 15:52:08 -04002831 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer)
2832 throws IllegalArgumentException, IllegalStateException {
Julia Reynolds20118f12015-02-11 12:34:08 -05002833 if (mService != null) {
2834 try {
Julia Reynolds731051e2015-05-11 15:52:08 -04002835 return mService.setDeviceInitializer(who, initializer);
Julia Reynolds20118f12015-02-11 12:34:08 -05002836 } catch (RemoteException re) {
2837 Log.w(TAG, "Failed to set device initializer");
2838 }
2839 }
2840 return false;
2841 }
2842
2843 /**
2844 * Used to determine if a particular package has been registered as the device initializer.
2845 *
2846 * @param packageName the package name of the app, to compare with the registered device
2847 * initializer app, if any.
2848 * @return whether or not the caller is registered as the device initializer app.
2849 */
2850 public boolean isDeviceInitializerApp(String packageName) {
2851 if (mService != null) {
2852 try {
2853 return mService.isDeviceInitializer(packageName);
2854 } catch (RemoteException re) {
2855 Log.w(TAG, "Failed to check device initializer");
2856 }
2857 }
2858 return false;
2859 }
2860
2861 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002862 * Removes the device initializer, so that it will not be invoked on user initialization for any
2863 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002864 * initializer itself. The caller must be an active administrator.
2865 *
2866 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002867 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002868 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002869 if (mService != null) {
2870 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002871 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002872 } catch (RemoteException re) {
2873 Log.w(TAG, "Failed to clear device initializer");
2874 }
2875 }
2876 }
2877
2878 /**
2879 * @hide
2880 * Gets the device initializer of the system.
2881 *
2882 * @return the package name of the device initializer.
2883 */
2884 @SystemApi
2885 public String getDeviceInitializerApp() {
2886 if (mService != null) {
2887 try {
2888 return mService.getDeviceInitializer();
2889 } catch (RemoteException re) {
2890 Log.w(TAG, "Failed to get device initializer");
2891 }
2892 }
2893 return null;
2894 }
2895
2896 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002897 * @hide
2898 * Gets the device initializer component of the system.
2899 *
2900 * @return the component name of the device initializer.
2901 */
2902 @SystemApi
2903 public ComponentName getDeviceInitializerComponent() {
2904 if (mService != null) {
2905 try {
2906 return mService.getDeviceInitializerComponent();
2907 } catch (RemoteException re) {
2908 Log.w(TAG, "Failed to get device initializer");
2909 }
2910 }
2911 return null;
2912 }
2913
2914
2915 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002916 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2917 * be used.
2918 *
2919 * <p>Device initializer must call this method to mark the user as functional.
2920 * Only the device initializer agent can call this.
2921 *
2922 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2923 * device initializer will no longer have elevated permissions to call methods in this class.
2924 * Additionally, it will be removed as an active administrator and its
2925 * {@link DeviceAdminReceiver} will be disabled.
2926 *
2927 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2928 * @return whether the user is now enabled.
2929 */
2930 public boolean setUserEnabled(ComponentName admin) {
2931 if (mService != null) {
2932 try {
2933 return mService.setUserEnabled(admin);
2934 } catch (RemoteException e) {
2935 Log.w(TAG, "Failed talking with device policy service", e);
2936 }
2937 }
2938 return false;
2939 }
2940
2941 /**
Adam Connors776c5552014-01-09 10:42:56 +00002942 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002943 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302944 * Sets the given component as an active admin and registers the package as the profile
2945 * owner for this user. The package must already be installed and there shouldn't be
2946 * an existing profile owner registered for this user. Also, this method must be called
2947 * before the user setup has been completed.
2948 * <p>
2949 * This method can only be called by system apps that hold MANAGE_USERS permission and
2950 * MANAGE_DEVICE_ADMINS permission.
2951 * @param admin The component to register as an active admin and profile owner.
2952 * @param ownerName The user-visible name of the entity that is managing this user.
2953 * @return whether the admin was successfully registered as the profile owner.
2954 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2955 * the user has already been set up.
2956 */
Justin Morey80440cc2014-07-24 09:16:35 -05002957 @SystemApi
Robin Leeddd553f2015-04-30 14:18:22 +01002958 public boolean setActiveProfileOwner(ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302959 throws IllegalArgumentException {
2960 if (mService != null) {
2961 try {
2962 final int myUserId = UserHandle.myUserId();
2963 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002964 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302965 } catch (RemoteException re) {
2966 Log.w(TAG, "Failed to set profile owner " + re);
2967 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2968 }
2969 }
2970 return false;
2971 }
2972
2973 /**
2974 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002975 * Clears the active profile owner and removes all user restrictions. The caller must
2976 * be from the same package as the active profile owner for this user, otherwise a
2977 * SecurityException will be thrown.
2978 *
2979 * @param admin The component to remove as the profile owner.
2980 * @return
2981 */
2982 @SystemApi
2983 public void clearProfileOwner(ComponentName admin) {
2984 if (mService != null) {
2985 try {
2986 mService.clearProfileOwner(admin);
2987 } catch (RemoteException re) {
2988 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2989 }
2990 }
2991 }
2992
2993 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002994 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002995 * Checks if the user was already setup.
2996 */
2997 public boolean hasUserSetupCompleted() {
2998 if (mService != null) {
2999 try {
3000 return mService.hasUserSetupCompleted();
3001 } catch (RemoteException re) {
3002 Log.w(TAG, "Failed to check if user setup has completed");
3003 }
3004 }
3005 return true;
3006 }
3007
3008 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003009 * @hide
3010 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003011 * already be installed. There must not already be a profile owner for this user.
3012 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3013 * this method.
3014 * Calling this after the setup phase of the specified user has completed is allowed only if:
3015 * - the caller is SYSTEM_UID.
3016 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003017 * @param admin the component name to be registered as profile owner.
3018 * @param ownerName the human readable name of the organisation associated with this DPM.
3019 * @param userHandle the userId to set the profile owner for.
3020 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003021 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3022 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003023 */
Robin Leeddd553f2015-04-30 14:18:22 +01003024 public boolean setProfileOwner(ComponentName admin, @Deprecated String ownerName,
3025 int userHandle) throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003026 if (admin == null) {
3027 throw new NullPointerException("admin cannot be null");
3028 }
Adam Connors776c5552014-01-09 10:42:56 +00003029 if (mService != null) {
3030 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003031 if (ownerName == null) {
3032 ownerName = "";
3033 }
3034 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003035 } catch (RemoteException re) {
3036 Log.w(TAG, "Failed to set profile owner", re);
3037 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3038 }
3039 }
3040 return false;
3041 }
3042
3043 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003044 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3045 * be used. Only the profile owner can call this.
3046 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003047 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003048 *
3049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3050 */
3051 public void setProfileEnabled(ComponentName admin) {
3052 if (mService != null) {
3053 try {
3054 mService.setProfileEnabled(admin);
3055 } catch (RemoteException e) {
3056 Log.w(TAG, "Failed talking with device policy service", e);
3057 }
3058 }
3059 }
3060
3061 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003062 * Sets the name of the profile. In the device owner case it sets the name of the user
3063 * 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 +01003064 * never called by the profile or device owner, the name will be set to default values.
3065 *
3066 * @see #isProfileOwnerApp
3067 * @see #isDeviceOwnerApp
3068 *
3069 * @param profileName The name of the profile.
3070 */
3071 public void setProfileName(ComponentName who, String profileName) {
3072 if (mService != null) {
3073 try {
3074 mService.setProfileName(who, profileName);
3075 } catch (RemoteException e) {
3076 Log.w(TAG, "Failed talking with device policy service", e);
3077 }
3078 }
3079}
3080
3081 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003082 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003083 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003084 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003085 *
3086 * @param packageName The package name of the app to compare with the registered profile owner.
3087 * @return Whether or not the package is registered as the profile owner.
3088 */
3089 public boolean isProfileOwnerApp(String packageName) {
3090 if (mService != null) {
3091 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003092 ComponentName profileOwner = mService.getProfileOwner(
3093 Process.myUserHandle().getIdentifier());
3094 return profileOwner != null
3095 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003096 } catch (RemoteException re) {
3097 Log.w(TAG, "Failed to check profile owner");
3098 }
3099 }
3100 return false;
3101 }
3102
3103 /**
3104 * @hide
3105 * @return the packageName of the owner of the given user profile or null if no profile
3106 * owner has been set for that user.
3107 * @throws IllegalArgumentException if the userId is invalid.
3108 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003109 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003110 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003111 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3112 }
3113
3114 /**
3115 * @see #getProfileOwner()
3116 * @hide
3117 */
3118 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003119 if (mService != null) {
3120 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003121 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003122 } catch (RemoteException re) {
3123 Log.w(TAG, "Failed to get profile owner");
3124 throw new IllegalArgumentException(
3125 "Requested profile owner for invalid userId", re);
3126 }
3127 }
3128 return null;
3129 }
3130
3131 /**
3132 * @hide
3133 * @return the human readable name of the organisation associated with this DPM or null if
3134 * one is not set.
3135 * @throws IllegalArgumentException if the userId is invalid.
3136 */
3137 public String getProfileOwnerName() throws IllegalArgumentException {
3138 if (mService != null) {
3139 try {
3140 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3141 } catch (RemoteException re) {
3142 Log.w(TAG, "Failed to get profile owner");
3143 throw new IllegalArgumentException(
3144 "Requested profile owner for invalid userId", re);
3145 }
3146 }
3147 return null;
3148 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003149
3150 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003151 * @hide
3152 * @param user The user for whom to fetch the profile owner name, if any.
3153 * @return the human readable name of the organisation associated with this profile owner or
3154 * null if one is not set.
3155 * @throws IllegalArgumentException if the userId is invalid.
3156 */
3157 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003158 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003159 if (mService != null) {
3160 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003161 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003162 } catch (RemoteException re) {
3163 Log.w(TAG, "Failed to get profile owner");
3164 throw new IllegalArgumentException(
3165 "Requested profile owner for invalid userId", re);
3166 }
3167 }
3168 return null;
3169 }
3170
3171 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003172 * Called by a profile owner or device owner to add a default intent handler activity for
3173 * intents that match a certain intent filter. This activity will remain the default intent
3174 * handler even if the set of potential event handlers for the intent filter changes and if
3175 * the intent preferences are reset.
3176 *
3177 * <p>The default disambiguation mechanism takes over if the activity is not installed
3178 * (anymore). When the activity is (re)installed, it is automatically reset as default
3179 * intent handler for the filter.
3180 *
3181 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3182 * security exception will be thrown.
3183 *
3184 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3185 * @param filter The IntentFilter for which a default handler is added.
3186 * @param activity The Activity that is added as default intent handler.
3187 */
3188 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
3189 ComponentName activity) {
3190 if (mService != null) {
3191 try {
3192 mService.addPersistentPreferredActivity(admin, filter, activity);
3193 } catch (RemoteException e) {
3194 Log.w(TAG, "Failed talking with device policy service", e);
3195 }
3196 }
3197 }
3198
3199 /**
3200 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003201 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003202 *
3203 * <p>The calling device admin must be a profile owner. If it is not, a security
3204 * exception will be thrown.
3205 *
3206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3207 * @param packageName The name of the package for which preferences are removed.
3208 */
3209 public void clearPackagePersistentPreferredActivities(ComponentName admin,
3210 String packageName) {
3211 if (mService != null) {
3212 try {
3213 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3214 } catch (RemoteException e) {
3215 Log.w(TAG, "Failed talking with device policy service", e);
3216 }
3217 }
3218 }
Robin Lee66e5d962014-04-09 16:44:21 +01003219
3220 /**
3221 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003222 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003223 *
3224 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003225 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003226 *
3227 * <p>The application restrictions are only made visible to the target application and the
3228 * profile or device owner.
3229 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003230 * <p>If the restrictions are not available yet, but may be applied in the near future,
3231 * the admin can notify the target application of that by adding
3232 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3233 *
Robin Lee66e5d962014-04-09 16:44:21 +01003234 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3235 * exception will be thrown.
3236 *
3237 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3238 * @param packageName The name of the package to update restricted settings for.
3239 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3240 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003241 *
3242 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003243 */
3244 public void setApplicationRestrictions(ComponentName admin, String packageName,
3245 Bundle settings) {
3246 if (mService != null) {
3247 try {
3248 mService.setApplicationRestrictions(admin, packageName, settings);
3249 } catch (RemoteException e) {
3250 Log.w(TAG, "Failed talking with device policy service", e);
3251 }
3252 }
3253 }
3254
3255 /**
Jim Millere303bf42014-08-26 17:12:29 -07003256 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3257 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3258 * trust agents but those enabled by this function call. If flag
3259 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003260 *
3261 * <p>The calling device admin must have requested
3262 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003263 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003264 *
3265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003266 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003267 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003268 * will be strictly disabled according to the state of the
3269 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3270 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3271 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3272 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003273 */
Jim Millere303bf42014-08-26 17:12:29 -07003274 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08003275 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003276 if (mService != null) {
3277 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003278 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003279 } catch (RemoteException e) {
3280 Log.w(TAG, "Failed talking with device policy service", e);
3281 }
3282 }
3283 }
3284
3285 /**
Jim Millere303bf42014-08-26 17:12:29 -07003286 * Gets configuration for the given trust agent based on aggregating all calls to
3287 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3288 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003289 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003290 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3291 * this function returns a list of configurations for all admins that declare
3292 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3293 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3294 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3295 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003296 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003297 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003298 */
Jim Millere303bf42014-08-26 17:12:29 -07003299 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3300 ComponentName agent) {
3301 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3302 }
3303
3304 /** @hide per-user version */
3305 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3306 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003307 if (mService != null) {
3308 try {
Jim Millere303bf42014-08-26 17:12:29 -07003309 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003310 } catch (RemoteException e) {
3311 Log.w(TAG, "Failed talking with device policy service", e);
3312 }
3313 }
Jim Millere303bf42014-08-26 17:12:29 -07003314 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003315 }
3316
3317 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003318 * Called by a profile owner of a managed profile to set whether caller-Id information from
3319 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003320 *
3321 * <p>The calling device admin must be a profile owner. If it is not, a
3322 * security exception will be thrown.
3323 *
3324 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3325 * @param disabled If true caller-Id information in the managed profile is not displayed.
3326 */
3327 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
3328 if (mService != null) {
3329 try {
3330 mService.setCrossProfileCallerIdDisabled(who, disabled);
3331 } catch (RemoteException e) {
3332 Log.w(TAG, "Failed talking with device policy service", e);
3333 }
3334 }
3335 }
3336
3337 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003338 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3339 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003340 *
3341 * <p>The calling device admin must be a profile owner. If it is not, a
3342 * security exception will be thrown.
3343 *
3344 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3345 */
3346 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3347 if (mService != null) {
3348 try {
3349 return mService.getCrossProfileCallerIdDisabled(who);
3350 } catch (RemoteException e) {
3351 Log.w(TAG, "Failed talking with device policy service", e);
3352 }
3353 }
3354 return false;
3355 }
3356
3357 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003358 * Determine whether or not caller-Id information has been disabled.
3359 *
3360 * @param userHandle The user for whom to check the caller-id permission
3361 * @hide
3362 */
3363 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3364 if (mService != null) {
3365 try {
3366 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3367 } catch (RemoteException e) {
3368 Log.w(TAG, "Failed talking with device policy service", e);
3369 }
3370 }
3371 return false;
3372 }
3373
3374 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003375 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3376 * @hide
3377 */
3378 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3379 Intent originalIntent) {
3380 if (mService != null) {
3381 try {
3382 mService.startManagedQuickContact(
3383 actualLookupKey, actualContactId, originalIntent);
3384 } catch (RemoteException e) {
3385 Log.w(TAG, "Failed talking with device policy service", e);
3386 }
3387 }
3388 }
3389
3390 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003391 * Called by a profile owner of a managed profile to set whether bluetooth
3392 * devices can access enterprise contacts.
3393 * <p>
3394 * The calling device admin must be a profile owner. If it is not, a
3395 * security exception will be thrown.
3396 * <p>
3397 * This API works on managed profile only.
3398 *
3399 * @param who Which {@link DeviceAdminReceiver} this request is associated
3400 * with.
3401 * @param disabled If true, bluetooth devices cannot access enterprise
3402 * contacts.
3403 */
3404 public void setBluetoothContactSharingDisabled(ComponentName who, boolean disabled) {
3405 if (mService != null) {
3406 try {
3407 mService.setBluetoothContactSharingDisabled(who, disabled);
3408 } catch (RemoteException e) {
3409 Log.w(TAG, "Failed talking with device policy service", e);
3410 }
3411 }
3412 }
3413
3414 /**
3415 * Called by a profile owner of a managed profile to determine whether or
3416 * not Bluetooth devices cannot access enterprise contacts.
3417 * <p>
3418 * The calling device admin must be a profile owner. If it is not, a
3419 * security exception will be thrown.
3420 * <p>
3421 * This API works on managed profile only.
3422 *
3423 * @param who Which {@link DeviceAdminReceiver} this request is associated
3424 * with.
3425 */
3426 public boolean getBluetoothContactSharingDisabled(ComponentName who) {
3427 if (mService != null) {
3428 try {
3429 return mService.getBluetoothContactSharingDisabled(who);
3430 } catch (RemoteException e) {
3431 Log.w(TAG, "Failed talking with device policy service", e);
3432 }
3433 }
3434 return true;
3435 }
3436
3437 /**
3438 * Determine whether or not Bluetooth devices cannot access contacts.
3439 * <p>
3440 * This API works on managed profile UserHandle only.
3441 *
3442 * @param userHandle The user for whom to check the caller-id permission
3443 * @hide
3444 */
3445 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3446 if (mService != null) {
3447 try {
3448 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3449 .getIdentifier());
3450 } catch (RemoteException e) {
3451 Log.w(TAG, "Failed talking with device policy service", e);
3452 }
3453 }
3454 return true;
3455 }
3456
3457 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003458 * Called by the profile owner of a managed profile so that some intents sent in the managed
3459 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003460 * Only activity intents are supported.
3461 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003462 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003463 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3464 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003465 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3466 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003467 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003468 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003469 if (mService != null) {
3470 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003471 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003472 } catch (RemoteException e) {
3473 Log.w(TAG, "Failed talking with device policy service", e);
3474 }
3475 }
3476 }
3477
3478 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003479 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3480 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003481 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003482 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3483 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003484 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003485 if (mService != null) {
3486 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003487 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003488 } catch (RemoteException e) {
3489 Log.w(TAG, "Failed talking with device policy service", e);
3490 }
3491 }
3492 }
3493
3494 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003495 * Called by a profile or device owner to set the permitted accessibility services. When
3496 * set by a device owner or profile owner the restriction applies to all profiles of the
3497 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003498 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003499 * By default the user can use any accessiblity service. When zero or more packages have
3500 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003501 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003502 *
3503 * <p> Calling with a null value for the list disables the restriction so that all services
3504 * can be used, calling with an empty list only allows the builtin system's services.
3505 *
3506 * <p> System accesibility services are always available to the user the list can't modify
3507 * this.
3508 *
3509 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3510 * @param packageNames List of accessibility service package names.
3511 *
3512 * @return true if setting the restriction succeeded. It fail if there is
3513 * one or more non-system accessibility services enabled, that are not in the list.
3514 */
3515 public boolean setPermittedAccessibilityServices(ComponentName admin,
3516 List<String> packageNames) {
3517 if (mService != null) {
3518 try {
3519 return mService.setPermittedAccessibilityServices(admin, packageNames);
3520 } catch (RemoteException e) {
3521 Log.w(TAG, "Failed talking with device policy service", e);
3522 }
3523 }
3524 return false;
3525 }
3526
3527 /**
3528 * Returns the list of permitted accessibility services set by this device or profile owner.
3529 *
3530 * <p>An empty list means no accessibility services except system services are allowed.
3531 * Null means all accessibility services are allowed.
3532 *
3533 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3534 * @return List of accessiblity service package names.
3535 */
3536 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3537 if (mService != null) {
3538 try {
3539 return mService.getPermittedAccessibilityServices(admin);
3540 } catch (RemoteException e) {
3541 Log.w(TAG, "Failed talking with device policy service", e);
3542 }
3543 }
3544 return null;
3545 }
3546
3547 /**
3548 * Returns the list of accessibility services permitted by the device or profiles
3549 * owners of this user.
3550 *
3551 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3552 * it will contain the intersection of the permitted lists for any device or profile
3553 * owners that apply to this user. It will also include any system accessibility services.
3554 *
3555 * @param userId which user to check for.
3556 * @return List of accessiblity service package names.
3557 * @hide
3558 */
3559 @SystemApi
3560 public List<String> getPermittedAccessibilityServices(int userId) {
3561 if (mService != null) {
3562 try {
3563 return mService.getPermittedAccessibilityServicesForUser(userId);
3564 } catch (RemoteException e) {
3565 Log.w(TAG, "Failed talking with device policy service", e);
3566 }
3567 }
3568 return null;
3569 }
3570
3571 /**
3572 * Called by a profile or device owner to set the permitted input methods services. When
3573 * set by a device owner or profile owner the restriction applies to all profiles of the
3574 * user the device owner or profile owner is an admin for.
3575 *
3576 * By default the user can use any input method. When zero or more packages have
3577 * been added, input method that are not in the list and not part of the system
3578 * can not be enabled by the user.
3579 *
3580 * This method will fail if it is called for a admin that is not for the foreground user
3581 * or a profile of the foreground user.
3582 *
3583 * <p> Calling with a null value for the list disables the restriction so that all input methods
3584 * can be used, calling with an empty list disables all but the system's own input methods.
3585 *
3586 * <p> System input methods are always available to the user this method can't modify this.
3587 *
3588 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3589 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003590 * @return true if setting the restriction succeeded. It will fail if there are
3591 * one or more non-system input methods currently enabled that are not in
3592 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003593 */
3594 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3595 if (mService != null) {
3596 try {
3597 return mService.setPermittedInputMethods(admin, packageNames);
3598 } catch (RemoteException e) {
3599 Log.w(TAG, "Failed talking with device policy service", e);
3600 }
3601 }
3602 return false;
3603 }
3604
3605
3606 /**
3607 * Returns the list of permitted input methods set by this device or profile owner.
3608 *
3609 * <p>An empty list means no input methods except system input methods are allowed.
3610 * Null means all input methods are allowed.
3611 *
3612 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3613 * @return List of input method package names.
3614 */
3615 public List<String> getPermittedInputMethods(ComponentName admin) {
3616 if (mService != null) {
3617 try {
3618 return mService.getPermittedInputMethods(admin);
3619 } catch (RemoteException e) {
3620 Log.w(TAG, "Failed talking with device policy service", e);
3621 }
3622 }
3623 return null;
3624 }
3625
3626 /**
3627 * Returns the list of input methods permitted by the device or profiles
3628 * owners of the current user.
3629 *
3630 * <p>Null means all input methods are allowed, if a non-null list is returned
3631 * it will contain the intersection of the permitted lists for any device or profile
3632 * owners that apply to this user. It will also include any system input methods.
3633 *
3634 * @return List of input method package names.
3635 * @hide
3636 */
3637 @SystemApi
3638 public List<String> getPermittedInputMethodsForCurrentUser() {
3639 if (mService != null) {
3640 try {
3641 return mService.getPermittedInputMethodsForCurrentUser();
3642 } catch (RemoteException e) {
3643 Log.w(TAG, "Failed talking with device policy service", e);
3644 }
3645 }
3646 return null;
3647 }
3648
3649 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003650 * Called by a device owner to create a user with the specified name. The UserHandle returned
3651 * by this method should not be persisted as user handles are recycled as users are removed and
3652 * created. If you need to persist an identifier for this user, use
3653 * {@link UserManager#getSerialNumberForUser}.
3654 *
3655 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3656 * @param name the user's name
3657 * @see UserHandle
3658 * @return the UserHandle object for the created user, or null if the user could not be created.
3659 */
3660 public UserHandle createUser(ComponentName admin, String name) {
3661 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
3691 * @return the UserHandle object for the created user, or null if the user could not be created.
3692 */
3693 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3694 ComponentName profileOwnerComponent, Bundle adminExtras) {
3695 try {
3696 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3697 adminExtras);
3698 } catch (RemoteException re) {
3699 Log.w(TAG, "Could not create a user", re);
3700 }
3701 return null;
3702 }
3703
3704 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003705 * Called by a device owner to remove a user and all associated data. The primary user can
3706 * not be removed.
3707 *
3708 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3709 * @param userHandle the user to remove.
3710 * @return {@code true} if the user was removed, {@code false} otherwise.
3711 */
3712 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3713 try {
3714 return mService.removeUser(admin, userHandle);
3715 } catch (RemoteException re) {
3716 Log.w(TAG, "Could not remove user ", re);
3717 return false;
3718 }
3719 }
3720
3721 /**
Jason Monk582d9112014-07-09 19:57:08 -04003722 * Called by a device owner to switch the specified user to the foreground.
3723 *
3724 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3725 * @param userHandle the user to switch to; null will switch to primary.
3726 * @return {@code true} if the switch was successful, {@code false} otherwise.
3727 *
3728 * @see Intent#ACTION_USER_FOREGROUND
3729 */
3730 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3731 try {
3732 return mService.switchUser(admin, userHandle);
3733 } catch (RemoteException re) {
3734 Log.w(TAG, "Could not switch user ", re);
3735 return false;
3736 }
3737 }
3738
3739 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003740 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003741 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003742 *
3743 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3744 * exception will be thrown.
3745 *
3746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3747 * @param packageName The name of the package to fetch restricted settings of.
3748 * @return {@link Bundle} of settings corresponding to what was set last time
3749 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3750 * if no restrictions have been set.
3751 */
3752 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3753 if (mService != null) {
3754 try {
3755 return mService.getApplicationRestrictions(admin, packageName);
3756 } catch (RemoteException e) {
3757 Log.w(TAG, "Failed talking with device policy service", e);
3758 }
3759 }
3760 return null;
3761 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003762
3763 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003764 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003765 * <p>
3766 * The calling device admin must be a profile or device owner; if it is not,
3767 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003768 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003769 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3770 * with.
3771 * @param key The key of the restriction. See the constants in
3772 * {@link android.os.UserManager} for the list of keys.
3773 */
3774 public void addUserRestriction(ComponentName admin, String key) {
3775 if (mService != null) {
3776 try {
3777 mService.setUserRestriction(admin, key, true);
3778 } catch (RemoteException e) {
3779 Log.w(TAG, "Failed talking with device policy service", e);
3780 }
3781 }
3782 }
3783
3784 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003785 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003786 * <p>
3787 * The calling device admin must be a profile or device owner; if it is not,
3788 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003789 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003790 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3791 * with.
3792 * @param key The key of the restriction. See the constants in
3793 * {@link android.os.UserManager} for the list of keys.
3794 */
3795 public void clearUserRestriction(ComponentName admin, String key) {
3796 if (mService != null) {
3797 try {
3798 mService.setUserRestriction(admin, key, false);
3799 } catch (RemoteException e) {
3800 Log.w(TAG, "Failed talking with device policy service", e);
3801 }
3802 }
3803 }
Adam Connors010cfd42014-04-16 12:48:13 +01003804
3805 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003806 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003807 * is unavailable for use, but the data and actual package file remain.
3808 *
3809 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003810 * @param packageName The name of the package to hide or unhide.
3811 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3812 * unhidden.
3813 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003814 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003815 public boolean setApplicationHidden(ComponentName admin, String packageName,
3816 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003817 if (mService != null) {
3818 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003819 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003820 } catch (RemoteException e) {
3821 Log.w(TAG, "Failed talking with device policy service", e);
3822 }
3823 }
3824 return false;
3825 }
3826
3827 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003828 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003829 *
3830 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003831 * @param packageName The name of the package to retrieve the hidden status of.
3832 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003833 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003834 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003835 if (mService != null) {
3836 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003837 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003838 } catch (RemoteException e) {
3839 Log.w(TAG, "Failed talking with device policy service", e);
3840 }
3841 }
3842 return false;
3843 }
3844
3845 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003846 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003847 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003848 *
3849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3850 * @param packageName The package to be re-enabled in the current profile.
3851 */
3852 public void enableSystemApp(ComponentName admin, String packageName) {
3853 if (mService != null) {
3854 try {
3855 mService.enableSystemApp(admin, packageName);
3856 } catch (RemoteException e) {
3857 Log.w(TAG, "Failed to install package: " + packageName);
3858 }
3859 }
3860 }
3861
3862 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003863 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003864 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003865 *
3866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3867 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3868 * intent will be re-enabled in the current profile.
3869 * @return int The number of activities that matched the intent and were installed.
3870 */
3871 public int enableSystemApp(ComponentName admin, Intent intent) {
3872 if (mService != null) {
3873 try {
3874 return mService.enableSystemAppWithIntent(admin, intent);
3875 } catch (RemoteException e) {
3876 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3877 }
3878 }
3879 return 0;
3880 }
3881
3882 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003883 * Called by a device owner or profile owner to disable account management for a specific type
3884 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003885 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003886 * <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 +01003887 * security exception will be thrown.
3888 *
3889 * <p>When account management is disabled for an account type, adding or removing an account
3890 * of that type will not be possible.
3891 *
3892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3893 * @param accountType For which account management is disabled or enabled.
3894 * @param disabled The boolean indicating that account management will be disabled (true) or
3895 * enabled (false).
3896 */
3897 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3898 boolean disabled) {
3899 if (mService != null) {
3900 try {
3901 mService.setAccountManagementDisabled(admin, accountType, disabled);
3902 } catch (RemoteException e) {
3903 Log.w(TAG, "Failed talking with device policy service", e);
3904 }
3905 }
3906 }
3907
3908 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003909 * Gets the array of accounts for which account management is disabled by the profile owner.
3910 *
3911 * <p> Account management can be disabled/enabled by calling
3912 * {@link #setAccountManagementDisabled}.
3913 *
3914 * @return a list of account types for which account management has been disabled.
3915 *
3916 * @see #setAccountManagementDisabled
3917 */
3918 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003919 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003920 }
3921
3922 /**
3923 * @see #getAccountTypesWithManagementDisabled()
3924 * @hide
3925 */
3926 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003927 if (mService != null) {
3928 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003929 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003930 } catch (RemoteException e) {
3931 Log.w(TAG, "Failed talking with device policy service", e);
3932 }
3933 }
3934
3935 return null;
3936 }
justinzhang511e0d82014-03-24 16:09:24 -04003937
3938 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003939 * Sets which packages may enter lock task mode.
3940 *
3941 * <p>Any packages that shares uid with an allowed package will also be allowed
3942 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003943 *
Jason Monkc5185f22014-06-24 11:12:42 -04003944 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003945 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003946 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003947 *
3948 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003949 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3950 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003951 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003952 */
Jason Monk48aacba2014-08-13 16:29:08 -04003953 public void setLockTaskPackages(ComponentName admin, String[] packages)
3954 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003955 if (mService != null) {
3956 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003957 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003958 } catch (RemoteException e) {
3959 Log.w(TAG, "Failed talking with device policy service", e);
3960 }
3961 }
3962 }
3963
3964 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003965 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003966 *
3967 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003968 * @hide
3969 */
Jason Monk48aacba2014-08-13 16:29:08 -04003970 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003971 if (mService != null) {
3972 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003973 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003974 } catch (RemoteException e) {
3975 Log.w(TAG, "Failed talking with device policy service", e);
3976 }
3977 }
3978 return null;
3979 }
3980
3981 /**
3982 * This function lets the caller know whether the given component is allowed to start the
3983 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003984 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003985 */
Jason Monkd7b86212014-06-16 13:15:38 -04003986 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003987 if (mService != null) {
3988 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003989 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003990 } catch (RemoteException e) {
3991 Log.w(TAG, "Failed talking with device policy service", e);
3992 }
3993 }
3994 return false;
3995 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003996
3997 /**
3998 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3999 * 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 -04004000 * <p>The settings that can be updated with this method are:
4001 * <ul>
4002 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4003 * <li>{@link Settings.Global#AUTO_TIME}</li>
4004 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00004005 * <li>{@link Settings.Global#BLUETOOTH_ON}
4006 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
4007 * {@link android.bluetooth.BluetoothAdapter#enable()} and
4008 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004009 * <li>{@link Settings.Global#DATA_ROAMING}</li>
4010 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4011 * <li>{@link Settings.Global#MODE_RINGER}</li>
4012 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4013 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00004014 * <li>{@link Settings.Global#WIFI_ON}
4015 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
4016 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004017 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004018 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
4019 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
4020 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004021 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004022 *
4023 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4024 * @param setting The name of the setting to update.
4025 * @param value The value to update the setting to.
4026 */
4027 public void setGlobalSetting(ComponentName admin, String setting, String value) {
4028 if (mService != null) {
4029 try {
4030 mService.setGlobalSetting(admin, setting, value);
4031 } catch (RemoteException e) {
4032 Log.w(TAG, "Failed talking with device policy service", e);
4033 }
4034 }
4035 }
4036
4037 /**
4038 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4039 * that the value of the setting is in the correct form for the setting type should be performed
4040 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004041 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004042 * <ul>
4043 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004044 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004045 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4046 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004047 * <p>A device owner can additionally update the following settings:
4048 * <ul>
4049 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4050 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4052 * @param setting The name of the setting to update.
4053 * @param value The value to update the setting to.
4054 */
4055 public void setSecureSetting(ComponentName admin, String setting, String value) {
4056 if (mService != null) {
4057 try {
4058 mService.setSecureSetting(admin, setting, value);
4059 } catch (RemoteException e) {
4060 Log.w(TAG, "Failed talking with device policy service", e);
4061 }
4062 }
4063 }
4064
Amith Yamasanif20d6402014-05-24 15:34:37 -07004065 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004066 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004067 * making permission requests of a local or remote administrator of the user.
4068 * <p/>
4069 * Only a profile owner can designate the restrictions provider.
4070 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004071 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004072 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004073 * it removes the restrictions provider previously assigned.
4074 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004075 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004076 if (mService != null) {
4077 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004078 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004079 } catch (RemoteException re) {
4080 Log.w(TAG, "Failed to set permission provider on device policy service");
4081 }
4082 }
4083 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004084
4085 /**
4086 * Called by profile or device owners to set the master volume mute on or off.
4087 *
4088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4089 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4090 */
4091 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
4092 if (mService != null) {
4093 try {
4094 mService.setMasterVolumeMuted(admin, on);
4095 } catch (RemoteException re) {
4096 Log.w(TAG, "Failed to setMasterMute on device policy service");
4097 }
4098 }
4099 }
4100
4101 /**
4102 * Called by profile or device owners to check whether the master volume mute is on or off.
4103 *
4104 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4105 * @return {@code true} if master volume is muted, {@code false} if it's not.
4106 */
4107 public boolean isMasterVolumeMuted(ComponentName admin) {
4108 if (mService != null) {
4109 try {
4110 return mService.isMasterVolumeMuted(admin);
4111 } catch (RemoteException re) {
4112 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4113 }
4114 }
4115 return false;
4116 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004117
4118 /**
4119 * Called by profile or device owners to change whether a user can uninstall
4120 * a package.
4121 *
4122 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4123 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004124 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004125 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004126 public void setUninstallBlocked(ComponentName admin, String packageName,
4127 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004128 if (mService != null) {
4129 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004130 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004131 } catch (RemoteException re) {
4132 Log.w(TAG, "Failed to call block uninstall on device policy service");
4133 }
4134 }
4135 }
4136
4137 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004138 * Check whether the current user has been blocked by device policy from uninstalling a package.
4139 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004140 * <p>
4141 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
4142 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
4143 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
4144 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004145 *
Rubin Xua97855b2014-11-07 05:41:00 +00004146 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00004147 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004148 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004149 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004150 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01004151 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004152 if (mService != null) {
4153 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004154 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004155 } catch (RemoteException re) {
4156 Log.w(TAG, "Failed to call block uninstall on device policy service");
4157 }
4158 }
4159 return false;
4160 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004161
4162 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004163 * Called by the profile owner of a managed profile to enable widget providers from a
4164 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004165 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004166 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004167 * a package may have zero or more provider components, where each component
4168 * provides a different widget type.
4169 * <p>
4170 * <strong>Note:</strong> By default no widget provider package is white-listed.
4171 * </p>
4172 *
4173 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4174 * @param packageName The package from which widget providers are white-listed.
4175 * @return Whether the package was added.
4176 *
4177 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4178 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4179 */
4180 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4181 if (mService != null) {
4182 try {
4183 return mService.addCrossProfileWidgetProvider(admin, packageName);
4184 } catch (RemoteException re) {
4185 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4186 }
4187 }
4188 return false;
4189 }
4190
4191 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004192 * Called by the profile owner of a managed profile to disable widget providers from a given
4193 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004194 * package should have been added via {@link #addCrossProfileWidgetProvider(
4195 * android.content.ComponentName, String)}.
4196 * <p>
4197 * <strong>Note:</strong> By default no widget provider package is white-listed.
4198 * </p>
4199 *
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 */
4208 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4209 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 */
4229 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
4230 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 */
4249 public void setUserIcon(ComponentName admin, Bitmap icon) {
4250 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 *
4276 * @param who Which {@link DeviceAdminReceiver} this request is associated with. All components
Rubin Xu5faad8e2015-04-20 17:43:48 +01004277 * in the device owner package can set system update policies and the most recent policy takes
4278 * effect.
4279 * @param policy the new policy, or null to clear the current policy.
4280 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004281 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004282 public void setSystemUpdatePolicy(ComponentName who, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004283 if (mService != null) {
4284 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004285 mService.setSystemUpdatePolicy(who, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004286 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004287 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004288 }
4289 }
4290 }
4291
4292 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004293 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004294 *
Rubin Xu5faad8e2015-04-20 17:43:48 +01004295 * @return The current policy object, or null if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004296 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004297 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004298 if (mService != null) {
4299 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004300 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004301 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004302 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004303 }
4304 }
4305 return null;
4306 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004307
4308 /**
4309 * Called by a device owner to disable the keyguard altogether.
4310 *
4311 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4312 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4313 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4314 * being disabled.
4315 *
4316 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004317 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004318 *
4319 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004320 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004321 */
Benjamin Franzbece8062015-05-06 12:14:31 +01004322 public boolean setKeyguardDisabled(ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004323 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004324 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004325 } catch (RemoteException re) {
4326 Log.w(TAG, "Failed talking with device policy service", re);
4327 return false;
4328 }
4329 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004330
4331 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004332 * Called by device owner to disable the status bar. Disabling the status bar blocks
4333 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004334 * a single use device.
4335 *
4336 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004337 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4338 *
4339 * @return {@code false} if attempting to disable the status bar failed.
4340 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004341 */
Benjamin Franzbece8062015-05-06 12:14:31 +01004342 public boolean setStatusBarDisabled(ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004343 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004344 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004345 } catch (RemoteException re) {
4346 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004347 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004348 }
4349 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004350
4351 /**
4352 * Callable by the system update service to notify device owners about pending updates.
4353 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4354 * permission.
4355 *
4356 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4357 * when the current pending update was first available. -1 if no update is available.
4358 * @hide
4359 */
4360 @SystemApi
4361 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4362 if (mService != null) {
4363 try {
4364 mService.notifyPendingSystemUpdate(updateReceivedTime);
4365 } catch (RemoteException re) {
4366 Log.w(TAG, "Could not notify device owner about pending system update", re);
4367 }
4368 }
4369 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004370
4371 /**
4372 * Called by a device initializer to set the activity to be launched on device boot or after a
4373 * user switch during user setup. This activity will be started regardless of the priority of
4374 * other 'home' activities. Once user setup is complete, the preferred setup activity will be
4375 * ignored.
4376 *
4377 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4378 * @param activity The Activity to be started by default during user setup.
4379 */
4380 public void setPreferredSetupActivity(ComponentName admin, ComponentName activity) {
4381 try {
4382 mService.setPreferredSetupActivity(admin, activity);
4383 } catch (RemoteException re) {
4384 Log.w(TAG, "Failed talking with device policy service", re);
4385 }
4386 }
Amith Yamasanid49489b2015-04-28 14:00:26 -07004387
4388 /**
4389 * Called by profile or device owners to set the default response for future runtime permission
4390 * requests by applications. The policy can allow for normal operation which prompts the
4391 * user to grant a permission, or can allow automatic granting or denying of runtime
4392 * permission requests by an application. This also applies to new permissions declared by app
4393 * updates.
4394 * @param admin Which profile or device owner this request is associated with.
4395 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4396 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
4397 */
4398 public void setPermissionPolicy(ComponentName admin, int policy) {
4399 try {
4400 mService.setPermissionPolicy(admin, policy);
4401 } catch (RemoteException re) {
4402 Log.w(TAG, "Failed talking with device policy service", re);
4403 }
4404 }
4405
4406 /**
4407 * Returns the current runtime permission policy set by the device or profile owner. The
4408 * default is {@link #PERMISSION_POLICY_PROMPT}.
4409 * @param admin Which profile or device owner this request is associated with.
4410 * @return the current policy for future permission requests.
4411 */
4412 public int getPermissionPolicy(ComponentName admin) {
4413 try {
4414 return mService.getPermissionPolicy(admin);
4415 } catch (RemoteException re) {
4416 return PERMISSION_POLICY_PROMPT;
4417 }
4418 }
4419
4420 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004421 * Sets the grant state of a runtime permission for a specific application. The state
4422 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4423 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4424 * is denied and the user cannot manage it through the UI, and {@link
4425 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4426 * user cannot manage it through the UI. This might affect all permissions in a
4427 * group that the runtime permission belongs to. This method can only be called
4428 * by a profile or device owner.
4429 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004430 * @param admin Which profile or device owner this request is associated with.
4431 * @param packageName The application to grant or revoke a permission to.
4432 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004433 * @param grantState The permission grant state which is one of {@link
4434 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4435 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4436 * @return whether the permission was successfully granted or revoked.
4437 *
4438 * @see #PERMISSION_GRANT_STATE_DENIED
4439 * @see #PERMISSION_GRANT_STATE_DEFAULT
4440 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004441 */
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004442 public boolean setPermissionGrantState(ComponentName admin, String packageName,
4443 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004444 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004445 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004446 } catch (RemoteException re) {
4447 Log.w(TAG, "Failed talking with device policy service", re);
4448 return false;
4449 }
4450 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004451
4452 /**
4453 * Returns the current grant state of a runtime permission for a specific application.
4454 *
4455 * @param admin Which profile or device owner this request is associated with.
4456 * @param packageName The application to check the grant state for.
4457 * @param permission The permission to check for.
4458 * @return the current grant state specified by device policy. If the profile or device owner
4459 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4460 * This does not indicate whether or not the permission is currently granted for the package.
4461 *
4462 * <p/>If a grant state was set by the profile or device owner, then the return value will
4463 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4464 * which indicates if the permission is currently denied or granted.
4465 *
4466 * @see #setPermissionGrantState(ComponentName, String, String, int)
4467 * @see PackageManager#checkPermission(String, String)
4468 */
4469 public int getPermissionGrantState(ComponentName admin, String packageName,
4470 String permission) {
4471 try {
4472 return mService.getPermissionGrantState(admin, packageName, permission);
4473 } catch (RemoteException re) {
4474 Log.w(TAG, "Failed talking with device policy service", re);
4475 return PERMISSION_GRANT_STATE_DEFAULT;
4476 }
4477 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004478}