blob: c9f5f9a018be470e8ec4f28992efe64eee837dbf [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
367 * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If
368 * this doesn't match the file at the download location an error will be shown to the user and
369 * the user will be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100370 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000371 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
372 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 */
374 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100375 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100376
377 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000378 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
379 * has completed successfully.
380 *
381 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
382 * intent (@see #ACTION_PROVISION_MANAGED_PROFILE).
383 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800384 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000385 * corresponds to the account requested to be migrated at provisioning time, if any.
386 */
387 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
388 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
389 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
390
391 /**
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500392 * A boolean extra indicating whether device encryption is required as part of Device Owner
393 * provisioning.
394 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400395 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500396 * provisioning via an NFC bump.
397 */
398 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
399 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
400
401 /**
Rubin Xu44ef750b2015-03-23 16:51:33 +0000402 * On devices managed by a device owner app, a {@link ComponentName} extra indicating the
403 * component of the application that is temporarily granted device owner privileges during
404 * device initialization and profile owner privileges during secondary user initialization.
Julia Reynolds20118f12015-02-11 12:34:08 -0500405 *
Rubin Xu44ef750b2015-03-23 16:51:33 +0000406 * <p>
Rubin Xu6a38e432015-03-26 14:47:45 +0000407 * 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 +0000408 * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a
409 * string first.
410 *
411 * @see ComponentName#flattenToShortString()
Julia Reynolds20118f12015-02-11 12:34:08 -0500412 */
413 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
414 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
415
416 /**
417 * A String extra holding an http url that specifies the download location of the device
418 * initializer package. When not provided it is assumed that the device initializer package is
419 * already installed.
420 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400421 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500422 * provisioning via an NFC bump.
423 */
424 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
425 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
426
427 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400428 * An int extra holding a minimum required version code for the device initializer package.
429 * If the initializer is already installed on the device, it will only be re-downloaded from
430 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
431 * the installed package is less than this version code.
432 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400433 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400434 * provisioning via an NFC bump.
435 */
436 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
437 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
438
439 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500440 * A String extra holding a http cookie header which should be used in the http request to the
441 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
442 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400443 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500444 * provisioning via an NFC bump.
445 */
446 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
447 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
448
449 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000450 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
451 * location specified in
Julia Reynolds20118f12015-02-11 12:34:08 -0500452 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't
453 * match the file at the download location an error will be shown to the user and the user will
454 * be asked to factory reset the device.
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 Reynolds20118f12015-02-11 12:34:08 -0500457 * provisioning via an NFC bump.
458 */
459 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
460 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
461
462 /**
Craig Lafayette97e473e2015-03-19 10:19:38 -0400463 * A String extra holding the MAC address of the Bluetooth device to connect to with status
464 * updates during provisioning.
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
Craig Lafayette97e473e2015-03-19 10:19:38 -0400467 * provisioning via an NFC bump.
468 */
469 public static final String EXTRA_PROVISIONING_BT_MAC_ADDRESS
470 = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS";
471
472 /**
473 * A String extra holding the Bluetooth service UUID on the device to connect to with status
474 * updates during provisioning.
475 *
476 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
477 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400478 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400479 * provisioning via an NFC bump.
480 */
481 public static final String EXTRA_PROVISIONING_BT_UUID
482 = "android.app.extra.PROVISIONING_BT_UUID";
483
484 /**
485 * A String extra holding a unique identifier used to identify the device connecting over
486 * Bluetooth. This identifier will be part of every status message sent to the remote device.
487 *
488 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
489 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400490 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400491 * provisioning via an NFC bump.
492 */
493 public static final String EXTRA_PROVISIONING_BT_DEVICE_ID
494 = "android.app.extra.PROVISIONING_BT_DEVICE_ID";
495
496 /**
497 * A Boolean extra that that will cause a provisioned device to temporarily proxy network
498 * traffic over Bluetooth. When a Wi-Fi network is available, the network proxy will stop.
499 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400500 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400501 * provisioning via an NFC bump.
502 */
503 public static final String EXTRA_PROVISIONING_BT_USE_PROXY
504 = "android.app.extra.PROVISIONING_BT_USE_PROXY";
Craig Lafayette8e27c4d2015-03-19 08:36:38 -0400505
506 /**
507 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
508 * holds data needed by the system to wipe factory reset protection. The data needed to wipe
509 * the device depend on the installed factory reset protection implementation. For example,
510 * if an account is needed to unlock a device, this extra may contain data used to
511 * authenticate that account.
512 *
513 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
514 * provisioning via an NFC bump.
515 */
516 public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS
517 = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS";
518
Craig Lafayette97e473e2015-03-19 10:19:38 -0400519 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400520 * This MIME type is used for starting the Device Owner provisioning that does not require
521 * provisioning features introduced in Android API level
522 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100523 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400524 * <p>For more information about the provisioning process see
525 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100526 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000527 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100528 * contains the following properties:
529 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400530 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
531 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100532 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400533 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100534 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
535 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
536 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
537 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
538 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
539 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
540 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
541 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
542 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
543 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400544 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100545 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000546 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400547 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
548 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
549 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
550 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
551 *
552 * @see #MIME_TYPE_PROVISIONING_NFC_V2
553 *
554 */
555 public static final String MIME_TYPE_PROVISIONING_NFC
556 = "application/com.android.managedprovisioning";
557
558
559 /**
560 * This MIME type is used for starting the Device Owner provisioning that requires
561 * new provisioning features introduced in API version
562 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
563 * versions.
564 *
565 * <p>During device owner provisioning a device admin app is set as the owner of the device.
566 * A device owner has full control over the device. The device owner can not be modified by the
567 * user and the only way of resetting the device is if the device owner app calls a factory
568 * reset.
569 *
570 * <p> A typical use case would be a device that is owned by a company, but used by either an
571 * employee or client.
572 *
573 * <p> The NFC message should be sent to an unprovisioned device.
574 *
575 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
576 * contains the following properties in addition to properties listed at
577 * {@link #MIME_TYPE_PROVISIONING_NFC}:
578 * <ul>
579 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
580 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
581 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
582 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
583 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
584 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
585 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
586 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
587 * should be converted to a String via
588 * {@link android.content.ComponentName#flattenToString()}</li>
589 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li>
590 * <li>{@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, optional</li>
591 * <li>{@link #EXTRA_PROVISIONING_BT_UUID}, optional</li>
592 * <li>{@link #EXTRA_PROVISIONING_BT_DEVICE_ID}, optional</li>
593 * <li>{@link #EXTRA_PROVISIONING_BT_USE_PROXY}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000594 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100595 * <p> When device owner provisioning has completed, an intent of the type
596 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
597 * device owner.
598 *
599 * <p>
600 * If provisioning fails, the device is factory reset.
601 *
602 * <p>Input: Nothing.</p>
603 * <p>Output: Nothing</p>
604 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400605 public static final String MIME_TYPE_PROVISIONING_NFC_V2
606 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100607
608 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800609 * Activity action: ask the user to add a new device administrator to the system.
610 * The desired policy is the ComponentName of the policy in the
611 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
612 * bring the user through adding the device administrator to the system (or
613 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700614 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800615 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
616 * field to provide the user with additional explanation (in addition
617 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800618 *
619 * <p>If your administrator is already active, this will ordinarily return immediately (without
620 * user intervention). However, if your administrator has been updated and is requesting
621 * additional uses-policy flags, the user will be presented with the new list. New policies
622 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800623 */
624 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
625 public static final String ACTION_ADD_DEVICE_ADMIN
626 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700627
Dianne Hackbornd6847842010-01-12 18:14:19 -0800628 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700629 * @hide
630 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700631 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700632 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700633 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
634 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700635 * to remotely control restrictions on the user.
636 *
637 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
638 * result of whether or not the user approved the action. If approved, the result will
639 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
640 * as a profile owner.
641 *
642 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
643 * field to provide the user with additional explanation (in addition
644 * to your component's description) about what is being added.
645 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700646 * <p>If there is already a profile owner active or the caller is not a system app, the
647 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700648 */
649 @SystemApi
650 public static final String ACTION_SET_PROFILE_OWNER
651 = "android.app.action.SET_PROFILE_OWNER";
652
653 /**
Craig Lafayettedbe31a62015-04-02 13:14:39 -0400654 * Protected broadcast action that will be sent to managed provisioning to notify it that a
655 * status update has been reported by the device initializer. The status update will be
656 * reported to the remote setup device over Bluetooth.
657 *
658 * <p>Broadcasts with this action must supply a
659 * {@linkplain DeviceInitializerStatus#isCustomStatus(int) custom} status code in the
660 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_CODE} extra.
661 *
662 * <p>Broadcasts may optionally contain a description in the
663 * {@link EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION} extra.
664 * @hide
665 */
666 @SystemApi
667 public static final String ACTION_SEND_DEVICE_INITIALIZER_STATUS
668 = "android.app.action.SEND_DEVICE_INITIALIZER_STATUS";
669
670 /**
671 * An integer extra that contains the status code that defines a status update. This extra must
672 * sent as part of a broadcast with an action of {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
673 *
674 * <p>The status code sent with this extra must be a custom status code as defined by
675 * {@link DeviceInitializerStatus#isCustomStatus(int)}.
676 * @hide
677 */
678 @SystemApi
679 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_CODE
680 = "android.app.extra.DEVICE_INITIALIZER_STATUS_CODE";
681
682 /**
683 * A {@code String} extra that contains an optional description accompanying a status update.
684 * This extra my be sent as part of a broadcast with an action of
685 * {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}.
686 * @hide
687 */
688 @SystemApi
689 public static final String EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION
690 = "android.app.extra.DEVICE_INITIALIZER_STATUS_DESCRIPTION";
691
692 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700693 * @hide
694 * Name of the profile owner admin that controls the user.
695 */
696 @SystemApi
697 public static final String EXTRA_PROFILE_OWNER_NAME
698 = "android.app.extra.PROFILE_OWNER_NAME";
699
700 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700701 * Activity action: send when any policy admin changes a policy.
702 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700703 *
Jim Miller284b62e2010-06-08 14:27:42 -0700704 * @hide
705 */
706 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
707 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
708
709 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800710 * The ComponentName of the administrator component.
711 *
712 * @see #ACTION_ADD_DEVICE_ADMIN
713 */
714 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700715
Dianne Hackbornd6847842010-01-12 18:14:19 -0800716 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800717 * An optional CharSequence providing additional explanation for why the
718 * admin is being added.
719 *
720 * @see #ACTION_ADD_DEVICE_ADMIN
721 */
722 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700723
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800724 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700725 * Activity action: have the user enter a new password. This activity should
726 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
727 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
728 * enter a new password that meets the current requirements. You can use
729 * {@link #isActivePasswordSufficient()} to determine whether you need to
730 * have the user select a new password in order to meet the current
731 * constraints. Upon being resumed from this activity, you can check the new
732 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800733 */
734 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
735 public static final String ACTION_SET_NEW_PASSWORD
736 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700737
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000738 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000739 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
740 * the parent profile to access intents sent from the managed profile.
741 * That is, when an app in the managed profile calls
742 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
743 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000744 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100745 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000746
747 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000748 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
749 * the managed profile to access intents sent from the parent profile.
750 * That is, when an app in the parent profile calls
751 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
752 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000753 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100754 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700755
Dianne Hackbornd6847842010-01-12 18:14:19 -0800756 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100757 * Broadcast action: notify that a new local system update policy has been set by the device
758 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000759 */
760 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100761 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
762 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000763
764
765 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800766 * Return true if the given administrator component is currently
767 * active (enabled) in the system.
768 */
769 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100770 return isAdminActiveAsUser(who, UserHandle.myUserId());
771 }
772
773 /**
774 * @see #isAdminActive(ComponentName)
775 * @hide
776 */
777 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800778 if (mService != null) {
779 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100780 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800781 } catch (RemoteException e) {
782 Log.w(TAG, "Failed talking with device policy service", e);
783 }
784 }
785 return false;
786 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800787 /**
788 * Return true if the given administrator component is currently being removed
789 * for the user.
790 * @hide
791 */
792 public boolean isRemovingAdmin(ComponentName who, int userId) {
793 if (mService != null) {
794 try {
795 return mService.isRemovingAdmin(who, userId);
796 } catch (RemoteException e) {
797 Log.w(TAG, "Failed talking with device policy service", e);
798 }
799 }
800 return false;
801 }
802
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700803
Dianne Hackbornd6847842010-01-12 18:14:19 -0800804 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800805 * Return a list of all currently active device administrator's component
806 * names. Note that if there are no administrators than null may be
807 * returned.
808 */
809 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100810 return getActiveAdminsAsUser(UserHandle.myUserId());
811 }
812
813 /**
814 * @see #getActiveAdmins()
815 * @hide
816 */
817 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800818 if (mService != null) {
819 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100820 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800821 } catch (RemoteException e) {
822 Log.w(TAG, "Failed talking with device policy service", e);
823 }
824 }
825 return null;
826 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700827
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800828 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700829 * Used by package administration code to determine if a package can be stopped
830 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800831 * @hide
832 */
833 public boolean packageHasActiveAdmins(String packageName) {
834 if (mService != null) {
835 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700836 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800837 } catch (RemoteException e) {
838 Log.w(TAG, "Failed talking with device policy service", e);
839 }
840 }
841 return false;
842 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700843
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800844 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800845 * Remove a current administration component. This can only be called
846 * by the application that owns the administration component; if you
847 * try to remove someone else's component, a security exception will be
848 * thrown.
849 */
850 public void removeActiveAdmin(ComponentName who) {
851 if (mService != null) {
852 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700853 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800854 } catch (RemoteException e) {
855 Log.w(TAG, "Failed talking with device policy service", e);
856 }
857 }
858 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700859
Dianne Hackbornd6847842010-01-12 18:14:19 -0800860 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800861 * Returns true if an administrator has been granted a particular device policy. This can
862 * be used to check if the administrator was activated under an earlier set of policies,
863 * but requires additional policies after an upgrade.
864 *
865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
866 * an active administrator, or an exception will be thrown.
867 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
868 */
869 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
870 if (mService != null) {
871 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700872 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800873 } catch (RemoteException e) {
874 Log.w(TAG, "Failed talking with device policy service", e);
875 }
876 }
877 return false;
878 }
879
880 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800881 * Constant for {@link #setPasswordQuality}: the policy has no requirements
882 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800883 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800884 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800885 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700886
Dianne Hackbornd6847842010-01-12 18:14:19 -0800887 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700888 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
889 * recognition technology. This implies technologies that can recognize the identity of
890 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
891 * Note that quality constants are ordered so that higher values are more restrictive.
892 */
893 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
894
895 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800896 * Constant for {@link #setPasswordQuality}: the policy requires some kind
897 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800898 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800899 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800900 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700901
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800902 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800903 * Constant for {@link #setPasswordQuality}: the user must have entered a
904 * password containing at least numeric characters. Note that quality
905 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800906 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800907 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700908
Dianne Hackbornd6847842010-01-12 18:14:19 -0800909 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800910 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800911 * password containing at least numeric characters with no repeating (4444)
912 * or ordered (1234, 4321, 2468) sequences. Note that quality
913 * constants are ordered so that higher values are more restrictive.
914 */
915 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
916
917 /**
918 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700919 * password containing at least alphabetic (or other symbol) characters.
920 * Note that quality constants are ordered so that higher values are more
921 * restrictive.
922 */
923 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700924
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700925 /**
926 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800927 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700928 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800929 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800930 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700931 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700932
Dianne Hackbornd6847842010-01-12 18:14:19 -0800933 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700934 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700935 * password containing at least a letter, a numerical digit and a special
936 * symbol, by default. With this password quality, passwords can be
937 * restricted to contain various sets of characters, like at least an
938 * uppercase letter, etc. These are specified using various methods,
939 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
940 * that quality constants are ordered so that higher values are more
941 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700942 */
943 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
944
945 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800946 * Called by an application that is administering the device to set the
947 * password restrictions it is imposing. After setting this, the user
948 * will not be able to enter a new password that is not at least as
949 * restrictive as what has been set. Note that the current password
950 * will remain until the user has set a new one, so the change does not
951 * take place immediately. To prompt the user for a new password, use
952 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700953 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800954 * <p>Quality constants are ordered so that higher values are more restrictive;
955 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800956 * the user's preference, and any other considerations) is the one that
957 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700958 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800959 * <p>The calling device admin must have requested
960 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
961 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700962 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800964 * @param quality The new desired quality. One of
965 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800966 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
967 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
968 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800969 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800970 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800971 if (mService != null) {
972 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800973 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800974 } catch (RemoteException e) {
975 Log.w(TAG, "Failed talking with device policy service", e);
976 }
977 }
978 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700979
Dianne Hackbornd6847842010-01-12 18:14:19 -0800980 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100981 * Retrieve the current minimum password quality for all admins of this user
982 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800983 * @param admin The name of the admin component to check, or null to aggregate
984 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800985 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800986 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700987 return getPasswordQuality(admin, UserHandle.myUserId());
988 }
989
990 /** @hide per-user version */
991 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800992 if (mService != null) {
993 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700994 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800995 } catch (RemoteException e) {
996 Log.w(TAG, "Failed talking with device policy service", e);
997 }
998 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800999 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001000 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001001
Dianne Hackbornd6847842010-01-12 18:14:19 -08001002 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001003 * Called by an application that is administering the device to set the
1004 * minimum allowed password length. After setting this, the user
1005 * will not be able to enter a new password that is not at least as
1006 * restrictive as what has been set. Note that the current password
1007 * will remain until the user has set a new one, so the change does not
1008 * take place immediately. To prompt the user for a new password, use
1009 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1010 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001011 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1012 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1013 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001014 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001015 * <p>The calling device admin must have requested
1016 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1017 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001018 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001019 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001020 * @param length The new desired minimum password length. A value of 0
1021 * means there is no restriction.
1022 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001023 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001024 if (mService != null) {
1025 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001026 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 } catch (RemoteException e) {
1028 Log.w(TAG, "Failed talking with device policy service", e);
1029 }
1030 }
1031 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001032
Dianne Hackbornd6847842010-01-12 18:14:19 -08001033 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001034 * Retrieve the current minimum password length for all admins of this
1035 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001036 * @param admin The name of the admin component to check, or null to aggregate
1037 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001038 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001039 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001040 return getPasswordMinimumLength(admin, UserHandle.myUserId());
1041 }
1042
1043 /** @hide per-user version */
1044 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001045 if (mService != null) {
1046 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001047 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001048 } catch (RemoteException e) {
1049 Log.w(TAG, "Failed talking with device policy service", e);
1050 }
1051 }
1052 return 0;
1053 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001054
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001055 /**
1056 * Called by an application that is administering the device to set the
1057 * minimum number of upper case letters required in the password. After
1058 * setting this, the user will not be able to enter a new password that is
1059 * not at least as restrictive as what has been set. Note that the current
1060 * password will remain until the user has set a new one, so the change does
1061 * not take place immediately. To prompt the user for a new password, use
1062 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1063 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001064 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1065 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001066 * <p>
1067 * The calling device admin must have requested
1068 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1069 * this method; if it has not, a security exception will be thrown.
1070 *
1071 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1072 * with.
1073 * @param length The new desired minimum number of upper case letters
1074 * required in the password. A value of 0 means there is no
1075 * restriction.
1076 */
1077 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
1078 if (mService != null) {
1079 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001080 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001081 } catch (RemoteException e) {
1082 Log.w(TAG, "Failed talking with device policy service", e);
1083 }
1084 }
1085 }
1086
1087 /**
1088 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001089 * password for all admins of this user and its profiles or a particular one.
1090 * This is the same value as set by
1091 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001092 * and only applies when the password quality is
1093 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001094 *
1095 * @param admin The name of the admin component to check, or null to
1096 * aggregate all admins.
1097 * @return The minimum number of upper case letters required in the
1098 * password.
1099 */
1100 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001101 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1102 }
1103
1104 /** @hide per-user version */
1105 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001106 if (mService != null) {
1107 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001108 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001109 } catch (RemoteException e) {
1110 Log.w(TAG, "Failed talking with device policy service", e);
1111 }
1112 }
1113 return 0;
1114 }
1115
1116 /**
1117 * Called by an application that is administering the device to set the
1118 * minimum number of lower case letters required in the password. After
1119 * setting this, the user will not be able to enter a new password that is
1120 * not at least as restrictive as what has been set. Note that the current
1121 * password will remain until the user has set a new one, so the change does
1122 * not take place immediately. To prompt the user for a new password, use
1123 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1124 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001125 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1126 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001127 * <p>
1128 * The calling device admin must have requested
1129 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1130 * this method; if it has not, a security exception will be thrown.
1131 *
1132 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1133 * with.
1134 * @param length The new desired minimum number of lower case letters
1135 * required in the password. A value of 0 means there is no
1136 * restriction.
1137 */
1138 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
1139 if (mService != null) {
1140 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001141 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001142 } catch (RemoteException e) {
1143 Log.w(TAG, "Failed talking with device policy service", e);
1144 }
1145 }
1146 }
1147
1148 /**
1149 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001150 * password for all admins of this user and its profiles or a particular one.
1151 * This is the same value as set by
1152 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001153 * and only applies when the password quality is
1154 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001155 *
1156 * @param admin The name of the admin component to check, or null to
1157 * aggregate all admins.
1158 * @return The minimum number of lower case letters required in the
1159 * password.
1160 */
1161 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001162 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1163 }
1164
1165 /** @hide per-user version */
1166 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001167 if (mService != null) {
1168 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001169 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001170 } catch (RemoteException e) {
1171 Log.w(TAG, "Failed talking with device policy service", e);
1172 }
1173 }
1174 return 0;
1175 }
1176
1177 /**
1178 * Called by an application that is administering the device to set the
1179 * minimum number of letters required in the password. After setting this,
1180 * the user will not be able to enter a new password that is not at least as
1181 * restrictive as what has been set. Note that the current password will
1182 * remain until the user has set a new one, so the change does not take
1183 * place immediately. To prompt the user for a new password, use
1184 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1185 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001186 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1187 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 * <p>
1189 * The calling device admin must have requested
1190 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1191 * this method; if it has not, a security exception will be thrown.
1192 *
1193 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1194 * with.
1195 * @param length The new desired minimum number of letters required in the
1196 * password. A value of 0 means there is no restriction.
1197 */
1198 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1199 if (mService != null) {
1200 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001201 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001202 } catch (RemoteException e) {
1203 Log.w(TAG, "Failed talking with device policy service", e);
1204 }
1205 }
1206 }
1207
1208 /**
1209 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001210 * admins or a particular one. This is the same value as
1211 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1212 * and only applies when the password quality is
1213 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001214 *
1215 * @param admin The name of the admin component to check, or null to
1216 * aggregate all admins.
1217 * @return The minimum number of letters required in the password.
1218 */
1219 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001220 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1221 }
1222
1223 /** @hide per-user version */
1224 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001225 if (mService != null) {
1226 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001227 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001228 } catch (RemoteException e) {
1229 Log.w(TAG, "Failed talking with device policy service", e);
1230 }
1231 }
1232 return 0;
1233 }
1234
1235 /**
1236 * Called by an application that is administering the device to set the
1237 * minimum number of numerical digits required in the password. After
1238 * setting this, the user will not be able to enter a new password that is
1239 * not at least as restrictive as what has been set. Note that the current
1240 * password will remain until the user has set a new one, so the change does
1241 * not take place immediately. To prompt the user for a new password, use
1242 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1243 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001244 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1245 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001246 * <p>
1247 * The calling device admin must have requested
1248 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1249 * this method; if it has not, a security exception will be thrown.
1250 *
1251 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1252 * with.
1253 * @param length The new desired minimum number of numerical digits required
1254 * in the password. A value of 0 means there is no restriction.
1255 */
1256 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1257 if (mService != null) {
1258 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001259 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001260 } catch (RemoteException e) {
1261 Log.w(TAG, "Failed talking with device policy service", e);
1262 }
1263 }
1264 }
1265
1266 /**
1267 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001268 * for all admins of this user and its profiles or a particular one.
1269 * This is the same value as set by
1270 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001271 * and only applies when the password quality is
1272 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001273 *
1274 * @param admin The name of the admin component to check, or null to
1275 * aggregate all admins.
1276 * @return The minimum number of numerical digits required in the password.
1277 */
1278 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001279 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1280 }
1281
1282 /** @hide per-user version */
1283 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001284 if (mService != null) {
1285 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001286 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001287 } catch (RemoteException e) {
1288 Log.w(TAG, "Failed talking with device policy service", e);
1289 }
1290 }
1291 return 0;
1292 }
1293
1294 /**
1295 * Called by an application that is administering the device to set the
1296 * minimum number of symbols required in the password. After setting this,
1297 * the user will not be able to enter a new password that is not at least as
1298 * restrictive as what has been set. Note that the current password will
1299 * remain until the user has set a new one, so the change does not take
1300 * place immediately. To prompt the user for a new password, use
1301 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1302 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001303 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1304 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001305 * <p>
1306 * The calling device admin must have requested
1307 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1308 * this method; if it has not, a security exception will be thrown.
1309 *
1310 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1311 * with.
1312 * @param length The new desired minimum number of symbols required in the
1313 * password. A value of 0 means there is no restriction.
1314 */
1315 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1316 if (mService != null) {
1317 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001318 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001319 } catch (RemoteException e) {
1320 Log.w(TAG, "Failed talking with device policy service", e);
1321 }
1322 }
1323 }
1324
1325 /**
1326 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001327 * admins or a particular one. This is the same value as
1328 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1329 * and only applies when the password quality is
1330 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001331 *
1332 * @param admin The name of the admin component to check, or null to
1333 * aggregate all admins.
1334 * @return The minimum number of symbols required in the password.
1335 */
1336 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001337 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1338 }
1339
1340 /** @hide per-user version */
1341 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001342 if (mService != null) {
1343 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001344 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001345 } catch (RemoteException e) {
1346 Log.w(TAG, "Failed talking with device policy service", e);
1347 }
1348 }
1349 return 0;
1350 }
1351
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001352 /**
1353 * Called by an application that is administering the device to set the
1354 * minimum number of non-letter characters (numerical digits or symbols)
1355 * required in the password. After setting this, the user will not be able
1356 * to enter a new password that is not at least as restrictive as what has
1357 * been set. Note that the current password will remain until the user has
1358 * set a new one, so the change does not take place immediately. To prompt
1359 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1360 * setting this value. This constraint is only imposed if the administrator
1361 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1362 * {@link #setPasswordQuality}. The default value is 0.
1363 * <p>
1364 * The calling device admin must have requested
1365 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1366 * this method; if it has not, a security exception will be thrown.
1367 *
1368 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1369 * with.
1370 * @param length The new desired minimum number of letters required in the
1371 * password. A value of 0 means there is no restriction.
1372 */
1373 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1374 if (mService != null) {
1375 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001376 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001377 } catch (RemoteException e) {
1378 Log.w(TAG, "Failed talking with device policy service", e);
1379 }
1380 }
1381 }
1382
1383 /**
1384 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001385 * password for all admins of this user and its profiles or a particular one.
1386 * This is the same value as set by
1387 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001388 * and only applies when the password quality is
1389 * {@link #PASSWORD_QUALITY_COMPLEX}.
1390 *
1391 * @param admin The name of the admin component to check, or null to
1392 * aggregate all admins.
1393 * @return The minimum number of letters required in the password.
1394 */
1395 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001396 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1397 }
1398
1399 /** @hide per-user version */
1400 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001401 if (mService != null) {
1402 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001403 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001404 } catch (RemoteException e) {
1405 Log.w(TAG, "Failed talking with device policy service", e);
1406 }
1407 }
1408 return 0;
1409 }
1410
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001411 /**
1412 * Called by an application that is administering the device to set the length
1413 * of the password history. After setting this, the user will not be able to
1414 * enter a new password that is the same as any password in the history. Note
1415 * that the current password will remain until the user has set a new one, so
1416 * the change does not take place immediately. To prompt the user for a new
1417 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1418 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001419 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1420 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1421 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001422 *
1423 * <p>
1424 * The calling device admin must have requested
1425 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1426 * method; if it has not, a security exception will be thrown.
1427 *
1428 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1429 * with.
1430 * @param length The new desired length of password history. A value of 0
1431 * means there is no restriction.
1432 */
1433 public void setPasswordHistoryLength(ComponentName admin, int length) {
1434 if (mService != null) {
1435 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001436 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001437 } catch (RemoteException e) {
1438 Log.w(TAG, "Failed talking with device policy service", e);
1439 }
1440 }
1441 }
1442
1443 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001444 * Called by a device admin to set the password expiration timeout. Calling this method
1445 * will restart the countdown for password expiration for the given admin, as will changing
1446 * the device password (for all admins).
1447 *
1448 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1449 * For example, to have the password expire 5 days from now, timeout would be
1450 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1451 *
1452 * <p>To disable password expiration, a value of 0 may be used for timeout.
1453 *
Jim Millera4e28d12010-11-08 16:15:47 -08001454 * <p>The calling device admin must have requested
1455 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1456 * method; if it has not, a security exception will be thrown.
1457 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001458 * <p> Note that setting the password will automatically reset the expiration time for all
1459 * active admins. Active admins do not need to explicitly call this method in that case.
1460 *
Jim Millera4e28d12010-11-08 16:15:47 -08001461 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1462 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1463 * means there is no restriction (unlimited).
1464 */
1465 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1466 if (mService != null) {
1467 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001468 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001469 } catch (RemoteException e) {
1470 Log.w(TAG, "Failed talking with device policy service", e);
1471 }
1472 }
1473 }
1474
1475 /**
Jim Miller6b857682011-02-16 16:27:41 -08001476 * Get the password expiration timeout for the given admin. The expiration timeout is the
1477 * recurring expiration timeout provided in the call to
1478 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1479 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001480 *
1481 * @param admin The name of the admin component to check, or null to aggregate all admins.
1482 * @return The timeout for the given admin or the minimum of all timeouts
1483 */
1484 public long getPasswordExpirationTimeout(ComponentName admin) {
1485 if (mService != null) {
1486 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001487 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001488 } catch (RemoteException e) {
1489 Log.w(TAG, "Failed talking with device policy service", e);
1490 }
1491 }
1492 return 0;
1493 }
1494
1495 /**
1496 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001497 * all admins of this user and its profiles if admin is null. If the password is
1498 * expired, this will return the time since the password expired as a negative number.
1499 * If admin is null, then a composite of all expiration timeouts is returned
1500 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001501 *
1502 * @param admin The name of the admin component to check, or null to aggregate all admins.
1503 * @return The password expiration time, in ms.
1504 */
1505 public long getPasswordExpiration(ComponentName admin) {
1506 if (mService != null) {
1507 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001508 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001509 } catch (RemoteException e) {
1510 Log.w(TAG, "Failed talking with device policy service", e);
1511 }
1512 }
1513 return 0;
1514 }
1515
1516 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001517 * Retrieve the current password history length for all admins of this
1518 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001519 * @param admin The name of the admin component to check, or null to aggregate
1520 * all admins.
1521 * @return The length of the password history
1522 */
1523 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001524 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1525 }
1526
1527 /** @hide per-user version */
1528 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001529 if (mService != null) {
1530 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001531 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001532 } catch (RemoteException e) {
1533 Log.w(TAG, "Failed talking with device policy service", e);
1534 }
1535 }
1536 return 0;
1537 }
1538
Dianne Hackbornd6847842010-01-12 18:14:19 -08001539 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001540 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001541 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001542 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001543 * @return Returns the maximum length that the user can enter.
1544 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001545 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001546 // Kind-of arbitrary.
1547 return 16;
1548 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001549
Dianne Hackborn254cb442010-01-27 19:23:59 -08001550 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001551 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001552 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001553 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001554 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001555 * <p>The calling device admin must have requested
1556 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1557 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001558 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001559 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001560 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001561 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001562 if (mService != null) {
1563 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001564 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001565 } catch (RemoteException e) {
1566 Log.w(TAG, "Failed talking with device policy service", e);
1567 }
1568 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001569 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001570 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001571
Dianne Hackbornd6847842010-01-12 18:14:19 -08001572 /**
1573 * Retrieve the number of times the user has failed at entering a
1574 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001575 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001576 * <p>The calling device admin must have requested
1577 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1578 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001579 */
1580 public int getCurrentFailedPasswordAttempts() {
1581 if (mService != null) {
1582 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001583 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001584 } catch (RemoteException e) {
1585 Log.w(TAG, "Failed talking with device policy service", e);
1586 }
1587 }
1588 return -1;
1589 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001590
1591 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001592 * Setting this to a value greater than zero enables a built-in policy
1593 * that will perform a device wipe after too many incorrect
1594 * device-unlock passwords have been entered. This built-in policy combines
1595 * watching for failed passwords and wiping the device, and requires
1596 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001597 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001598 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001599 * <p>To implement any other policy (e.g. wiping data for a particular
1600 * application only, erasing or revoking credentials, or reporting the
1601 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001602 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001603 * instead. Do not use this API, because if the maximum count is reached,
1604 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001605 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001606 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001607 * @param num The number of failed password attempts at which point the
1608 * device will wipe its data.
1609 */
1610 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1611 if (mService != null) {
1612 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001613 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001614 } catch (RemoteException e) {
1615 Log.w(TAG, "Failed talking with device policy service", e);
1616 }
1617 }
1618 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001619
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001620 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001621 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001622 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001623 * or a particular one.
1624 * @param admin The name of the admin component to check, or null to aggregate
1625 * all admins.
1626 */
1627 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001628 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1629 }
1630
1631 /** @hide per-user version */
1632 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001633 if (mService != null) {
1634 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001635 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001636 } catch (RemoteException e) {
1637 Log.w(TAG, "Failed talking with device policy service", e);
1638 }
1639 }
1640 return 0;
1641 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001642
Dianne Hackborn254cb442010-01-27 19:23:59 -08001643 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001644 * Returns the profile with the smallest maximum failed passwords for wipe,
1645 * for the given user. So for primary user, it might return the primary or
1646 * a managed profile. For a secondary user, it would be the same as the
1647 * user passed in.
1648 * @hide Used only by Keyguard
1649 */
1650 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1651 if (mService != null) {
1652 try {
1653 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1654 } catch (RemoteException e) {
1655 Log.w(TAG, "Failed talking with device policy service", e);
1656 }
1657 }
1658 return UserHandle.USER_NULL;
1659 }
1660
1661 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001662 * Flag for {@link #resetPassword}: don't allow other admins to change
1663 * the password again until the user has entered it.
1664 */
1665 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001666
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001667 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001668 * Force a new device unlock password (the password needed to access the
1669 * entire device, not for individual accounts) on the user. This takes
1670 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001671 * The given password must be sufficient for the
1672 * current password quality and length constraints as returned by
1673 * {@link #getPasswordQuality(ComponentName)} and
1674 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1675 * these constraints, then it will be rejected and false returned. Note
1676 * that the password may be a stronger quality (containing alphanumeric
1677 * characters when the requested quality is only numeric), in which case
1678 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001679 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001680 * <p>Calling with a null or empty password will clear any existing PIN,
1681 * pattern or password if the current password constraints allow it.
1682 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001683 * <p>The calling device admin must have requested
1684 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1685 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001686 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001687 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001688 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001689 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001690 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001691 * @return Returns true if the password was applied, or false if it is
1692 * not acceptable for the current constraints.
1693 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001694 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001695 if (mService != null) {
1696 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001697 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001698 } catch (RemoteException e) {
1699 Log.w(TAG, "Failed talking with device policy service", e);
1700 }
1701 }
1702 return false;
1703 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001704
Dianne Hackbornd6847842010-01-12 18:14:19 -08001705 /**
1706 * Called by an application that is administering the device to set the
1707 * maximum time for user activity until the device will lock. This limits
1708 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001709 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001710 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001711 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001712 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001713 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001714 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001715 * @param timeMs The new desired maximum time to lock in milliseconds.
1716 * A value of 0 means there is no restriction.
1717 */
1718 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1719 if (mService != null) {
1720 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001721 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001722 } catch (RemoteException e) {
1723 Log.w(TAG, "Failed talking with device policy service", e);
1724 }
1725 }
1726 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001727
Dianne Hackbornd6847842010-01-12 18:14:19 -08001728 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001729 * Retrieve the current maximum time to unlock for all admins of this user
1730 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001731 * @param admin The name of the admin component to check, or null to aggregate
1732 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001733 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001734 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001735 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001736 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001737 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1738 }
1739
1740 /** @hide per-user version */
1741 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001742 if (mService != null) {
1743 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001744 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001745 } catch (RemoteException e) {
1746 Log.w(TAG, "Failed talking with device policy service", e);
1747 }
1748 }
1749 return 0;
1750 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001751
Dianne Hackbornd6847842010-01-12 18:14:19 -08001752 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001753 * Make the device lock immediately, as if the lock screen timeout has
1754 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001755 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001756 * <p>The calling device admin must have requested
1757 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1758 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001759 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001760 public void lockNow() {
1761 if (mService != null) {
1762 try {
1763 mService.lockNow();
1764 } catch (RemoteException e) {
1765 Log.w(TAG, "Failed talking with device policy service", e);
1766 }
1767 }
1768 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001769
Dianne Hackbornd6847842010-01-12 18:14:19 -08001770 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001771 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001772 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001773 */
1774 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1775
1776 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001777 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1778 * data.
1779 *
Paul Crowley2934b262014-12-02 11:21:13 +00001780 * <p>This flag may only be set by device owner admins; if it is set by
1781 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001782 */
1783 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1784
1785 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001786 * Ask the user data be wiped. Wiping the primary user will cause the
1787 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001788 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001789 * <p>The calling device admin must have requested
1790 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1791 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001792 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001793 * @param flags Bit mask of additional options: currently supported flags
1794 * are {@link #WIPE_EXTERNAL_STORAGE} and
1795 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001796 */
1797 public void wipeData(int flags) {
1798 if (mService != null) {
1799 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001800 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001801 } catch (RemoteException e) {
1802 Log.w(TAG, "Failed talking with device policy service", e);
1803 }
1804 }
1805 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001806
Dianne Hackbornd6847842010-01-12 18:14:19 -08001807 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001808 * Called by an application that is administering the device to set the
1809 * global proxy and exclusion list.
1810 * <p>
1811 * The calling device admin must have requested
1812 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1813 * this method; if it has not, a security exception will be thrown.
1814 * Only the first device admin can set the proxy. If a second admin attempts
1815 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1816 * proxy will be returned. If successful in setting the proxy, null will
1817 * be returned.
1818 * The method can be called repeatedly by the device admin alrady setting the
1819 * proxy to update the proxy and exclusion list.
1820 *
1821 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1822 * with.
1823 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1824 * Pass Proxy.NO_PROXY to reset the proxy.
1825 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001826 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1827 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001828 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001829 */
1830 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1831 List<String> exclusionList ) {
1832 if (proxySpec == null) {
1833 throw new NullPointerException();
1834 }
1835 if (mService != null) {
1836 try {
1837 String hostSpec;
1838 String exclSpec;
1839 if (proxySpec.equals(Proxy.NO_PROXY)) {
1840 hostSpec = null;
1841 exclSpec = null;
1842 } else {
1843 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1844 throw new IllegalArgumentException();
1845 }
1846 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1847 String hostName = sa.getHostName();
1848 int port = sa.getPort();
1849 StringBuilder hostBuilder = new StringBuilder();
1850 hostSpec = hostBuilder.append(hostName)
1851 .append(":").append(Integer.toString(port)).toString();
1852 if (exclusionList == null) {
1853 exclSpec = "";
1854 } else {
1855 StringBuilder listBuilder = new StringBuilder();
1856 boolean firstDomain = true;
1857 for (String exclDomain : exclusionList) {
1858 if (!firstDomain) {
1859 listBuilder = listBuilder.append(",");
1860 } else {
1861 firstDomain = false;
1862 }
1863 listBuilder = listBuilder.append(exclDomain.trim());
1864 }
1865 exclSpec = listBuilder.toString();
1866 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001867 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1868 != android.net.Proxy.PROXY_VALID)
1869 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001870 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001871 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001872 } catch (RemoteException e) {
1873 Log.w(TAG, "Failed talking with device policy service", e);
1874 }
1875 }
1876 return null;
1877 }
1878
1879 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001880 * Set a network-independent global HTTP proxy. This is not normally what you want
1881 * for typical HTTP proxies - they are generally network dependent. However if you're
1882 * doing something unusual like general internal filtering this may be useful. On
1883 * a private network where the proxy is not accessible, you may break HTTP using this.
1884 *
1885 * <p>This method requires the caller to be the device owner.
1886 *
1887 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1888 * @see ProxyInfo
1889 *
1890 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1891 * with.
1892 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1893 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1894 */
1895 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1896 if (mService != null) {
1897 try {
1898 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1899 } catch (RemoteException e) {
1900 Log.w(TAG, "Failed talking with device policy service", e);
1901 }
1902 }
1903 }
1904
1905 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001906 * Returns the component name setting the global proxy.
1907 * @return ComponentName object of the device admin that set the global proxy, or
1908 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001909 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001910 */
1911 public ComponentName getGlobalProxyAdmin() {
1912 if (mService != null) {
1913 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001914 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001915 } catch (RemoteException e) {
1916 Log.w(TAG, "Failed talking with device policy service", e);
1917 }
1918 }
1919 return null;
1920 }
1921
1922 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001923 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001924 * indicating that encryption is not supported.
1925 */
1926 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1927
1928 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001929 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001930 * indicating that encryption is supported, but is not currently active.
1931 */
1932 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1933
1934 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001935 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001936 * indicating that encryption is not currently active, but is currently
1937 * being activated. This is only reported by devices that support
1938 * encryption of data and only when the storage is currently
1939 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1940 * to become encrypted will never return this value.
1941 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001942 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001943
1944 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001945 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001946 * indicating that encryption is active.
1947 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001948 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001949
1950 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001951 * Result code for {@link #getStorageEncryptionStatus}:
1952 * indicating that encryption is active, but an encryption key has not
1953 * been set by the user.
1954 */
1955 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1956
1957 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001958 * Activity action: begin the process of encrypting data on the device. This activity should
1959 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1960 * After resuming from this activity, use {@link #getStorageEncryption}
1961 * to check encryption status. However, on some devices this activity may never return, as
1962 * it may trigger a reboot and in some cases a complete data wipe of the device.
1963 */
1964 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1965 public static final String ACTION_START_ENCRYPTION
1966 = "android.app.action.START_ENCRYPTION";
1967
1968 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001969 * Widgets are enabled in keyguard
1970 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001971 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001972
1973 /**
Jim Miller50e62182014-04-23 17:25:00 -07001974 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001975 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001976 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1977
1978 /**
1979 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1980 */
1981 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1982
1983 /**
Jim Miller50e62182014-04-23 17:25:00 -07001984 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1985 */
1986 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1987
1988 /**
1989 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1990 */
1991 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1992
1993 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001994 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001995 * (e.g. PIN/Pattern/Password).
1996 */
1997 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1998
1999 /**
Jim Miller06e34502014-07-17 14:46:05 -07002000 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2001 */
2002 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2003
2004 /**
Jim Miller35207742012-11-02 15:33:20 -07002005 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002006 */
2007 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002008
2009 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002010 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002011 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002012 *
2013 * <p>When multiple device administrators attempt to control device
2014 * encryption, the most secure, supported setting will always be
2015 * used. If any device administrator requests device encryption,
2016 * it will be enabled; Conversely, if a device administrator
2017 * attempts to disable device encryption while another
2018 * device administrator has enabled it, the call to disable will
2019 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2020 *
2021 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002022 * written to other storage areas may or may not be encrypted, and this policy does not require
2023 * or control the encryption of any other storage areas.
2024 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2025 * {@code true}, then the directory returned by
2026 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2027 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002028 *
2029 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2030 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2031 * the encryption key may not be fully secured. For maximum security, the administrator should
2032 * also require (and check for) a pattern, PIN, or password.
2033 *
2034 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2035 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002036 * @return the new request status (for all active admins) - will be one of
2037 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2038 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2039 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002040 */
2041 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
2042 if (mService != null) {
2043 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002044 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002045 } catch (RemoteException e) {
2046 Log.w(TAG, "Failed talking with device policy service", e);
2047 }
2048 }
2049 return ENCRYPTION_STATUS_UNSUPPORTED;
2050 }
2051
2052 /**
2053 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002054 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002055 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2057 * this will return the requested encryption setting as an aggregate of all active
2058 * administrators.
2059 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002060 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002061 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002062 if (mService != null) {
2063 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002064 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002065 } catch (RemoteException e) {
2066 Log.w(TAG, "Failed talking with device policy service", e);
2067 }
2068 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002069 return false;
2070 }
2071
2072 /**
2073 * Called by an application that is administering the device to
2074 * determine the current encryption status of the device.
2075 *
2076 * Depending on the returned status code, the caller may proceed in different
2077 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2078 * storage system does not support encryption. If the
2079 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2080 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002081 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2082 * storage system has enabled encryption but no password is set so further action
2083 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002084 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2085 *
Robin Lee7e678712014-07-24 16:41:31 +01002086 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002087 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002088 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2089 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002090 */
2091 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002092 return getStorageEncryptionStatus(UserHandle.myUserId());
2093 }
2094
2095 /** @hide per-user version */
2096 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002097 if (mService != null) {
2098 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002099 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002100 } catch (RemoteException e) {
2101 Log.w(TAG, "Failed talking with device policy service", e);
2102 }
2103 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002104 return ENCRYPTION_STATUS_UNSUPPORTED;
2105 }
2106
2107 /**
Robin Lee7e678712014-07-24 16:41:31 +01002108 * Installs the given certificate as a user CA.
2109 *
Rubin Xuec32b562015-03-03 17:34:05 +00002110 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2111 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002112 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002113 *
2114 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002115 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002116 */
Robin Lee7e678712014-07-24 16:41:31 +01002117 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002118 if (mService != null) {
2119 try {
Robin Lee7e678712014-07-24 16:41:31 +01002120 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002121 } catch (RemoteException e) {
2122 Log.w(TAG, "Failed talking with device policy service", e);
2123 }
2124 }
2125 return false;
2126 }
2127
2128 /**
Robin Lee7e678712014-07-24 16:41:31 +01002129 * Uninstalls the given certificate from trusted user CAs, if present.
2130 *
Rubin Xuec32b562015-03-03 17:34:05 +00002131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2132 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002133 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002134 */
Robin Lee7e678712014-07-24 16:41:31 +01002135 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002136 if (mService != null) {
2137 try {
Robin Lee306fe082014-06-19 14:04:24 +00002138 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002139 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002140 } catch (CertificateException e) {
2141 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002142 } catch (RemoteException e) {
2143 Log.w(TAG, "Failed talking with device policy service", e);
2144 }
2145 }
2146 }
2147
2148 /**
Robin Lee7e678712014-07-24 16:41:31 +01002149 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2150 * If a user has installed any certificates by other means than device policy these will be
2151 * included too.
2152 *
Rubin Xuec32b562015-03-03 17:34:05 +00002153 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2154 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002155 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002156 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002157 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002158 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002159 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002160 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002161 mService.enforceCanManageCaCerts(admin);
2162 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2163 for (String alias : certStore.userAliases()) {
2164 try {
2165 certs.add(certStore.getCertificate(alias).getEncoded());
2166 } catch (CertificateException ce) {
2167 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2168 }
2169 }
2170 } catch (RemoteException re) {
2171 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002172 }
2173 }
2174 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002175 }
2176
2177 /**
Robin Lee7e678712014-07-24 16:41:31 +01002178 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2179 * means other than device policy will also be removed, except for system CA certificates.
2180 *
Rubin Xuec32b562015-03-03 17:34:05 +00002181 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2182 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002183 */
2184 public void uninstallAllUserCaCerts(ComponentName admin) {
2185 if (mService != null) {
2186 for (String alias : new TrustedCertificateStore().userAliases()) {
2187 try {
2188 mService.uninstallCaCert(admin, alias);
2189 } catch (RemoteException re) {
2190 Log.w(TAG, "Failed talking with device policy service", re);
2191 }
2192 }
2193 }
2194 }
2195
2196 /**
2197 * Returns whether this certificate is installed as a trusted CA.
2198 *
Rubin Xuec32b562015-03-03 17:34:05 +00002199 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2200 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002201 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002202 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002203 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2204 if (mService != null) {
2205 try {
2206 mService.enforceCanManageCaCerts(admin);
2207 return getCaCertAlias(certBuffer) != null;
2208 } catch (RemoteException re) {
2209 Log.w(TAG, "Failed talking with device policy service", re);
2210 } catch (CertificateException ce) {
2211 Log.w(TAG, "Could not parse certificate", ce);
2212 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002213 }
2214 return false;
2215 }
2216
2217 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002218 * Called by a device or profile owner to install a certificate and private key pair. The
2219 * keypair will be visible to all apps within the profile.
2220 *
Rubin Xuacdc1832015-04-02 12:40:20 +01002221 * @param who Which {@link DeviceAdminReceiver} this request is associated with. Use
2222 * <code>null</code> if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002223 * @param privKey The private key to install.
2224 * @param cert The certificate to install.
2225 * @param alias The private key alias under which to install the certificate. If a certificate
2226 * with that alias already exists, it will be overwritten.
2227 * @return {@code true} if the keys were installed, {@code false} otherwise.
2228 */
2229 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2230 String alias) {
2231 try {
2232 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002233 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2234 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2235 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002236 } catch (RemoteException e) {
2237 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002238 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2239 Log.w(TAG, "Failed to obtain private key material", e);
2240 } catch (CertificateException | IOException e) {
2241 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002242 }
2243 return false;
2244 }
2245
2246 /**
Robin Lee306fe082014-06-19 14:04:24 +00002247 * Returns the alias of a given CA certificate in the certificate store, or null if it
2248 * doesn't exist.
2249 */
2250 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2251 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2252 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2253 new ByteArrayInputStream(certBuffer));
2254 return new TrustedCertificateStore().getCertificateAlias(cert);
2255 }
2256
2257 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002258 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002259 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002260 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002261 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002262 * <p>
2263 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2264 * it is later cleared by calling this method with a null value or uninstallling the certificate
2265 * installer.
2266 *
2267 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2268 * @param installerPackage The package name of the certificate installer which will be given
2269 * access. If <code>null</code> is given the current package will be cleared.
2270 */
2271 public void setCertInstallerPackage(ComponentName who, String installerPackage)
2272 throws SecurityException {
2273 if (mService != null) {
2274 try {
2275 mService.setCertInstallerPackage(who, installerPackage);
2276 } catch (RemoteException e) {
2277 Log.w(TAG, "Failed talking with device policy service", e);
2278 }
2279 }
2280 }
2281
2282 /**
2283 * Called by a profile owner or device owner to retrieve the certificate installer for the
2284 * current user. null if none is set.
2285 *
2286 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2287 * @return The package name of the current delegated certificate installer. <code>null</code>
2288 * if none is set.
2289 */
2290 public String getCertInstallerPackage(ComponentName who) throws SecurityException {
2291 if (mService != null) {
2292 try {
2293 return mService.getCertInstallerPackage(who);
2294 } catch (RemoteException e) {
2295 Log.w(TAG, "Failed talking with device policy service", e);
2296 }
2297 }
2298 return null;
2299 }
2300
2301 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002302 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002303 * on the device, for this user. After setting this, no applications running as this user
2304 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002305 *
2306 * <p>The calling device admin must have requested
2307 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2308 * this method; if it has not, a security exception will be thrown.
2309 *
2310 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2311 * @param disabled Whether or not the camera should be disabled.
2312 */
2313 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2314 if (mService != null) {
2315 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002316 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002317 } catch (RemoteException e) {
2318 Log.w(TAG, "Failed talking with device policy service", e);
2319 }
2320 }
2321 }
2322
2323 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002324 * Determine whether or not the device's cameras have been disabled for this user,
2325 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002326 * @param admin The name of the admin component to check, or null to check if any admins
2327 * have disabled the camera
2328 */
2329 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002330 return getCameraDisabled(admin, UserHandle.myUserId());
2331 }
2332
2333 /** @hide per-user version */
2334 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002335 if (mService != null) {
2336 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002337 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002338 } catch (RemoteException e) {
2339 Log.w(TAG, "Failed talking with device policy service", e);
2340 }
2341 }
2342 return false;
2343 }
2344
2345 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002346 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2347 * screen capture also prevents the content from being shown on display devices that do not have
2348 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2349 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002350 *
2351 * <p>The calling device admin must be a device or profile owner. If it is not, a
2352 * security exception will be thrown.
2353 *
2354 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002355 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002356 */
2357 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2358 if (mService != null) {
2359 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002360 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002361 } catch (RemoteException e) {
2362 Log.w(TAG, "Failed talking with device policy service", e);
2363 }
2364 }
2365 }
2366
2367 /**
2368 * Determine whether or not screen capture has been disabled by the current
2369 * admin, if specified, or all admins.
2370 * @param admin The name of the admin component to check, or null to check if any admins
2371 * have disabled screen capture.
2372 */
2373 public boolean getScreenCaptureDisabled(ComponentName admin) {
2374 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2375 }
2376
2377 /** @hide per-user version */
2378 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2379 if (mService != null) {
2380 try {
2381 return mService.getScreenCaptureDisabled(admin, userHandle);
2382 } catch (RemoteException e) {
2383 Log.w(TAG, "Failed talking with device policy service", e);
2384 }
2385 }
2386 return false;
2387 }
2388
2389 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002390 * Called by a device owner to set whether auto time is required. If auto time is
2391 * required the user cannot set the date and time, but has to use network date and time.
2392 *
2393 * <p>Note: if auto time is required the user can still manually set the time zone.
2394 *
2395 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2396 * be thrown.
2397 *
2398 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2399 * @param required Whether auto time is set required or not.
2400 */
2401 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2402 if (mService != null) {
2403 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002404 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002405 } catch (RemoteException e) {
2406 Log.w(TAG, "Failed talking with device policy service", e);
2407 }
2408 }
2409 }
2410
2411 /**
2412 * @return true if auto time is required.
2413 */
2414 public boolean getAutoTimeRequired() {
2415 if (mService != null) {
2416 try {
2417 return mService.getAutoTimeRequired();
2418 } catch (RemoteException e) {
2419 Log.w(TAG, "Failed talking with device policy service", e);
2420 }
2421 }
2422 return false;
2423 }
2424
2425 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002426 * Called by an application that is administering the device to disable keyguard customizations,
2427 * such as widgets. After setting this, keyguard features will be disabled according to the
2428 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002429 *
2430 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002431 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002432 * this method; if it has not, a security exception will be thrown.
2433 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002434 * <p>Calling this from a managed profile will throw a security exception.
2435 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002436 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002437 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2438 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002439 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2440 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002441 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002442 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002443 if (mService != null) {
2444 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002445 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002446 } catch (RemoteException e) {
2447 Log.w(TAG, "Failed talking with device policy service", e);
2448 }
2449 }
2450 }
2451
2452 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002453 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002454 * admin, if specified, or all admins.
2455 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002456 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002457 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2458 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002459 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002460 public int getKeyguardDisabledFeatures(ComponentName admin) {
2461 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002462 }
2463
2464 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002465 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002466 if (mService != null) {
2467 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002468 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002469 } catch (RemoteException e) {
2470 Log.w(TAG, "Failed talking with device policy service", e);
2471 }
2472 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002473 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002474 }
2475
2476 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002477 * @hide
2478 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002479 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002480 if (mService != null) {
2481 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002482 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002483 } catch (RemoteException e) {
2484 Log.w(TAG, "Failed talking with device policy service", e);
2485 }
2486 }
2487 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002488
Dianne Hackbornd6847842010-01-12 18:14:19 -08002489 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002490 * @hide
2491 */
2492 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2493 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2494 }
2495
2496 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002497 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002498 * @hide
2499 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002500 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002501 ActivityInfo ai;
2502 try {
2503 ai = mContext.getPackageManager().getReceiverInfo(cn,
2504 PackageManager.GET_META_DATA);
2505 } catch (PackageManager.NameNotFoundException e) {
2506 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2507 return null;
2508 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002509
Dianne Hackbornd6847842010-01-12 18:14:19 -08002510 ResolveInfo ri = new ResolveInfo();
2511 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002512
Dianne Hackbornd6847842010-01-12 18:14:19 -08002513 try {
2514 return new DeviceAdminInfo(mContext, ri);
2515 } catch (XmlPullParserException e) {
2516 Log.w(TAG, "Unable to parse device policy " + cn, e);
2517 return null;
2518 } catch (IOException e) {
2519 Log.w(TAG, "Unable to parse device policy " + cn, e);
2520 return null;
2521 }
2522 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002523
Dianne Hackbornd6847842010-01-12 18:14:19 -08002524 /**
2525 * @hide
2526 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002527 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2528 if (mService != null) {
2529 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002530 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002531 } catch (RemoteException e) {
2532 Log.w(TAG, "Failed talking with device policy service", e);
2533 }
2534 }
2535 }
2536
2537 /**
2538 * @hide
2539 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002540 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002541 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002542 if (mService != null) {
2543 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002544 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002545 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002546 } catch (RemoteException e) {
2547 Log.w(TAG, "Failed talking with device policy service", e);
2548 }
2549 }
2550 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002551
Dianne Hackbornd6847842010-01-12 18:14:19 -08002552 /**
2553 * @hide
2554 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002555 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002556 if (mService != null) {
2557 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002558 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002559 } catch (RemoteException e) {
2560 Log.w(TAG, "Failed talking with device policy service", e);
2561 }
2562 }
2563 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002564
Dianne Hackbornd6847842010-01-12 18:14:19 -08002565 /**
2566 * @hide
2567 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002568 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002569 if (mService != null) {
2570 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002571 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002572 } catch (RemoteException e) {
2573 Log.w(TAG, "Failed talking with device policy service", e);
2574 }
2575 }
2576 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002577
2578 /**
2579 * @hide
2580 * Sets the given package as the device owner. The package must already be installed and there
2581 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2582 * method must be called before the device is provisioned.
2583 * @param packageName the package name of the application to be registered as the device owner.
2584 * @return whether the package was successfully registered as the device owner.
2585 * @throws IllegalArgumentException if the package name is null or invalid
2586 * @throws IllegalStateException if a device owner is already registered or the device has
2587 * already been provisioned.
2588 */
2589 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2590 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002591 return setDeviceOwner(packageName, null);
2592 }
2593
2594 /**
2595 * @hide
2596 * Sets the given package as the device owner. The package must already be installed and there
2597 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2598 * method must be called before the device is provisioned.
2599 * @param packageName the package name of the application to be registered as the device owner.
2600 * @param ownerName the human readable name of the institution that owns this device.
2601 * @return whether the package was successfully registered as the device owner.
2602 * @throws IllegalArgumentException if the package name is null or invalid
2603 * @throws IllegalStateException if a device owner is already registered or the device has
2604 * already been provisioned.
2605 */
2606 public boolean setDeviceOwner(String packageName, String ownerName)
2607 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002608 if (mService != null) {
2609 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002610 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002611 } catch (RemoteException re) {
2612 Log.w(TAG, "Failed to set device owner");
2613 }
2614 }
2615 return false;
2616 }
2617
2618 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002619 * Used to determine if a particular package has been registered as a Device Owner app.
2620 * A device owner app is a special device admin that cannot be deactivated by the user, once
2621 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2622 * package is currently registered as the device owner app, pass in the package name from
2623 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2624 * admin apps that want to check if they are also registered as the device owner app. The
2625 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2626 * the setup process.
2627 * @param packageName the package name of the app, to compare with the registered device owner
2628 * app, if any.
2629 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002630 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002631 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002632 if (mService != null) {
2633 try {
2634 return mService.isDeviceOwner(packageName);
2635 } catch (RemoteException re) {
2636 Log.w(TAG, "Failed to check device owner");
2637 }
2638 }
2639 return false;
2640 }
2641
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002642 /**
2643 * @hide
2644 * Redirect to isDeviceOwnerApp.
2645 */
2646 public boolean isDeviceOwner(String packageName) {
2647 return isDeviceOwnerApp(packageName);
2648 }
2649
Jason Monkb0dced82014-06-06 14:36:20 -04002650 /**
2651 * Clears the current device owner. The caller must be the device owner.
2652 *
2653 * This function should be used cautiously as once it is called it cannot
2654 * be undone. The device owner can only be set as a part of device setup
2655 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002656 *
2657 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002658 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002659 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002660 if (mService != null) {
2661 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002662 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002663 } catch (RemoteException re) {
2664 Log.w(TAG, "Failed to clear device owner");
2665 }
2666 }
2667 }
2668
Amith Yamasani71e6c692013-03-24 17:39:28 -07002669 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002670 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002671 public String getDeviceOwner() {
2672 if (mService != null) {
2673 try {
2674 return mService.getDeviceOwner();
2675 } catch (RemoteException re) {
2676 Log.w(TAG, "Failed to get device owner");
2677 }
2678 }
2679 return null;
2680 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002681
2682 /** @hide */
2683 public String getDeviceOwnerName() {
2684 if (mService != null) {
2685 try {
2686 return mService.getDeviceOwnerName();
2687 } catch (RemoteException re) {
2688 Log.w(TAG, "Failed to get device owner");
2689 }
2690 }
2691 return null;
2692 }
Adam Connors776c5552014-01-09 10:42:56 +00002693
2694 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002695 * Sets the given component as the device initializer. The package must already be installed and
2696 * set as an active device administrator, and there must not be an existing device initializer,
2697 * for this call to succeed. This method can only be called by an app holding the
2698 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2699 * device initializer app is granted device owner privileges during device initialization and
2700 * profile owner privileges during secondary user initialization.
2701 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2702 * called by the device owner.
2703 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2704 * @param initializerName The user-visible name of the device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002705 * @return whether the component was successfully registered as the device initializer.
2706 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002707 * @throws IllegalStateException if the caller is not device owner or the device has
2708 * already been provisioned or a device initializer already exists.
2709 */
2710 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2711 String initializerName) throws IllegalArgumentException, IllegalStateException {
2712 if (mService != null) {
2713 try {
2714 return mService.setDeviceInitializer(who, initializer, initializerName);
2715 } catch (RemoteException re) {
2716 Log.w(TAG, "Failed to set device initializer");
2717 }
2718 }
2719 return false;
2720 }
2721
2722 /**
2723 * Used to determine if a particular package has been registered as the device initializer.
2724 *
2725 * @param packageName the package name of the app, to compare with the registered device
2726 * initializer app, if any.
2727 * @return whether or not the caller is registered as the device initializer app.
2728 */
2729 public boolean isDeviceInitializerApp(String packageName) {
2730 if (mService != null) {
2731 try {
2732 return mService.isDeviceInitializer(packageName);
2733 } catch (RemoteException re) {
2734 Log.w(TAG, "Failed to check device initializer");
2735 }
2736 }
2737 return false;
2738 }
2739
2740 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002741 * Removes the device initializer, so that it will not be invoked on user initialization for any
2742 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002743 * initializer itself. The caller must be an active administrator.
2744 *
2745 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002746 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002747 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002748 if (mService != null) {
2749 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002750 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002751 } catch (RemoteException re) {
2752 Log.w(TAG, "Failed to clear device initializer");
2753 }
2754 }
2755 }
2756
2757 /**
2758 * @hide
2759 * Gets the device initializer of the system.
2760 *
2761 * @return the package name of the device initializer.
2762 */
2763 @SystemApi
2764 public String getDeviceInitializerApp() {
2765 if (mService != null) {
2766 try {
2767 return mService.getDeviceInitializer();
2768 } catch (RemoteException re) {
2769 Log.w(TAG, "Failed to get device initializer");
2770 }
2771 }
2772 return null;
2773 }
2774
2775 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002776 * @hide
2777 * Gets the device initializer component of the system.
2778 *
2779 * @return the component name of the device initializer.
2780 */
2781 @SystemApi
2782 public ComponentName getDeviceInitializerComponent() {
2783 if (mService != null) {
2784 try {
2785 return mService.getDeviceInitializerComponent();
2786 } catch (RemoteException re) {
2787 Log.w(TAG, "Failed to get device initializer");
2788 }
2789 }
2790 return null;
2791 }
2792
2793
2794 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002795 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2796 * be used.
2797 *
2798 * <p>Device initializer must call this method to mark the user as functional.
2799 * Only the device initializer agent can call this.
2800 *
2801 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2802 * device initializer will no longer have elevated permissions to call methods in this class.
2803 * Additionally, it will be removed as an active administrator and its
2804 * {@link DeviceAdminReceiver} will be disabled.
2805 *
2806 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2807 * @return whether the user is now enabled.
2808 */
2809 public boolean setUserEnabled(ComponentName admin) {
2810 if (mService != null) {
2811 try {
2812 return mService.setUserEnabled(admin);
2813 } catch (RemoteException e) {
2814 Log.w(TAG, "Failed talking with device policy service", e);
2815 }
2816 }
2817 return false;
2818 }
2819
2820 /**
Adam Connors776c5552014-01-09 10:42:56 +00002821 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002822 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302823 * Sets the given component as an active admin and registers the package as the profile
2824 * owner for this user. The package must already be installed and there shouldn't be
2825 * an existing profile owner registered for this user. Also, this method must be called
2826 * before the user setup has been completed.
2827 * <p>
2828 * This method can only be called by system apps that hold MANAGE_USERS permission and
2829 * MANAGE_DEVICE_ADMINS permission.
2830 * @param admin The component to register as an active admin and profile owner.
2831 * @param ownerName The user-visible name of the entity that is managing this user.
2832 * @return whether the admin was successfully registered as the profile owner.
2833 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2834 * the user has already been set up.
2835 */
Justin Morey80440cc2014-07-24 09:16:35 -05002836 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302837 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2838 throws IllegalArgumentException {
2839 if (mService != null) {
2840 try {
2841 final int myUserId = UserHandle.myUserId();
2842 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002843 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302844 } catch (RemoteException re) {
2845 Log.w(TAG, "Failed to set profile owner " + re);
2846 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2847 }
2848 }
2849 return false;
2850 }
2851
2852 /**
2853 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002854 * Clears the active profile owner and removes all user restrictions. The caller must
2855 * be from the same package as the active profile owner for this user, otherwise a
2856 * SecurityException will be thrown.
2857 *
2858 * @param admin The component to remove as the profile owner.
2859 * @return
2860 */
2861 @SystemApi
2862 public void clearProfileOwner(ComponentName admin) {
2863 if (mService != null) {
2864 try {
2865 mService.clearProfileOwner(admin);
2866 } catch (RemoteException re) {
2867 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2868 }
2869 }
2870 }
2871
2872 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002873 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002874 * Checks if the user was already setup.
2875 */
2876 public boolean hasUserSetupCompleted() {
2877 if (mService != null) {
2878 try {
2879 return mService.hasUserSetupCompleted();
2880 } catch (RemoteException re) {
2881 Log.w(TAG, "Failed to check if user setup has completed");
2882 }
2883 }
2884 return true;
2885 }
2886
2887 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002888 * @hide
2889 * Sets the given component as the profile owner of the given user profile. The package must
2890 * already be installed and there shouldn't be an existing profile owner registered for this
2891 * user. Only the system can call this API if the user has already completed setup.
2892 * @param admin the component name to be registered as profile owner.
2893 * @param ownerName the human readable name of the organisation associated with this DPM.
2894 * @param userHandle the userId to set the profile owner for.
2895 * @return whether the component was successfully registered as the profile owner.
2896 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2897 * the user has already been set up.
2898 */
2899 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2900 throws IllegalArgumentException {
2901 if (admin == null) {
2902 throw new NullPointerException("admin cannot be null");
2903 }
Adam Connors776c5552014-01-09 10:42:56 +00002904 if (mService != null) {
2905 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002906 if (ownerName == null) {
2907 ownerName = "";
2908 }
2909 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002910 } catch (RemoteException re) {
2911 Log.w(TAG, "Failed to set profile owner", re);
2912 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2913 }
2914 }
2915 return false;
2916 }
2917
2918 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002919 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2920 * be used. Only the profile owner can call this.
2921 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002922 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002923 *
2924 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2925 */
2926 public void setProfileEnabled(ComponentName admin) {
2927 if (mService != null) {
2928 try {
2929 mService.setProfileEnabled(admin);
2930 } catch (RemoteException e) {
2931 Log.w(TAG, "Failed talking with device policy service", e);
2932 }
2933 }
2934 }
2935
2936 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002937 * Sets the name of the profile. In the device owner case it sets the name of the user
2938 * 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 +01002939 * never called by the profile or device owner, the name will be set to default values.
2940 *
2941 * @see #isProfileOwnerApp
2942 * @see #isDeviceOwnerApp
2943 *
2944 * @param profileName The name of the profile.
2945 */
2946 public void setProfileName(ComponentName who, String profileName) {
2947 if (mService != null) {
2948 try {
2949 mService.setProfileName(who, profileName);
2950 } catch (RemoteException e) {
2951 Log.w(TAG, "Failed talking with device policy service", e);
2952 }
2953 }
2954}
2955
2956 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002957 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002958 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002959 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002960 *
2961 * @param packageName The package name of the app to compare with the registered profile owner.
2962 * @return Whether or not the package is registered as the profile owner.
2963 */
2964 public boolean isProfileOwnerApp(String packageName) {
2965 if (mService != null) {
2966 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002967 ComponentName profileOwner = mService.getProfileOwner(
2968 Process.myUserHandle().getIdentifier());
2969 return profileOwner != null
2970 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002971 } catch (RemoteException re) {
2972 Log.w(TAG, "Failed to check profile owner");
2973 }
2974 }
2975 return false;
2976 }
2977
2978 /**
2979 * @hide
2980 * @return the packageName of the owner of the given user profile or null if no profile
2981 * owner has been set for that user.
2982 * @throws IllegalArgumentException if the userId is invalid.
2983 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002984 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002985 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002986 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2987 }
2988
2989 /**
2990 * @see #getProfileOwner()
2991 * @hide
2992 */
2993 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002994 if (mService != null) {
2995 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002996 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002997 } catch (RemoteException re) {
2998 Log.w(TAG, "Failed to get profile owner");
2999 throw new IllegalArgumentException(
3000 "Requested profile owner for invalid userId", re);
3001 }
3002 }
3003 return null;
3004 }
3005
3006 /**
3007 * @hide
3008 * @return the human readable name of the organisation associated with this DPM or null if
3009 * one is not set.
3010 * @throws IllegalArgumentException if the userId is invalid.
3011 */
3012 public String getProfileOwnerName() throws IllegalArgumentException {
3013 if (mService != null) {
3014 try {
3015 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3016 } catch (RemoteException re) {
3017 Log.w(TAG, "Failed to get profile owner");
3018 throw new IllegalArgumentException(
3019 "Requested profile owner for invalid userId", re);
3020 }
3021 }
3022 return null;
3023 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003024
3025 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003026 * @hide
3027 * @param user The user for whom to fetch the profile owner name, if any.
3028 * @return the human readable name of the organisation associated with this profile owner or
3029 * null if one is not set.
3030 * @throws IllegalArgumentException if the userId is invalid.
3031 */
3032 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003033 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003034 if (mService != null) {
3035 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003036 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003037 } catch (RemoteException re) {
3038 Log.w(TAG, "Failed to get profile owner");
3039 throw new IllegalArgumentException(
3040 "Requested profile owner for invalid userId", re);
3041 }
3042 }
3043 return null;
3044 }
3045
3046 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003047 * Called by a profile owner or device owner to add a default intent handler activity for
3048 * intents that match a certain intent filter. This activity will remain the default intent
3049 * handler even if the set of potential event handlers for the intent filter changes and if
3050 * the intent preferences are reset.
3051 *
3052 * <p>The default disambiguation mechanism takes over if the activity is not installed
3053 * (anymore). When the activity is (re)installed, it is automatically reset as default
3054 * intent handler for the filter.
3055 *
3056 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3057 * security exception will be thrown.
3058 *
3059 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3060 * @param filter The IntentFilter for which a default handler is added.
3061 * @param activity The Activity that is added as default intent handler.
3062 */
3063 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
3064 ComponentName activity) {
3065 if (mService != null) {
3066 try {
3067 mService.addPersistentPreferredActivity(admin, filter, activity);
3068 } catch (RemoteException e) {
3069 Log.w(TAG, "Failed talking with device policy service", e);
3070 }
3071 }
3072 }
3073
3074 /**
3075 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003076 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003077 *
3078 * <p>The calling device admin must be a profile owner. If it is not, a security
3079 * exception will be thrown.
3080 *
3081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3082 * @param packageName The name of the package for which preferences are removed.
3083 */
3084 public void clearPackagePersistentPreferredActivities(ComponentName admin,
3085 String packageName) {
3086 if (mService != null) {
3087 try {
3088 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3089 } catch (RemoteException e) {
3090 Log.w(TAG, "Failed talking with device policy service", e);
3091 }
3092 }
3093 }
Robin Lee66e5d962014-04-09 16:44:21 +01003094
3095 /**
3096 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003097 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003098 *
3099 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003100 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003101 *
3102 * <p>The application restrictions are only made visible to the target application and the
3103 * profile or device owner.
3104 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003105 * <p>If the restrictions are not available yet, but may be applied in the near future,
3106 * the admin can notify the target application of that by adding
3107 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3108 *
Robin Lee66e5d962014-04-09 16:44:21 +01003109 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3110 * exception will be thrown.
3111 *
3112 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3113 * @param packageName The name of the package to update restricted settings for.
3114 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3115 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003116 *
3117 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003118 */
3119 public void setApplicationRestrictions(ComponentName admin, String packageName,
3120 Bundle settings) {
3121 if (mService != null) {
3122 try {
3123 mService.setApplicationRestrictions(admin, packageName, settings);
3124 } catch (RemoteException e) {
3125 Log.w(TAG, "Failed talking with device policy service", e);
3126 }
3127 }
3128 }
3129
3130 /**
Jim Millere303bf42014-08-26 17:12:29 -07003131 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3132 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3133 * trust agents but those enabled by this function call. If flag
3134 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003135 *
3136 * <p>The calling device admin must have requested
3137 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003138 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003139 *
3140 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003141 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003142 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003143 * will be strictly disabled according to the state of the
3144 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3145 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3146 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3147 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003148 */
Jim Millere303bf42014-08-26 17:12:29 -07003149 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08003150 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003151 if (mService != null) {
3152 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003153 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003154 } catch (RemoteException e) {
3155 Log.w(TAG, "Failed talking with device policy service", e);
3156 }
3157 }
3158 }
3159
3160 /**
Jim Millere303bf42014-08-26 17:12:29 -07003161 * Gets configuration for the given trust agent based on aggregating all calls to
3162 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3163 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003164 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3166 * this function returns a list of configurations for all admins that declare
3167 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3168 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3169 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3170 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003171 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003172 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003173 */
Jim Millere303bf42014-08-26 17:12:29 -07003174 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3175 ComponentName agent) {
3176 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3177 }
3178
3179 /** @hide per-user version */
3180 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3181 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003182 if (mService != null) {
3183 try {
Jim Millere303bf42014-08-26 17:12:29 -07003184 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003185 } catch (RemoteException e) {
3186 Log.w(TAG, "Failed talking with device policy service", e);
3187 }
3188 }
Jim Millere303bf42014-08-26 17:12:29 -07003189 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003190 }
3191
3192 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003193 * Called by a profile owner of a managed profile to set whether caller-Id information from
3194 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003195 *
3196 * <p>The calling device admin must be a profile owner. If it is not, a
3197 * security exception will be thrown.
3198 *
3199 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3200 * @param disabled If true caller-Id information in the managed profile is not displayed.
3201 */
3202 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
3203 if (mService != null) {
3204 try {
3205 mService.setCrossProfileCallerIdDisabled(who, disabled);
3206 } catch (RemoteException e) {
3207 Log.w(TAG, "Failed talking with device policy service", e);
3208 }
3209 }
3210 }
3211
3212 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003213 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3214 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003215 *
3216 * <p>The calling device admin must be a profile owner. If it is not, a
3217 * security exception will be thrown.
3218 *
3219 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3220 */
3221 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3222 if (mService != null) {
3223 try {
3224 return mService.getCrossProfileCallerIdDisabled(who);
3225 } catch (RemoteException e) {
3226 Log.w(TAG, "Failed talking with device policy service", e);
3227 }
3228 }
3229 return false;
3230 }
3231
3232 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003233 * Determine whether or not caller-Id information has been disabled.
3234 *
3235 * @param userHandle The user for whom to check the caller-id permission
3236 * @hide
3237 */
3238 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3239 if (mService != null) {
3240 try {
3241 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3242 } catch (RemoteException e) {
3243 Log.w(TAG, "Failed talking with device policy service", e);
3244 }
3245 }
3246 return false;
3247 }
3248
3249 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003250 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3251 * @hide
3252 */
3253 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3254 Intent originalIntent) {
3255 if (mService != null) {
3256 try {
3257 mService.startManagedQuickContact(
3258 actualLookupKey, actualContactId, originalIntent);
3259 } catch (RemoteException e) {
3260 Log.w(TAG, "Failed talking with device policy service", e);
3261 }
3262 }
3263 }
3264
3265 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003266 * Called by a profile owner of a managed profile to set whether bluetooth
3267 * devices can access enterprise contacts.
3268 * <p>
3269 * The calling device admin must be a profile owner. If it is not, a
3270 * security exception will be thrown.
3271 * <p>
3272 * This API works on managed profile only.
3273 *
3274 * @param who Which {@link DeviceAdminReceiver} this request is associated
3275 * with.
3276 * @param disabled If true, bluetooth devices cannot access enterprise
3277 * contacts.
3278 */
3279 public void setBluetoothContactSharingDisabled(ComponentName who, boolean disabled) {
3280 if (mService != null) {
3281 try {
3282 mService.setBluetoothContactSharingDisabled(who, disabled);
3283 } catch (RemoteException e) {
3284 Log.w(TAG, "Failed talking with device policy service", e);
3285 }
3286 }
3287 }
3288
3289 /**
3290 * Called by a profile owner of a managed profile to determine whether or
3291 * not Bluetooth devices cannot access enterprise contacts.
3292 * <p>
3293 * The calling device admin must be a profile owner. If it is not, a
3294 * security exception will be thrown.
3295 * <p>
3296 * This API works on managed profile only.
3297 *
3298 * @param who Which {@link DeviceAdminReceiver} this request is associated
3299 * with.
3300 */
3301 public boolean getBluetoothContactSharingDisabled(ComponentName who) {
3302 if (mService != null) {
3303 try {
3304 return mService.getBluetoothContactSharingDisabled(who);
3305 } catch (RemoteException e) {
3306 Log.w(TAG, "Failed talking with device policy service", e);
3307 }
3308 }
3309 return true;
3310 }
3311
3312 /**
3313 * Determine whether or not Bluetooth devices cannot access contacts.
3314 * <p>
3315 * This API works on managed profile UserHandle only.
3316 *
3317 * @param userHandle The user for whom to check the caller-id permission
3318 * @hide
3319 */
3320 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3321 if (mService != null) {
3322 try {
3323 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3324 .getIdentifier());
3325 } catch (RemoteException e) {
3326 Log.w(TAG, "Failed talking with device policy service", e);
3327 }
3328 }
3329 return true;
3330 }
3331
3332 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003333 * Called by the profile owner of a managed profile so that some intents sent in the managed
3334 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003335 * Only activity intents are supported.
3336 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003337 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003338 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3339 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003340 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3341 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003342 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003343 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003344 if (mService != null) {
3345 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003346 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003347 } catch (RemoteException e) {
3348 Log.w(TAG, "Failed talking with device policy service", e);
3349 }
3350 }
3351 }
3352
3353 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003354 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3355 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003356 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003357 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3358 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003359 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003360 if (mService != null) {
3361 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003362 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003363 } catch (RemoteException e) {
3364 Log.w(TAG, "Failed talking with device policy service", e);
3365 }
3366 }
3367 }
3368
3369 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003370 * Called by a profile or device owner to set the permitted accessibility services. When
3371 * set by a device owner or profile owner the restriction applies to all profiles of the
3372 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003373 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003374 * By default the user can use any accessiblity service. When zero or more packages have
3375 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003376 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003377 *
3378 * <p> Calling with a null value for the list disables the restriction so that all services
3379 * can be used, calling with an empty list only allows the builtin system's services.
3380 *
3381 * <p> System accesibility services are always available to the user the list can't modify
3382 * this.
3383 *
3384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3385 * @param packageNames List of accessibility service package names.
3386 *
3387 * @return true if setting the restriction succeeded. It fail if there is
3388 * one or more non-system accessibility services enabled, that are not in the list.
3389 */
3390 public boolean setPermittedAccessibilityServices(ComponentName admin,
3391 List<String> packageNames) {
3392 if (mService != null) {
3393 try {
3394 return mService.setPermittedAccessibilityServices(admin, packageNames);
3395 } catch (RemoteException e) {
3396 Log.w(TAG, "Failed talking with device policy service", e);
3397 }
3398 }
3399 return false;
3400 }
3401
3402 /**
3403 * Returns the list of permitted accessibility services set by this device or profile owner.
3404 *
3405 * <p>An empty list means no accessibility services except system services are allowed.
3406 * Null means all accessibility services are allowed.
3407 *
3408 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3409 * @return List of accessiblity service package names.
3410 */
3411 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3412 if (mService != null) {
3413 try {
3414 return mService.getPermittedAccessibilityServices(admin);
3415 } catch (RemoteException e) {
3416 Log.w(TAG, "Failed talking with device policy service", e);
3417 }
3418 }
3419 return null;
3420 }
3421
3422 /**
3423 * Returns the list of accessibility services permitted by the device or profiles
3424 * owners of this user.
3425 *
3426 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3427 * it will contain the intersection of the permitted lists for any device or profile
3428 * owners that apply to this user. It will also include any system accessibility services.
3429 *
3430 * @param userId which user to check for.
3431 * @return List of accessiblity service package names.
3432 * @hide
3433 */
3434 @SystemApi
3435 public List<String> getPermittedAccessibilityServices(int userId) {
3436 if (mService != null) {
3437 try {
3438 return mService.getPermittedAccessibilityServicesForUser(userId);
3439 } catch (RemoteException e) {
3440 Log.w(TAG, "Failed talking with device policy service", e);
3441 }
3442 }
3443 return null;
3444 }
3445
3446 /**
3447 * Called by a profile or device owner to set the permitted input methods services. When
3448 * set by a device owner or profile owner the restriction applies to all profiles of the
3449 * user the device owner or profile owner is an admin for.
3450 *
3451 * By default the user can use any input method. When zero or more packages have
3452 * been added, input method that are not in the list and not part of the system
3453 * can not be enabled by the user.
3454 *
3455 * This method will fail if it is called for a admin that is not for the foreground user
3456 * or a profile of the foreground user.
3457 *
3458 * <p> Calling with a null value for the list disables the restriction so that all input methods
3459 * can be used, calling with an empty list disables all but the system's own input methods.
3460 *
3461 * <p> System input methods are always available to the user this method can't modify this.
3462 *
3463 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3464 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003465 * @return true if setting the restriction succeeded. It will fail if there are
3466 * one or more non-system input methods currently enabled that are not in
3467 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003468 */
3469 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3470 if (mService != null) {
3471 try {
3472 return mService.setPermittedInputMethods(admin, packageNames);
3473 } catch (RemoteException e) {
3474 Log.w(TAG, "Failed talking with device policy service", e);
3475 }
3476 }
3477 return false;
3478 }
3479
3480
3481 /**
3482 * Returns the list of permitted input methods set by this device or profile owner.
3483 *
3484 * <p>An empty list means no input methods except system input methods are allowed.
3485 * Null means all input methods are allowed.
3486 *
3487 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3488 * @return List of input method package names.
3489 */
3490 public List<String> getPermittedInputMethods(ComponentName admin) {
3491 if (mService != null) {
3492 try {
3493 return mService.getPermittedInputMethods(admin);
3494 } catch (RemoteException e) {
3495 Log.w(TAG, "Failed talking with device policy service", e);
3496 }
3497 }
3498 return null;
3499 }
3500
3501 /**
3502 * Returns the list of input methods permitted by the device or profiles
3503 * owners of the current user.
3504 *
3505 * <p>Null means all input methods are allowed, if a non-null list is returned
3506 * it will contain the intersection of the permitted lists for any device or profile
3507 * owners that apply to this user. It will also include any system input methods.
3508 *
3509 * @return List of input method package names.
3510 * @hide
3511 */
3512 @SystemApi
3513 public List<String> getPermittedInputMethodsForCurrentUser() {
3514 if (mService != null) {
3515 try {
3516 return mService.getPermittedInputMethodsForCurrentUser();
3517 } catch (RemoteException e) {
3518 Log.w(TAG, "Failed talking with device policy service", e);
3519 }
3520 }
3521 return null;
3522 }
3523
3524 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003525 * Called by a device owner to create a user with the specified name. The UserHandle returned
3526 * by this method should not be persisted as user handles are recycled as users are removed and
3527 * created. If you need to persist an identifier for this user, use
3528 * {@link UserManager#getSerialNumberForUser}.
3529 *
3530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3531 * @param name the user's name
3532 * @see UserHandle
3533 * @return the UserHandle object for the created user, or null if the user could not be created.
3534 */
3535 public UserHandle createUser(ComponentName admin, String name) {
3536 try {
3537 return mService.createUser(admin, name);
3538 } catch (RemoteException re) {
3539 Log.w(TAG, "Could not create a user", re);
3540 }
3541 return null;
3542 }
3543
3544 /**
Jason Monk03978a42014-06-10 15:05:30 -04003545 * Called by a device owner to create a user with the specified name. The UserHandle returned
3546 * by this method should not be persisted as user handles are recycled as users are removed and
3547 * created. If you need to persist an identifier for this user, use
3548 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3549 * immediately.
3550 *
3551 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3552 * as registered as an active admin on the new user. The profile owner package will be
3553 * installed on the new user if it already is installed on the device.
3554 *
3555 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3556 * profileOwnerComponent when onEnable is called.
3557 *
3558 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3559 * @param name the user's name
3560 * @param ownerName the human readable name of the organisation associated with this DPM.
3561 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3562 * the user.
3563 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3564 * on the new user.
3565 * @see UserHandle
3566 * @return the UserHandle object for the created user, or null if the user could not be created.
3567 */
3568 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3569 ComponentName profileOwnerComponent, Bundle adminExtras) {
3570 try {
3571 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3572 adminExtras);
3573 } catch (RemoteException re) {
3574 Log.w(TAG, "Could not create a user", re);
3575 }
3576 return null;
3577 }
3578
3579 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003580 * Called by a device owner to remove a user and all associated data. The primary user can
3581 * not be removed.
3582 *
3583 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3584 * @param userHandle the user to remove.
3585 * @return {@code true} if the user was removed, {@code false} otherwise.
3586 */
3587 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3588 try {
3589 return mService.removeUser(admin, userHandle);
3590 } catch (RemoteException re) {
3591 Log.w(TAG, "Could not remove user ", re);
3592 return false;
3593 }
3594 }
3595
3596 /**
Jason Monk582d9112014-07-09 19:57:08 -04003597 * Called by a device owner to switch the specified user to the foreground.
3598 *
3599 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3600 * @param userHandle the user to switch to; null will switch to primary.
3601 * @return {@code true} if the switch was successful, {@code false} otherwise.
3602 *
3603 * @see Intent#ACTION_USER_FOREGROUND
3604 */
3605 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3606 try {
3607 return mService.switchUser(admin, userHandle);
3608 } catch (RemoteException re) {
3609 Log.w(TAG, "Could not switch user ", re);
3610 return false;
3611 }
3612 }
3613
3614 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003615 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003616 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003617 *
3618 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3619 * exception will be thrown.
3620 *
3621 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3622 * @param packageName The name of the package to fetch restricted settings of.
3623 * @return {@link Bundle} of settings corresponding to what was set last time
3624 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3625 * if no restrictions have been set.
3626 */
3627 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3628 if (mService != null) {
3629 try {
3630 return mService.getApplicationRestrictions(admin, packageName);
3631 } catch (RemoteException e) {
3632 Log.w(TAG, "Failed talking with device policy service", e);
3633 }
3634 }
3635 return null;
3636 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003637
3638 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003639 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003640 * <p>
3641 * The calling device admin must be a profile or device owner; if it is not,
3642 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003643 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003644 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3645 * with.
3646 * @param key The key of the restriction. See the constants in
3647 * {@link android.os.UserManager} for the list of keys.
3648 */
3649 public void addUserRestriction(ComponentName admin, String key) {
3650 if (mService != null) {
3651 try {
3652 mService.setUserRestriction(admin, key, true);
3653 } catch (RemoteException e) {
3654 Log.w(TAG, "Failed talking with device policy service", e);
3655 }
3656 }
3657 }
3658
3659 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003660 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003661 * <p>
3662 * The calling device admin must be a profile or device owner; if it is not,
3663 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003664 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003665 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3666 * with.
3667 * @param key The key of the restriction. See the constants in
3668 * {@link android.os.UserManager} for the list of keys.
3669 */
3670 public void clearUserRestriction(ComponentName admin, String key) {
3671 if (mService != null) {
3672 try {
3673 mService.setUserRestriction(admin, key, false);
3674 } catch (RemoteException e) {
3675 Log.w(TAG, "Failed talking with device policy service", e);
3676 }
3677 }
3678 }
Adam Connors010cfd42014-04-16 12:48:13 +01003679
3680 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003681 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003682 * is unavailable for use, but the data and actual package file remain.
3683 *
3684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003685 * @param packageName The name of the package to hide or unhide.
3686 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3687 * unhidden.
3688 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003689 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003690 public boolean setApplicationHidden(ComponentName admin, String packageName,
3691 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003692 if (mService != null) {
3693 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003694 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003695 } catch (RemoteException e) {
3696 Log.w(TAG, "Failed talking with device policy service", e);
3697 }
3698 }
3699 return false;
3700 }
3701
3702 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003703 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003704 *
3705 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003706 * @param packageName The name of the package to retrieve the hidden status of.
3707 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003708 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003709 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003710 if (mService != null) {
3711 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003712 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003713 } catch (RemoteException e) {
3714 Log.w(TAG, "Failed talking with device policy service", e);
3715 }
3716 }
3717 return false;
3718 }
3719
3720 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003721 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003722 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003723 *
3724 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3725 * @param packageName The package to be re-enabled in the current profile.
3726 */
3727 public void enableSystemApp(ComponentName admin, String packageName) {
3728 if (mService != null) {
3729 try {
3730 mService.enableSystemApp(admin, packageName);
3731 } catch (RemoteException e) {
3732 Log.w(TAG, "Failed to install package: " + packageName);
3733 }
3734 }
3735 }
3736
3737 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003738 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003739 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003740 *
3741 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3742 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3743 * intent will be re-enabled in the current profile.
3744 * @return int The number of activities that matched the intent and were installed.
3745 */
3746 public int enableSystemApp(ComponentName admin, Intent intent) {
3747 if (mService != null) {
3748 try {
3749 return mService.enableSystemAppWithIntent(admin, intent);
3750 } catch (RemoteException e) {
3751 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3752 }
3753 }
3754 return 0;
3755 }
3756
3757 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003758 * Called by a device owner or profile owner to disable account management for a specific type
3759 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003760 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003761 * <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 +01003762 * security exception will be thrown.
3763 *
3764 * <p>When account management is disabled for an account type, adding or removing an account
3765 * of that type will not be possible.
3766 *
3767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3768 * @param accountType For which account management is disabled or enabled.
3769 * @param disabled The boolean indicating that account management will be disabled (true) or
3770 * enabled (false).
3771 */
3772 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3773 boolean disabled) {
3774 if (mService != null) {
3775 try {
3776 mService.setAccountManagementDisabled(admin, accountType, disabled);
3777 } catch (RemoteException e) {
3778 Log.w(TAG, "Failed talking with device policy service", e);
3779 }
3780 }
3781 }
3782
3783 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003784 * Gets the array of accounts for which account management is disabled by the profile owner.
3785 *
3786 * <p> Account management can be disabled/enabled by calling
3787 * {@link #setAccountManagementDisabled}.
3788 *
3789 * @return a list of account types for which account management has been disabled.
3790 *
3791 * @see #setAccountManagementDisabled
3792 */
3793 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003794 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003795 }
3796
3797 /**
3798 * @see #getAccountTypesWithManagementDisabled()
3799 * @hide
3800 */
3801 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003802 if (mService != null) {
3803 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003804 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003805 } catch (RemoteException e) {
3806 Log.w(TAG, "Failed talking with device policy service", e);
3807 }
3808 }
3809
3810 return null;
3811 }
justinzhang511e0d82014-03-24 16:09:24 -04003812
3813 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003814 * Sets which packages may enter lock task mode.
3815 *
3816 * <p>Any packages that shares uid with an allowed package will also be allowed
3817 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003818 *
Jason Monkc5185f22014-06-24 11:12:42 -04003819 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003820 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003821 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003822 *
3823 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003824 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3825 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003826 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003827 */
Jason Monk48aacba2014-08-13 16:29:08 -04003828 public void setLockTaskPackages(ComponentName admin, String[] packages)
3829 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003830 if (mService != null) {
3831 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003832 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003833 } catch (RemoteException e) {
3834 Log.w(TAG, "Failed talking with device policy service", e);
3835 }
3836 }
3837 }
3838
3839 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003840 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003841 *
3842 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003843 * @hide
3844 */
Jason Monk48aacba2014-08-13 16:29:08 -04003845 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003846 if (mService != null) {
3847 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003848 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003849 } catch (RemoteException e) {
3850 Log.w(TAG, "Failed talking with device policy service", e);
3851 }
3852 }
3853 return null;
3854 }
3855
3856 /**
3857 * This function lets the caller know whether the given component is allowed to start the
3858 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003859 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003860 */
Jason Monkd7b86212014-06-16 13:15:38 -04003861 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003862 if (mService != null) {
3863 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003864 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003865 } catch (RemoteException e) {
3866 Log.w(TAG, "Failed talking with device policy service", e);
3867 }
3868 }
3869 return false;
3870 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003871
3872 /**
3873 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3874 * 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 -04003875 * <p>The settings that can be updated with this method are:
3876 * <ul>
3877 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3878 * <li>{@link Settings.Global#AUTO_TIME}</li>
3879 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003880 * <li>{@link Settings.Global#BLUETOOTH_ON}
3881 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3882 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3883 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003884 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3885 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3886 * <li>{@link Settings.Global#MODE_RINGER}</li>
3887 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3888 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003889 * <li>{@link Settings.Global#WIFI_ON}
3890 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3891 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003892 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003893 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3894 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3895 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003896 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003897 *
3898 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3899 * @param setting The name of the setting to update.
3900 * @param value The value to update the setting to.
3901 */
3902 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3903 if (mService != null) {
3904 try {
3905 mService.setGlobalSetting(admin, setting, value);
3906 } catch (RemoteException e) {
3907 Log.w(TAG, "Failed talking with device policy service", e);
3908 }
3909 }
3910 }
3911
3912 /**
3913 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3914 * that the value of the setting is in the correct form for the setting type should be performed
3915 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003916 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003917 * <ul>
3918 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003919 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003920 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3921 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003922 * <p>A device owner can additionally update the following settings:
3923 * <ul>
3924 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3925 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3927 * @param setting The name of the setting to update.
3928 * @param value The value to update the setting to.
3929 */
3930 public void setSecureSetting(ComponentName admin, String setting, String value) {
3931 if (mService != null) {
3932 try {
3933 mService.setSecureSetting(admin, setting, value);
3934 } catch (RemoteException e) {
3935 Log.w(TAG, "Failed talking with device policy service", e);
3936 }
3937 }
3938 }
3939
Amith Yamasanif20d6402014-05-24 15:34:37 -07003940 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003941 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003942 * making permission requests of a local or remote administrator of the user.
3943 * <p/>
3944 * Only a profile owner can designate the restrictions provider.
3945 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003946 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003947 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003948 * it removes the restrictions provider previously assigned.
3949 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003950 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003951 if (mService != null) {
3952 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003953 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003954 } catch (RemoteException re) {
3955 Log.w(TAG, "Failed to set permission provider on device policy service");
3956 }
3957 }
3958 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003959
3960 /**
3961 * Called by profile or device owners to set the master volume mute on or off.
3962 *
3963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3964 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3965 */
3966 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3967 if (mService != null) {
3968 try {
3969 mService.setMasterVolumeMuted(admin, on);
3970 } catch (RemoteException re) {
3971 Log.w(TAG, "Failed to setMasterMute on device policy service");
3972 }
3973 }
3974 }
3975
3976 /**
3977 * Called by profile or device owners to check whether the master volume mute is on or off.
3978 *
3979 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3980 * @return {@code true} if master volume is muted, {@code false} if it's not.
3981 */
3982 public boolean isMasterVolumeMuted(ComponentName admin) {
3983 if (mService != null) {
3984 try {
3985 return mService.isMasterVolumeMuted(admin);
3986 } catch (RemoteException re) {
3987 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3988 }
3989 }
3990 return false;
3991 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003992
3993 /**
3994 * Called by profile or device owners to change whether a user can uninstall
3995 * a package.
3996 *
3997 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3998 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003999 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004000 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004001 public void setUninstallBlocked(ComponentName admin, String packageName,
4002 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004003 if (mService != null) {
4004 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004005 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004006 } catch (RemoteException re) {
4007 Log.w(TAG, "Failed to call block uninstall on device policy service");
4008 }
4009 }
4010 }
4011
4012 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004013 * Check whether the current user has been blocked by device policy from uninstalling a package.
4014 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004015 * <p>
4016 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
4017 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
4018 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
4019 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004020 *
Rubin Xua97855b2014-11-07 05:41:00 +00004021 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00004022 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004023 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004024 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004025 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01004026 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004027 if (mService != null) {
4028 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004029 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004030 } catch (RemoteException re) {
4031 Log.w(TAG, "Failed to call block uninstall on device policy service");
4032 }
4033 }
4034 return false;
4035 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004036
4037 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004038 * Called by the profile owner of a managed profile to enable widget providers from a
4039 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004040 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004041 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004042 * a package may have zero or more provider components, where each component
4043 * provides a different widget type.
4044 * <p>
4045 * <strong>Note:</strong> By default no widget provider package is white-listed.
4046 * </p>
4047 *
4048 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4049 * @param packageName The package from which widget providers are white-listed.
4050 * @return Whether the package was added.
4051 *
4052 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4053 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4054 */
4055 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4056 if (mService != null) {
4057 try {
4058 return mService.addCrossProfileWidgetProvider(admin, packageName);
4059 } catch (RemoteException re) {
4060 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4061 }
4062 }
4063 return false;
4064 }
4065
4066 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004067 * Called by the profile owner of a managed profile to disable widget providers from a given
4068 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004069 * package should have been added via {@link #addCrossProfileWidgetProvider(
4070 * android.content.ComponentName, String)}.
4071 * <p>
4072 * <strong>Note:</strong> By default no widget provider package is white-listed.
4073 * </p>
4074 *
4075 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4076 * @param packageName The package from which widget providers are no longer
4077 * white-listed.
4078 * @return Whether the package was removed.
4079 *
4080 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4081 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4082 */
4083 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
4084 if (mService != null) {
4085 try {
4086 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4087 } catch (RemoteException re) {
4088 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4089 }
4090 }
4091 return false;
4092 }
4093
4094 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004095 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004096 * available in the parent profile.
4097 *
4098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4099 * @return The white-listed package list.
4100 *
4101 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4102 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4103 */
4104 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
4105 if (mService != null) {
4106 try {
4107 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4108 if (providers != null) {
4109 return providers;
4110 }
4111 } catch (RemoteException re) {
4112 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4113 }
4114 }
4115 return Collections.emptyList();
4116 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004117
4118 /**
4119 * Called by profile or device owners to set the current user's photo.
4120 *
4121 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4122 * @param icon the bitmap to set as the photo.
4123 */
4124 public void setUserIcon(ComponentName admin, Bitmap icon) {
4125 try {
4126 mService.setUserIcon(admin, icon);
4127 } catch (RemoteException re) {
4128 Log.w(TAG, "Could not set the user icon ", re);
4129 }
4130 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004131
4132 /**
4133 * Called by device initializer to send a provisioning status update to the remote setup device.
4134 *
4135 * @param statusCode a custom status code value as defined by
4136 * {@link DeviceInitializerStatus#isCustomStatus(int)}.
4137 * @param description custom description of the status code sent
4138 */
4139 public void sendDeviceInitializerStatus(int statusCode, String description) {
4140 try {
4141 mService.sendDeviceInitializerStatus(statusCode, description);
4142 } catch (RemoteException re) {
4143 Log.w(TAG, "Could not send device initializer status", re);
4144 }
4145 }
Rubin Xu8027a4f2015-03-10 17:52:37 +00004146
Rubin Xu5faad8e2015-04-20 17:43:48 +01004147 /**
4148 * Called by device owners to set a local system update policy. When a new policy is set,
4149 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004150 *
4151 * @param who Which {@link DeviceAdminReceiver} this request is associated with. All components
Rubin Xu5faad8e2015-04-20 17:43:48 +01004152 * in the device owner package can set system update policies and the most recent policy takes
4153 * effect.
4154 * @param policy the new policy, or null to clear the current policy.
4155 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004156 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004157 public void setSystemUpdatePolicy(ComponentName who, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004158 if (mService != null) {
4159 try {
4160 if (policy != null) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004161 mService.setSystemUpdatePolicy(who, policy.getPolicyBundle());
Rubin Xu8027a4f2015-03-10 17:52:37 +00004162 } else {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004163 mService.setSystemUpdatePolicy(who, null);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004164 }
4165 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004166 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004167 }
4168 }
4169 }
4170
4171 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004172 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004173 *
Rubin Xu5faad8e2015-04-20 17:43:48 +01004174 * @return The current policy object, or null if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004175 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004176 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004177 if (mService != null) {
4178 try {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004179 PersistableBundle bundle = mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004180 if (bundle != null) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004181 return new SystemUpdatePolicy(bundle);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004182 } else {
4183 return null;
4184 }
4185 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004186 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004187 }
4188 }
4189 return null;
4190 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004191
4192 /**
4193 * Called by a device owner to disable the keyguard altogether.
4194 *
4195 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4196 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4197 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4198 * being disabled.
4199 *
4200 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4201 * @param enabled New state of the keyguard.
4202 *
4203 * @return {@code false} if attempting to disable the keyguard while a lock password was in
4204 * place. {@code true} otherwise."
4205 */
4206 public boolean setKeyguardEnabledState(ComponentName admin, boolean enabled) {
4207 try {
4208 return mService.setKeyguardEnabledState(admin, enabled);
4209 } catch (RemoteException re) {
4210 Log.w(TAG, "Failed talking with device policy service", re);
4211 return false;
4212 }
4213 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004214
4215 /**
4216 * Called by device owner to set the enabled state of the status bar. Disabling the status
4217 * bar blocks notifications, quick settings and other screen overlays that allow escaping from
4218 * a single use device.
4219 *
4220 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4221 * @param enabled New state of the status bar.
4222 */
4223 public void setStatusBarEnabledState(ComponentName admin, boolean enabled) {
4224 try {
4225 mService.setStatusBarEnabledState(admin, enabled);
4226 } catch (RemoteException re) {
4227 Log.w(TAG, "Failed talking with device policy service", re);
4228 }
4229 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004230}