blob: e8630b186a3977b5675b8fd13aaf97df73f7bb8a [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
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400178 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000179 *
180 * @see DeviceAdminReceiver
181 */
182 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
183 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
184
185 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000186 * An {@link android.accounts.Account} extra holding the account to migrate during managed
187 * profile provisioning. If the account supplied is present in the primary user, it will be
188 * copied, along with its credentials to the managed profile and removed from the primary user.
189 *
190 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
191 */
192
193 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
194 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
195
196 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100197 * A String extra that, holds the email address of the account which a managed profile is
198 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
199 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100200 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100201 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
202 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100203 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
204 * contains this extra, it is forwarded in the
205 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
206 * device management application that was set as the profile owner during provisioning.
207 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100208 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100209 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
210 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100211
212 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000213 * A Boolean extra that can be used by the mobile device management application to skip the
214 * disabling of system apps during provisioning when set to <code>true</code>.
215 *
216 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
217 * provisioning via an NFC bump.
218 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000219 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
220 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000221
222 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100223 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
224 * will be set to.
225 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000226 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
227 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100228 */
229 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100230 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100231
232 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100233 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
234 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100235 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000236 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
237 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100238 */
239 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100240 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100241
242 /**
243 * A String extra holding the {@link java.util.Locale} that the device will be set to.
244 * Format: xx_yy, where xx is the language code, and yy the country code.
245 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000246 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
247 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100248 */
249 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100250 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100251
252 /**
253 * A String extra holding the ssid of the wifi network that should be used during nfc device
254 * owner provisioning for downloading the mobile device management application.
255 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000256 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
257 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100258 */
259 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100260 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100261
262 /**
263 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
264 * is hidden or not.
265 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000266 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
267 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100268 */
269 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100270 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100271
272 /**
273 * A String extra indicating the security type of the wifi network in
274 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
275 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000276 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
277 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100278 */
279 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100280 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100281
282 /**
283 * A String extra holding the password of the wifi network in
284 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
285 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000286 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
287 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100288 */
289 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100290 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100291
292 /**
293 * A String extra holding the proxy host for the wifi network in
294 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
295 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000296 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
297 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100298 */
299 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100300 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100301
302 /**
303 * An int extra holding the proxy port for the wifi network in
304 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
305 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000306 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
307 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100308 */
309 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100310 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100311
312 /**
313 * A String extra holding the proxy bypass for the wifi network in
314 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
315 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000316 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
317 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100318 */
319 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100320 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100321
322 /**
323 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
324 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
325 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000326 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
327 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100328 */
329 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100330 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100331
332 /**
333 * A String extra holding a url that specifies the download location of the device admin
334 * package. When not provided it is assumed that the device admin package is already installed.
335 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000336 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
337 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100338 */
339 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100340 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100341
342 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400343 * An int extra holding a minimum required version code for the device admin package. If the
344 * device admin is already installed on the device, it will only be re-downloaded from
345 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
346 * installed package is less than this version code.
347 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400348 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400349 * provisioning via an NFC bump.
350 */
351 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
352 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
353
354 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100355 * A String extra holding a http cookie header which should be used in the http request to the
356 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
357 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000358 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
359 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100360 */
361 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100362 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100363
364 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000365 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
366 * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If
367 * this doesn't match the file at the download location an error will be shown to the user and
368 * the user will be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100369 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000370 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
371 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100372 */
373 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100374 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100375
376 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000377 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
378 * has completed successfully.
379 *
380 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
381 * intent (@see #ACTION_PROVISION_MANAGED_PROFILE).
382 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800383 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000384 * corresponds to the account requested to be migrated at provisioning time, if any.
385 */
386 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
387 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
388 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
389
390 /**
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500391 * A boolean extra indicating whether device encryption is required as part of Device Owner
392 * provisioning.
393 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400394 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500395 * provisioning via an NFC bump.
396 */
397 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
398 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
399
400 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500401 * On devices managed by a device owner app, a String representation of a Component name extra
402 * indicating the component of the application that is temporarily granted device owner
403 * privileges during device initialization and profile owner privileges during secondary user
404 * initialization.
405 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400406 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500407 * provisioning via an NFC bump.
408 * @see ComponentName#unflattenFromString()
409 */
410 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
411 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
412
413 /**
414 * A String extra holding an http url that specifies the download location of the device
415 * initializer package. When not provided it is assumed that the device initializer package is
416 * already installed.
417 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400418 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500419 * provisioning via an NFC bump.
420 */
421 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
422 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
423
424 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400425 * An int extra holding a minimum required version code for the device initializer package.
426 * If the initializer is already installed on the device, it will only be re-downloaded from
427 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
428 * the installed package is less than this version code.
429 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400430 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400431 * provisioning via an NFC bump.
432 */
433 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
434 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
435
436 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500437 * A String extra holding a http cookie header which should be used in the http request to the
438 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
439 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400440 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500441 * provisioning via an NFC bump.
442 */
443 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
444 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
445
446 /**
Rubin Xue30ab112015-03-24 11:22:28 +0000447 * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download
448 * location specified in
Julia Reynolds20118f12015-02-11 12:34:08 -0500449 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't
450 * match the file at the download location an error will be shown to the user and the user will
451 * be asked to factory reset the device.
452 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400453 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Julia Reynolds20118f12015-02-11 12:34:08 -0500454 * provisioning via an NFC bump.
455 */
456 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM
457 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM";
458
459 /**
Craig Lafayette97e473e2015-03-19 10:19:38 -0400460 * A String extra holding the MAC address of the Bluetooth device to connect to with status
461 * updates during provisioning.
462 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400463 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400464 * provisioning via an NFC bump.
465 */
466 public static final String EXTRA_PROVISIONING_BT_MAC_ADDRESS
467 = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS";
468
469 /**
470 * A String extra holding the Bluetooth service UUID on the device to connect to with status
471 * updates during provisioning.
472 *
473 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
474 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400475 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400476 * provisioning via an NFC bump.
477 */
478 public static final String EXTRA_PROVISIONING_BT_UUID
479 = "android.app.extra.PROVISIONING_BT_UUID";
480
481 /**
482 * A String extra holding a unique identifier used to identify the device connecting over
483 * Bluetooth. This identifier will be part of every status message sent to the remote device.
484 *
485 * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present.
486 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400487 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400488 * provisioning via an NFC bump.
489 */
490 public static final String EXTRA_PROVISIONING_BT_DEVICE_ID
491 = "android.app.extra.PROVISIONING_BT_DEVICE_ID";
492
493 /**
494 * A Boolean extra that that will cause a provisioned device to temporarily proxy network
495 * traffic over Bluetooth. When a Wi-Fi network is available, the network proxy will stop.
496 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400497 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner
Craig Lafayette97e473e2015-03-19 10:19:38 -0400498 * provisioning via an NFC bump.
499 */
500 public static final String EXTRA_PROVISIONING_BT_USE_PROXY
501 = "android.app.extra.PROVISIONING_BT_USE_PROXY";
Craig Lafayette97e473e2015-03-19 10:19:38 -0400502 /**
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400503 * This MIME type is used for starting the Device Owner provisioning that does not require
504 * provisioning features introduced in Android API level
505 * {@link android.os.Build.VERSION_CODES#MNC} or later levels.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100506 *
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400507 * <p>For more information about the provisioning process see
508 * {@link #MIME_TYPE_PROVISIONING_NFC_V2}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000510 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100511 * contains the following properties:
512 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400513 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
514 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100515 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400516 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100517 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
518 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
519 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
520 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
521 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
522 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
523 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
524 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
525 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
526 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400527 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100528 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000529 * <p>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400530 * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain
531 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
532 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
533 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
534 *
535 * @see #MIME_TYPE_PROVISIONING_NFC_V2
536 *
537 */
538 public static final String MIME_TYPE_PROVISIONING_NFC
539 = "application/com.android.managedprovisioning";
540
541
542 /**
543 * This MIME type is used for starting the Device Owner provisioning that requires
544 * new provisioning features introduced in API version
545 * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier
546 * versions.
547 *
548 * <p>During device owner provisioning a device admin app is set as the owner of the device.
549 * A device owner has full control over the device. The device owner can not be modified by the
550 * user and the only way of resetting the device is if the device owner app calls a factory
551 * reset.
552 *
553 * <p> A typical use case would be a device that is owned by a company, but used by either an
554 * employee or client.
555 *
556 * <p> The NFC message should be sent to an unprovisioned device.
557 *
558 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
559 * contains the following properties in addition to properties listed at
560 * {@link #MIME_TYPE_PROVISIONING_NFC}:
561 * <ul>
562 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
563 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li>
564 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
565 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
566 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li>
567 * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li>
568 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
569 * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property
570 * should be converted to a String via
571 * {@link android.content.ComponentName#flattenToString()}</li>
572 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li>
573 * <li>{@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, optional</li>
574 * <li>{@link #EXTRA_PROVISIONING_BT_UUID}, optional</li>
575 * <li>{@link #EXTRA_PROVISIONING_BT_DEVICE_ID}, optional</li>
576 * <li>{@link #EXTRA_PROVISIONING_BT_USE_PROXY}, optional</li></ul>
Nicolas Prevot18440252015-03-09 14:07:17 +0000577 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100578 * <p> When device owner provisioning has completed, an intent of the type
579 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
580 * device owner.
581 *
582 * <p>
583 * If provisioning fails, the device is factory reset.
584 *
585 * <p>Input: Nothing.</p>
586 * <p>Output: Nothing</p>
587 */
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400588 public static final String MIME_TYPE_PROVISIONING_NFC_V2
589 = "application/com.android.managedprovisioning.v2";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590
591 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800592 * Activity action: ask the user to add a new device administrator to the system.
593 * The desired policy is the ComponentName of the policy in the
594 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
595 * bring the user through adding the device administrator to the system (or
596 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700597 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800598 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
599 * field to provide the user with additional explanation (in addition
600 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800601 *
602 * <p>If your administrator is already active, this will ordinarily return immediately (without
603 * user intervention). However, if your administrator has been updated and is requesting
604 * additional uses-policy flags, the user will be presented with the new list. New policies
605 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800606 */
607 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
608 public static final String ACTION_ADD_DEVICE_ADMIN
609 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700610
Dianne Hackbornd6847842010-01-12 18:14:19 -0800611 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700612 * @hide
613 * Activity action: ask the user to add a new device administrator as the profile owner
614 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
615 * permission can call this API.
616 *
617 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
618 * field. This will invoke a UI to bring the user through adding the profile owner admin
619 * to remotely control restrictions on the user.
620 *
621 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
622 * result of whether or not the user approved the action. If approved, the result will
623 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
624 * as a profile owner.
625 *
626 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
627 * field to provide the user with additional explanation (in addition
628 * to your component's description) about what is being added.
629 *
630 * <p>If there is already a profile owner active or the caller doesn't have the required
631 * permissions, the operation will return a failure result.
632 */
633 @SystemApi
634 public static final String ACTION_SET_PROFILE_OWNER
635 = "android.app.action.SET_PROFILE_OWNER";
636
637 /**
638 * @hide
639 * Name of the profile owner admin that controls the user.
640 */
641 @SystemApi
642 public static final String EXTRA_PROFILE_OWNER_NAME
643 = "android.app.extra.PROFILE_OWNER_NAME";
644
645 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700646 * Activity action: send when any policy admin changes a policy.
647 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700648 *
Jim Miller284b62e2010-06-08 14:27:42 -0700649 * @hide
650 */
651 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
652 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
653
654 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800655 * The ComponentName of the administrator component.
656 *
657 * @see #ACTION_ADD_DEVICE_ADMIN
658 */
659 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700660
Dianne Hackbornd6847842010-01-12 18:14:19 -0800661 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800662 * An optional CharSequence providing additional explanation for why the
663 * admin is being added.
664 *
665 * @see #ACTION_ADD_DEVICE_ADMIN
666 */
667 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700668
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800669 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700670 * Activity action: have the user enter a new password. This activity should
671 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
672 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
673 * enter a new password that meets the current requirements. You can use
674 * {@link #isActivePasswordSufficient()} to determine whether you need to
675 * have the user select a new password in order to meet the current
676 * constraints. Upon being resumed from this activity, you can check the new
677 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800678 */
679 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
680 public static final String ACTION_SET_NEW_PASSWORD
681 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700682
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000683 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000684 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
685 * the parent profile to access intents sent from the managed profile.
686 * That is, when an app in the managed profile calls
687 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
688 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000689 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100690 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000691
692 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000693 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
694 * the managed profile to access intents sent from the parent profile.
695 * That is, when an app in the parent profile calls
696 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
697 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000698 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100699 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700700
Dianne Hackbornd6847842010-01-12 18:14:19 -0800701 /**
702 * Return true if the given administrator component is currently
703 * active (enabled) in the system.
704 */
705 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100706 return isAdminActiveAsUser(who, UserHandle.myUserId());
707 }
708
709 /**
710 * @see #isAdminActive(ComponentName)
711 * @hide
712 */
713 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800714 if (mService != null) {
715 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100716 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800717 } catch (RemoteException e) {
718 Log.w(TAG, "Failed talking with device policy service", e);
719 }
720 }
721 return false;
722 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800723 /**
724 * Return true if the given administrator component is currently being removed
725 * for the user.
726 * @hide
727 */
728 public boolean isRemovingAdmin(ComponentName who, int userId) {
729 if (mService != null) {
730 try {
731 return mService.isRemovingAdmin(who, userId);
732 } catch (RemoteException e) {
733 Log.w(TAG, "Failed talking with device policy service", e);
734 }
735 }
736 return false;
737 }
738
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700739
Dianne Hackbornd6847842010-01-12 18:14:19 -0800740 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800741 * Return a list of all currently active device administrator's component
742 * names. Note that if there are no administrators than null may be
743 * returned.
744 */
745 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100746 return getActiveAdminsAsUser(UserHandle.myUserId());
747 }
748
749 /**
750 * @see #getActiveAdmins()
751 * @hide
752 */
753 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800754 if (mService != null) {
755 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100756 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800757 } catch (RemoteException e) {
758 Log.w(TAG, "Failed talking with device policy service", e);
759 }
760 }
761 return null;
762 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700763
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800764 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700765 * Used by package administration code to determine if a package can be stopped
766 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800767 * @hide
768 */
769 public boolean packageHasActiveAdmins(String packageName) {
770 if (mService != null) {
771 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700772 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800773 } catch (RemoteException e) {
774 Log.w(TAG, "Failed talking with device policy service", e);
775 }
776 }
777 return false;
778 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700779
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800780 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800781 * Remove a current administration component. This can only be called
782 * by the application that owns the administration component; if you
783 * try to remove someone else's component, a security exception will be
784 * thrown.
785 */
786 public void removeActiveAdmin(ComponentName who) {
787 if (mService != null) {
788 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700789 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800790 } catch (RemoteException e) {
791 Log.w(TAG, "Failed talking with device policy service", e);
792 }
793 }
794 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700795
Dianne Hackbornd6847842010-01-12 18:14:19 -0800796 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800797 * Returns true if an administrator has been granted a particular device policy. This can
798 * be used to check if the administrator was activated under an earlier set of policies,
799 * but requires additional policies after an upgrade.
800 *
801 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
802 * an active administrator, or an exception will be thrown.
803 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
804 */
805 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
806 if (mService != null) {
807 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700808 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800809 } catch (RemoteException e) {
810 Log.w(TAG, "Failed talking with device policy service", e);
811 }
812 }
813 return false;
814 }
815
816 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800817 * Constant for {@link #setPasswordQuality}: the policy has no requirements
818 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800819 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800820 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800821 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700822
Dianne Hackbornd6847842010-01-12 18:14:19 -0800823 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700824 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
825 * recognition technology. This implies technologies that can recognize the identity of
826 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
827 * Note that quality constants are ordered so that higher values are more restrictive.
828 */
829 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
830
831 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800832 * Constant for {@link #setPasswordQuality}: the policy requires some kind
833 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800834 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800835 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800836 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700837
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800838 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800839 * Constant for {@link #setPasswordQuality}: the user must have entered a
840 * password containing at least numeric characters. Note that quality
841 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800842 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800843 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700844
Dianne Hackbornd6847842010-01-12 18:14:19 -0800845 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800846 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800847 * password containing at least numeric characters with no repeating (4444)
848 * or ordered (1234, 4321, 2468) sequences. Note that quality
849 * constants are ordered so that higher values are more restrictive.
850 */
851 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
852
853 /**
854 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700855 * password containing at least alphabetic (or other symbol) characters.
856 * Note that quality constants are ordered so that higher values are more
857 * restrictive.
858 */
859 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700860
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700861 /**
862 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800863 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700864 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800865 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800866 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700867 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700868
Dianne Hackbornd6847842010-01-12 18:14:19 -0800869 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700870 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700871 * password containing at least a letter, a numerical digit and a special
872 * symbol, by default. With this password quality, passwords can be
873 * restricted to contain various sets of characters, like at least an
874 * uppercase letter, etc. These are specified using various methods,
875 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
876 * that quality constants are ordered so that higher values are more
877 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700878 */
879 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
880
881 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800882 * Called by an application that is administering the device to set the
883 * password restrictions it is imposing. After setting this, the user
884 * will not be able to enter a new password that is not at least as
885 * restrictive as what has been set. Note that the current password
886 * will remain until the user has set a new one, so the change does not
887 * take place immediately. To prompt the user for a new password, use
888 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700889 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800890 * <p>Quality constants are ordered so that higher values are more restrictive;
891 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800892 * the user's preference, and any other considerations) is the one that
893 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700894 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800895 * <p>The calling device admin must have requested
896 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
897 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700898 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800900 * @param quality The new desired quality. One of
901 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800902 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
903 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
904 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800905 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800906 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800907 if (mService != null) {
908 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800909 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800910 } catch (RemoteException e) {
911 Log.w(TAG, "Failed talking with device policy service", e);
912 }
913 }
914 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700915
Dianne Hackbornd6847842010-01-12 18:14:19 -0800916 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100917 * Retrieve the current minimum password quality for all admins of this user
918 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800919 * @param admin The name of the admin component to check, or null to aggregate
920 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800921 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800922 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700923 return getPasswordQuality(admin, UserHandle.myUserId());
924 }
925
926 /** @hide per-user version */
927 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800928 if (mService != null) {
929 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700930 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800931 } catch (RemoteException e) {
932 Log.w(TAG, "Failed talking with device policy service", e);
933 }
934 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800935 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800936 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700937
Dianne Hackbornd6847842010-01-12 18:14:19 -0800938 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800939 * Called by an application that is administering the device to set the
940 * minimum allowed password length. After setting this, the user
941 * will not be able to enter a new password that is not at least as
942 * restrictive as what has been set. Note that the current password
943 * will remain until the user has set a new one, so the change does not
944 * take place immediately. To prompt the user for a new password, use
945 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
946 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800947 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
948 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
949 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700950 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800951 * <p>The calling device admin must have requested
952 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
953 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700954 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800955 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800956 * @param length The new desired minimum password length. A value of 0
957 * means there is no restriction.
958 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800959 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800960 if (mService != null) {
961 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800962 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800963 } catch (RemoteException e) {
964 Log.w(TAG, "Failed talking with device policy service", e);
965 }
966 }
967 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700968
Dianne Hackbornd6847842010-01-12 18:14:19 -0800969 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100970 * Retrieve the current minimum password length for all admins of this
971 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800972 * @param admin The name of the admin component to check, or null to aggregate
973 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800974 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800975 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700976 return getPasswordMinimumLength(admin, UserHandle.myUserId());
977 }
978
979 /** @hide per-user version */
980 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800981 if (mService != null) {
982 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700983 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800984 } catch (RemoteException e) {
985 Log.w(TAG, "Failed talking with device policy service", e);
986 }
987 }
988 return 0;
989 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700990
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700991 /**
992 * Called by an application that is administering the device to set the
993 * minimum number of upper case letters required in the password. After
994 * setting this, the user will not be able to enter a new password that is
995 * not at least as restrictive as what has been set. Note that the current
996 * password will remain until the user has set a new one, so the change does
997 * not take place immediately. To prompt the user for a new password, use
998 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
999 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001000 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1001 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001002 * <p>
1003 * The calling device admin must have requested
1004 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1005 * this method; if it has not, a security exception will be thrown.
1006 *
1007 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1008 * with.
1009 * @param length The new desired minimum number of upper case letters
1010 * required in the password. A value of 0 means there is no
1011 * restriction.
1012 */
1013 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
1014 if (mService != null) {
1015 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001016 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001017 } catch (RemoteException e) {
1018 Log.w(TAG, "Failed talking with device policy service", e);
1019 }
1020 }
1021 }
1022
1023 /**
1024 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001025 * password for all admins of this user and its profiles or a particular one.
1026 * This is the same value as set by
1027 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001028 * and only applies when the password quality is
1029 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001030 *
1031 * @param admin The name of the admin component to check, or null to
1032 * aggregate all admins.
1033 * @return The minimum number of upper case letters required in the
1034 * password.
1035 */
1036 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001037 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1038 }
1039
1040 /** @hide per-user version */
1041 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001042 if (mService != null) {
1043 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001044 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001045 } catch (RemoteException e) {
1046 Log.w(TAG, "Failed talking with device policy service", e);
1047 }
1048 }
1049 return 0;
1050 }
1051
1052 /**
1053 * Called by an application that is administering the device to set the
1054 * minimum number of lower case letters required in the password. After
1055 * setting this, the user will not be able to enter a new password that is
1056 * not at least as restrictive as what has been set. Note that the current
1057 * password will remain until the user has set a new one, so the change does
1058 * not take place immediately. To prompt the user for a new password, use
1059 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1060 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001061 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1062 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001063 * <p>
1064 * The calling device admin must have requested
1065 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1066 * this method; if it has not, a security exception will be thrown.
1067 *
1068 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1069 * with.
1070 * @param length The new desired minimum number of lower case letters
1071 * required in the password. A value of 0 means there is no
1072 * restriction.
1073 */
1074 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
1075 if (mService != null) {
1076 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001077 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001078 } catch (RemoteException e) {
1079 Log.w(TAG, "Failed talking with device policy service", e);
1080 }
1081 }
1082 }
1083
1084 /**
1085 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001086 * password for all admins of this user and its profiles or a particular one.
1087 * This is the same value as set by
1088 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001089 * and only applies when the password quality is
1090 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001091 *
1092 * @param admin The name of the admin component to check, or null to
1093 * aggregate all admins.
1094 * @return The minimum number of lower case letters required in the
1095 * password.
1096 */
1097 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001098 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1099 }
1100
1101 /** @hide per-user version */
1102 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001103 if (mService != null) {
1104 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001105 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001106 } catch (RemoteException e) {
1107 Log.w(TAG, "Failed talking with device policy service", e);
1108 }
1109 }
1110 return 0;
1111 }
1112
1113 /**
1114 * Called by an application that is administering the device to set the
1115 * minimum number of letters required in the password. After setting this,
1116 * the user will not be able to enter a new password that is not at least as
1117 * restrictive as what has been set. Note that the current password will
1118 * remain until the user has set a new one, so the change does not take
1119 * place immediately. To prompt the user for a new password, use
1120 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1121 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001122 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1123 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001124 * <p>
1125 * The calling device admin must have requested
1126 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1127 * this method; if it has not, a security exception will be thrown.
1128 *
1129 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1130 * with.
1131 * @param length The new desired minimum number of letters required in the
1132 * password. A value of 0 means there is no restriction.
1133 */
1134 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1135 if (mService != null) {
1136 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001137 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001138 } catch (RemoteException e) {
1139 Log.w(TAG, "Failed talking with device policy service", e);
1140 }
1141 }
1142 }
1143
1144 /**
1145 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001146 * admins or a particular one. This is the same value as
1147 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1148 * and only applies when the password quality is
1149 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001150 *
1151 * @param admin The name of the admin component to check, or null to
1152 * aggregate all admins.
1153 * @return The minimum number of letters required in the password.
1154 */
1155 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001156 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1157 }
1158
1159 /** @hide per-user version */
1160 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001161 if (mService != null) {
1162 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001163 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001164 } catch (RemoteException e) {
1165 Log.w(TAG, "Failed talking with device policy service", e);
1166 }
1167 }
1168 return 0;
1169 }
1170
1171 /**
1172 * Called by an application that is administering the device to set the
1173 * minimum number of numerical digits required in the password. After
1174 * setting this, the user will not be able to enter a new password that is
1175 * not at least as restrictive as what has been set. Note that the current
1176 * password will remain until the user has set a new one, so the change does
1177 * not take place immediately. To prompt the user for a new password, use
1178 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1179 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001180 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1181 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001182 * <p>
1183 * The calling device admin must have requested
1184 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1185 * this method; if it has not, a security exception will be thrown.
1186 *
1187 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1188 * with.
1189 * @param length The new desired minimum number of numerical digits required
1190 * in the password. A value of 0 means there is no restriction.
1191 */
1192 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1193 if (mService != null) {
1194 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001195 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001196 } catch (RemoteException e) {
1197 Log.w(TAG, "Failed talking with device policy service", e);
1198 }
1199 }
1200 }
1201
1202 /**
1203 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001204 * for all admins of this user and its profiles or a particular one.
1205 * This is the same value as set by
1206 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001207 * and only applies when the password quality is
1208 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001209 *
1210 * @param admin The name of the admin component to check, or null to
1211 * aggregate all admins.
1212 * @return The minimum number of numerical digits required in the password.
1213 */
1214 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001215 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1216 }
1217
1218 /** @hide per-user version */
1219 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001220 if (mService != null) {
1221 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001222 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001223 } catch (RemoteException e) {
1224 Log.w(TAG, "Failed talking with device policy service", e);
1225 }
1226 }
1227 return 0;
1228 }
1229
1230 /**
1231 * Called by an application that is administering the device to set the
1232 * minimum number of symbols required in the password. After setting this,
1233 * the user will not be able to enter a new password that is not at least as
1234 * restrictive as what has been set. Note that the current password will
1235 * remain until the user has set a new one, so the change does not take
1236 * place immediately. To prompt the user for a new password, use
1237 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1238 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001239 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1240 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001241 * <p>
1242 * The calling device admin must have requested
1243 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1244 * this method; if it has not, a security exception will be thrown.
1245 *
1246 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1247 * with.
1248 * @param length The new desired minimum number of symbols required in the
1249 * password. A value of 0 means there is no restriction.
1250 */
1251 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1252 if (mService != null) {
1253 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001254 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001255 } catch (RemoteException e) {
1256 Log.w(TAG, "Failed talking with device policy service", e);
1257 }
1258 }
1259 }
1260
1261 /**
1262 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001263 * admins or a particular one. This is the same value as
1264 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1265 * and only applies when the password quality is
1266 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001267 *
1268 * @param admin The name of the admin component to check, or null to
1269 * aggregate all admins.
1270 * @return The minimum number of symbols required in the password.
1271 */
1272 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001273 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1274 }
1275
1276 /** @hide per-user version */
1277 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001278 if (mService != null) {
1279 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001280 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001281 } catch (RemoteException e) {
1282 Log.w(TAG, "Failed talking with device policy service", e);
1283 }
1284 }
1285 return 0;
1286 }
1287
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001288 /**
1289 * Called by an application that is administering the device to set the
1290 * minimum number of non-letter characters (numerical digits or symbols)
1291 * required in the password. After setting this, the user will not be able
1292 * to enter a new password that is not at least as restrictive as what has
1293 * been set. Note that the current password will remain until the user has
1294 * set a new one, so the change does not take place immediately. To prompt
1295 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1296 * setting this value. This constraint is only imposed if the administrator
1297 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1298 * {@link #setPasswordQuality}. The default value is 0.
1299 * <p>
1300 * The calling device admin must have requested
1301 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1302 * this method; if it has not, a security exception will be thrown.
1303 *
1304 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1305 * with.
1306 * @param length The new desired minimum number of letters required in the
1307 * password. A value of 0 means there is no restriction.
1308 */
1309 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1310 if (mService != null) {
1311 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001312 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001313 } catch (RemoteException e) {
1314 Log.w(TAG, "Failed talking with device policy service", e);
1315 }
1316 }
1317 }
1318
1319 /**
1320 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001321 * password for all admins of this user and its profiles or a particular one.
1322 * This is the same value as set by
1323 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001324 * and only applies when the password quality is
1325 * {@link #PASSWORD_QUALITY_COMPLEX}.
1326 *
1327 * @param admin The name of the admin component to check, or null to
1328 * aggregate all admins.
1329 * @return The minimum number of letters required in the password.
1330 */
1331 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001332 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1333 }
1334
1335 /** @hide per-user version */
1336 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001337 if (mService != null) {
1338 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001339 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001340 } catch (RemoteException e) {
1341 Log.w(TAG, "Failed talking with device policy service", e);
1342 }
1343 }
1344 return 0;
1345 }
1346
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001347 /**
1348 * Called by an application that is administering the device to set the length
1349 * of the password history. After setting this, the user will not be able to
1350 * enter a new password that is the same as any password in the history. Note
1351 * that the current password will remain until the user has set a new one, so
1352 * the change does not take place immediately. To prompt the user for a new
1353 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1354 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001355 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1356 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1357 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001358 *
1359 * <p>
1360 * The calling device admin must have requested
1361 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1362 * method; if it has not, a security exception will be thrown.
1363 *
1364 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1365 * with.
1366 * @param length The new desired length of password history. A value of 0
1367 * means there is no restriction.
1368 */
1369 public void setPasswordHistoryLength(ComponentName admin, int length) {
1370 if (mService != null) {
1371 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001372 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001373 } catch (RemoteException e) {
1374 Log.w(TAG, "Failed talking with device policy service", e);
1375 }
1376 }
1377 }
1378
1379 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001380 * Called by a device admin to set the password expiration timeout. Calling this method
1381 * will restart the countdown for password expiration for the given admin, as will changing
1382 * the device password (for all admins).
1383 *
1384 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1385 * For example, to have the password expire 5 days from now, timeout would be
1386 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1387 *
1388 * <p>To disable password expiration, a value of 0 may be used for timeout.
1389 *
Jim Millera4e28d12010-11-08 16:15:47 -08001390 * <p>The calling device admin must have requested
1391 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1392 * method; if it has not, a security exception will be thrown.
1393 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001394 * <p> Note that setting the password will automatically reset the expiration time for all
1395 * active admins. Active admins do not need to explicitly call this method in that case.
1396 *
Jim Millera4e28d12010-11-08 16:15:47 -08001397 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1398 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1399 * means there is no restriction (unlimited).
1400 */
1401 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1402 if (mService != null) {
1403 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001404 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001405 } catch (RemoteException e) {
1406 Log.w(TAG, "Failed talking with device policy service", e);
1407 }
1408 }
1409 }
1410
1411 /**
Jim Miller6b857682011-02-16 16:27:41 -08001412 * Get the password expiration timeout for the given admin. The expiration timeout is the
1413 * recurring expiration timeout provided in the call to
1414 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1415 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001416 *
1417 * @param admin The name of the admin component to check, or null to aggregate all admins.
1418 * @return The timeout for the given admin or the minimum of all timeouts
1419 */
1420 public long getPasswordExpirationTimeout(ComponentName admin) {
1421 if (mService != null) {
1422 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001423 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001424 } catch (RemoteException e) {
1425 Log.w(TAG, "Failed talking with device policy service", e);
1426 }
1427 }
1428 return 0;
1429 }
1430
1431 /**
1432 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001433 * all admins of this user and its profiles if admin is null. If the password is
1434 * expired, this will return the time since the password expired as a negative number.
1435 * If admin is null, then a composite of all expiration timeouts is returned
1436 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001437 *
1438 * @param admin The name of the admin component to check, or null to aggregate all admins.
1439 * @return The password expiration time, in ms.
1440 */
1441 public long getPasswordExpiration(ComponentName admin) {
1442 if (mService != null) {
1443 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001444 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001445 } catch (RemoteException e) {
1446 Log.w(TAG, "Failed talking with device policy service", e);
1447 }
1448 }
1449 return 0;
1450 }
1451
1452 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001453 * Retrieve the current password history length for all admins of this
1454 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001455 * @param admin The name of the admin component to check, or null to aggregate
1456 * all admins.
1457 * @return The length of the password history
1458 */
1459 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001460 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1461 }
1462
1463 /** @hide per-user version */
1464 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001465 if (mService != null) {
1466 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001467 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001468 } catch (RemoteException e) {
1469 Log.w(TAG, "Failed talking with device policy service", e);
1470 }
1471 }
1472 return 0;
1473 }
1474
Dianne Hackbornd6847842010-01-12 18:14:19 -08001475 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001476 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001477 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001478 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001479 * @return Returns the maximum length that the user can enter.
1480 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001481 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001482 // Kind-of arbitrary.
1483 return 16;
1484 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001485
Dianne Hackborn254cb442010-01-27 19:23:59 -08001486 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001487 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001488 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001489 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001490 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001491 * <p>The calling device admin must have requested
1492 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1493 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001494 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001495 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001496 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001497 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001498 if (mService != null) {
1499 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001500 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001501 } catch (RemoteException e) {
1502 Log.w(TAG, "Failed talking with device policy service", e);
1503 }
1504 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001505 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001506 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001507
Dianne Hackbornd6847842010-01-12 18:14:19 -08001508 /**
1509 * Retrieve the number of times the user has failed at entering a
1510 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001511 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001512 * <p>The calling device admin must have requested
1513 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1514 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001515 */
1516 public int getCurrentFailedPasswordAttempts() {
1517 if (mService != null) {
1518 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001519 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001520 } catch (RemoteException e) {
1521 Log.w(TAG, "Failed talking with device policy service", e);
1522 }
1523 }
1524 return -1;
1525 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001526
1527 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001528 * Setting this to a value greater than zero enables a built-in policy
1529 * that will perform a device wipe after too many incorrect
1530 * device-unlock passwords have been entered. This built-in policy combines
1531 * watching for failed passwords and wiping the device, and requires
1532 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001533 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001534 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001535 * <p>To implement any other policy (e.g. wiping data for a particular
1536 * application only, erasing or revoking credentials, or reporting the
1537 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001538 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001539 * instead. Do not use this API, because if the maximum count is reached,
1540 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001541 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001542 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001543 * @param num The number of failed password attempts at which point the
1544 * device will wipe its data.
1545 */
1546 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1547 if (mService != null) {
1548 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001549 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001550 } catch (RemoteException e) {
1551 Log.w(TAG, "Failed talking with device policy service", e);
1552 }
1553 }
1554 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001555
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001556 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001557 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001558 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001559 * or a particular one.
1560 * @param admin The name of the admin component to check, or null to aggregate
1561 * all admins.
1562 */
1563 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001564 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1565 }
1566
1567 /** @hide per-user version */
1568 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001569 if (mService != null) {
1570 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001571 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001572 } catch (RemoteException e) {
1573 Log.w(TAG, "Failed talking with device policy service", e);
1574 }
1575 }
1576 return 0;
1577 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001578
Dianne Hackborn254cb442010-01-27 19:23:59 -08001579 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001580 * Returns the profile with the smallest maximum failed passwords for wipe,
1581 * for the given user. So for primary user, it might return the primary or
1582 * a managed profile. For a secondary user, it would be the same as the
1583 * user passed in.
1584 * @hide Used only by Keyguard
1585 */
1586 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1587 if (mService != null) {
1588 try {
1589 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1590 } catch (RemoteException e) {
1591 Log.w(TAG, "Failed talking with device policy service", e);
1592 }
1593 }
1594 return UserHandle.USER_NULL;
1595 }
1596
1597 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001598 * Flag for {@link #resetPassword}: don't allow other admins to change
1599 * the password again until the user has entered it.
1600 */
1601 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001602
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001603 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001604 * Force a new device unlock password (the password needed to access the
1605 * entire device, not for individual accounts) on the user. This takes
1606 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001607 * The given password must be sufficient for the
1608 * current password quality and length constraints as returned by
1609 * {@link #getPasswordQuality(ComponentName)} and
1610 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1611 * these constraints, then it will be rejected and false returned. Note
1612 * that the password may be a stronger quality (containing alphanumeric
1613 * characters when the requested quality is only numeric), in which case
1614 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001615 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001616 * <p>Calling with a null or empty password will clear any existing PIN,
1617 * pattern or password if the current password constraints allow it.
1618 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001619 * <p>The calling device admin must have requested
1620 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1621 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001622 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001623 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001624 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001625 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001626 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001627 * @return Returns true if the password was applied, or false if it is
1628 * not acceptable for the current constraints.
1629 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001630 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001631 if (mService != null) {
1632 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001633 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001634 } catch (RemoteException e) {
1635 Log.w(TAG, "Failed talking with device policy service", e);
1636 }
1637 }
1638 return false;
1639 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001640
Dianne Hackbornd6847842010-01-12 18:14:19 -08001641 /**
1642 * Called by an application that is administering the device to set the
1643 * maximum time for user activity until the device will lock. This limits
1644 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001645 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001646 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001647 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001648 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001649 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001651 * @param timeMs The new desired maximum time to lock in milliseconds.
1652 * A value of 0 means there is no restriction.
1653 */
1654 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1655 if (mService != null) {
1656 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001657 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001658 } catch (RemoteException e) {
1659 Log.w(TAG, "Failed talking with device policy service", e);
1660 }
1661 }
1662 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001663
Dianne Hackbornd6847842010-01-12 18:14:19 -08001664 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001665 * Retrieve the current maximum time to unlock for all admins of this user
1666 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001667 * @param admin The name of the admin component to check, or null to aggregate
1668 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001669 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001670 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001671 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001672 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001673 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1674 }
1675
1676 /** @hide per-user version */
1677 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001678 if (mService != null) {
1679 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001680 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001681 } catch (RemoteException e) {
1682 Log.w(TAG, "Failed talking with device policy service", e);
1683 }
1684 }
1685 return 0;
1686 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001687
Dianne Hackbornd6847842010-01-12 18:14:19 -08001688 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001689 * Make the device lock immediately, as if the lock screen timeout has
1690 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001691 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001692 * <p>The calling device admin must have requested
1693 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1694 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001695 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001696 public void lockNow() {
1697 if (mService != null) {
1698 try {
1699 mService.lockNow();
1700 } catch (RemoteException e) {
1701 Log.w(TAG, "Failed talking with device policy service", e);
1702 }
1703 }
1704 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001705
Dianne Hackbornd6847842010-01-12 18:14:19 -08001706 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001707 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001708 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001709 */
1710 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1711
1712 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001713 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1714 * data.
1715 *
Paul Crowley2934b262014-12-02 11:21:13 +00001716 * <p>This flag may only be set by device owner admins; if it is set by
1717 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001718 */
1719 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1720
1721 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001722 * Ask the user data be wiped. Wiping the primary user will cause the
1723 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001724 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001725 * <p>The calling device admin must have requested
1726 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1727 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001728 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001729 * @param flags Bit mask of additional options: currently supported flags
1730 * are {@link #WIPE_EXTERNAL_STORAGE} and
1731 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001732 */
1733 public void wipeData(int flags) {
1734 if (mService != null) {
1735 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001736 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001737 } catch (RemoteException e) {
1738 Log.w(TAG, "Failed talking with device policy service", e);
1739 }
1740 }
1741 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001742
Dianne Hackbornd6847842010-01-12 18:14:19 -08001743 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001744 * Called by an application that is administering the device to set the
1745 * global proxy and exclusion list.
1746 * <p>
1747 * The calling device admin must have requested
1748 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1749 * this method; if it has not, a security exception will be thrown.
1750 * Only the first device admin can set the proxy. If a second admin attempts
1751 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1752 * proxy will be returned. If successful in setting the proxy, null will
1753 * be returned.
1754 * The method can be called repeatedly by the device admin alrady setting the
1755 * proxy to update the proxy and exclusion list.
1756 *
1757 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1758 * with.
1759 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1760 * Pass Proxy.NO_PROXY to reset the proxy.
1761 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001762 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1763 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001764 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001765 */
1766 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1767 List<String> exclusionList ) {
1768 if (proxySpec == null) {
1769 throw new NullPointerException();
1770 }
1771 if (mService != null) {
1772 try {
1773 String hostSpec;
1774 String exclSpec;
1775 if (proxySpec.equals(Proxy.NO_PROXY)) {
1776 hostSpec = null;
1777 exclSpec = null;
1778 } else {
1779 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1780 throw new IllegalArgumentException();
1781 }
1782 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1783 String hostName = sa.getHostName();
1784 int port = sa.getPort();
1785 StringBuilder hostBuilder = new StringBuilder();
1786 hostSpec = hostBuilder.append(hostName)
1787 .append(":").append(Integer.toString(port)).toString();
1788 if (exclusionList == null) {
1789 exclSpec = "";
1790 } else {
1791 StringBuilder listBuilder = new StringBuilder();
1792 boolean firstDomain = true;
1793 for (String exclDomain : exclusionList) {
1794 if (!firstDomain) {
1795 listBuilder = listBuilder.append(",");
1796 } else {
1797 firstDomain = false;
1798 }
1799 listBuilder = listBuilder.append(exclDomain.trim());
1800 }
1801 exclSpec = listBuilder.toString();
1802 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001803 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1804 != android.net.Proxy.PROXY_VALID)
1805 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001806 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001807 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001808 } catch (RemoteException e) {
1809 Log.w(TAG, "Failed talking with device policy service", e);
1810 }
1811 }
1812 return null;
1813 }
1814
1815 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001816 * Set a network-independent global HTTP proxy. This is not normally what you want
1817 * for typical HTTP proxies - they are generally network dependent. However if you're
1818 * doing something unusual like general internal filtering this may be useful. On
1819 * a private network where the proxy is not accessible, you may break HTTP using this.
1820 *
1821 * <p>This method requires the caller to be the device owner.
1822 *
1823 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1824 * @see ProxyInfo
1825 *
1826 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1827 * with.
1828 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1829 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1830 */
1831 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1832 if (mService != null) {
1833 try {
1834 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1835 } catch (RemoteException e) {
1836 Log.w(TAG, "Failed talking with device policy service", e);
1837 }
1838 }
1839 }
1840
1841 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001842 * Returns the component name setting the global proxy.
1843 * @return ComponentName object of the device admin that set the global proxy, or
1844 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001845 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001846 */
1847 public ComponentName getGlobalProxyAdmin() {
1848 if (mService != null) {
1849 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001850 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001851 } catch (RemoteException e) {
1852 Log.w(TAG, "Failed talking with device policy service", e);
1853 }
1854 }
1855 return null;
1856 }
1857
1858 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001859 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001860 * indicating that encryption is not supported.
1861 */
1862 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1863
1864 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001865 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001866 * indicating that encryption is supported, but is not currently active.
1867 */
1868 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1869
1870 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001871 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001872 * indicating that encryption is not currently active, but is currently
1873 * being activated. This is only reported by devices that support
1874 * encryption of data and only when the storage is currently
1875 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1876 * to become encrypted will never return this value.
1877 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001878 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001879
1880 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001881 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001882 * indicating that encryption is active.
1883 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001884 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001885
1886 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001887 * Result code for {@link #getStorageEncryptionStatus}:
1888 * indicating that encryption is active, but an encryption key has not
1889 * been set by the user.
1890 */
1891 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1892
1893 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001894 * Activity action: begin the process of encrypting data on the device. This activity should
1895 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1896 * After resuming from this activity, use {@link #getStorageEncryption}
1897 * to check encryption status. However, on some devices this activity may never return, as
1898 * it may trigger a reboot and in some cases a complete data wipe of the device.
1899 */
1900 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1901 public static final String ACTION_START_ENCRYPTION
1902 = "android.app.action.START_ENCRYPTION";
1903
1904 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001905 * Widgets are enabled in keyguard
1906 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001907 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001908
1909 /**
Jim Miller50e62182014-04-23 17:25:00 -07001910 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001911 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001912 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1913
1914 /**
1915 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1916 */
1917 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1918
1919 /**
Jim Miller50e62182014-04-23 17:25:00 -07001920 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1921 */
1922 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1923
1924 /**
1925 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1926 */
1927 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1928
1929 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001930 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001931 * (e.g. PIN/Pattern/Password).
1932 */
1933 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1934
1935 /**
Jim Miller06e34502014-07-17 14:46:05 -07001936 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1937 */
1938 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1939
1940 /**
Jim Miller35207742012-11-02 15:33:20 -07001941 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001942 */
1943 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001944
1945 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001946 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001947 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001948 *
1949 * <p>When multiple device administrators attempt to control device
1950 * encryption, the most secure, supported setting will always be
1951 * used. If any device administrator requests device encryption,
1952 * it will be enabled; Conversely, if a device administrator
1953 * attempts to disable device encryption while another
1954 * device administrator has enabled it, the call to disable will
1955 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1956 *
1957 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001958 * written to other storage areas may or may not be encrypted, and this policy does not require
1959 * or control the encryption of any other storage areas.
1960 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1961 * {@code true}, then the directory returned by
1962 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1963 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001964 *
1965 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1966 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1967 * the encryption key may not be fully secured. For maximum security, the administrator should
1968 * also require (and check for) a pattern, PIN, or password.
1969 *
1970 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1971 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001972 * @return the new request status (for all active admins) - will be one of
1973 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1974 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1975 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001976 */
1977 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1978 if (mService != null) {
1979 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001980 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001981 } catch (RemoteException e) {
1982 Log.w(TAG, "Failed talking with device policy service", e);
1983 }
1984 }
1985 return ENCRYPTION_STATUS_UNSUPPORTED;
1986 }
1987
1988 /**
1989 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001990 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001991 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001992 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1993 * this will return the requested encryption setting as an aggregate of all active
1994 * administrators.
1995 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001996 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001997 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001998 if (mService != null) {
1999 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002000 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002001 } catch (RemoteException e) {
2002 Log.w(TAG, "Failed talking with device policy service", e);
2003 }
2004 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002005 return false;
2006 }
2007
2008 /**
2009 * Called by an application that is administering the device to
2010 * determine the current encryption status of the device.
2011 *
2012 * Depending on the returned status code, the caller may proceed in different
2013 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2014 * storage system does not support encryption. If the
2015 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2016 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002017 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2018 * storage system has enabled encryption but no password is set so further action
2019 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002020 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2021 *
Robin Lee7e678712014-07-24 16:41:31 +01002022 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002023 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002024 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2025 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002026 */
2027 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002028 return getStorageEncryptionStatus(UserHandle.myUserId());
2029 }
2030
2031 /** @hide per-user version */
2032 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002033 if (mService != null) {
2034 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002035 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002036 } catch (RemoteException e) {
2037 Log.w(TAG, "Failed talking with device policy service", e);
2038 }
2039 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002040 return ENCRYPTION_STATUS_UNSUPPORTED;
2041 }
2042
2043 /**
Robin Lee7e678712014-07-24 16:41:31 +01002044 * Installs the given certificate as a user CA.
2045 *
Rubin Xuec32b562015-03-03 17:34:05 +00002046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2047 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002048 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002049 *
2050 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002051 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002052 */
Robin Lee7e678712014-07-24 16:41:31 +01002053 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002054 if (mService != null) {
2055 try {
Robin Lee7e678712014-07-24 16:41:31 +01002056 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002057 } catch (RemoteException e) {
2058 Log.w(TAG, "Failed talking with device policy service", e);
2059 }
2060 }
2061 return false;
2062 }
2063
2064 /**
Robin Lee7e678712014-07-24 16:41:31 +01002065 * Uninstalls the given certificate from trusted user CAs, if present.
2066 *
Rubin Xuec32b562015-03-03 17:34:05 +00002067 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2068 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002069 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002070 */
Robin Lee7e678712014-07-24 16:41:31 +01002071 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002072 if (mService != null) {
2073 try {
Robin Lee306fe082014-06-19 14:04:24 +00002074 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002075 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002076 } catch (CertificateException e) {
2077 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002078 } catch (RemoteException e) {
2079 Log.w(TAG, "Failed talking with device policy service", e);
2080 }
2081 }
2082 }
2083
2084 /**
Robin Lee7e678712014-07-24 16:41:31 +01002085 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2086 * If a user has installed any certificates by other means than device policy these will be
2087 * included too.
2088 *
Rubin Xuec32b562015-03-03 17:34:05 +00002089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2090 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002091 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002092 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002093 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002094 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002095 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002096 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002097 mService.enforceCanManageCaCerts(admin);
2098 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2099 for (String alias : certStore.userAliases()) {
2100 try {
2101 certs.add(certStore.getCertificate(alias).getEncoded());
2102 } catch (CertificateException ce) {
2103 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2104 }
2105 }
2106 } catch (RemoteException re) {
2107 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002108 }
2109 }
2110 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002111 }
2112
2113 /**
Robin Lee7e678712014-07-24 16:41:31 +01002114 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2115 * means other than device policy will also be removed, except for system CA certificates.
2116 *
Rubin Xuec32b562015-03-03 17:34:05 +00002117 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2118 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002119 */
2120 public void uninstallAllUserCaCerts(ComponentName admin) {
2121 if (mService != null) {
2122 for (String alias : new TrustedCertificateStore().userAliases()) {
2123 try {
2124 mService.uninstallCaCert(admin, alias);
2125 } catch (RemoteException re) {
2126 Log.w(TAG, "Failed talking with device policy service", re);
2127 }
2128 }
2129 }
2130 }
2131
2132 /**
2133 * Returns whether this certificate is installed as a trusted CA.
2134 *
Rubin Xuec32b562015-03-03 17:34:05 +00002135 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2136 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002137 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002138 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002139 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2140 if (mService != null) {
2141 try {
2142 mService.enforceCanManageCaCerts(admin);
2143 return getCaCertAlias(certBuffer) != null;
2144 } catch (RemoteException re) {
2145 Log.w(TAG, "Failed talking with device policy service", re);
2146 } catch (CertificateException ce) {
2147 Log.w(TAG, "Could not parse certificate", ce);
2148 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002149 }
2150 return false;
2151 }
2152
2153 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002154 * Called by a device or profile owner to install a certificate and private key pair. The
2155 * keypair will be visible to all apps within the profile.
2156 *
2157 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2158 * @param privKey The private key to install.
2159 * @param cert The certificate to install.
2160 * @param alias The private key alias under which to install the certificate. If a certificate
2161 * with that alias already exists, it will be overwritten.
2162 * @return {@code true} if the keys were installed, {@code false} otherwise.
2163 */
2164 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2165 String alias) {
2166 try {
2167 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002168 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2169 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2170 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002171 } catch (RemoteException e) {
2172 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002173 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2174 Log.w(TAG, "Failed to obtain private key material", e);
2175 } catch (CertificateException | IOException e) {
2176 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002177 }
2178 return false;
2179 }
2180
2181 /**
Robin Lee306fe082014-06-19 14:04:24 +00002182 * Returns the alias of a given CA certificate in the certificate store, or null if it
2183 * doesn't exist.
2184 */
2185 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2186 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2187 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2188 new ByteArrayInputStream(certBuffer));
2189 return new TrustedCertificateStore().getCertificateAlias(cert);
2190 }
2191
2192 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002193 * Called by a profile owner or device owner to grant access to privileged certificate
2194 * manipulation APIs to a third-party CA certificate installer app. Granted APIs include
2195 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
2196 * {@link #uninstallCaCert} and {@link #uninstallAllUserCaCerts}.
2197 * <p>
2198 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2199 * it is later cleared by calling this method with a null value or uninstallling the certificate
2200 * installer.
2201 *
2202 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2203 * @param installerPackage The package name of the certificate installer which will be given
2204 * access. If <code>null</code> is given the current package will be cleared.
2205 */
2206 public void setCertInstallerPackage(ComponentName who, String installerPackage)
2207 throws SecurityException {
2208 if (mService != null) {
2209 try {
2210 mService.setCertInstallerPackage(who, installerPackage);
2211 } catch (RemoteException e) {
2212 Log.w(TAG, "Failed talking with device policy service", e);
2213 }
2214 }
2215 }
2216
2217 /**
2218 * Called by a profile owner or device owner to retrieve the certificate installer for the
2219 * current user. null if none is set.
2220 *
2221 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2222 * @return The package name of the current delegated certificate installer. <code>null</code>
2223 * if none is set.
2224 */
2225 public String getCertInstallerPackage(ComponentName who) throws SecurityException {
2226 if (mService != null) {
2227 try {
2228 return mService.getCertInstallerPackage(who);
2229 } catch (RemoteException e) {
2230 Log.w(TAG, "Failed talking with device policy service", e);
2231 }
2232 }
2233 return null;
2234 }
2235
2236 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002237 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002238 * on the device, for this user. After setting this, no applications running as this user
2239 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002240 *
2241 * <p>The calling device admin must have requested
2242 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2243 * this method; if it has not, a security exception will be thrown.
2244 *
2245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2246 * @param disabled Whether or not the camera should be disabled.
2247 */
2248 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2249 if (mService != null) {
2250 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002251 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002252 } catch (RemoteException e) {
2253 Log.w(TAG, "Failed talking with device policy service", e);
2254 }
2255 }
2256 }
2257
2258 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002259 * Determine whether or not the device's cameras have been disabled for this user,
2260 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002261 * @param admin The name of the admin component to check, or null to check if any admins
2262 * have disabled the camera
2263 */
2264 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002265 return getCameraDisabled(admin, UserHandle.myUserId());
2266 }
2267
2268 /** @hide per-user version */
2269 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002270 if (mService != null) {
2271 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002272 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002273 } catch (RemoteException e) {
2274 Log.w(TAG, "Failed talking with device policy service", e);
2275 }
2276 }
2277 return false;
2278 }
2279
2280 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002281 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2282 * screen capture also prevents the content from being shown on display devices that do not have
2283 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2284 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002285 *
2286 * <p>The calling device admin must be a device or profile owner. If it is not, a
2287 * security exception will be thrown.
2288 *
2289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002290 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002291 */
2292 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2293 if (mService != null) {
2294 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002295 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002296 } catch (RemoteException e) {
2297 Log.w(TAG, "Failed talking with device policy service", e);
2298 }
2299 }
2300 }
2301
2302 /**
2303 * Determine whether or not screen capture has been disabled by the current
2304 * admin, if specified, or all admins.
2305 * @param admin The name of the admin component to check, or null to check if any admins
2306 * have disabled screen capture.
2307 */
2308 public boolean getScreenCaptureDisabled(ComponentName admin) {
2309 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2310 }
2311
2312 /** @hide per-user version */
2313 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2314 if (mService != null) {
2315 try {
2316 return mService.getScreenCaptureDisabled(admin, userHandle);
2317 } catch (RemoteException e) {
2318 Log.w(TAG, "Failed talking with device policy service", e);
2319 }
2320 }
2321 return false;
2322 }
2323
2324 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002325 * Called by a device owner to set whether auto time is required. If auto time is
2326 * required the user cannot set the date and time, but has to use network date and time.
2327 *
2328 * <p>Note: if auto time is required the user can still manually set the time zone.
2329 *
2330 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2331 * be thrown.
2332 *
2333 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2334 * @param required Whether auto time is set required or not.
2335 */
2336 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2337 if (mService != null) {
2338 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002339 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002340 } catch (RemoteException e) {
2341 Log.w(TAG, "Failed talking with device policy service", e);
2342 }
2343 }
2344 }
2345
2346 /**
2347 * @return true if auto time is required.
2348 */
2349 public boolean getAutoTimeRequired() {
2350 if (mService != null) {
2351 try {
2352 return mService.getAutoTimeRequired();
2353 } catch (RemoteException e) {
2354 Log.w(TAG, "Failed talking with device policy service", e);
2355 }
2356 }
2357 return false;
2358 }
2359
2360 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002361 * Called by an application that is administering the device to disable keyguard customizations,
2362 * such as widgets. After setting this, keyguard features will be disabled according to the
2363 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002364 *
2365 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002366 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002367 * this method; if it has not, a security exception will be thrown.
2368 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002369 * <p>Calling this from a managed profile will throw a security exception.
2370 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002372 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2373 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002374 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2375 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002376 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002377 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002378 if (mService != null) {
2379 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002380 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002381 } catch (RemoteException e) {
2382 Log.w(TAG, "Failed talking with device policy service", e);
2383 }
2384 }
2385 }
2386
2387 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002388 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002389 * admin, if specified, or all admins.
2390 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002391 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002392 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2393 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002394 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002395 public int getKeyguardDisabledFeatures(ComponentName admin) {
2396 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002397 }
2398
2399 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002400 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002401 if (mService != null) {
2402 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002403 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002404 } catch (RemoteException e) {
2405 Log.w(TAG, "Failed talking with device policy service", e);
2406 }
2407 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002408 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002409 }
2410
2411 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002412 * @hide
2413 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002414 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002415 if (mService != null) {
2416 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002417 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002418 } catch (RemoteException e) {
2419 Log.w(TAG, "Failed talking with device policy service", e);
2420 }
2421 }
2422 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002423
Dianne Hackbornd6847842010-01-12 18:14:19 -08002424 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002425 * @hide
2426 */
2427 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2428 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2429 }
2430
2431 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002432 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002433 * @hide
2434 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002435 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002436 ActivityInfo ai;
2437 try {
2438 ai = mContext.getPackageManager().getReceiverInfo(cn,
2439 PackageManager.GET_META_DATA);
2440 } catch (PackageManager.NameNotFoundException e) {
2441 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2442 return null;
2443 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002444
Dianne Hackbornd6847842010-01-12 18:14:19 -08002445 ResolveInfo ri = new ResolveInfo();
2446 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002447
Dianne Hackbornd6847842010-01-12 18:14:19 -08002448 try {
2449 return new DeviceAdminInfo(mContext, ri);
2450 } catch (XmlPullParserException e) {
2451 Log.w(TAG, "Unable to parse device policy " + cn, e);
2452 return null;
2453 } catch (IOException e) {
2454 Log.w(TAG, "Unable to parse device policy " + cn, e);
2455 return null;
2456 }
2457 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002458
Dianne Hackbornd6847842010-01-12 18:14:19 -08002459 /**
2460 * @hide
2461 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002462 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2463 if (mService != null) {
2464 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002465 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002466 } catch (RemoteException e) {
2467 Log.w(TAG, "Failed talking with device policy service", e);
2468 }
2469 }
2470 }
2471
2472 /**
2473 * @hide
2474 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002475 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002476 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002477 if (mService != null) {
2478 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002479 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002480 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002481 } catch (RemoteException e) {
2482 Log.w(TAG, "Failed talking with device policy service", e);
2483 }
2484 }
2485 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002486
Dianne Hackbornd6847842010-01-12 18:14:19 -08002487 /**
2488 * @hide
2489 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002490 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002491 if (mService != null) {
2492 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002493 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002494 } catch (RemoteException e) {
2495 Log.w(TAG, "Failed talking with device policy service", e);
2496 }
2497 }
2498 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002499
Dianne Hackbornd6847842010-01-12 18:14:19 -08002500 /**
2501 * @hide
2502 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002503 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002504 if (mService != null) {
2505 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002506 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002507 } catch (RemoteException e) {
2508 Log.w(TAG, "Failed talking with device policy service", e);
2509 }
2510 }
2511 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002512
2513 /**
2514 * @hide
2515 * Sets the given package as the device owner. The package must already be installed and there
2516 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2517 * method must be called before the device is provisioned.
2518 * @param packageName the package name of the application to be registered as the device owner.
2519 * @return whether the package was successfully registered as the device owner.
2520 * @throws IllegalArgumentException if the package name is null or invalid
2521 * @throws IllegalStateException if a device owner is already registered or the device has
2522 * already been provisioned.
2523 */
2524 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2525 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002526 return setDeviceOwner(packageName, null);
2527 }
2528
2529 /**
2530 * @hide
2531 * Sets the given package as the device owner. The package must already be installed and there
2532 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2533 * method must be called before the device is provisioned.
2534 * @param packageName the package name of the application to be registered as the device owner.
2535 * @param ownerName the human readable name of the institution that owns this device.
2536 * @return whether the package was successfully registered as the device owner.
2537 * @throws IllegalArgumentException if the package name is null or invalid
2538 * @throws IllegalStateException if a device owner is already registered or the device has
2539 * already been provisioned.
2540 */
2541 public boolean setDeviceOwner(String packageName, String ownerName)
2542 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002543 if (mService != null) {
2544 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002545 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002546 } catch (RemoteException re) {
2547 Log.w(TAG, "Failed to set device owner");
2548 }
2549 }
2550 return false;
2551 }
2552
2553 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002554 * Used to determine if a particular package has been registered as a Device Owner app.
2555 * A device owner app is a special device admin that cannot be deactivated by the user, once
2556 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2557 * package is currently registered as the device owner app, pass in the package name from
2558 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2559 * admin apps that want to check if they are also registered as the device owner app. The
2560 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2561 * the setup process.
2562 * @param packageName the package name of the app, to compare with the registered device owner
2563 * app, if any.
2564 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002565 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002566 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002567 if (mService != null) {
2568 try {
2569 return mService.isDeviceOwner(packageName);
2570 } catch (RemoteException re) {
2571 Log.w(TAG, "Failed to check device owner");
2572 }
2573 }
2574 return false;
2575 }
2576
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002577 /**
2578 * @hide
2579 * Redirect to isDeviceOwnerApp.
2580 */
2581 public boolean isDeviceOwner(String packageName) {
2582 return isDeviceOwnerApp(packageName);
2583 }
2584
Jason Monkb0dced82014-06-06 14:36:20 -04002585 /**
2586 * Clears the current device owner. The caller must be the device owner.
2587 *
2588 * This function should be used cautiously as once it is called it cannot
2589 * be undone. The device owner can only be set as a part of device setup
2590 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002591 *
2592 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002593 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002594 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002595 if (mService != null) {
2596 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002597 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002598 } catch (RemoteException re) {
2599 Log.w(TAG, "Failed to clear device owner");
2600 }
2601 }
2602 }
2603
Amith Yamasani71e6c692013-03-24 17:39:28 -07002604 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002605 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002606 public String getDeviceOwner() {
2607 if (mService != null) {
2608 try {
2609 return mService.getDeviceOwner();
2610 } catch (RemoteException re) {
2611 Log.w(TAG, "Failed to get device owner");
2612 }
2613 }
2614 return null;
2615 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002616
2617 /** @hide */
2618 public String getDeviceOwnerName() {
2619 if (mService != null) {
2620 try {
2621 return mService.getDeviceOwnerName();
2622 } catch (RemoteException re) {
2623 Log.w(TAG, "Failed to get device owner");
2624 }
2625 }
2626 return null;
2627 }
Adam Connors776c5552014-01-09 10:42:56 +00002628
2629 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002630 * Sets the given component as the device initializer. The package must already be installed and
2631 * set as an active device administrator, and there must not be an existing device initializer,
2632 * for this call to succeed. This method can only be called by an app holding the
2633 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2634 * device initializer app is granted device owner privileges during device initialization and
2635 * profile owner privileges during secondary user initialization.
2636 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2637 * called by the device owner.
2638 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2639 * @param initializerName The user-visible name of the device initializer.
2640 * @return whether the package was successfully registered as the device initializer.
2641 * @throws IllegalArgumentException if the package name is null or invalid
2642 * @throws IllegalStateException if the caller is not device owner or the device has
2643 * already been provisioned or a device initializer already exists.
2644 */
2645 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2646 String initializerName) throws IllegalArgumentException, IllegalStateException {
2647 if (mService != null) {
2648 try {
2649 return mService.setDeviceInitializer(who, initializer, initializerName);
2650 } catch (RemoteException re) {
2651 Log.w(TAG, "Failed to set device initializer");
2652 }
2653 }
2654 return false;
2655 }
2656
2657 /**
2658 * Used to determine if a particular package has been registered as the device initializer.
2659 *
2660 * @param packageName the package name of the app, to compare with the registered device
2661 * initializer app, if any.
2662 * @return whether or not the caller is registered as the device initializer app.
2663 */
2664 public boolean isDeviceInitializerApp(String packageName) {
2665 if (mService != null) {
2666 try {
2667 return mService.isDeviceInitializer(packageName);
2668 } catch (RemoteException re) {
2669 Log.w(TAG, "Failed to check device initializer");
2670 }
2671 }
2672 return false;
2673 }
2674
2675 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002676 * Removes the device initializer, so that it will not be invoked on user initialization for any
2677 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002678 * initializer itself. The caller must be an active administrator.
2679 *
2680 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002681 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002682 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002683 if (mService != null) {
2684 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002685 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002686 } catch (RemoteException re) {
2687 Log.w(TAG, "Failed to clear device initializer");
2688 }
2689 }
2690 }
2691
2692 /**
2693 * @hide
2694 * Gets the device initializer of the system.
2695 *
2696 * @return the package name of the device initializer.
2697 */
2698 @SystemApi
2699 public String getDeviceInitializerApp() {
2700 if (mService != null) {
2701 try {
2702 return mService.getDeviceInitializer();
2703 } catch (RemoteException re) {
2704 Log.w(TAG, "Failed to get device initializer");
2705 }
2706 }
2707 return null;
2708 }
2709
2710 /**
2711 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2712 * be used.
2713 *
2714 * <p>Device initializer must call this method to mark the user as functional.
2715 * Only the device initializer agent can call this.
2716 *
2717 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2718 * device initializer will no longer have elevated permissions to call methods in this class.
2719 * Additionally, it will be removed as an active administrator and its
2720 * {@link DeviceAdminReceiver} will be disabled.
2721 *
2722 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2723 * @return whether the user is now enabled.
2724 */
2725 public boolean setUserEnabled(ComponentName admin) {
2726 if (mService != null) {
2727 try {
2728 return mService.setUserEnabled(admin);
2729 } catch (RemoteException e) {
2730 Log.w(TAG, "Failed talking with device policy service", e);
2731 }
2732 }
2733 return false;
2734 }
2735
2736 /**
Adam Connors776c5552014-01-09 10:42:56 +00002737 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002738 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302739 * Sets the given component as an active admin and registers the package as the profile
2740 * owner for this user. The package must already be installed and there shouldn't be
2741 * an existing profile owner registered for this user. Also, this method must be called
2742 * before the user setup has been completed.
2743 * <p>
2744 * This method can only be called by system apps that hold MANAGE_USERS permission and
2745 * MANAGE_DEVICE_ADMINS permission.
2746 * @param admin The component to register as an active admin and profile owner.
2747 * @param ownerName The user-visible name of the entity that is managing this user.
2748 * @return whether the admin was successfully registered as the profile owner.
2749 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2750 * the user has already been set up.
2751 */
Justin Morey80440cc2014-07-24 09:16:35 -05002752 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302753 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2754 throws IllegalArgumentException {
2755 if (mService != null) {
2756 try {
2757 final int myUserId = UserHandle.myUserId();
2758 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002759 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302760 } catch (RemoteException re) {
2761 Log.w(TAG, "Failed to set profile owner " + re);
2762 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2763 }
2764 }
2765 return false;
2766 }
2767
2768 /**
2769 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002770 * Clears the active profile owner and removes all user restrictions. The caller must
2771 * be from the same package as the active profile owner for this user, otherwise a
2772 * SecurityException will be thrown.
2773 *
2774 * @param admin The component to remove as the profile owner.
2775 * @return
2776 */
2777 @SystemApi
2778 public void clearProfileOwner(ComponentName admin) {
2779 if (mService != null) {
2780 try {
2781 mService.clearProfileOwner(admin);
2782 } catch (RemoteException re) {
2783 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2784 }
2785 }
2786 }
2787
2788 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002789 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002790 * Checks if the user was already setup.
2791 */
2792 public boolean hasUserSetupCompleted() {
2793 if (mService != null) {
2794 try {
2795 return mService.hasUserSetupCompleted();
2796 } catch (RemoteException re) {
2797 Log.w(TAG, "Failed to check if user setup has completed");
2798 }
2799 }
2800 return true;
2801 }
2802
2803 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002804 * @hide
2805 * Sets the given component as the profile owner of the given user profile. The package must
2806 * already be installed and there shouldn't be an existing profile owner registered for this
2807 * user. Only the system can call this API if the user has already completed setup.
2808 * @param admin the component name to be registered as profile owner.
2809 * @param ownerName the human readable name of the organisation associated with this DPM.
2810 * @param userHandle the userId to set the profile owner for.
2811 * @return whether the component was successfully registered as the profile owner.
2812 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2813 * the user has already been set up.
2814 */
2815 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2816 throws IllegalArgumentException {
2817 if (admin == null) {
2818 throw new NullPointerException("admin cannot be null");
2819 }
Adam Connors776c5552014-01-09 10:42:56 +00002820 if (mService != null) {
2821 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002822 if (ownerName == null) {
2823 ownerName = "";
2824 }
2825 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002826 } catch (RemoteException re) {
2827 Log.w(TAG, "Failed to set profile owner", re);
2828 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2829 }
2830 }
2831 return false;
2832 }
2833
2834 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002835 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2836 * be used. Only the profile owner can call this.
2837 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002838 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002839 *
2840 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2841 */
2842 public void setProfileEnabled(ComponentName admin) {
2843 if (mService != null) {
2844 try {
2845 mService.setProfileEnabled(admin);
2846 } catch (RemoteException e) {
2847 Log.w(TAG, "Failed talking with device policy service", e);
2848 }
2849 }
2850 }
2851
2852 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002853 * Sets the name of the profile. In the device owner case it sets the name of the user
2854 * 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 +01002855 * never called by the profile or device owner, the name will be set to default values.
2856 *
2857 * @see #isProfileOwnerApp
2858 * @see #isDeviceOwnerApp
2859 *
2860 * @param profileName The name of the profile.
2861 */
2862 public void setProfileName(ComponentName who, String profileName) {
2863 if (mService != null) {
2864 try {
2865 mService.setProfileName(who, profileName);
2866 } catch (RemoteException e) {
2867 Log.w(TAG, "Failed talking with device policy service", e);
2868 }
2869 }
2870}
2871
2872 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002873 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002874 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002875 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002876 *
2877 * @param packageName The package name of the app to compare with the registered profile owner.
2878 * @return Whether or not the package is registered as the profile owner.
2879 */
2880 public boolean isProfileOwnerApp(String packageName) {
2881 if (mService != null) {
2882 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002883 ComponentName profileOwner = mService.getProfileOwner(
2884 Process.myUserHandle().getIdentifier());
2885 return profileOwner != null
2886 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002887 } catch (RemoteException re) {
2888 Log.w(TAG, "Failed to check profile owner");
2889 }
2890 }
2891 return false;
2892 }
2893
2894 /**
2895 * @hide
2896 * @return the packageName of the owner of the given user profile or null if no profile
2897 * owner has been set for that user.
2898 * @throws IllegalArgumentException if the userId is invalid.
2899 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002900 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002901 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002902 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2903 }
2904
2905 /**
2906 * @see #getProfileOwner()
2907 * @hide
2908 */
2909 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002910 if (mService != null) {
2911 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002912 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002913 } catch (RemoteException re) {
2914 Log.w(TAG, "Failed to get profile owner");
2915 throw new IllegalArgumentException(
2916 "Requested profile owner for invalid userId", re);
2917 }
2918 }
2919 return null;
2920 }
2921
2922 /**
2923 * @hide
2924 * @return the human readable name of the organisation associated with this DPM or null if
2925 * one is not set.
2926 * @throws IllegalArgumentException if the userId is invalid.
2927 */
2928 public String getProfileOwnerName() throws IllegalArgumentException {
2929 if (mService != null) {
2930 try {
2931 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2932 } catch (RemoteException re) {
2933 Log.w(TAG, "Failed to get profile owner");
2934 throw new IllegalArgumentException(
2935 "Requested profile owner for invalid userId", re);
2936 }
2937 }
2938 return null;
2939 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002940
2941 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002942 * @hide
2943 * @param user The user for whom to fetch the profile owner name, if any.
2944 * @return the human readable name of the organisation associated with this profile owner or
2945 * null if one is not set.
2946 * @throws IllegalArgumentException if the userId is invalid.
2947 */
2948 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002949 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002950 if (mService != null) {
2951 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002952 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002953 } 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 }
2961
2962 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002963 * Called by a profile owner or device owner to add a default intent handler activity for
2964 * intents that match a certain intent filter. This activity will remain the default intent
2965 * handler even if the set of potential event handlers for the intent filter changes and if
2966 * the intent preferences are reset.
2967 *
2968 * <p>The default disambiguation mechanism takes over if the activity is not installed
2969 * (anymore). When the activity is (re)installed, it is automatically reset as default
2970 * intent handler for the filter.
2971 *
2972 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2973 * security exception will be thrown.
2974 *
2975 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2976 * @param filter The IntentFilter for which a default handler is added.
2977 * @param activity The Activity that is added as default intent handler.
2978 */
2979 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2980 ComponentName activity) {
2981 if (mService != null) {
2982 try {
2983 mService.addPersistentPreferredActivity(admin, filter, activity);
2984 } catch (RemoteException e) {
2985 Log.w(TAG, "Failed talking with device policy service", e);
2986 }
2987 }
2988 }
2989
2990 /**
2991 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002992 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002993 *
2994 * <p>The calling device admin must be a profile owner. If it is not, a security
2995 * exception will be thrown.
2996 *
2997 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2998 * @param packageName The name of the package for which preferences are removed.
2999 */
3000 public void clearPackagePersistentPreferredActivities(ComponentName admin,
3001 String packageName) {
3002 if (mService != null) {
3003 try {
3004 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3005 } catch (RemoteException e) {
3006 Log.w(TAG, "Failed talking with device policy service", e);
3007 }
3008 }
3009 }
Robin Lee66e5d962014-04-09 16:44:21 +01003010
3011 /**
3012 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003013 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003014 *
3015 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01003016 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01003017 *
3018 * <p>The application restrictions are only made visible to the target application and the
3019 * profile or device owner.
3020 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003021 * <p>If the restrictions are not available yet, but may be applied in the near future,
3022 * the admin can notify the target application of that by adding
3023 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3024 *
Robin Lee66e5d962014-04-09 16:44:21 +01003025 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3026 * exception will be thrown.
3027 *
3028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3029 * @param packageName The name of the package to update restricted settings for.
3030 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3031 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003032 *
3033 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003034 */
3035 public void setApplicationRestrictions(ComponentName admin, String packageName,
3036 Bundle settings) {
3037 if (mService != null) {
3038 try {
3039 mService.setApplicationRestrictions(admin, packageName, settings);
3040 } catch (RemoteException e) {
3041 Log.w(TAG, "Failed talking with device policy service", e);
3042 }
3043 }
3044 }
3045
3046 /**
Jim Millere303bf42014-08-26 17:12:29 -07003047 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3048 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3049 * trust agents but those enabled by this function call. If flag
3050 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003051 *
3052 * <p>The calling device admin must have requested
3053 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003054 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003055 *
3056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003057 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003058 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003059 * will be strictly disabled according to the state of the
3060 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3061 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3062 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3063 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003064 */
Jim Millere303bf42014-08-26 17:12:29 -07003065 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08003066 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003067 if (mService != null) {
3068 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003069 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003070 } catch (RemoteException e) {
3071 Log.w(TAG, "Failed talking with device policy service", e);
3072 }
3073 }
3074 }
3075
3076 /**
Jim Millere303bf42014-08-26 17:12:29 -07003077 * Gets configuration for the given trust agent based on aggregating all calls to
3078 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3079 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003080 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3082 * this function returns a list of configurations for all admins that declare
3083 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3084 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3085 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3086 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003087 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003088 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003089 */
Jim Millere303bf42014-08-26 17:12:29 -07003090 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3091 ComponentName agent) {
3092 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3093 }
3094
3095 /** @hide per-user version */
3096 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3097 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003098 if (mService != null) {
3099 try {
Jim Millere303bf42014-08-26 17:12:29 -07003100 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003101 } catch (RemoteException e) {
3102 Log.w(TAG, "Failed talking with device policy service", e);
3103 }
3104 }
Jim Millere303bf42014-08-26 17:12:29 -07003105 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003106 }
3107
3108 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003109 * Called by a profile owner of a managed profile to set whether caller-Id information from
3110 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003111 *
3112 * <p>The calling device admin must be a profile owner. If it is not, a
3113 * security exception will be thrown.
3114 *
3115 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3116 * @param disabled If true caller-Id information in the managed profile is not displayed.
3117 */
3118 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
3119 if (mService != null) {
3120 try {
3121 mService.setCrossProfileCallerIdDisabled(who, disabled);
3122 } catch (RemoteException e) {
3123 Log.w(TAG, "Failed talking with device policy service", e);
3124 }
3125 }
3126 }
3127
3128 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003129 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3130 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003131 *
3132 * <p>The calling device admin must be a profile owner. If it is not, a
3133 * security exception will be thrown.
3134 *
3135 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3136 */
3137 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3138 if (mService != null) {
3139 try {
3140 return mService.getCrossProfileCallerIdDisabled(who);
3141 } catch (RemoteException e) {
3142 Log.w(TAG, "Failed talking with device policy service", e);
3143 }
3144 }
3145 return false;
3146 }
3147
3148 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003149 * Determine whether or not caller-Id information has been disabled.
3150 *
3151 * @param userHandle The user for whom to check the caller-id permission
3152 * @hide
3153 */
3154 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3155 if (mService != null) {
3156 try {
3157 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3158 } catch (RemoteException e) {
3159 Log.w(TAG, "Failed talking with device policy service", e);
3160 }
3161 }
3162 return false;
3163 }
3164
3165 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003166 * Called by the profile owner of a managed profile so that some intents sent in the managed
3167 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003168 * Only activity intents are supported.
3169 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003171 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3172 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003173 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3174 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003175 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003176 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003177 if (mService != null) {
3178 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003179 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003180 } catch (RemoteException e) {
3181 Log.w(TAG, "Failed talking with device policy service", e);
3182 }
3183 }
3184 }
3185
3186 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003187 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3188 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003189 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003190 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3191 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003192 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003193 if (mService != null) {
3194 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003195 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003196 } catch (RemoteException e) {
3197 Log.w(TAG, "Failed talking with device policy service", e);
3198 }
3199 }
3200 }
3201
3202 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003203 * Called by a profile or device owner to set the permitted accessibility services. When
3204 * set by a device owner or profile owner the restriction applies to all profiles of the
3205 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003206 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003207 * By default the user can use any accessiblity service. When zero or more packages have
3208 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003209 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003210 *
3211 * <p> Calling with a null value for the list disables the restriction so that all services
3212 * can be used, calling with an empty list only allows the builtin system's services.
3213 *
3214 * <p> System accesibility services are always available to the user the list can't modify
3215 * this.
3216 *
3217 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3218 * @param packageNames List of accessibility service package names.
3219 *
3220 * @return true if setting the restriction succeeded. It fail if there is
3221 * one or more non-system accessibility services enabled, that are not in the list.
3222 */
3223 public boolean setPermittedAccessibilityServices(ComponentName admin,
3224 List<String> packageNames) {
3225 if (mService != null) {
3226 try {
3227 return mService.setPermittedAccessibilityServices(admin, packageNames);
3228 } catch (RemoteException e) {
3229 Log.w(TAG, "Failed talking with device policy service", e);
3230 }
3231 }
3232 return false;
3233 }
3234
3235 /**
3236 * Returns the list of permitted accessibility services set by this device or profile owner.
3237 *
3238 * <p>An empty list means no accessibility services except system services are allowed.
3239 * Null means all accessibility services are allowed.
3240 *
3241 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3242 * @return List of accessiblity service package names.
3243 */
3244 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3245 if (mService != null) {
3246 try {
3247 return mService.getPermittedAccessibilityServices(admin);
3248 } catch (RemoteException e) {
3249 Log.w(TAG, "Failed talking with device policy service", e);
3250 }
3251 }
3252 return null;
3253 }
3254
3255 /**
3256 * Returns the list of accessibility services permitted by the device or profiles
3257 * owners of this user.
3258 *
3259 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3260 * it will contain the intersection of the permitted lists for any device or profile
3261 * owners that apply to this user. It will also include any system accessibility services.
3262 *
3263 * @param userId which user to check for.
3264 * @return List of accessiblity service package names.
3265 * @hide
3266 */
3267 @SystemApi
3268 public List<String> getPermittedAccessibilityServices(int userId) {
3269 if (mService != null) {
3270 try {
3271 return mService.getPermittedAccessibilityServicesForUser(userId);
3272 } catch (RemoteException e) {
3273 Log.w(TAG, "Failed talking with device policy service", e);
3274 }
3275 }
3276 return null;
3277 }
3278
3279 /**
3280 * Called by a profile or device owner to set the permitted input methods services. When
3281 * set by a device owner or profile owner the restriction applies to all profiles of the
3282 * user the device owner or profile owner is an admin for.
3283 *
3284 * By default the user can use any input method. When zero or more packages have
3285 * been added, input method that are not in the list and not part of the system
3286 * can not be enabled by the user.
3287 *
3288 * This method will fail if it is called for a admin that is not for the foreground user
3289 * or a profile of the foreground user.
3290 *
3291 * <p> Calling with a null value for the list disables the restriction so that all input methods
3292 * can be used, calling with an empty list disables all but the system's own input methods.
3293 *
3294 * <p> System input methods are always available to the user this method can't modify this.
3295 *
3296 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3297 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003298 * @return true if setting the restriction succeeded. It will fail if there are
3299 * one or more non-system input methods currently enabled that are not in
3300 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003301 */
3302 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3303 if (mService != null) {
3304 try {
3305 return mService.setPermittedInputMethods(admin, packageNames);
3306 } catch (RemoteException e) {
3307 Log.w(TAG, "Failed talking with device policy service", e);
3308 }
3309 }
3310 return false;
3311 }
3312
3313
3314 /**
3315 * Returns the list of permitted input methods set by this device or profile owner.
3316 *
3317 * <p>An empty list means no input methods except system input methods are allowed.
3318 * Null means all input methods are allowed.
3319 *
3320 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3321 * @return List of input method package names.
3322 */
3323 public List<String> getPermittedInputMethods(ComponentName admin) {
3324 if (mService != null) {
3325 try {
3326 return mService.getPermittedInputMethods(admin);
3327 } catch (RemoteException e) {
3328 Log.w(TAG, "Failed talking with device policy service", e);
3329 }
3330 }
3331 return null;
3332 }
3333
3334 /**
3335 * Returns the list of input methods permitted by the device or profiles
3336 * owners of the current user.
3337 *
3338 * <p>Null means all input methods are allowed, if a non-null list is returned
3339 * it will contain the intersection of the permitted lists for any device or profile
3340 * owners that apply to this user. It will also include any system input methods.
3341 *
3342 * @return List of input method package names.
3343 * @hide
3344 */
3345 @SystemApi
3346 public List<String> getPermittedInputMethodsForCurrentUser() {
3347 if (mService != null) {
3348 try {
3349 return mService.getPermittedInputMethodsForCurrentUser();
3350 } catch (RemoteException e) {
3351 Log.w(TAG, "Failed talking with device policy service", e);
3352 }
3353 }
3354 return null;
3355 }
3356
3357 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003358 * Called by a device owner to create a user with the specified name. The UserHandle returned
3359 * by this method should not be persisted as user handles are recycled as users are removed and
3360 * created. If you need to persist an identifier for this user, use
3361 * {@link UserManager#getSerialNumberForUser}.
3362 *
3363 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3364 * @param name the user's name
3365 * @see UserHandle
3366 * @return the UserHandle object for the created user, or null if the user could not be created.
3367 */
3368 public UserHandle createUser(ComponentName admin, String name) {
3369 try {
3370 return mService.createUser(admin, name);
3371 } catch (RemoteException re) {
3372 Log.w(TAG, "Could not create a user", re);
3373 }
3374 return null;
3375 }
3376
3377 /**
Jason Monk03978a42014-06-10 15:05:30 -04003378 * Called by a device owner to create a user with the specified name. The UserHandle returned
3379 * by this method should not be persisted as user handles are recycled as users are removed and
3380 * created. If you need to persist an identifier for this user, use
3381 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3382 * immediately.
3383 *
3384 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3385 * as registered as an active admin on the new user. The profile owner package will be
3386 * installed on the new user if it already is installed on the device.
3387 *
3388 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3389 * profileOwnerComponent when onEnable is called.
3390 *
3391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3392 * @param name the user's name
3393 * @param ownerName the human readable name of the organisation associated with this DPM.
3394 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3395 * the user.
3396 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3397 * on the new user.
3398 * @see UserHandle
3399 * @return the UserHandle object for the created user, or null if the user could not be created.
3400 */
3401 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3402 ComponentName profileOwnerComponent, Bundle adminExtras) {
3403 try {
3404 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3405 adminExtras);
3406 } catch (RemoteException re) {
3407 Log.w(TAG, "Could not create a user", re);
3408 }
3409 return null;
3410 }
3411
3412 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003413 * Called by a device owner to remove a user and all associated data. The primary user can
3414 * not be removed.
3415 *
3416 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3417 * @param userHandle the user to remove.
3418 * @return {@code true} if the user was removed, {@code false} otherwise.
3419 */
3420 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3421 try {
3422 return mService.removeUser(admin, userHandle);
3423 } catch (RemoteException re) {
3424 Log.w(TAG, "Could not remove user ", re);
3425 return false;
3426 }
3427 }
3428
3429 /**
Jason Monk582d9112014-07-09 19:57:08 -04003430 * Called by a device owner to switch the specified user to the foreground.
3431 *
3432 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3433 * @param userHandle the user to switch to; null will switch to primary.
3434 * @return {@code true} if the switch was successful, {@code false} otherwise.
3435 *
3436 * @see Intent#ACTION_USER_FOREGROUND
3437 */
3438 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3439 try {
3440 return mService.switchUser(admin, userHandle);
3441 } catch (RemoteException re) {
3442 Log.w(TAG, "Could not switch user ", re);
3443 return false;
3444 }
3445 }
3446
3447 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003448 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003449 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003450 *
3451 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3452 * exception will be thrown.
3453 *
3454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3455 * @param packageName The name of the package to fetch restricted settings of.
3456 * @return {@link Bundle} of settings corresponding to what was set last time
3457 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3458 * if no restrictions have been set.
3459 */
3460 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3461 if (mService != null) {
3462 try {
3463 return mService.getApplicationRestrictions(admin, packageName);
3464 } catch (RemoteException e) {
3465 Log.w(TAG, "Failed talking with device policy service", e);
3466 }
3467 }
3468 return null;
3469 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003470
3471 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003472 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003473 * <p>
3474 * The calling device admin must be a profile or device owner; if it is not,
3475 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003476 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003477 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3478 * with.
3479 * @param key The key of the restriction. See the constants in
3480 * {@link android.os.UserManager} for the list of keys.
3481 */
3482 public void addUserRestriction(ComponentName admin, String key) {
3483 if (mService != null) {
3484 try {
3485 mService.setUserRestriction(admin, key, true);
3486 } catch (RemoteException e) {
3487 Log.w(TAG, "Failed talking with device policy service", e);
3488 }
3489 }
3490 }
3491
3492 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003493 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003494 * <p>
3495 * The calling device admin must be a profile or device owner; if it is not,
3496 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003497 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003498 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3499 * with.
3500 * @param key The key of the restriction. See the constants in
3501 * {@link android.os.UserManager} for the list of keys.
3502 */
3503 public void clearUserRestriction(ComponentName admin, String key) {
3504 if (mService != null) {
3505 try {
3506 mService.setUserRestriction(admin, key, false);
3507 } catch (RemoteException e) {
3508 Log.w(TAG, "Failed talking with device policy service", e);
3509 }
3510 }
3511 }
Adam Connors010cfd42014-04-16 12:48:13 +01003512
3513 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003514 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003515 * is unavailable for use, but the data and actual package file remain.
3516 *
3517 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003518 * @param packageName The name of the package to hide or unhide.
3519 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3520 * unhidden.
3521 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003522 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003523 public boolean setApplicationHidden(ComponentName admin, String packageName,
3524 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003525 if (mService != null) {
3526 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003527 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003528 } catch (RemoteException e) {
3529 Log.w(TAG, "Failed talking with device policy service", e);
3530 }
3531 }
3532 return false;
3533 }
3534
3535 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003536 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003537 *
3538 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003539 * @param packageName The name of the package to retrieve the hidden status of.
3540 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003541 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003542 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003543 if (mService != null) {
3544 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003545 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003546 } catch (RemoteException e) {
3547 Log.w(TAG, "Failed talking with device policy service", e);
3548 }
3549 }
3550 return false;
3551 }
3552
3553 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003554 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003555 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003556 *
3557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3558 * @param packageName The package to be re-enabled in the current profile.
3559 */
3560 public void enableSystemApp(ComponentName admin, String packageName) {
3561 if (mService != null) {
3562 try {
3563 mService.enableSystemApp(admin, packageName);
3564 } catch (RemoteException e) {
3565 Log.w(TAG, "Failed to install package: " + packageName);
3566 }
3567 }
3568 }
3569
3570 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003571 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003572 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003573 *
3574 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3575 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3576 * intent will be re-enabled in the current profile.
3577 * @return int The number of activities that matched the intent and were installed.
3578 */
3579 public int enableSystemApp(ComponentName admin, Intent intent) {
3580 if (mService != null) {
3581 try {
3582 return mService.enableSystemAppWithIntent(admin, intent);
3583 } catch (RemoteException e) {
3584 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3585 }
3586 }
3587 return 0;
3588 }
3589
3590 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003591 * Called by a device owner or profile owner to disable account management for a specific type
3592 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003593 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003594 * <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 +01003595 * security exception will be thrown.
3596 *
3597 * <p>When account management is disabled for an account type, adding or removing an account
3598 * of that type will not be possible.
3599 *
3600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3601 * @param accountType For which account management is disabled or enabled.
3602 * @param disabled The boolean indicating that account management will be disabled (true) or
3603 * enabled (false).
3604 */
3605 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3606 boolean disabled) {
3607 if (mService != null) {
3608 try {
3609 mService.setAccountManagementDisabled(admin, accountType, disabled);
3610 } catch (RemoteException e) {
3611 Log.w(TAG, "Failed talking with device policy service", e);
3612 }
3613 }
3614 }
3615
3616 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003617 * Gets the array of accounts for which account management is disabled by the profile owner.
3618 *
3619 * <p> Account management can be disabled/enabled by calling
3620 * {@link #setAccountManagementDisabled}.
3621 *
3622 * @return a list of account types for which account management has been disabled.
3623 *
3624 * @see #setAccountManagementDisabled
3625 */
3626 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003627 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003628 }
3629
3630 /**
3631 * @see #getAccountTypesWithManagementDisabled()
3632 * @hide
3633 */
3634 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003635 if (mService != null) {
3636 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003637 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003638 } catch (RemoteException e) {
3639 Log.w(TAG, "Failed talking with device policy service", e);
3640 }
3641 }
3642
3643 return null;
3644 }
justinzhang511e0d82014-03-24 16:09:24 -04003645
3646 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003647 * Sets which packages may enter lock task mode.
3648 *
3649 * <p>Any packages that shares uid with an allowed package will also be allowed
3650 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003651 *
Jason Monkc5185f22014-06-24 11:12:42 -04003652 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003653 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003655 *
3656 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003657 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3658 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003659 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003660 */
Jason Monk48aacba2014-08-13 16:29:08 -04003661 public void setLockTaskPackages(ComponentName admin, String[] packages)
3662 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003663 if (mService != null) {
3664 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003665 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003666 } catch (RemoteException e) {
3667 Log.w(TAG, "Failed talking with device policy service", e);
3668 }
3669 }
3670 }
3671
3672 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003673 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003674 *
3675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003676 * @hide
3677 */
Jason Monk48aacba2014-08-13 16:29:08 -04003678 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003679 if (mService != null) {
3680 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003681 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003682 } catch (RemoteException e) {
3683 Log.w(TAG, "Failed talking with device policy service", e);
3684 }
3685 }
3686 return null;
3687 }
3688
3689 /**
3690 * This function lets the caller know whether the given component is allowed to start the
3691 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003692 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003693 */
Jason Monkd7b86212014-06-16 13:15:38 -04003694 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003695 if (mService != null) {
3696 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003697 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003698 } catch (RemoteException e) {
3699 Log.w(TAG, "Failed talking with device policy service", e);
3700 }
3701 }
3702 return false;
3703 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003704
3705 /**
3706 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3707 * 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 -04003708 * <p>The settings that can be updated with this method are:
3709 * <ul>
3710 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3711 * <li>{@link Settings.Global#AUTO_TIME}</li>
3712 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003713 * <li>{@link Settings.Global#BLUETOOTH_ON}
3714 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3715 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3716 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003717 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3718 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3719 * <li>{@link Settings.Global#MODE_RINGER}</li>
3720 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3721 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003722 * <li>{@link Settings.Global#WIFI_ON}
3723 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3724 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003725 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003726 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3727 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3728 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003729 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003730 *
3731 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3732 * @param setting The name of the setting to update.
3733 * @param value The value to update the setting to.
3734 */
3735 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3736 if (mService != null) {
3737 try {
3738 mService.setGlobalSetting(admin, setting, value);
3739 } catch (RemoteException e) {
3740 Log.w(TAG, "Failed talking with device policy service", e);
3741 }
3742 }
3743 }
3744
3745 /**
3746 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3747 * that the value of the setting is in the correct form for the setting type should be performed
3748 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003749 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003750 * <ul>
3751 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003752 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003753 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3754 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003755 * <p>A device owner can additionally update the following settings:
3756 * <ul>
3757 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3758 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003759 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3760 * @param setting The name of the setting to update.
3761 * @param value The value to update the setting to.
3762 */
3763 public void setSecureSetting(ComponentName admin, String setting, String value) {
3764 if (mService != null) {
3765 try {
3766 mService.setSecureSetting(admin, setting, value);
3767 } catch (RemoteException e) {
3768 Log.w(TAG, "Failed talking with device policy service", e);
3769 }
3770 }
3771 }
3772
Amith Yamasanif20d6402014-05-24 15:34:37 -07003773 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003774 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003775 * making permission requests of a local or remote administrator of the user.
3776 * <p/>
3777 * Only a profile owner can designate the restrictions provider.
3778 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003779 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003780 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003781 * it removes the restrictions provider previously assigned.
3782 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003783 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003784 if (mService != null) {
3785 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003786 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003787 } catch (RemoteException re) {
3788 Log.w(TAG, "Failed to set permission provider on device policy service");
3789 }
3790 }
3791 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003792
3793 /**
3794 * Called by profile or device owners to set the master volume mute on or off.
3795 *
3796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3797 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3798 */
3799 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3800 if (mService != null) {
3801 try {
3802 mService.setMasterVolumeMuted(admin, on);
3803 } catch (RemoteException re) {
3804 Log.w(TAG, "Failed to setMasterMute on device policy service");
3805 }
3806 }
3807 }
3808
3809 /**
3810 * Called by profile or device owners to check whether the master volume mute is on or off.
3811 *
3812 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3813 * @return {@code true} if master volume is muted, {@code false} if it's not.
3814 */
3815 public boolean isMasterVolumeMuted(ComponentName admin) {
3816 if (mService != null) {
3817 try {
3818 return mService.isMasterVolumeMuted(admin);
3819 } catch (RemoteException re) {
3820 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3821 }
3822 }
3823 return false;
3824 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003825
3826 /**
3827 * Called by profile or device owners to change whether a user can uninstall
3828 * a package.
3829 *
3830 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3831 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003832 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003833 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003834 public void setUninstallBlocked(ComponentName admin, String packageName,
3835 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003836 if (mService != null) {
3837 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003838 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003839 } catch (RemoteException re) {
3840 Log.w(TAG, "Failed to call block uninstall on device policy service");
3841 }
3842 }
3843 }
3844
3845 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003846 * Check whether the current user has been blocked by device policy from uninstalling a package.
3847 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00003848 * <p>
3849 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
3850 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
3851 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
3852 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01003853 *
Rubin Xua97855b2014-11-07 05:41:00 +00003854 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00003855 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003856 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003857 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003858 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003859 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003860 if (mService != null) {
3861 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003862 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003863 } catch (RemoteException re) {
3864 Log.w(TAG, "Failed to call block uninstall on device policy service");
3865 }
3866 }
3867 return false;
3868 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003869
3870 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003871 * Called by the profile owner of a managed profile to enable widget providers from a
3872 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003873 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003874 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003875 * a package may have zero or more provider components, where each component
3876 * provides a different widget type.
3877 * <p>
3878 * <strong>Note:</strong> By default no widget provider package is white-listed.
3879 * </p>
3880 *
3881 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3882 * @param packageName The package from which widget providers are white-listed.
3883 * @return Whether the package was added.
3884 *
3885 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3886 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3887 */
3888 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3889 if (mService != null) {
3890 try {
3891 return mService.addCrossProfileWidgetProvider(admin, packageName);
3892 } catch (RemoteException re) {
3893 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3894 }
3895 }
3896 return false;
3897 }
3898
3899 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003900 * Called by the profile owner of a managed profile to disable widget providers from a given
3901 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003902 * package should have been added via {@link #addCrossProfileWidgetProvider(
3903 * android.content.ComponentName, String)}.
3904 * <p>
3905 * <strong>Note:</strong> By default no widget provider package is white-listed.
3906 * </p>
3907 *
3908 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3909 * @param packageName The package from which widget providers are no longer
3910 * white-listed.
3911 * @return Whether the package was removed.
3912 *
3913 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3914 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3915 */
3916 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3917 if (mService != null) {
3918 try {
3919 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3920 } catch (RemoteException re) {
3921 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3922 }
3923 }
3924 return false;
3925 }
3926
3927 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003928 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003929 * available in the parent profile.
3930 *
3931 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3932 * @return The white-listed package list.
3933 *
3934 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3935 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3936 */
3937 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3938 if (mService != null) {
3939 try {
3940 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3941 if (providers != null) {
3942 return providers;
3943 }
3944 } catch (RemoteException re) {
3945 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3946 }
3947 }
3948 return Collections.emptyList();
3949 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05003950
3951 /**
3952 * Called by profile or device owners to set the current user's photo.
3953 *
3954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3955 * @param icon the bitmap to set as the photo.
3956 */
3957 public void setUserIcon(ComponentName admin, Bitmap icon) {
3958 try {
3959 mService.setUserIcon(admin, icon);
3960 } catch (RemoteException re) {
3961 Log.w(TAG, "Could not set the user icon ", re);
3962 }
3963 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003964}