blob: e9175228bf5a23f6d1cb784b947dfffed0c86ad0 [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 Lafayette97e473e2015-03-19 10:19:38 -0400505 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400506 * This MIME type is used for starting the Device Owner provisioning that does not require
507 * provisioning features introduced in Android API level
508 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400510 * <p>For more information about the provisioning process see
511 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100512 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000513 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100514 * contains the following properties:
515 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400516 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
517 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100518 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400519 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100520 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
521 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
522 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
523 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
524 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
525 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
526 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
527 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
528 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
529 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400530 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100531 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000532 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400533 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
534 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
535 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
536 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
537 *
538 * @see #MIME_TYPE_PROVISIONING_NFC_V2
539 *
540 */
541 public static final String MIME_TYPE_PROVISIONING_NFC
542 = "application/com.android.managedprovisioning";
543
544
545 /**
546 * This MIME type is used for starting the Device Owner provisioning that requires
547 * new provisioning features introduced in API version
548 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
549 * versions.
550 *
551 * <p>During device owner provisioning a device admin app is set as the owner of the device.
552 * A device owner has full control over the device. The device owner can not be modified by the
553 * user and the only way of resetting the device is if the device owner app calls a factory
554 * reset.
555 *
556 * <p> A typical use case would be a device that is owned by a company, but used by either an
557 * employee or client.
558 *
559 * <p> The NFC message should be sent to an unprovisioned device.
560 *
561 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
562 * contains the following properties in addition to properties listed at
563 * {@link #MIME_TYPE_PROVISIONING_NFC}:
564 * <ul>
565 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
566 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
567 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
568 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
569 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
570 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
571 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
572 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
573 * should be converted to a String via
574 * {@link android.content.ComponentName#flattenToString()}</li>
575 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li>
576 * <li>{@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, optional</li>
577 * <li>{@link #EXTRA_PROVISIONING_BT_UUID}, optional</li>
578 * <li>{@link #EXTRA_PROVISIONING_BT_DEVICE_ID}, optional</li>
579 * <li>{@link #EXTRA_PROVISIONING_BT_USE_PROXY}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000580 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100581 * <p> When device owner provisioning has completed, an intent of the type
582 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
583 * device owner.
584 *
585 * <p>
586 * If provisioning fails, the device is factory reset.
587 *
588 * <p>Input: Nothing.</p>
589 * <p>Output: Nothing</p>
590 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400591 public static final String MIME_TYPE_PROVISIONING_NFC_V2
592 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100593
594 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800595 * Activity action: ask the user to add a new device administrator to the system.
596 * The desired policy is the ComponentName of the policy in the
597 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
598 * bring the user through adding the device administrator to the system (or
599 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700600 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800601 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
602 * field to provide the user with additional explanation (in addition
603 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800604 *
605 * <p>If your administrator is already active, this will ordinarily return immediately (without
606 * user intervention). However, if your administrator has been updated and is requesting
607 * additional uses-policy flags, the user will be presented with the new list. New policies
608 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800609 */
610 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
611 public static final String ACTION_ADD_DEVICE_ADMIN
612 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700613
Dianne Hackbornd6847842010-01-12 18:14:19 -0800614 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700615 * @hide
616 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700617 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700618 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700619 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
620 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700621 * to remotely control restrictions on the user.
622 *
623 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
624 * result of whether or not the user approved the action. If approved, the result will
625 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
626 * as a profile owner.
627 *
628 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
629 * field to provide the user with additional explanation (in addition
630 * to your component's description) about what is being added.
631 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700632 * <p>If there is already a profile owner active or the caller is not a system app, the
633 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700634 */
635 @SystemApi
636 public static final String ACTION_SET_PROFILE_OWNER
637 = "android.app.action.SET_PROFILE_OWNER";
638
639 /**
640 * @hide
641 * Name of the profile owner admin that controls the user.
642 */
643 @SystemApi
644 public static final String EXTRA_PROFILE_OWNER_NAME
645 = "android.app.extra.PROFILE_OWNER_NAME";
646
647 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700648 * Activity action: send when any policy admin changes a policy.
649 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700650 *
Jim Miller284b62e2010-06-08 14:27:42 -0700651 * @hide
652 */
653 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
654 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
655
656 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800657 * The ComponentName of the administrator component.
658 *
659 * @see #ACTION_ADD_DEVICE_ADMIN
660 */
661 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700662
Dianne Hackbornd6847842010-01-12 18:14:19 -0800663 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800664 * An optional CharSequence providing additional explanation for why the
665 * admin is being added.
666 *
667 * @see #ACTION_ADD_DEVICE_ADMIN
668 */
669 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700670
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800671 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700672 * Activity action: have the user enter a new password. This activity should
673 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
674 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
675 * enter a new password that meets the current requirements. You can use
676 * {@link #isActivePasswordSufficient()} to determine whether you need to
677 * have the user select a new password in order to meet the current
678 * constraints. Upon being resumed from this activity, you can check the new
679 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800680 */
681 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
682 public static final String ACTION_SET_NEW_PASSWORD
683 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700684
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000685 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000686 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
687 * the parent profile to access intents sent from the managed profile.
688 * That is, when an app in the managed profile calls
689 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
690 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000691 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100692 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000693
694 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000695 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
696 * the managed profile to access intents sent from the parent profile.
697 * That is, when an app in the parent profile calls
698 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
699 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000700 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100701 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700702
Dianne Hackbornd6847842010-01-12 18:14:19 -0800703 /**
704 * Return true if the given administrator component is currently
705 * active (enabled) in the system.
706 */
707 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100708 return isAdminActiveAsUser(who, UserHandle.myUserId());
709 }
710
711 /**
712 * @see #isAdminActive(ComponentName)
713 * @hide
714 */
715 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800716 if (mService != null) {
717 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100718 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800719 } catch (RemoteException e) {
720 Log.w(TAG, "Failed talking with device policy service", e);
721 }
722 }
723 return false;
724 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800725 /**
726 * Return true if the given administrator component is currently being removed
727 * for the user.
728 * @hide
729 */
730 public boolean isRemovingAdmin(ComponentName who, int userId) {
731 if (mService != null) {
732 try {
733 return mService.isRemovingAdmin(who, userId);
734 } catch (RemoteException e) {
735 Log.w(TAG, "Failed talking with device policy service", e);
736 }
737 }
738 return false;
739 }
740
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700741
Dianne Hackbornd6847842010-01-12 18:14:19 -0800742 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800743 * Return a list of all currently active device administrator's component
744 * names. Note that if there are no administrators than null may be
745 * returned.
746 */
747 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100748 return getActiveAdminsAsUser(UserHandle.myUserId());
749 }
750
751 /**
752 * @see #getActiveAdmins()
753 * @hide
754 */
755 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800756 if (mService != null) {
757 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100758 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800759 } catch (RemoteException e) {
760 Log.w(TAG, "Failed talking with device policy service", e);
761 }
762 }
763 return null;
764 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700765
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800766 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700767 * Used by package administration code to determine if a package can be stopped
768 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800769 * @hide
770 */
771 public boolean packageHasActiveAdmins(String packageName) {
772 if (mService != null) {
773 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700774 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800775 } catch (RemoteException e) {
776 Log.w(TAG, "Failed talking with device policy service", e);
777 }
778 }
779 return false;
780 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700781
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800782 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800783 * Remove a current administration component. This can only be called
784 * by the application that owns the administration component; if you
785 * try to remove someone else's component, a security exception will be
786 * thrown.
787 */
788 public void removeActiveAdmin(ComponentName who) {
789 if (mService != null) {
790 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700791 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800792 } catch (RemoteException e) {
793 Log.w(TAG, "Failed talking with device policy service", e);
794 }
795 }
796 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700797
Dianne Hackbornd6847842010-01-12 18:14:19 -0800798 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800799 * Returns true if an administrator has been granted a particular device policy. This can
800 * be used to check if the administrator was activated under an earlier set of policies,
801 * but requires additional policies after an upgrade.
802 *
803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
804 * an active administrator, or an exception will be thrown.
805 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
806 */
807 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
808 if (mService != null) {
809 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700810 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800811 } catch (RemoteException e) {
812 Log.w(TAG, "Failed talking with device policy service", e);
813 }
814 }
815 return false;
816 }
817
818 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800819 * Constant for {@link #setPasswordQuality}: the policy has no requirements
820 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800821 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800822 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800823 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700824
Dianne Hackbornd6847842010-01-12 18:14:19 -0800825 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700826 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
827 * recognition technology. This implies technologies that can recognize the identity of
828 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
829 * Note that quality constants are ordered so that higher values are more restrictive.
830 */
831 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
832
833 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800834 * Constant for {@link #setPasswordQuality}: the policy requires some kind
835 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800836 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800837 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800838 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700839
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800840 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800841 * Constant for {@link #setPasswordQuality}: the user must have entered a
842 * password containing at least numeric characters. Note that quality
843 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800844 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800845 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700846
Dianne Hackbornd6847842010-01-12 18:14:19 -0800847 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800848 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800849 * password containing at least numeric characters with no repeating (4444)
850 * or ordered (1234, 4321, 2468) sequences. Note that quality
851 * constants are ordered so that higher values are more restrictive.
852 */
853 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
854
855 /**
856 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700857 * password containing at least alphabetic (or other symbol) characters.
858 * Note that quality constants are ordered so that higher values are more
859 * restrictive.
860 */
861 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700862
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700863 /**
864 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800865 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700866 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800867 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800868 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700869 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700870
Dianne Hackbornd6847842010-01-12 18:14:19 -0800871 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700872 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700873 * password containing at least a letter, a numerical digit and a special
874 * symbol, by default. With this password quality, passwords can be
875 * restricted to contain various sets of characters, like at least an
876 * uppercase letter, etc. These are specified using various methods,
877 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
878 * that quality constants are ordered so that higher values are more
879 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700880 */
881 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
882
883 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800884 * Called by an application that is administering the device to set the
885 * password restrictions it is imposing. After setting this, the user
886 * will not be able to enter a new password that is not at least as
887 * restrictive as what has been set. Note that the current password
888 * will remain until the user has set a new one, so the change does not
889 * take place immediately. To prompt the user for a new password, use
890 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700891 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800892 * <p>Quality constants are ordered so that higher values are more restrictive;
893 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800894 * the user's preference, and any other considerations) is the one that
895 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700896 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800897 * <p>The calling device admin must have requested
898 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
899 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700900 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800901 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800902 * @param quality The new desired quality. One of
903 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800904 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
905 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
906 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800907 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800908 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800909 if (mService != null) {
910 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800911 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800912 } catch (RemoteException e) {
913 Log.w(TAG, "Failed talking with device policy service", e);
914 }
915 }
916 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700917
Dianne Hackbornd6847842010-01-12 18:14:19 -0800918 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100919 * Retrieve the current minimum password quality for all admins of this user
920 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800921 * @param admin The name of the admin component to check, or null to aggregate
922 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800923 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800924 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700925 return getPasswordQuality(admin, UserHandle.myUserId());
926 }
927
928 /** @hide per-user version */
929 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800930 if (mService != null) {
931 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700932 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800933 } catch (RemoteException e) {
934 Log.w(TAG, "Failed talking with device policy service", e);
935 }
936 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800937 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800938 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700939
Dianne Hackbornd6847842010-01-12 18:14:19 -0800940 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800941 * Called by an application that is administering the device to set the
942 * minimum allowed password length. After setting this, the user
943 * will not be able to enter a new password that is not at least as
944 * restrictive as what has been set. Note that the current password
945 * will remain until the user has set a new one, so the change does not
946 * take place immediately. To prompt the user for a new password, use
947 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
948 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800949 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
950 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
951 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700952 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800953 * <p>The calling device admin must have requested
954 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
955 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700956 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800957 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800958 * @param length The new desired minimum password length. A value of 0
959 * means there is no restriction.
960 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800961 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800962 if (mService != null) {
963 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800964 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800965 } catch (RemoteException e) {
966 Log.w(TAG, "Failed talking with device policy service", e);
967 }
968 }
969 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700970
Dianne Hackbornd6847842010-01-12 18:14:19 -0800971 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100972 * Retrieve the current minimum password length for all admins of this
973 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800974 * @param admin The name of the admin component to check, or null to aggregate
975 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800976 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800977 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700978 return getPasswordMinimumLength(admin, UserHandle.myUserId());
979 }
980
981 /** @hide per-user version */
982 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800983 if (mService != null) {
984 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700985 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800986 } catch (RemoteException e) {
987 Log.w(TAG, "Failed talking with device policy service", e);
988 }
989 }
990 return 0;
991 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700992
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700993 /**
994 * Called by an application that is administering the device to set the
995 * minimum number of upper case letters required in the password. After
996 * setting this, the user will not be able to enter a new password that is
997 * not at least as restrictive as what has been set. Note that the current
998 * password will remain until the user has set a new one, so the change does
999 * not take place immediately. To prompt the user for a new password, use
1000 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1001 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001002 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1003 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001004 * <p>
1005 * The calling device admin must have requested
1006 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1007 * this method; if it has not, a security exception will be thrown.
1008 *
1009 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1010 * with.
1011 * @param length The new desired minimum number of upper case letters
1012 * required in the password. A value of 0 means there is no
1013 * restriction.
1014 */
1015 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
1016 if (mService != null) {
1017 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001018 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001019 } catch (RemoteException e) {
1020 Log.w(TAG, "Failed talking with device policy service", e);
1021 }
1022 }
1023 }
1024
1025 /**
1026 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001027 * password for all admins of this user and its profiles or a particular one.
1028 * This is the same value as set by
1029 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001030 * and only applies when the password quality is
1031 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001032 *
1033 * @param admin The name of the admin component to check, or null to
1034 * aggregate all admins.
1035 * @return The minimum number of upper case letters required in the
1036 * password.
1037 */
1038 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001039 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1040 }
1041
1042 /** @hide per-user version */
1043 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001044 if (mService != null) {
1045 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001046 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001047 } catch (RemoteException e) {
1048 Log.w(TAG, "Failed talking with device policy service", e);
1049 }
1050 }
1051 return 0;
1052 }
1053
1054 /**
1055 * Called by an application that is administering the device to set the
1056 * minimum number of lower case letters required in the password. After
1057 * setting this, the user will not be able to enter a new password that is
1058 * not at least as restrictive as what has been set. Note that the current
1059 * password will remain until the user has set a new one, so the change does
1060 * not take place immediately. To prompt the user for a new password, use
1061 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1062 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001063 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1064 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001065 * <p>
1066 * The calling device admin must have requested
1067 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1068 * this method; if it has not, a security exception will be thrown.
1069 *
1070 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1071 * with.
1072 * @param length The new desired minimum number of lower case letters
1073 * required in the password. A value of 0 means there is no
1074 * restriction.
1075 */
1076 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
1077 if (mService != null) {
1078 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001079 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001080 } catch (RemoteException e) {
1081 Log.w(TAG, "Failed talking with device policy service", e);
1082 }
1083 }
1084 }
1085
1086 /**
1087 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001088 * password for all admins of this user and its profiles or a particular one.
1089 * This is the same value as set by
1090 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001091 * and only applies when the password quality is
1092 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001093 *
1094 * @param admin The name of the admin component to check, or null to
1095 * aggregate all admins.
1096 * @return The minimum number of lower case letters required in the
1097 * password.
1098 */
1099 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001100 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1101 }
1102
1103 /** @hide per-user version */
1104 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001105 if (mService != null) {
1106 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001107 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001108 } catch (RemoteException e) {
1109 Log.w(TAG, "Failed talking with device policy service", e);
1110 }
1111 }
1112 return 0;
1113 }
1114
1115 /**
1116 * Called by an application that is administering the device to set the
1117 * minimum number of letters required in the password. After setting this,
1118 * the user will not be able to enter a new password that is not at least as
1119 * restrictive as what has been set. Note that the current password will
1120 * remain until the user has set a new one, so the change does not take
1121 * place immediately. To prompt the user for a new password, use
1122 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1123 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001124 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1125 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001126 * <p>
1127 * The calling device admin must have requested
1128 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1129 * this method; if it has not, a security exception will be thrown.
1130 *
1131 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1132 * with.
1133 * @param length The new desired minimum number of letters required in the
1134 * password. A value of 0 means there is no restriction.
1135 */
1136 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1137 if (mService != null) {
1138 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001139 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001140 } catch (RemoteException e) {
1141 Log.w(TAG, "Failed talking with device policy service", e);
1142 }
1143 }
1144 }
1145
1146 /**
1147 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001148 * admins or a particular one. This is the same value as
1149 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1150 * and only applies when the password quality is
1151 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001152 *
1153 * @param admin The name of the admin component to check, or null to
1154 * aggregate all admins.
1155 * @return The minimum number of letters required in the password.
1156 */
1157 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001158 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1159 }
1160
1161 /** @hide per-user version */
1162 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001163 if (mService != null) {
1164 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001165 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001166 } catch (RemoteException e) {
1167 Log.w(TAG, "Failed talking with device policy service", e);
1168 }
1169 }
1170 return 0;
1171 }
1172
1173 /**
1174 * Called by an application that is administering the device to set the
1175 * minimum number of numerical digits required in the password. After
1176 * setting this, the user will not be able to enter a new password that is
1177 * not at least as restrictive as what has been set. Note that the current
1178 * password will remain until the user has set a new one, so the change does
1179 * not take place immediately. To prompt the user for a new password, use
1180 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1181 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001182 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1183 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001184 * <p>
1185 * The calling device admin must have requested
1186 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1187 * this method; if it has not, a security exception will be thrown.
1188 *
1189 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1190 * with.
1191 * @param length The new desired minimum number of numerical digits required
1192 * in the password. A value of 0 means there is no restriction.
1193 */
1194 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1195 if (mService != null) {
1196 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001197 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001198 } catch (RemoteException e) {
1199 Log.w(TAG, "Failed talking with device policy service", e);
1200 }
1201 }
1202 }
1203
1204 /**
1205 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001206 * for all admins of this user and its profiles or a particular one.
1207 * This is the same value as set by
1208 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001209 * and only applies when the password quality is
1210 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001211 *
1212 * @param admin The name of the admin component to check, or null to
1213 * aggregate all admins.
1214 * @return The minimum number of numerical digits required in the password.
1215 */
1216 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001217 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1218 }
1219
1220 /** @hide per-user version */
1221 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001222 if (mService != null) {
1223 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001224 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001225 } catch (RemoteException e) {
1226 Log.w(TAG, "Failed talking with device policy service", e);
1227 }
1228 }
1229 return 0;
1230 }
1231
1232 /**
1233 * Called by an application that is administering the device to set the
1234 * minimum number of symbols required in the password. After setting this,
1235 * the user will not be able to enter a new password that is not at least as
1236 * restrictive as what has been set. Note that the current password will
1237 * remain until the user has set a new one, so the change does not take
1238 * place immediately. To prompt the user for a new password, use
1239 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1240 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001241 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1242 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001243 * <p>
1244 * The calling device admin must have requested
1245 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1246 * this method; if it has not, a security exception will be thrown.
1247 *
1248 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1249 * with.
1250 * @param length The new desired minimum number of symbols required in the
1251 * password. A value of 0 means there is no restriction.
1252 */
1253 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1254 if (mService != null) {
1255 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001256 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001257 } catch (RemoteException e) {
1258 Log.w(TAG, "Failed talking with device policy service", e);
1259 }
1260 }
1261 }
1262
1263 /**
1264 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001265 * admins or a particular one. This is the same value as
1266 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1267 * and only applies when the password quality is
1268 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001269 *
1270 * @param admin The name of the admin component to check, or null to
1271 * aggregate all admins.
1272 * @return The minimum number of symbols required in the password.
1273 */
1274 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001275 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1276 }
1277
1278 /** @hide per-user version */
1279 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001280 if (mService != null) {
1281 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001282 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001283 } catch (RemoteException e) {
1284 Log.w(TAG, "Failed talking with device policy service", e);
1285 }
1286 }
1287 return 0;
1288 }
1289
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001290 /**
1291 * Called by an application that is administering the device to set the
1292 * minimum number of non-letter characters (numerical digits or symbols)
1293 * required in the password. After setting this, the user will not be able
1294 * to enter a new password that is not at least as restrictive as what has
1295 * been set. Note that the current password will remain until the user has
1296 * set a new one, so the change does not take place immediately. To prompt
1297 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1298 * setting this value. This constraint is only imposed if the administrator
1299 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1300 * {@link #setPasswordQuality}. The default value is 0.
1301 * <p>
1302 * The calling device admin must have requested
1303 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1304 * this method; if it has not, a security exception will be thrown.
1305 *
1306 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1307 * with.
1308 * @param length The new desired minimum number of letters required in the
1309 * password. A value of 0 means there is no restriction.
1310 */
1311 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1312 if (mService != null) {
1313 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001314 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001315 } catch (RemoteException e) {
1316 Log.w(TAG, "Failed talking with device policy service", e);
1317 }
1318 }
1319 }
1320
1321 /**
1322 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001323 * password for all admins of this user and its profiles or a particular one.
1324 * This is the same value as set by
1325 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001326 * and only applies when the password quality is
1327 * {@link #PASSWORD_QUALITY_COMPLEX}.
1328 *
1329 * @param admin The name of the admin component to check, or null to
1330 * aggregate all admins.
1331 * @return The minimum number of letters required in the password.
1332 */
1333 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001334 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1335 }
1336
1337 /** @hide per-user version */
1338 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001339 if (mService != null) {
1340 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001341 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001342 } catch (RemoteException e) {
1343 Log.w(TAG, "Failed talking with device policy service", e);
1344 }
1345 }
1346 return 0;
1347 }
1348
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001349 /**
1350 * Called by an application that is administering the device to set the length
1351 * of the password history. After setting this, the user will not be able to
1352 * enter a new password that is the same as any password in the history. Note
1353 * that the current password will remain until the user has set a new one, so
1354 * the change does not take place immediately. To prompt the user for a new
1355 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1356 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001357 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1358 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1359 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001360 *
1361 * <p>
1362 * The calling device admin must have requested
1363 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1364 * method; if it has not, a security exception will be thrown.
1365 *
1366 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1367 * with.
1368 * @param length The new desired length of password history. A value of 0
1369 * means there is no restriction.
1370 */
1371 public void setPasswordHistoryLength(ComponentName admin, int length) {
1372 if (mService != null) {
1373 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001374 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001375 } catch (RemoteException e) {
1376 Log.w(TAG, "Failed talking with device policy service", e);
1377 }
1378 }
1379 }
1380
1381 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001382 * Called by a device admin to set the password expiration timeout. Calling this method
1383 * will restart the countdown for password expiration for the given admin, as will changing
1384 * the device password (for all admins).
1385 *
1386 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1387 * For example, to have the password expire 5 days from now, timeout would be
1388 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1389 *
1390 * <p>To disable password expiration, a value of 0 may be used for timeout.
1391 *
Jim Millera4e28d12010-11-08 16:15:47 -08001392 * <p>The calling device admin must have requested
1393 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1394 * method; if it has not, a security exception will be thrown.
1395 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001396 * <p> Note that setting the password will automatically reset the expiration time for all
1397 * active admins. Active admins do not need to explicitly call this method in that case.
1398 *
Jim Millera4e28d12010-11-08 16:15:47 -08001399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1400 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1401 * means there is no restriction (unlimited).
1402 */
1403 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1404 if (mService != null) {
1405 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001406 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001407 } catch (RemoteException e) {
1408 Log.w(TAG, "Failed talking with device policy service", e);
1409 }
1410 }
1411 }
1412
1413 /**
Jim Miller6b857682011-02-16 16:27:41 -08001414 * Get the password expiration timeout for the given admin. The expiration timeout is the
1415 * recurring expiration timeout provided in the call to
1416 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1417 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001418 *
1419 * @param admin The name of the admin component to check, or null to aggregate all admins.
1420 * @return The timeout for the given admin or the minimum of all timeouts
1421 */
1422 public long getPasswordExpirationTimeout(ComponentName admin) {
1423 if (mService != null) {
1424 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001425 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001426 } catch (RemoteException e) {
1427 Log.w(TAG, "Failed talking with device policy service", e);
1428 }
1429 }
1430 return 0;
1431 }
1432
1433 /**
1434 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001435 * all admins of this user and its profiles if admin is null. If the password is
1436 * expired, this will return the time since the password expired as a negative number.
1437 * If admin is null, then a composite of all expiration timeouts is returned
1438 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001439 *
1440 * @param admin The name of the admin component to check, or null to aggregate all admins.
1441 * @return The password expiration time, in ms.
1442 */
1443 public long getPasswordExpiration(ComponentName admin) {
1444 if (mService != null) {
1445 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001446 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001447 } catch (RemoteException e) {
1448 Log.w(TAG, "Failed talking with device policy service", e);
1449 }
1450 }
1451 return 0;
1452 }
1453
1454 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001455 * Retrieve the current password history length for all admins of this
1456 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001457 * @param admin The name of the admin component to check, or null to aggregate
1458 * all admins.
1459 * @return The length of the password history
1460 */
1461 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001462 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1463 }
1464
1465 /** @hide per-user version */
1466 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001467 if (mService != null) {
1468 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001469 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001470 } catch (RemoteException e) {
1471 Log.w(TAG, "Failed talking with device policy service", e);
1472 }
1473 }
1474 return 0;
1475 }
1476
Dianne Hackbornd6847842010-01-12 18:14:19 -08001477 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001478 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001479 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001480 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001481 * @return Returns the maximum length that the user can enter.
1482 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001483 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001484 // Kind-of arbitrary.
1485 return 16;
1486 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001487
Dianne Hackborn254cb442010-01-27 19:23:59 -08001488 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001489 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001490 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001491 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001492 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001493 * <p>The calling device admin must have requested
1494 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1495 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001496 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001497 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001498 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001499 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001500 if (mService != null) {
1501 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001502 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001503 } catch (RemoteException e) {
1504 Log.w(TAG, "Failed talking with device policy service", e);
1505 }
1506 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001507 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001508 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001509
Dianne Hackbornd6847842010-01-12 18:14:19 -08001510 /**
1511 * Retrieve the number of times the user has failed at entering a
1512 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001513 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001514 * <p>The calling device admin must have requested
1515 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1516 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001517 */
1518 public int getCurrentFailedPasswordAttempts() {
1519 if (mService != null) {
1520 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001521 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001522 } catch (RemoteException e) {
1523 Log.w(TAG, "Failed talking with device policy service", e);
1524 }
1525 }
1526 return -1;
1527 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001528
1529 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001530 * Setting this to a value greater than zero enables a built-in policy
1531 * that will perform a device wipe after too many incorrect
1532 * device-unlock passwords have been entered. This built-in policy combines
1533 * watching for failed passwords and wiping the device, and requires
1534 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001535 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001536 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001537 * <p>To implement any other policy (e.g. wiping data for a particular
1538 * application only, erasing or revoking credentials, or reporting the
1539 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001540 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001541 * instead. Do not use this API, because if the maximum count is reached,
1542 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001543 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001544 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001545 * @param num The number of failed password attempts at which point the
1546 * device will wipe its data.
1547 */
1548 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1549 if (mService != null) {
1550 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001551 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001552 } catch (RemoteException e) {
1553 Log.w(TAG, "Failed talking with device policy service", e);
1554 }
1555 }
1556 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001557
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001558 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001559 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001560 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001561 * or a particular one.
1562 * @param admin The name of the admin component to check, or null to aggregate
1563 * all admins.
1564 */
1565 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001566 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1567 }
1568
1569 /** @hide per-user version */
1570 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001571 if (mService != null) {
1572 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001573 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001574 } catch (RemoteException e) {
1575 Log.w(TAG, "Failed talking with device policy service", e);
1576 }
1577 }
1578 return 0;
1579 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001580
Dianne Hackborn254cb442010-01-27 19:23:59 -08001581 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001582 * Returns the profile with the smallest maximum failed passwords for wipe,
1583 * for the given user. So for primary user, it might return the primary or
1584 * a managed profile. For a secondary user, it would be the same as the
1585 * user passed in.
1586 * @hide Used only by Keyguard
1587 */
1588 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1589 if (mService != null) {
1590 try {
1591 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1592 } catch (RemoteException e) {
1593 Log.w(TAG, "Failed talking with device policy service", e);
1594 }
1595 }
1596 return UserHandle.USER_NULL;
1597 }
1598
1599 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001600 * Flag for {@link #resetPassword}: don't allow other admins to change
1601 * the password again until the user has entered it.
1602 */
1603 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001604
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001605 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001606 * Force a new device unlock password (the password needed to access the
1607 * entire device, not for individual accounts) on the user. This takes
1608 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001609 * The given password must be sufficient for the
1610 * current password quality and length constraints as returned by
1611 * {@link #getPasswordQuality(ComponentName)} and
1612 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1613 * these constraints, then it will be rejected and false returned. Note
1614 * that the password may be a stronger quality (containing alphanumeric
1615 * characters when the requested quality is only numeric), in which case
1616 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001617 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001618 * <p>Calling with a null or empty password will clear any existing PIN,
1619 * pattern or password if the current password constraints allow it.
1620 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001621 * <p>The calling device admin must have requested
1622 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1623 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001624 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001625 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001626 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001627 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001628 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001629 * @return Returns true if the password was applied, or false if it is
1630 * not acceptable for the current constraints.
1631 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001632 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001633 if (mService != null) {
1634 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001635 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001636 } catch (RemoteException e) {
1637 Log.w(TAG, "Failed talking with device policy service", e);
1638 }
1639 }
1640 return false;
1641 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001642
Dianne Hackbornd6847842010-01-12 18:14:19 -08001643 /**
1644 * Called by an application that is administering the device to set the
1645 * maximum time for user activity until the device will lock. This limits
1646 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001647 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001648 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001649 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001650 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001651 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001652 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001653 * @param timeMs The new desired maximum time to lock in milliseconds.
1654 * A value of 0 means there is no restriction.
1655 */
1656 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1657 if (mService != null) {
1658 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001659 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001660 } catch (RemoteException e) {
1661 Log.w(TAG, "Failed talking with device policy service", e);
1662 }
1663 }
1664 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001665
Dianne Hackbornd6847842010-01-12 18:14:19 -08001666 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001667 * Retrieve the current maximum time to unlock for all admins of this user
1668 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001669 * @param admin The name of the admin component to check, or null to aggregate
1670 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001671 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001672 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001673 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001674 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001675 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1676 }
1677
1678 /** @hide per-user version */
1679 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001680 if (mService != null) {
1681 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001682 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001683 } catch (RemoteException e) {
1684 Log.w(TAG, "Failed talking with device policy service", e);
1685 }
1686 }
1687 return 0;
1688 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001689
Dianne Hackbornd6847842010-01-12 18:14:19 -08001690 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001691 * Make the device lock immediately, as if the lock screen timeout has
1692 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001693 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001694 * <p>The calling device admin must have requested
1695 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1696 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001697 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001698 public void lockNow() {
1699 if (mService != null) {
1700 try {
1701 mService.lockNow();
1702 } catch (RemoteException e) {
1703 Log.w(TAG, "Failed talking with device policy service", e);
1704 }
1705 }
1706 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001707
Dianne Hackbornd6847842010-01-12 18:14:19 -08001708 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001709 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001710 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001711 */
1712 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1713
1714 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001715 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1716 * data.
1717 *
Paul Crowley2934b262014-12-02 11:21:13 +00001718 * <p>This flag may only be set by device owner admins; if it is set by
1719 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001720 */
1721 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1722
1723 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001724 * Ask the user data be wiped. Wiping the primary user will cause the
1725 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001726 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001727 * <p>The calling device admin must have requested
1728 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1729 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001730 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001731 * @param flags Bit mask of additional options: currently supported flags
1732 * are {@link #WIPE_EXTERNAL_STORAGE} and
1733 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001734 */
1735 public void wipeData(int flags) {
1736 if (mService != null) {
1737 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001738 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001739 } catch (RemoteException e) {
1740 Log.w(TAG, "Failed talking with device policy service", e);
1741 }
1742 }
1743 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001744
Dianne Hackbornd6847842010-01-12 18:14:19 -08001745 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001746 * Called by an application that is administering the device to set the
1747 * global proxy and exclusion list.
1748 * <p>
1749 * The calling device admin must have requested
1750 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1751 * this method; if it has not, a security exception will be thrown.
1752 * Only the first device admin can set the proxy. If a second admin attempts
1753 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1754 * proxy will be returned. If successful in setting the proxy, null will
1755 * be returned.
1756 * The method can be called repeatedly by the device admin alrady setting the
1757 * proxy to update the proxy and exclusion list.
1758 *
1759 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1760 * with.
1761 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1762 * Pass Proxy.NO_PROXY to reset the proxy.
1763 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001764 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1765 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001766 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001767 */
1768 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1769 List<String> exclusionList ) {
1770 if (proxySpec == null) {
1771 throw new NullPointerException();
1772 }
1773 if (mService != null) {
1774 try {
1775 String hostSpec;
1776 String exclSpec;
1777 if (proxySpec.equals(Proxy.NO_PROXY)) {
1778 hostSpec = null;
1779 exclSpec = null;
1780 } else {
1781 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1782 throw new IllegalArgumentException();
1783 }
1784 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1785 String hostName = sa.getHostName();
1786 int port = sa.getPort();
1787 StringBuilder hostBuilder = new StringBuilder();
1788 hostSpec = hostBuilder.append(hostName)
1789 .append(":").append(Integer.toString(port)).toString();
1790 if (exclusionList == null) {
1791 exclSpec = "";
1792 } else {
1793 StringBuilder listBuilder = new StringBuilder();
1794 boolean firstDomain = true;
1795 for (String exclDomain : exclusionList) {
1796 if (!firstDomain) {
1797 listBuilder = listBuilder.append(",");
1798 } else {
1799 firstDomain = false;
1800 }
1801 listBuilder = listBuilder.append(exclDomain.trim());
1802 }
1803 exclSpec = listBuilder.toString();
1804 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001805 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1806 != android.net.Proxy.PROXY_VALID)
1807 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001808 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001809 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001810 } catch (RemoteException e) {
1811 Log.w(TAG, "Failed talking with device policy service", e);
1812 }
1813 }
1814 return null;
1815 }
1816
1817 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001818 * Set a network-independent global HTTP proxy. This is not normally what you want
1819 * for typical HTTP proxies - they are generally network dependent. However if you're
1820 * doing something unusual like general internal filtering this may be useful. On
1821 * a private network where the proxy is not accessible, you may break HTTP using this.
1822 *
1823 * <p>This method requires the caller to be the device owner.
1824 *
1825 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1826 * @see ProxyInfo
1827 *
1828 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1829 * with.
1830 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1831 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1832 */
1833 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1834 if (mService != null) {
1835 try {
1836 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1837 } catch (RemoteException e) {
1838 Log.w(TAG, "Failed talking with device policy service", e);
1839 }
1840 }
1841 }
1842
1843 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001844 * Returns the component name setting the global proxy.
1845 * @return ComponentName object of the device admin that set the global proxy, or
1846 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001847 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001848 */
1849 public ComponentName getGlobalProxyAdmin() {
1850 if (mService != null) {
1851 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001852 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001853 } catch (RemoteException e) {
1854 Log.w(TAG, "Failed talking with device policy service", e);
1855 }
1856 }
1857 return null;
1858 }
1859
1860 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001861 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001862 * indicating that encryption is not supported.
1863 */
1864 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1865
1866 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001867 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001868 * indicating that encryption is supported, but is not currently active.
1869 */
1870 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1871
1872 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001873 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001874 * indicating that encryption is not currently active, but is currently
1875 * being activated. This is only reported by devices that support
1876 * encryption of data and only when the storage is currently
1877 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1878 * to become encrypted will never return this value.
1879 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001880 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001881
1882 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001883 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001884 * indicating that encryption is active.
1885 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001886 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001887
1888 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001889 * Result code for {@link #getStorageEncryptionStatus}:
1890 * indicating that encryption is active, but an encryption key has not
1891 * been set by the user.
1892 */
1893 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1894
1895 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001896 * Activity action: begin the process of encrypting data on the device. This activity should
1897 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1898 * After resuming from this activity, use {@link #getStorageEncryption}
1899 * to check encryption status. However, on some devices this activity may never return, as
1900 * it may trigger a reboot and in some cases a complete data wipe of the device.
1901 */
1902 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1903 public static final String ACTION_START_ENCRYPTION
1904 = "android.app.action.START_ENCRYPTION";
1905
1906 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001907 * Widgets are enabled in keyguard
1908 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001909 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001910
1911 /**
Jim Miller50e62182014-04-23 17:25:00 -07001912 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001913 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001914 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1915
1916 /**
1917 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1918 */
1919 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1920
1921 /**
Jim Miller50e62182014-04-23 17:25:00 -07001922 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1923 */
1924 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1925
1926 /**
1927 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1928 */
1929 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1930
1931 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001932 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001933 * (e.g. PIN/Pattern/Password).
1934 */
1935 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1936
1937 /**
Jim Miller06e34502014-07-17 14:46:05 -07001938 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1939 */
1940 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1941
1942 /**
Jim Miller35207742012-11-02 15:33:20 -07001943 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001944 */
1945 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001946
1947 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001948 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001949 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001950 *
1951 * <p>When multiple device administrators attempt to control device
1952 * encryption, the most secure, supported setting will always be
1953 * used. If any device administrator requests device encryption,
1954 * it will be enabled; Conversely, if a device administrator
1955 * attempts to disable device encryption while another
1956 * device administrator has enabled it, the call to disable will
1957 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1958 *
1959 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001960 * written to other storage areas may or may not be encrypted, and this policy does not require
1961 * or control the encryption of any other storage areas.
1962 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1963 * {@code true}, then the directory returned by
1964 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1965 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001966 *
1967 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1968 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1969 * the encryption key may not be fully secured. For maximum security, the administrator should
1970 * also require (and check for) a pattern, PIN, or password.
1971 *
1972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1973 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001974 * @return the new request status (for all active admins) - will be one of
1975 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1976 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1977 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001978 */
1979 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1980 if (mService != null) {
1981 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001982 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001983 } catch (RemoteException e) {
1984 Log.w(TAG, "Failed talking with device policy service", e);
1985 }
1986 }
1987 return ENCRYPTION_STATUS_UNSUPPORTED;
1988 }
1989
1990 /**
1991 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001992 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001993 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001994 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1995 * this will return the requested encryption setting as an aggregate of all active
1996 * administrators.
1997 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001998 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001999 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002000 if (mService != null) {
2001 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002002 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002003 } catch (RemoteException e) {
2004 Log.w(TAG, "Failed talking with device policy service", e);
2005 }
2006 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002007 return false;
2008 }
2009
2010 /**
2011 * Called by an application that is administering the device to
2012 * determine the current encryption status of the device.
2013 *
2014 * Depending on the returned status code, the caller may proceed in different
2015 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2016 * storage system does not support encryption. If the
2017 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2018 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002019 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2020 * storage system has enabled encryption but no password is set so further action
2021 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002022 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2023 *
Robin Lee7e678712014-07-24 16:41:31 +01002024 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002025 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002026 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2027 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002028 */
2029 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002030 return getStorageEncryptionStatus(UserHandle.myUserId());
2031 }
2032
2033 /** @hide per-user version */
2034 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002035 if (mService != null) {
2036 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002037 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002038 } catch (RemoteException e) {
2039 Log.w(TAG, "Failed talking with device policy service", e);
2040 }
2041 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002042 return ENCRYPTION_STATUS_UNSUPPORTED;
2043 }
2044
2045 /**
Robin Lee7e678712014-07-24 16:41:31 +01002046 * Installs the given certificate as a user CA.
2047 *
Rubin Xuec32b562015-03-03 17:34:05 +00002048 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2049 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002050 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002051 *
2052 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002053 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002054 */
Robin Lee7e678712014-07-24 16:41:31 +01002055 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002056 if (mService != null) {
2057 try {
Robin Lee7e678712014-07-24 16:41:31 +01002058 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002059 } catch (RemoteException e) {
2060 Log.w(TAG, "Failed talking with device policy service", e);
2061 }
2062 }
2063 return false;
2064 }
2065
2066 /**
Robin Lee7e678712014-07-24 16:41:31 +01002067 * Uninstalls the given certificate from trusted user CAs, if present.
2068 *
Rubin Xuec32b562015-03-03 17:34:05 +00002069 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2070 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002071 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002072 */
Robin Lee7e678712014-07-24 16:41:31 +01002073 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002074 if (mService != null) {
2075 try {
Robin Lee306fe082014-06-19 14:04:24 +00002076 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002077 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002078 } catch (CertificateException e) {
2079 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002080 } catch (RemoteException e) {
2081 Log.w(TAG, "Failed talking with device policy service", e);
2082 }
2083 }
2084 }
2085
2086 /**
Robin Lee7e678712014-07-24 16:41:31 +01002087 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2088 * If a user has installed any certificates by other means than device policy these will be
2089 * included too.
2090 *
Rubin Xuec32b562015-03-03 17:34:05 +00002091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2092 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002093 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002094 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002095 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002096 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002097 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002098 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002099 mService.enforceCanManageCaCerts(admin);
2100 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2101 for (String alias : certStore.userAliases()) {
2102 try {
2103 certs.add(certStore.getCertificate(alias).getEncoded());
2104 } catch (CertificateException ce) {
2105 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2106 }
2107 }
2108 } catch (RemoteException re) {
2109 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002110 }
2111 }
2112 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002113 }
2114
2115 /**
Robin Lee7e678712014-07-24 16:41:31 +01002116 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2117 * means other than device policy will also be removed, except for system CA certificates.
2118 *
Rubin Xuec32b562015-03-03 17:34:05 +00002119 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2120 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002121 */
2122 public void uninstallAllUserCaCerts(ComponentName admin) {
2123 if (mService != null) {
2124 for (String alias : new TrustedCertificateStore().userAliases()) {
2125 try {
2126 mService.uninstallCaCert(admin, alias);
2127 } catch (RemoteException re) {
2128 Log.w(TAG, "Failed talking with device policy service", re);
2129 }
2130 }
2131 }
2132 }
2133
2134 /**
2135 * Returns whether this certificate is installed as a trusted CA.
2136 *
Rubin Xuec32b562015-03-03 17:34:05 +00002137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2138 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002139 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002140 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002141 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2142 if (mService != null) {
2143 try {
2144 mService.enforceCanManageCaCerts(admin);
2145 return getCaCertAlias(certBuffer) != null;
2146 } catch (RemoteException re) {
2147 Log.w(TAG, "Failed talking with device policy service", re);
2148 } catch (CertificateException ce) {
2149 Log.w(TAG, "Could not parse certificate", ce);
2150 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002151 }
2152 return false;
2153 }
2154
2155 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002156 * Called by a device or profile owner to install a certificate and private key pair. The
2157 * keypair will be visible to all apps within the profile.
2158 *
2159 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2160 * @param privKey The private key to install.
2161 * @param cert The certificate to install.
2162 * @param alias The private key alias under which to install the certificate. If a certificate
2163 * with that alias already exists, it will be overwritten.
2164 * @return {@code true} if the keys were installed, {@code false} otherwise.
2165 */
2166 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2167 String alias) {
2168 try {
2169 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002170 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2171 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2172 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002173 } catch (RemoteException e) {
2174 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002175 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2176 Log.w(TAG, "Failed to obtain private key material", e);
2177 } catch (CertificateException | IOException e) {
2178 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002179 }
2180 return false;
2181 }
2182
2183 /**
Robin Lee306fe082014-06-19 14:04:24 +00002184 * Returns the alias of a given CA certificate in the certificate store, or null if it
2185 * doesn't exist.
2186 */
2187 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2188 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2189 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2190 new ByteArrayInputStream(certBuffer));
2191 return new TrustedCertificateStore().getCertificateAlias(cert);
2192 }
2193
2194 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002195 * Called by a profile owner or device owner to grant access to privileged certificate
2196 * manipulation APIs to a third-party CA certificate installer app. Granted APIs include
2197 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
2198 * {@link #uninstallCaCert} and {@link #uninstallAllUserCaCerts}.
2199 * <p>
2200 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2201 * it is later cleared by calling this method with a null value or uninstallling the certificate
2202 * installer.
2203 *
2204 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2205 * @param installerPackage The package name of the certificate installer which will be given
2206 * access. If <code>null</code> is given the current package will be cleared.
2207 */
2208 public void setCertInstallerPackage(ComponentName who, String installerPackage)
2209 throws SecurityException {
2210 if (mService != null) {
2211 try {
2212 mService.setCertInstallerPackage(who, installerPackage);
2213 } catch (RemoteException e) {
2214 Log.w(TAG, "Failed talking with device policy service", e);
2215 }
2216 }
2217 }
2218
2219 /**
2220 * Called by a profile owner or device owner to retrieve the certificate installer for the
2221 * current user. null if none is set.
2222 *
2223 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2224 * @return The package name of the current delegated certificate installer. <code>null</code>
2225 * if none is set.
2226 */
2227 public String getCertInstallerPackage(ComponentName who) throws SecurityException {
2228 if (mService != null) {
2229 try {
2230 return mService.getCertInstallerPackage(who);
2231 } catch (RemoteException e) {
2232 Log.w(TAG, "Failed talking with device policy service", e);
2233 }
2234 }
2235 return null;
2236 }
2237
2238 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002239 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002240 * on the device, for this user. After setting this, no applications running as this user
2241 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002242 *
2243 * <p>The calling device admin must have requested
2244 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2245 * this method; if it has not, a security exception will be thrown.
2246 *
2247 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2248 * @param disabled Whether or not the camera should be disabled.
2249 */
2250 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2251 if (mService != null) {
2252 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002253 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002254 } catch (RemoteException e) {
2255 Log.w(TAG, "Failed talking with device policy service", e);
2256 }
2257 }
2258 }
2259
2260 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002261 * Determine whether or not the device's cameras have been disabled for this user,
2262 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002263 * @param admin The name of the admin component to check, or null to check if any admins
2264 * have disabled the camera
2265 */
2266 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002267 return getCameraDisabled(admin, UserHandle.myUserId());
2268 }
2269
2270 /** @hide per-user version */
2271 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002272 if (mService != null) {
2273 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002274 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002275 } catch (RemoteException e) {
2276 Log.w(TAG, "Failed talking with device policy service", e);
2277 }
2278 }
2279 return false;
2280 }
2281
2282 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002283 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2284 * screen capture also prevents the content from being shown on display devices that do not have
2285 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2286 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002287 *
2288 * <p>The calling device admin must be a device or profile owner. If it is not, a
2289 * security exception will be thrown.
2290 *
2291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002292 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002293 */
2294 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2295 if (mService != null) {
2296 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002297 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002298 } catch (RemoteException e) {
2299 Log.w(TAG, "Failed talking with device policy service", e);
2300 }
2301 }
2302 }
2303
2304 /**
2305 * Determine whether or not screen capture has been disabled by the current
2306 * admin, if specified, or all admins.
2307 * @param admin The name of the admin component to check, or null to check if any admins
2308 * have disabled screen capture.
2309 */
2310 public boolean getScreenCaptureDisabled(ComponentName admin) {
2311 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2312 }
2313
2314 /** @hide per-user version */
2315 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2316 if (mService != null) {
2317 try {
2318 return mService.getScreenCaptureDisabled(admin, userHandle);
2319 } catch (RemoteException e) {
2320 Log.w(TAG, "Failed talking with device policy service", e);
2321 }
2322 }
2323 return false;
2324 }
2325
2326 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002327 * Called by a device owner to set whether auto time is required. If auto time is
2328 * required the user cannot set the date and time, but has to use network date and time.
2329 *
2330 * <p>Note: if auto time is required the user can still manually set the time zone.
2331 *
2332 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2333 * be thrown.
2334 *
2335 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2336 * @param required Whether auto time is set required or not.
2337 */
2338 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2339 if (mService != null) {
2340 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002341 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002342 } catch (RemoteException e) {
2343 Log.w(TAG, "Failed talking with device policy service", e);
2344 }
2345 }
2346 }
2347
2348 /**
2349 * @return true if auto time is required.
2350 */
2351 public boolean getAutoTimeRequired() {
2352 if (mService != null) {
2353 try {
2354 return mService.getAutoTimeRequired();
2355 } catch (RemoteException e) {
2356 Log.w(TAG, "Failed talking with device policy service", e);
2357 }
2358 }
2359 return false;
2360 }
2361
2362 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002363 * Called by an application that is administering the device to disable keyguard customizations,
2364 * such as widgets. After setting this, keyguard features will be disabled according to the
2365 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002366 *
2367 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002368 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002369 * this method; if it has not, a security exception will be thrown.
2370 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002371 * <p>Calling this from a managed profile will throw a security exception.
2372 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002373 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002374 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2375 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002376 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2377 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002378 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002379 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002380 if (mService != null) {
2381 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002382 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002383 } catch (RemoteException e) {
2384 Log.w(TAG, "Failed talking with device policy service", e);
2385 }
2386 }
2387 }
2388
2389 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002390 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002391 * admin, if specified, or all admins.
2392 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002393 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002394 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2395 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002396 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002397 public int getKeyguardDisabledFeatures(ComponentName admin) {
2398 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002399 }
2400
2401 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002402 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002403 if (mService != null) {
2404 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002405 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002406 } catch (RemoteException e) {
2407 Log.w(TAG, "Failed talking with device policy service", e);
2408 }
2409 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002410 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002411 }
2412
2413 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002414 * @hide
2415 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002416 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002417 if (mService != null) {
2418 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002419 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002420 } catch (RemoteException e) {
2421 Log.w(TAG, "Failed talking with device policy service", e);
2422 }
2423 }
2424 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002425
Dianne Hackbornd6847842010-01-12 18:14:19 -08002426 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002427 * @hide
2428 */
2429 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2430 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2431 }
2432
2433 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002434 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002435 * @hide
2436 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002437 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002438 ActivityInfo ai;
2439 try {
2440 ai = mContext.getPackageManager().getReceiverInfo(cn,
2441 PackageManager.GET_META_DATA);
2442 } catch (PackageManager.NameNotFoundException e) {
2443 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2444 return null;
2445 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002446
Dianne Hackbornd6847842010-01-12 18:14:19 -08002447 ResolveInfo ri = new ResolveInfo();
2448 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002449
Dianne Hackbornd6847842010-01-12 18:14:19 -08002450 try {
2451 return new DeviceAdminInfo(mContext, ri);
2452 } catch (XmlPullParserException e) {
2453 Log.w(TAG, "Unable to parse device policy " + cn, e);
2454 return null;
2455 } catch (IOException e) {
2456 Log.w(TAG, "Unable to parse device policy " + cn, e);
2457 return null;
2458 }
2459 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002460
Dianne Hackbornd6847842010-01-12 18:14:19 -08002461 /**
2462 * @hide
2463 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002464 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2465 if (mService != null) {
2466 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002467 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002468 } catch (RemoteException e) {
2469 Log.w(TAG, "Failed talking with device policy service", e);
2470 }
2471 }
2472 }
2473
2474 /**
2475 * @hide
2476 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002477 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002478 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002479 if (mService != null) {
2480 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002481 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002482 numbers, symbols, nonletter, 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 /**
2490 * @hide
2491 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002492 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002493 if (mService != null) {
2494 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002495 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002496 } catch (RemoteException e) {
2497 Log.w(TAG, "Failed talking with device policy service", e);
2498 }
2499 }
2500 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002501
Dianne Hackbornd6847842010-01-12 18:14:19 -08002502 /**
2503 * @hide
2504 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002505 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002506 if (mService != null) {
2507 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002508 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002509 } catch (RemoteException e) {
2510 Log.w(TAG, "Failed talking with device policy service", e);
2511 }
2512 }
2513 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002514
2515 /**
2516 * @hide
2517 * Sets the given package as the device owner. The package must already be installed and there
2518 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2519 * method must be called before the device is provisioned.
2520 * @param packageName the package name of the application to be registered as the device owner.
2521 * @return whether the package was successfully registered as the device owner.
2522 * @throws IllegalArgumentException if the package name is null or invalid
2523 * @throws IllegalStateException if a device owner is already registered or the device has
2524 * already been provisioned.
2525 */
2526 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2527 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002528 return setDeviceOwner(packageName, null);
2529 }
2530
2531 /**
2532 * @hide
2533 * Sets the given package as the device owner. The package must already be installed and there
2534 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2535 * method must be called before the device is provisioned.
2536 * @param packageName the package name of the application to be registered as the device owner.
2537 * @param ownerName the human readable name of the institution that owns this device.
2538 * @return whether the package was successfully registered as the device owner.
2539 * @throws IllegalArgumentException if the package name is null or invalid
2540 * @throws IllegalStateException if a device owner is already registered or the device has
2541 * already been provisioned.
2542 */
2543 public boolean setDeviceOwner(String packageName, String ownerName)
2544 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002545 if (mService != null) {
2546 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002547 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002548 } catch (RemoteException re) {
2549 Log.w(TAG, "Failed to set device owner");
2550 }
2551 }
2552 return false;
2553 }
2554
2555 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002556 * Used to determine if a particular package has been registered as a Device Owner app.
2557 * A device owner app is a special device admin that cannot be deactivated by the user, once
2558 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2559 * package is currently registered as the device owner app, pass in the package name from
2560 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2561 * admin apps that want to check if they are also registered as the device owner app. The
2562 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2563 * the setup process.
2564 * @param packageName the package name of the app, to compare with the registered device owner
2565 * app, if any.
2566 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002567 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002568 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002569 if (mService != null) {
2570 try {
2571 return mService.isDeviceOwner(packageName);
2572 } catch (RemoteException re) {
2573 Log.w(TAG, "Failed to check device owner");
2574 }
2575 }
2576 return false;
2577 }
2578
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002579 /**
2580 * @hide
2581 * Redirect to isDeviceOwnerApp.
2582 */
2583 public boolean isDeviceOwner(String packageName) {
2584 return isDeviceOwnerApp(packageName);
2585 }
2586
Jason Monkb0dced82014-06-06 14:36:20 -04002587 /**
2588 * Clears the current device owner. The caller must be the device owner.
2589 *
2590 * This function should be used cautiously as once it is called it cannot
2591 * be undone. The device owner can only be set as a part of device setup
2592 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002593 *
2594 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002595 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002596 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002597 if (mService != null) {
2598 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002599 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002600 } catch (RemoteException re) {
2601 Log.w(TAG, "Failed to clear device owner");
2602 }
2603 }
2604 }
2605
Amith Yamasani71e6c692013-03-24 17:39:28 -07002606 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002607 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002608 public String getDeviceOwner() {
2609 if (mService != null) {
2610 try {
2611 return mService.getDeviceOwner();
2612 } catch (RemoteException re) {
2613 Log.w(TAG, "Failed to get device owner");
2614 }
2615 }
2616 return null;
2617 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002618
2619 /** @hide */
2620 public String getDeviceOwnerName() {
2621 if (mService != null) {
2622 try {
2623 return mService.getDeviceOwnerName();
2624 } catch (RemoteException re) {
2625 Log.w(TAG, "Failed to get device owner");
2626 }
2627 }
2628 return null;
2629 }
Adam Connors776c5552014-01-09 10:42:56 +00002630
2631 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002632 * Sets the given component as the device initializer. The package must already be installed and
2633 * set as an active device administrator, and there must not be an existing device initializer,
2634 * for this call to succeed. This method can only be called by an app holding the
2635 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2636 * device initializer app is granted device owner privileges during device initialization and
2637 * profile owner privileges during secondary user initialization.
2638 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2639 * called by the device owner.
2640 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2641 * @param initializerName The user-visible name of the device initializer.
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002642 * @return whether the component was successfully registered as the device initializer.
2643 * @throws IllegalArgumentException if the componentname is null or invalid
Julia Reynolds20118f12015-02-11 12:34:08 -05002644 * @throws IllegalStateException if the caller is not device owner or the device has
2645 * already been provisioned or a device initializer already exists.
2646 */
2647 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2648 String initializerName) throws IllegalArgumentException, IllegalStateException {
2649 if (mService != null) {
2650 try {
2651 return mService.setDeviceInitializer(who, initializer, initializerName);
2652 } catch (RemoteException re) {
2653 Log.w(TAG, "Failed to set device initializer");
2654 }
2655 }
2656 return false;
2657 }
2658
2659 /**
2660 * Used to determine if a particular package has been registered as the device initializer.
2661 *
2662 * @param packageName the package name of the app, to compare with the registered device
2663 * initializer app, if any.
2664 * @return whether or not the caller is registered as the device initializer app.
2665 */
2666 public boolean isDeviceInitializerApp(String packageName) {
2667 if (mService != null) {
2668 try {
2669 return mService.isDeviceInitializer(packageName);
2670 } catch (RemoteException re) {
2671 Log.w(TAG, "Failed to check device initializer");
2672 }
2673 }
2674 return false;
2675 }
2676
2677 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002678 * Removes the device initializer, so that it will not be invoked on user initialization for any
2679 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002680 * initializer itself. The caller must be an active administrator.
2681 *
2682 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002683 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002684 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002685 if (mService != null) {
2686 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002687 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002688 } catch (RemoteException re) {
2689 Log.w(TAG, "Failed to clear device initializer");
2690 }
2691 }
2692 }
2693
2694 /**
2695 * @hide
2696 * Gets the device initializer of the system.
2697 *
2698 * @return the package name of the device initializer.
2699 */
2700 @SystemApi
2701 public String getDeviceInitializerApp() {
2702 if (mService != null) {
2703 try {
2704 return mService.getDeviceInitializer();
2705 } catch (RemoteException re) {
2706 Log.w(TAG, "Failed to get device initializer");
2707 }
2708 }
2709 return null;
2710 }
2711
2712 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002713 * @hide
2714 * Gets the device initializer component of the system.
2715 *
2716 * @return the component name of the device initializer.
2717 */
2718 @SystemApi
2719 public ComponentName getDeviceInitializerComponent() {
2720 if (mService != null) {
2721 try {
2722 return mService.getDeviceInitializerComponent();
2723 } catch (RemoteException re) {
2724 Log.w(TAG, "Failed to get device initializer");
2725 }
2726 }
2727 return null;
2728 }
2729
2730
2731 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002732 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2733 * be used.
2734 *
2735 * <p>Device initializer must call this method to mark the user as functional.
2736 * Only the device initializer agent can call this.
2737 *
2738 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2739 * device initializer will no longer have elevated permissions to call methods in this class.
2740 * Additionally, it will be removed as an active administrator and its
2741 * {@link DeviceAdminReceiver} will be disabled.
2742 *
2743 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2744 * @return whether the user is now enabled.
2745 */
2746 public boolean setUserEnabled(ComponentName admin) {
2747 if (mService != null) {
2748 try {
2749 return mService.setUserEnabled(admin);
2750 } catch (RemoteException e) {
2751 Log.w(TAG, "Failed talking with device policy service", e);
2752 }
2753 }
2754 return false;
2755 }
2756
2757 /**
Adam Connors776c5552014-01-09 10:42:56 +00002758 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002759 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302760 * Sets the given component as an active admin and registers the package as the profile
2761 * owner for this user. The package must already be installed and there shouldn't be
2762 * an existing profile owner registered for this user. Also, this method must be called
2763 * before the user setup has been completed.
2764 * <p>
2765 * This method can only be called by system apps that hold MANAGE_USERS permission and
2766 * MANAGE_DEVICE_ADMINS permission.
2767 * @param admin The component to register as an active admin and profile owner.
2768 * @param ownerName The user-visible name of the entity that is managing this user.
2769 * @return whether the admin was successfully registered as the profile owner.
2770 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2771 * the user has already been set up.
2772 */
Justin Morey80440cc2014-07-24 09:16:35 -05002773 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302774 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2775 throws IllegalArgumentException {
2776 if (mService != null) {
2777 try {
2778 final int myUserId = UserHandle.myUserId();
2779 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002780 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302781 } catch (RemoteException re) {
2782 Log.w(TAG, "Failed to set profile owner " + re);
2783 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2784 }
2785 }
2786 return false;
2787 }
2788
2789 /**
2790 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002791 * Clears the active profile owner and removes all user restrictions. The caller must
2792 * be from the same package as the active profile owner for this user, otherwise a
2793 * SecurityException will be thrown.
2794 *
2795 * @param admin The component to remove as the profile owner.
2796 * @return
2797 */
2798 @SystemApi
2799 public void clearProfileOwner(ComponentName admin) {
2800 if (mService != null) {
2801 try {
2802 mService.clearProfileOwner(admin);
2803 } catch (RemoteException re) {
2804 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2805 }
2806 }
2807 }
2808
2809 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002810 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002811 * Checks if the user was already setup.
2812 */
2813 public boolean hasUserSetupCompleted() {
2814 if (mService != null) {
2815 try {
2816 return mService.hasUserSetupCompleted();
2817 } catch (RemoteException re) {
2818 Log.w(TAG, "Failed to check if user setup has completed");
2819 }
2820 }
2821 return true;
2822 }
2823
2824 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002825 * @hide
2826 * Sets the given component as the profile owner of the given user profile. The package must
2827 * already be installed and there shouldn't be an existing profile owner registered for this
2828 * user. Only the system can call this API if the user has already completed setup.
2829 * @param admin the component name to be registered as profile owner.
2830 * @param ownerName the human readable name of the organisation associated with this DPM.
2831 * @param userHandle the userId to set the profile owner for.
2832 * @return whether the component was successfully registered as the profile owner.
2833 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2834 * the user has already been set up.
2835 */
2836 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2837 throws IllegalArgumentException {
2838 if (admin == null) {
2839 throw new NullPointerException("admin cannot be null");
2840 }
Adam Connors776c5552014-01-09 10:42:56 +00002841 if (mService != null) {
2842 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002843 if (ownerName == null) {
2844 ownerName = "";
2845 }
2846 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002847 } catch (RemoteException re) {
2848 Log.w(TAG, "Failed to set profile owner", re);
2849 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2850 }
2851 }
2852 return false;
2853 }
2854
2855 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002856 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2857 * be used. Only the profile owner can call this.
2858 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002859 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002860 *
2861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2862 */
2863 public void setProfileEnabled(ComponentName admin) {
2864 if (mService != null) {
2865 try {
2866 mService.setProfileEnabled(admin);
2867 } catch (RemoteException e) {
2868 Log.w(TAG, "Failed talking with device policy service", e);
2869 }
2870 }
2871 }
2872
2873 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002874 * Sets the name of the profile. In the device owner case it sets the name of the user
2875 * 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 +01002876 * never called by the profile or device owner, the name will be set to default values.
2877 *
2878 * @see #isProfileOwnerApp
2879 * @see #isDeviceOwnerApp
2880 *
2881 * @param profileName The name of the profile.
2882 */
2883 public void setProfileName(ComponentName who, String profileName) {
2884 if (mService != null) {
2885 try {
2886 mService.setProfileName(who, profileName);
2887 } catch (RemoteException e) {
2888 Log.w(TAG, "Failed talking with device policy service", e);
2889 }
2890 }
2891}
2892
2893 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002894 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002895 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002896 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002897 *
2898 * @param packageName The package name of the app to compare with the registered profile owner.
2899 * @return Whether or not the package is registered as the profile owner.
2900 */
2901 public boolean isProfileOwnerApp(String packageName) {
2902 if (mService != null) {
2903 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002904 ComponentName profileOwner = mService.getProfileOwner(
2905 Process.myUserHandle().getIdentifier());
2906 return profileOwner != null
2907 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002908 } catch (RemoteException re) {
2909 Log.w(TAG, "Failed to check profile owner");
2910 }
2911 }
2912 return false;
2913 }
2914
2915 /**
2916 * @hide
2917 * @return the packageName of the owner of the given user profile or null if no profile
2918 * owner has been set for that user.
2919 * @throws IllegalArgumentException if the userId is invalid.
2920 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002921 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002922 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002923 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2924 }
2925
2926 /**
2927 * @see #getProfileOwner()
2928 * @hide
2929 */
2930 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002931 if (mService != null) {
2932 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002933 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002934 } catch (RemoteException re) {
2935 Log.w(TAG, "Failed to get profile owner");
2936 throw new IllegalArgumentException(
2937 "Requested profile owner for invalid userId", re);
2938 }
2939 }
2940 return null;
2941 }
2942
2943 /**
2944 * @hide
2945 * @return the human readable name of the organisation associated with this DPM or null if
2946 * one is not set.
2947 * @throws IllegalArgumentException if the userId is invalid.
2948 */
2949 public String getProfileOwnerName() throws IllegalArgumentException {
2950 if (mService != null) {
2951 try {
2952 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2953 } catch (RemoteException re) {
2954 Log.w(TAG, "Failed to get profile owner");
2955 throw new IllegalArgumentException(
2956 "Requested profile owner for invalid userId", re);
2957 }
2958 }
2959 return null;
2960 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002961
2962 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002963 * @hide
2964 * @param user The user for whom to fetch the profile owner name, if any.
2965 * @return the human readable name of the organisation associated with this profile owner or
2966 * null if one is not set.
2967 * @throws IllegalArgumentException if the userId is invalid.
2968 */
2969 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002970 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002971 if (mService != null) {
2972 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002973 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002974 } catch (RemoteException re) {
2975 Log.w(TAG, "Failed to get profile owner");
2976 throw new IllegalArgumentException(
2977 "Requested profile owner for invalid userId", re);
2978 }
2979 }
2980 return null;
2981 }
2982
2983 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002984 * Called by a profile owner or device owner to add a default intent handler activity for
2985 * intents that match a certain intent filter. This activity will remain the default intent
2986 * handler even if the set of potential event handlers for the intent filter changes and if
2987 * the intent preferences are reset.
2988 *
2989 * <p>The default disambiguation mechanism takes over if the activity is not installed
2990 * (anymore). When the activity is (re)installed, it is automatically reset as default
2991 * intent handler for the filter.
2992 *
2993 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2994 * security exception will be thrown.
2995 *
2996 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2997 * @param filter The IntentFilter for which a default handler is added.
2998 * @param activity The Activity that is added as default intent handler.
2999 */
3000 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
3001 ComponentName activity) {
3002 if (mService != null) {
3003 try {
3004 mService.addPersistentPreferredActivity(admin, filter, activity);
3005 } catch (RemoteException e) {
3006 Log.w(TAG, "Failed talking with device policy service", e);
3007 }
3008 }
3009 }
3010
3011 /**
3012 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003013 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003014 *
3015 * <p>The calling device admin must be a profile owner. If it is not, a security
3016 * exception will be thrown.
3017 *
3018 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3019 * @param packageName The name of the package for which preferences are removed.
3020 */
3021 public void clearPackagePersistentPreferredActivities(ComponentName admin,
3022 String packageName) {
3023 if (mService != null) {
3024 try {
3025 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3026 } catch (RemoteException e) {
3027 Log.w(TAG, "Failed talking with device policy service", e);
3028 }
3029 }
3030 }
Robin Lee66e5d962014-04-09 16:44:21 +01003031
3032 /**
3033 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003034 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003035 *
3036 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003037 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003038 *
3039 * <p>The application restrictions are only made visible to the target application and the
3040 * profile or device owner.
3041 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003042 * <p>If the restrictions are not available yet, but may be applied in the near future,
3043 * the admin can notify the target application of that by adding
3044 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3045 *
Robin Lee66e5d962014-04-09 16:44:21 +01003046 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3047 * exception will be thrown.
3048 *
3049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3050 * @param packageName The name of the package to update restricted settings for.
3051 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3052 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003053 *
3054 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003055 */
3056 public void setApplicationRestrictions(ComponentName admin, String packageName,
3057 Bundle settings) {
3058 if (mService != null) {
3059 try {
3060 mService.setApplicationRestrictions(admin, packageName, settings);
3061 } catch (RemoteException e) {
3062 Log.w(TAG, "Failed talking with device policy service", e);
3063 }
3064 }
3065 }
3066
3067 /**
Jim Millere303bf42014-08-26 17:12:29 -07003068 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3069 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3070 * trust agents but those enabled by this function call. If flag
3071 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003072 *
3073 * <p>The calling device admin must have requested
3074 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003075 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003076 *
3077 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003078 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003079 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003080 * will be strictly disabled according to the state of the
3081 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3082 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3083 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3084 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003085 */
Jim Millere303bf42014-08-26 17:12:29 -07003086 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08003087 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003088 if (mService != null) {
3089 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003090 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003091 } catch (RemoteException e) {
3092 Log.w(TAG, "Failed talking with device policy service", e);
3093 }
3094 }
3095 }
3096
3097 /**
Jim Millere303bf42014-08-26 17:12:29 -07003098 * Gets configuration for the given trust agent based on aggregating all calls to
3099 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3100 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003101 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3103 * this function returns a list of configurations for all admins that declare
3104 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3105 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3106 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3107 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003108 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003109 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003110 */
Jim Millere303bf42014-08-26 17:12:29 -07003111 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3112 ComponentName agent) {
3113 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3114 }
3115
3116 /** @hide per-user version */
3117 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3118 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003119 if (mService != null) {
3120 try {
Jim Millere303bf42014-08-26 17:12:29 -07003121 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003122 } catch (RemoteException e) {
3123 Log.w(TAG, "Failed talking with device policy service", e);
3124 }
3125 }
Jim Millere303bf42014-08-26 17:12:29 -07003126 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003127 }
3128
3129 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003130 * Called by a profile owner of a managed profile to set whether caller-Id information from
3131 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003132 *
3133 * <p>The calling device admin must be a profile owner. If it is not, a
3134 * security exception will be thrown.
3135 *
3136 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3137 * @param disabled If true caller-Id information in the managed profile is not displayed.
3138 */
3139 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
3140 if (mService != null) {
3141 try {
3142 mService.setCrossProfileCallerIdDisabled(who, disabled);
3143 } catch (RemoteException e) {
3144 Log.w(TAG, "Failed talking with device policy service", e);
3145 }
3146 }
3147 }
3148
3149 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003150 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3151 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003152 *
3153 * <p>The calling device admin must be a profile owner. If it is not, a
3154 * security exception will be thrown.
3155 *
3156 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3157 */
3158 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3159 if (mService != null) {
3160 try {
3161 return mService.getCrossProfileCallerIdDisabled(who);
3162 } catch (RemoteException e) {
3163 Log.w(TAG, "Failed talking with device policy service", e);
3164 }
3165 }
3166 return false;
3167 }
3168
3169 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003170 * Determine whether or not caller-Id information has been disabled.
3171 *
3172 * @param userHandle The user for whom to check the caller-id permission
3173 * @hide
3174 */
3175 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3176 if (mService != null) {
3177 try {
3178 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3179 } catch (RemoteException e) {
3180 Log.w(TAG, "Failed talking with device policy service", e);
3181 }
3182 }
3183 return false;
3184 }
3185
3186 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003187 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3188 * @hide
3189 */
3190 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3191 Intent originalIntent) {
3192 if (mService != null) {
3193 try {
3194 mService.startManagedQuickContact(
3195 actualLookupKey, actualContactId, originalIntent);
3196 } catch (RemoteException e) {
3197 Log.w(TAG, "Failed talking with device policy service", e);
3198 }
3199 }
3200 }
3201
3202 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003203 * Called by the profile owner of a managed profile so that some intents sent in the managed
3204 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003205 * Only activity intents are supported.
3206 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003207 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003208 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3209 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003210 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3211 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003212 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003213 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003214 if (mService != null) {
3215 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003216 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003217 } catch (RemoteException e) {
3218 Log.w(TAG, "Failed talking with device policy service", e);
3219 }
3220 }
3221 }
3222
3223 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003224 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3225 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003226 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003227 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3228 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003229 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003230 if (mService != null) {
3231 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003232 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003233 } catch (RemoteException e) {
3234 Log.w(TAG, "Failed talking with device policy service", e);
3235 }
3236 }
3237 }
3238
3239 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003240 * Called by a profile or device owner to set the permitted accessibility services. When
3241 * set by a device owner or profile owner the restriction applies to all profiles of the
3242 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003243 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003244 * By default the user can use any accessiblity service. When zero or more packages have
3245 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003246 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003247 *
3248 * <p> Calling with a null value for the list disables the restriction so that all services
3249 * can be used, calling with an empty list only allows the builtin system's services.
3250 *
3251 * <p> System accesibility services are always available to the user the list can't modify
3252 * this.
3253 *
3254 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3255 * @param packageNames List of accessibility service package names.
3256 *
3257 * @return true if setting the restriction succeeded. It fail if there is
3258 * one or more non-system accessibility services enabled, that are not in the list.
3259 */
3260 public boolean setPermittedAccessibilityServices(ComponentName admin,
3261 List<String> packageNames) {
3262 if (mService != null) {
3263 try {
3264 return mService.setPermittedAccessibilityServices(admin, packageNames);
3265 } catch (RemoteException e) {
3266 Log.w(TAG, "Failed talking with device policy service", e);
3267 }
3268 }
3269 return false;
3270 }
3271
3272 /**
3273 * Returns the list of permitted accessibility services set by this device or profile owner.
3274 *
3275 * <p>An empty list means no accessibility services except system services are allowed.
3276 * Null means all accessibility services are allowed.
3277 *
3278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3279 * @return List of accessiblity service package names.
3280 */
3281 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3282 if (mService != null) {
3283 try {
3284 return mService.getPermittedAccessibilityServices(admin);
3285 } catch (RemoteException e) {
3286 Log.w(TAG, "Failed talking with device policy service", e);
3287 }
3288 }
3289 return null;
3290 }
3291
3292 /**
3293 * Returns the list of accessibility services permitted by the device or profiles
3294 * owners of this user.
3295 *
3296 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3297 * it will contain the intersection of the permitted lists for any device or profile
3298 * owners that apply to this user. It will also include any system accessibility services.
3299 *
3300 * @param userId which user to check for.
3301 * @return List of accessiblity service package names.
3302 * @hide
3303 */
3304 @SystemApi
3305 public List<String> getPermittedAccessibilityServices(int userId) {
3306 if (mService != null) {
3307 try {
3308 return mService.getPermittedAccessibilityServicesForUser(userId);
3309 } catch (RemoteException e) {
3310 Log.w(TAG, "Failed talking with device policy service", e);
3311 }
3312 }
3313 return null;
3314 }
3315
3316 /**
3317 * Called by a profile or device owner to set the permitted input methods services. When
3318 * set by a device owner or profile owner the restriction applies to all profiles of the
3319 * user the device owner or profile owner is an admin for.
3320 *
3321 * By default the user can use any input method. When zero or more packages have
3322 * been added, input method that are not in the list and not part of the system
3323 * can not be enabled by the user.
3324 *
3325 * This method will fail if it is called for a admin that is not for the foreground user
3326 * or a profile of the foreground user.
3327 *
3328 * <p> Calling with a null value for the list disables the restriction so that all input methods
3329 * can be used, calling with an empty list disables all but the system's own input methods.
3330 *
3331 * <p> System input methods are always available to the user this method can't modify this.
3332 *
3333 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3334 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003335 * @return true if setting the restriction succeeded. It will fail if there are
3336 * one or more non-system input methods currently enabled that are not in
3337 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003338 */
3339 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3340 if (mService != null) {
3341 try {
3342 return mService.setPermittedInputMethods(admin, packageNames);
3343 } catch (RemoteException e) {
3344 Log.w(TAG, "Failed talking with device policy service", e);
3345 }
3346 }
3347 return false;
3348 }
3349
3350
3351 /**
3352 * Returns the list of permitted input methods set by this device or profile owner.
3353 *
3354 * <p>An empty list means no input methods except system input methods are allowed.
3355 * Null means all input methods are allowed.
3356 *
3357 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3358 * @return List of input method package names.
3359 */
3360 public List<String> getPermittedInputMethods(ComponentName admin) {
3361 if (mService != null) {
3362 try {
3363 return mService.getPermittedInputMethods(admin);
3364 } catch (RemoteException e) {
3365 Log.w(TAG, "Failed talking with device policy service", e);
3366 }
3367 }
3368 return null;
3369 }
3370
3371 /**
3372 * Returns the list of input methods permitted by the device or profiles
3373 * owners of the current user.
3374 *
3375 * <p>Null means all input methods are allowed, if a non-null list is returned
3376 * it will contain the intersection of the permitted lists for any device or profile
3377 * owners that apply to this user. It will also include any system input methods.
3378 *
3379 * @return List of input method package names.
3380 * @hide
3381 */
3382 @SystemApi
3383 public List<String> getPermittedInputMethodsForCurrentUser() {
3384 if (mService != null) {
3385 try {
3386 return mService.getPermittedInputMethodsForCurrentUser();
3387 } catch (RemoteException e) {
3388 Log.w(TAG, "Failed talking with device policy service", e);
3389 }
3390 }
3391 return null;
3392 }
3393
3394 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003395 * Called by a device owner to create a user with the specified name. The UserHandle returned
3396 * by this method should not be persisted as user handles are recycled as users are removed and
3397 * created. If you need to persist an identifier for this user, use
3398 * {@link UserManager#getSerialNumberForUser}.
3399 *
3400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3401 * @param name the user's name
3402 * @see UserHandle
3403 * @return the UserHandle object for the created user, or null if the user could not be created.
3404 */
3405 public UserHandle createUser(ComponentName admin, String name) {
3406 try {
3407 return mService.createUser(admin, name);
3408 } catch (RemoteException re) {
3409 Log.w(TAG, "Could not create a user", re);
3410 }
3411 return null;
3412 }
3413
3414 /**
Jason Monk03978a42014-06-10 15:05:30 -04003415 * Called by a device owner to create a user with the specified name. The UserHandle returned
3416 * by this method should not be persisted as user handles are recycled as users are removed and
3417 * created. If you need to persist an identifier for this user, use
3418 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3419 * immediately.
3420 *
3421 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3422 * as registered as an active admin on the new user. The profile owner package will be
3423 * installed on the new user if it already is installed on the device.
3424 *
3425 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3426 * profileOwnerComponent when onEnable is called.
3427 *
3428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3429 * @param name the user's name
3430 * @param ownerName the human readable name of the organisation associated with this DPM.
3431 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3432 * the user.
3433 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3434 * on the new user.
3435 * @see UserHandle
3436 * @return the UserHandle object for the created user, or null if the user could not be created.
3437 */
3438 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3439 ComponentName profileOwnerComponent, Bundle adminExtras) {
3440 try {
3441 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3442 adminExtras);
3443 } catch (RemoteException re) {
3444 Log.w(TAG, "Could not create a user", re);
3445 }
3446 return null;
3447 }
3448
3449 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003450 * Called by a device owner to remove a user and all associated data. The primary user can
3451 * not be removed.
3452 *
3453 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3454 * @param userHandle the user to remove.
3455 * @return {@code true} if the user was removed, {@code false} otherwise.
3456 */
3457 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3458 try {
3459 return mService.removeUser(admin, userHandle);
3460 } catch (RemoteException re) {
3461 Log.w(TAG, "Could not remove user ", re);
3462 return false;
3463 }
3464 }
3465
3466 /**
Jason Monk582d9112014-07-09 19:57:08 -04003467 * Called by a device owner to switch the specified user to the foreground.
3468 *
3469 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3470 * @param userHandle the user to switch to; null will switch to primary.
3471 * @return {@code true} if the switch was successful, {@code false} otherwise.
3472 *
3473 * @see Intent#ACTION_USER_FOREGROUND
3474 */
3475 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3476 try {
3477 return mService.switchUser(admin, userHandle);
3478 } catch (RemoteException re) {
3479 Log.w(TAG, "Could not switch user ", re);
3480 return false;
3481 }
3482 }
3483
3484 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003485 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003486 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003487 *
3488 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3489 * exception will be thrown.
3490 *
3491 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3492 * @param packageName The name of the package to fetch restricted settings of.
3493 * @return {@link Bundle} of settings corresponding to what was set last time
3494 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3495 * if no restrictions have been set.
3496 */
3497 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3498 if (mService != null) {
3499 try {
3500 return mService.getApplicationRestrictions(admin, packageName);
3501 } catch (RemoteException e) {
3502 Log.w(TAG, "Failed talking with device policy service", e);
3503 }
3504 }
3505 return null;
3506 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003507
3508 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003509 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003510 * <p>
3511 * The calling device admin must be a profile or device owner; if it is not,
3512 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003513 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003514 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3515 * with.
3516 * @param key The key of the restriction. See the constants in
3517 * {@link android.os.UserManager} for the list of keys.
3518 */
3519 public void addUserRestriction(ComponentName admin, String key) {
3520 if (mService != null) {
3521 try {
3522 mService.setUserRestriction(admin, key, true);
3523 } catch (RemoteException e) {
3524 Log.w(TAG, "Failed talking with device policy service", e);
3525 }
3526 }
3527 }
3528
3529 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003530 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003531 * <p>
3532 * The calling device admin must be a profile or device owner; if it is not,
3533 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003534 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003535 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3536 * with.
3537 * @param key The key of the restriction. See the constants in
3538 * {@link android.os.UserManager} for the list of keys.
3539 */
3540 public void clearUserRestriction(ComponentName admin, String key) {
3541 if (mService != null) {
3542 try {
3543 mService.setUserRestriction(admin, key, false);
3544 } catch (RemoteException e) {
3545 Log.w(TAG, "Failed talking with device policy service", e);
3546 }
3547 }
3548 }
Adam Connors010cfd42014-04-16 12:48:13 +01003549
3550 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003551 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003552 * is unavailable for use, but the data and actual package file remain.
3553 *
3554 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003555 * @param packageName The name of the package to hide or unhide.
3556 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3557 * unhidden.
3558 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003559 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003560 public boolean setApplicationHidden(ComponentName admin, String packageName,
3561 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003562 if (mService != null) {
3563 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003564 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003565 } catch (RemoteException e) {
3566 Log.w(TAG, "Failed talking with device policy service", e);
3567 }
3568 }
3569 return false;
3570 }
3571
3572 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003573 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003574 *
3575 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003576 * @param packageName The name of the package to retrieve the hidden status of.
3577 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003578 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003579 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003580 if (mService != null) {
3581 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003582 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003583 } catch (RemoteException e) {
3584 Log.w(TAG, "Failed talking with device policy service", e);
3585 }
3586 }
3587 return false;
3588 }
3589
3590 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003591 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003592 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003593 *
3594 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3595 * @param packageName The package to be re-enabled in the current profile.
3596 */
3597 public void enableSystemApp(ComponentName admin, String packageName) {
3598 if (mService != null) {
3599 try {
3600 mService.enableSystemApp(admin, packageName);
3601 } catch (RemoteException e) {
3602 Log.w(TAG, "Failed to install package: " + packageName);
3603 }
3604 }
3605 }
3606
3607 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003608 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003609 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003610 *
3611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3612 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3613 * intent will be re-enabled in the current profile.
3614 * @return int The number of activities that matched the intent and were installed.
3615 */
3616 public int enableSystemApp(ComponentName admin, Intent intent) {
3617 if (mService != null) {
3618 try {
3619 return mService.enableSystemAppWithIntent(admin, intent);
3620 } catch (RemoteException e) {
3621 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3622 }
3623 }
3624 return 0;
3625 }
3626
3627 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003628 * Called by a device owner or profile owner to disable account management for a specific type
3629 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003630 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003631 * <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 +01003632 * security exception will be thrown.
3633 *
3634 * <p>When account management is disabled for an account type, adding or removing an account
3635 * of that type will not be possible.
3636 *
3637 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3638 * @param accountType For which account management is disabled or enabled.
3639 * @param disabled The boolean indicating that account management will be disabled (true) or
3640 * enabled (false).
3641 */
3642 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3643 boolean disabled) {
3644 if (mService != null) {
3645 try {
3646 mService.setAccountManagementDisabled(admin, accountType, disabled);
3647 } catch (RemoteException e) {
3648 Log.w(TAG, "Failed talking with device policy service", e);
3649 }
3650 }
3651 }
3652
3653 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003654 * Gets the array of accounts for which account management is disabled by the profile owner.
3655 *
3656 * <p> Account management can be disabled/enabled by calling
3657 * {@link #setAccountManagementDisabled}.
3658 *
3659 * @return a list of account types for which account management has been disabled.
3660 *
3661 * @see #setAccountManagementDisabled
3662 */
3663 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003664 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003665 }
3666
3667 /**
3668 * @see #getAccountTypesWithManagementDisabled()
3669 * @hide
3670 */
3671 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003672 if (mService != null) {
3673 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003674 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003675 } catch (RemoteException e) {
3676 Log.w(TAG, "Failed talking with device policy service", e);
3677 }
3678 }
3679
3680 return null;
3681 }
justinzhang511e0d82014-03-24 16:09:24 -04003682
3683 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003684 * Sets which packages may enter lock task mode.
3685 *
3686 * <p>Any packages that shares uid with an allowed package will also be allowed
3687 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003688 *
Jason Monkc5185f22014-06-24 11:12:42 -04003689 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003690 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003692 *
3693 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003694 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3695 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003696 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003697 */
Jason Monk48aacba2014-08-13 16:29:08 -04003698 public void setLockTaskPackages(ComponentName admin, String[] packages)
3699 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003700 if (mService != null) {
3701 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003702 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003703 } catch (RemoteException e) {
3704 Log.w(TAG, "Failed talking with device policy service", e);
3705 }
3706 }
3707 }
3708
3709 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003710 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003711 *
3712 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003713 * @hide
3714 */
Jason Monk48aacba2014-08-13 16:29:08 -04003715 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003716 if (mService != null) {
3717 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003718 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003719 } catch (RemoteException e) {
3720 Log.w(TAG, "Failed talking with device policy service", e);
3721 }
3722 }
3723 return null;
3724 }
3725
3726 /**
3727 * This function lets the caller know whether the given component is allowed to start the
3728 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003729 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003730 */
Jason Monkd7b86212014-06-16 13:15:38 -04003731 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003732 if (mService != null) {
3733 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003734 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003735 } catch (RemoteException e) {
3736 Log.w(TAG, "Failed talking with device policy service", e);
3737 }
3738 }
3739 return false;
3740 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003741
3742 /**
3743 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3744 * 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 -04003745 * <p>The settings that can be updated with this method are:
3746 * <ul>
3747 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3748 * <li>{@link Settings.Global#AUTO_TIME}</li>
3749 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003750 * <li>{@link Settings.Global#BLUETOOTH_ON}
3751 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3752 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3753 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003754 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3755 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3756 * <li>{@link Settings.Global#MODE_RINGER}</li>
3757 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3758 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003759 * <li>{@link Settings.Global#WIFI_ON}
3760 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3761 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003762 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003763 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3764 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3765 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003766 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003767 *
3768 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3769 * @param setting The name of the setting to update.
3770 * @param value The value to update the setting to.
3771 */
3772 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3773 if (mService != null) {
3774 try {
3775 mService.setGlobalSetting(admin, setting, value);
3776 } catch (RemoteException e) {
3777 Log.w(TAG, "Failed talking with device policy service", e);
3778 }
3779 }
3780 }
3781
3782 /**
3783 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3784 * that the value of the setting is in the correct form for the setting type should be performed
3785 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003786 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003787 * <ul>
3788 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003789 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003790 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3791 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003792 * <p>A device owner can additionally update the following settings:
3793 * <ul>
3794 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3795 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3797 * @param setting The name of the setting to update.
3798 * @param value The value to update the setting to.
3799 */
3800 public void setSecureSetting(ComponentName admin, String setting, String value) {
3801 if (mService != null) {
3802 try {
3803 mService.setSecureSetting(admin, setting, value);
3804 } catch (RemoteException e) {
3805 Log.w(TAG, "Failed talking with device policy service", e);
3806 }
3807 }
3808 }
3809
Amith Yamasanif20d6402014-05-24 15:34:37 -07003810 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003811 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003812 * making permission requests of a local or remote administrator of the user.
3813 * <p/>
3814 * Only a profile owner can designate the restrictions provider.
3815 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003816 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003817 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003818 * it removes the restrictions provider previously assigned.
3819 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003820 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003821 if (mService != null) {
3822 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003823 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003824 } catch (RemoteException re) {
3825 Log.w(TAG, "Failed to set permission provider on device policy service");
3826 }
3827 }
3828 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003829
3830 /**
3831 * Called by profile or device owners to set the master volume mute on or off.
3832 *
3833 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3834 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3835 */
3836 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3837 if (mService != null) {
3838 try {
3839 mService.setMasterVolumeMuted(admin, on);
3840 } catch (RemoteException re) {
3841 Log.w(TAG, "Failed to setMasterMute on device policy service");
3842 }
3843 }
3844 }
3845
3846 /**
3847 * Called by profile or device owners to check whether the master volume mute is on or off.
3848 *
3849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3850 * @return {@code true} if master volume is muted, {@code false} if it's not.
3851 */
3852 public boolean isMasterVolumeMuted(ComponentName admin) {
3853 if (mService != null) {
3854 try {
3855 return mService.isMasterVolumeMuted(admin);
3856 } catch (RemoteException re) {
3857 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3858 }
3859 }
3860 return false;
3861 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003862
3863 /**
3864 * Called by profile or device owners to change whether a user can uninstall
3865 * a package.
3866 *
3867 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3868 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003869 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003870 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003871 public void setUninstallBlocked(ComponentName admin, String packageName,
3872 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003873 if (mService != null) {
3874 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003875 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003876 } catch (RemoteException re) {
3877 Log.w(TAG, "Failed to call block uninstall on device policy service");
3878 }
3879 }
3880 }
3881
3882 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003883 * Check whether the current user has been blocked by device policy from uninstalling a package.
3884 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00003885 * <p>
3886 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
3887 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
3888 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
3889 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01003890 *
Rubin Xua97855b2014-11-07 05:41:00 +00003891 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00003892 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003893 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003894 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003895 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003896 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003897 if (mService != null) {
3898 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003899 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003900 } catch (RemoteException re) {
3901 Log.w(TAG, "Failed to call block uninstall on device policy service");
3902 }
3903 }
3904 return false;
3905 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003906
3907 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003908 * Called by the profile owner of a managed profile to enable widget providers from a
3909 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003910 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003911 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003912 * a package may have zero or more provider components, where each component
3913 * provides a different widget type.
3914 * <p>
3915 * <strong>Note:</strong> By default no widget provider package is white-listed.
3916 * </p>
3917 *
3918 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3919 * @param packageName The package from which widget providers are white-listed.
3920 * @return Whether the package was added.
3921 *
3922 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3923 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3924 */
3925 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3926 if (mService != null) {
3927 try {
3928 return mService.addCrossProfileWidgetProvider(admin, packageName);
3929 } catch (RemoteException re) {
3930 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3931 }
3932 }
3933 return false;
3934 }
3935
3936 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003937 * Called by the profile owner of a managed profile to disable widget providers from a given
3938 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003939 * package should have been added via {@link #addCrossProfileWidgetProvider(
3940 * android.content.ComponentName, String)}.
3941 * <p>
3942 * <strong>Note:</strong> By default no widget provider package is white-listed.
3943 * </p>
3944 *
3945 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3946 * @param packageName The package from which widget providers are no longer
3947 * white-listed.
3948 * @return Whether the package was removed.
3949 *
3950 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3951 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3952 */
3953 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3954 if (mService != null) {
3955 try {
3956 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3957 } catch (RemoteException re) {
3958 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3959 }
3960 }
3961 return false;
3962 }
3963
3964 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003965 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003966 * available in the parent profile.
3967 *
3968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3969 * @return The white-listed package list.
3970 *
3971 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3972 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3973 */
3974 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3975 if (mService != null) {
3976 try {
3977 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3978 if (providers != null) {
3979 return providers;
3980 }
3981 } catch (RemoteException re) {
3982 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3983 }
3984 }
3985 return Collections.emptyList();
3986 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05003987
3988 /**
3989 * Called by profile or device owners to set the current user's photo.
3990 *
3991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3992 * @param icon the bitmap to set as the photo.
3993 */
3994 public void setUserIcon(ComponentName admin, Bitmap icon) {
3995 try {
3996 mService.setUserIcon(admin, icon);
3997 } catch (RemoteException re) {
3998 Log.w(TAG, "Could not set the user icon ", re);
3999 }
4000 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004001}