blob: 0fa333e50204624e13730151a24f706cfd2931e4 [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;
Svetoslav976e8bd2014-07-16 15:12:03 -070023import android.app.admin.IDevicePolicyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.content.ComponentName;
25import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010026import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000027import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080028import android.content.pm.ActivityInfo;
29import android.content.pm.PackageManager;
30import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050031import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040032import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010033import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080034import android.os.Handler;
Jim Millere303bf42014-08-26 17:12:29 -070035import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000036import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080037import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080038import android.os.RemoteException;
39import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070040import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040041import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040042import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010043import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070044import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080045import android.util.Log;
46
Maggie Benthallda51e682013-08-08 22:35:44 -040047import com.android.org.conscrypt.TrustedCertificateStore;
48
Jessica Hummel91da58d2014-04-10 17:39:43 +010049import org.xmlpull.v1.XmlPullParserException;
50
Maggie Benthallda51e682013-08-08 22:35:44 -040051import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080052import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070053import java.net.InetSocketAddress;
54import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010055import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010056import java.security.PrivateKey;
57import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040058import java.security.cert.CertificateException;
59import java.security.cert.CertificateFactory;
60import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010061import java.security.spec.PKCS8EncodedKeySpec;
62import java.security.spec.InvalidKeySpecException;
63import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070064import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070065import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080066import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080067
68/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000069 * Public interface for managing policies enforced on a device. Most clients of this class must be
70 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000071 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000072 * a device administrator may be registered as either a profile or device owner. A given method is
73 * accessible to all device administrators unless the documentation for that method specifies that
74 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080075 *
76 * <div class="special reference">
77 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000078 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080079 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
80 * developer guide.</p>
81 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080082 */
83public class DevicePolicyManager {
84 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080085
86 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080087 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070088
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080089 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080091 mService = IDevicePolicyManager.Stub.asInterface(
92 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
93 }
94
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080095 /** @hide */
96 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080097 DevicePolicyManager me = new DevicePolicyManager(context, handler);
98 return me.mService != null ? me : null;
99 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700100
Dianne Hackbornd6847842010-01-12 18:14:19 -0800101 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000102 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000103 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100104 * <p>A managed profile allows data separation for example for the usage of a
105 * device as a personal and corporate device. The user which provisioning is started from and
106 * the managed profile share a launcher.
107 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800108 * <p>This intent will typically be sent by a mobile device management application (MDM).
109 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
110 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100111 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000112 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
113 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
114 * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain the extra
115 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
116 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000117 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000118 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
119 * in the provisioning intent. The
120 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
121 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
122 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100123 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100124 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
125 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000126 *
127 * <p>Input: Nothing.</p>
128 * <p>Output: Nothing</p>
129 */
130 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
131 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100132 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000133
134 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700135 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
136 * a mobile device management application that starts managed profile provisioning to pass data
137 * to itself on the managed profile when provisioning completes. The mobile device management
138 * application sends this extra in an intent with the action
139 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
140 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
141 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
142 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100143 */
144 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100145 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100146
147 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100148 * A String extra holding the package name of the mobile device management application that
149 * will be set as the profile owner or device owner.
150 *
151 * <p>If an application starts provisioning directly via an intent with action
152 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
153 * application that started provisioning. The package will be set as profile owner in that case.
154 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000155 * <p>This package is set as device owner when device owner provisioning is started by an NFC
156 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000157 *
158 * <p> When this extra is set, the application must have exactly one device admin receiver.
159 * This receiver will be set as the profile or device owner and active admin.</p>
160
161 * @see DeviceAdminReceiver
162 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
163 * supported.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000164 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000165 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000166 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100167 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000168
169 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000170 * A ComponentName extra indicating the device admin receiver of the mobile device management
171 * application that will be set as the profile owner or device owner and active admin.
172 *
173 * <p>If an application starts provisioning directly via an intent with action
174 * {@link #ACTION_PROVISION_MANAGED_PROFILE} the package name of this component has to match the
175 * package name of the application that started provisioning.
176 *
177 * <p>This component is set as device owner and active admin when device owner provisioning is
178 * started by an NFC message containing an NFC record with MIME type
179 * {@link #MIME_TYPE_PROVISIONING_NFC}.
180 *
181 * @see DeviceAdminReceiver
182 */
183 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
184 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
185
186 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000187 * An {@link android.accounts.Account} extra holding the account to migrate during managed
188 * profile provisioning. If the account supplied is present in the primary user, it will be
189 * copied, along with its credentials to the managed profile and removed from the primary user.
190 *
191 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
192 */
193
194 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
195 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
196
197 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100198 * A String extra that, holds the email address of the account which a managed profile is
199 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
200 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100201 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100202 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
203 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100204 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
205 * contains this extra, it is forwarded in the
206 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
207 * device management application that was set as the profile owner during provisioning.
208 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100209 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100210 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
211 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100212
213 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000214 * A Boolean extra that can be used by the mobile device management application to skip the
215 * disabling of system apps during provisioning when set to <code>true</code>.
216 *
217 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
218 * provisioning via an NFC bump.
219 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000220 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
221 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000222
223 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100224 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
225 * will be set to.
226 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000227 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
228 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100229 */
230 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100231 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100232
233 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100234 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
235 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100236 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000237 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
238 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100239 */
240 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100241 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100242
243 /**
244 * A String extra holding the {@link java.util.Locale} that the device will be set to.
245 * Format: xx_yy, where xx is the language code, and yy the country code.
246 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000247 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
248 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100249 */
250 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100251 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100252
253 /**
254 * A String extra holding the ssid of the wifi network that should be used during nfc device
255 * owner provisioning for downloading the mobile device management application.
256 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000257 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
258 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100259 */
260 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100261 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100262
263 /**
264 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
265 * is hidden or not.
266 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000267 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
268 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100269 */
270 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100271 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100272
273 /**
274 * A String extra indicating the security type of the wifi network in
275 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
276 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000277 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
278 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100279 */
280 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100281 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100282
283 /**
284 * A String extra holding the password of the wifi network in
285 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
286 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000287 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
288 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100289 */
290 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100291 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100292
293 /**
294 * A String extra holding the proxy host for the wifi network in
295 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
296 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000297 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
298 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100299 */
300 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100301 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100302
303 /**
304 * An int extra holding the proxy port for the wifi network in
305 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
306 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000307 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
308 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100309 */
310 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100311 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100312
313 /**
314 * A String extra holding the proxy bypass for the wifi network in
315 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
316 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000317 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
318 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319 */
320 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100321 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100322
323 /**
324 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
325 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
326 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000327 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
328 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329 */
330 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100331 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100332
333 /**
334 * A String extra holding a url that specifies the download location of the device admin
335 * package. When not provided it is assumed that the device admin package is already installed.
336 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000337 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
338 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100339 */
340 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100341 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100342
343 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400344 * An int extra holding a minimum required version code for the device admin package. If the
345 * device admin is already installed on the device, it will only be re-downloaded from
346 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
347 * installed package is less than this version code.
348 *
349 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
350 * provisioning via an NFC bump.
351 */
352 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
353 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
354
355 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100356 * A String extra holding a http cookie header which should be used in the http request to the
357 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
358 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000359 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
360 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100361 */
362 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100363 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100364
365 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100366 * A String extra holding the SHA-1 checksum of the file at download location specified in
367 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
368 * the file at the download location an error will be shown to the user and the user will be
369 * asked to factory reset the device.
370 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000371 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
372 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 */
374 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100375 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100376
377 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000378 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
379 * has completed successfully.
380 *
381 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
382 * intent (@see #ACTION_PROVISION_MANAGED_PROFILE).
383 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800384 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000385 * corresponds to the account requested to be migrated at provisioning time, if any.
386 */
387 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
388 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
389 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
390
391 /**
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500392 * A boolean extra indicating whether device encryption is required as part of Device Owner
393 * provisioning.
394 *
395 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
396 * provisioning via an NFC bump.
397 */
398 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
399 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
400
401 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500402 * On devices managed by a device owner app, a String representation of a Component name extra
403 * indicating the component of the application that is temporarily granted device owner
404 * privileges during device initialization and profile owner privileges during secondary user
405 * initialization.
406 *
407 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
408 * provisioning via an NFC bump.
409 * @see ComponentName#unflattenFromString()
410 */
411 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME
412 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME";
413
414 /**
415 * A String extra holding an http url that specifies the download location of the device
416 * initializer package. When not provided it is assumed that the device initializer package is
417 * already installed.
418 *
419 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
420 * provisioning via an NFC bump.
421 */
422 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION
423 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION";
424
425 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400426 * An int extra holding a minimum required version code for the device initializer package.
427 * If the initializer is already installed on the device, it will only be re-downloaded from
428 * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of
429 * the installed package is less than this version code.
430 *
431 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
432 * provisioning via an NFC bump.
433 */
434 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE
435 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE";
436
437 /**
Julia Reynolds20118f12015-02-11 12:34:08 -0500438 * A String extra holding a http cookie header which should be used in the http request to the
439 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}.
440 *
441 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
442 * provisioning via an NFC bump.
443 */
444 public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER
445 = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER";
446
447 /**
448 * A String extra holding the SHA-1 checksum of the file at download location specified in
449 * {@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 *
453 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
454 * 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 *
463 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
464 * 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 *
475 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
476 * 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 *
487 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
488 * 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 *
497 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
498 * provisioning via an NFC bump.
499 */
500 public static final String EXTRA_PROVISIONING_BT_USE_PROXY
501 = "android.app.extra.PROVISIONING_BT_USE_PROXY";
502
503 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100504 * This MIME type is used for starting the Device Owner provisioning.
505 *
506 * <p>During device owner provisioning a device admin app is set as the owner of the device.
507 * A device owner has full control over the device. The device owner can not be modified by the
508 * user and the only way of resetting the device is if the device owner app calls a factory
509 * reset.
510 *
511 * <p> A typical use case would be a device that is owned by a company, but used by either an
512 * employee or client.
513 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000514 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100515 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000516 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100517 * contains the following properties:
518 * <ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100519 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100520 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100521 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
522 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
523 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
524 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
525 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
526 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
527 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
528 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
529 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
530 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
531 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500532 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
533 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100534 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000535 * <p>
536 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, it should also contain
537 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
538 * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain
539 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, (although
540 * specifying only {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
541 * This componentName must have been converted to a String via
542 * {@link android.content.ComponentName#flattenToString()}
543 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100544 * <p> When device owner provisioning has completed, an intent of the type
545 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
546 * device owner.
547 *
548 * <p>
549 * If provisioning fails, the device is factory reset.
550 *
551 * <p>Input: Nothing.</p>
552 * <p>Output: Nothing</p>
553 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100554 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100555 = "application/com.android.managedprovisioning";
556
557 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800558 * Activity action: ask the user to add a new device administrator to the system.
559 * The desired policy is the ComponentName of the policy in the
560 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
561 * bring the user through adding the device administrator to the system (or
562 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700563 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800564 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
565 * field to provide the user with additional explanation (in addition
566 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800567 *
568 * <p>If your administrator is already active, this will ordinarily return immediately (without
569 * user intervention). However, if your administrator has been updated and is requesting
570 * additional uses-policy flags, the user will be presented with the new list. New policies
571 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800572 */
573 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
574 public static final String ACTION_ADD_DEVICE_ADMIN
575 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700576
Dianne Hackbornd6847842010-01-12 18:14:19 -0800577 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700578 * @hide
579 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700580 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700581 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700582 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
583 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700584 * to remotely control restrictions on the user.
585 *
586 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
587 * result of whether or not the user approved the action. If approved, the result will
588 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
589 * as a profile owner.
590 *
591 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
592 * field to provide the user with additional explanation (in addition
593 * to your component's description) about what is being added.
594 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700595 * <p>If there is already a profile owner active or the caller is not a system app, the
596 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700597 */
598 @SystemApi
599 public static final String ACTION_SET_PROFILE_OWNER
600 = "android.app.action.SET_PROFILE_OWNER";
601
602 /**
603 * @hide
604 * Name of the profile owner admin that controls the user.
605 */
606 @SystemApi
607 public static final String EXTRA_PROFILE_OWNER_NAME
608 = "android.app.extra.PROFILE_OWNER_NAME";
609
610 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700611 * Activity action: send when any policy admin changes a policy.
612 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700613 *
Jim Miller284b62e2010-06-08 14:27:42 -0700614 * @hide
615 */
616 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
617 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
618
619 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800620 * The ComponentName of the administrator component.
621 *
622 * @see #ACTION_ADD_DEVICE_ADMIN
623 */
624 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700625
Dianne Hackbornd6847842010-01-12 18:14:19 -0800626 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800627 * An optional CharSequence providing additional explanation for why the
628 * admin is being added.
629 *
630 * @see #ACTION_ADD_DEVICE_ADMIN
631 */
632 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700633
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800634 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700635 * Activity action: have the user enter a new password. This activity should
636 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
637 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
638 * enter a new password that meets the current requirements. You can use
639 * {@link #isActivePasswordSufficient()} to determine whether you need to
640 * have the user select a new password in order to meet the current
641 * constraints. Upon being resumed from this activity, you can check the new
642 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800643 */
644 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
645 public static final String ACTION_SET_NEW_PASSWORD
646 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700647
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000648 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000649 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
650 * the parent profile to access intents sent from the managed profile.
651 * That is, when an app in the managed profile calls
652 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
653 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000654 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100655 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000656
657 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000658 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
659 * the managed profile to access intents sent from the parent profile.
660 * That is, when an app in the parent profile calls
661 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
662 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000663 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100664 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700665
Dianne Hackbornd6847842010-01-12 18:14:19 -0800666 /**
667 * Return true if the given administrator component is currently
668 * active (enabled) in the system.
669 */
670 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100671 return isAdminActiveAsUser(who, UserHandle.myUserId());
672 }
673
674 /**
675 * @see #isAdminActive(ComponentName)
676 * @hide
677 */
678 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800679 if (mService != null) {
680 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100681 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800682 } catch (RemoteException e) {
683 Log.w(TAG, "Failed talking with device policy service", e);
684 }
685 }
686 return false;
687 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800688 /**
689 * Return true if the given administrator component is currently being removed
690 * for the user.
691 * @hide
692 */
693 public boolean isRemovingAdmin(ComponentName who, int userId) {
694 if (mService != null) {
695 try {
696 return mService.isRemovingAdmin(who, userId);
697 } catch (RemoteException e) {
698 Log.w(TAG, "Failed talking with device policy service", e);
699 }
700 }
701 return false;
702 }
703
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700704
Dianne Hackbornd6847842010-01-12 18:14:19 -0800705 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800706 * Return a list of all currently active device administrator's component
707 * names. Note that if there are no administrators than null may be
708 * returned.
709 */
710 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100711 return getActiveAdminsAsUser(UserHandle.myUserId());
712 }
713
714 /**
715 * @see #getActiveAdmins()
716 * @hide
717 */
718 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800719 if (mService != null) {
720 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100721 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800722 } catch (RemoteException e) {
723 Log.w(TAG, "Failed talking with device policy service", e);
724 }
725 }
726 return null;
727 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700728
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800729 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700730 * Used by package administration code to determine if a package can be stopped
731 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800732 * @hide
733 */
734 public boolean packageHasActiveAdmins(String packageName) {
735 if (mService != null) {
736 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700737 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800738 } catch (RemoteException e) {
739 Log.w(TAG, "Failed talking with device policy service", e);
740 }
741 }
742 return false;
743 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700744
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800745 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800746 * Remove a current administration component. This can only be called
747 * by the application that owns the administration component; if you
748 * try to remove someone else's component, a security exception will be
749 * thrown.
750 */
751 public void removeActiveAdmin(ComponentName who) {
752 if (mService != null) {
753 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700754 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800755 } catch (RemoteException e) {
756 Log.w(TAG, "Failed talking with device policy service", e);
757 }
758 }
759 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700760
Dianne Hackbornd6847842010-01-12 18:14:19 -0800761 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800762 * Returns true if an administrator has been granted a particular device policy. This can
763 * be used to check if the administrator was activated under an earlier set of policies,
764 * but requires additional policies after an upgrade.
765 *
766 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
767 * an active administrator, or an exception will be thrown.
768 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
769 */
770 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
771 if (mService != null) {
772 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700773 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800774 } catch (RemoteException e) {
775 Log.w(TAG, "Failed talking with device policy service", e);
776 }
777 }
778 return false;
779 }
780
781 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800782 * Constant for {@link #setPasswordQuality}: the policy has no requirements
783 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800784 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800785 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800786 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700787
Dianne Hackbornd6847842010-01-12 18:14:19 -0800788 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700789 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
790 * recognition technology. This implies technologies that can recognize the identity of
791 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
792 * Note that quality constants are ordered so that higher values are more restrictive.
793 */
794 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
795
796 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800797 * Constant for {@link #setPasswordQuality}: the policy requires some kind
798 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800799 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800800 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800801 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700802
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800803 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800804 * Constant for {@link #setPasswordQuality}: the user must have entered a
805 * password containing at least numeric characters. Note that quality
806 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800807 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800808 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700809
Dianne Hackbornd6847842010-01-12 18:14:19 -0800810 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800811 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800812 * password containing at least numeric characters with no repeating (4444)
813 * or ordered (1234, 4321, 2468) sequences. Note that quality
814 * constants are ordered so that higher values are more restrictive.
815 */
816 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
817
818 /**
819 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700820 * password containing at least alphabetic (or other symbol) characters.
821 * Note that quality constants are ordered so that higher values are more
822 * restrictive.
823 */
824 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700825
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700826 /**
827 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800828 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700829 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800830 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800831 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700832 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700833
Dianne Hackbornd6847842010-01-12 18:14:19 -0800834 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700835 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700836 * password containing at least a letter, a numerical digit and a special
837 * symbol, by default. With this password quality, passwords can be
838 * restricted to contain various sets of characters, like at least an
839 * uppercase letter, etc. These are specified using various methods,
840 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
841 * that quality constants are ordered so that higher values are more
842 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700843 */
844 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
845
846 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800847 * Called by an application that is administering the device to set the
848 * password restrictions it is imposing. After setting this, the user
849 * will not be able to enter a new password that is not at least as
850 * restrictive as what has been set. Note that the current password
851 * will remain until the user has set a new one, so the change does not
852 * take place immediately. To prompt the user for a new password, use
853 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700854 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800855 * <p>Quality constants are ordered so that higher values are more restrictive;
856 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800857 * the user's preference, and any other considerations) is the one that
858 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700859 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800860 * <p>The calling device admin must have requested
861 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
862 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700863 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800864 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800865 * @param quality The new desired quality. One of
866 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800867 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
868 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
869 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800870 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800871 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800872 if (mService != null) {
873 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800874 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800875 } catch (RemoteException e) {
876 Log.w(TAG, "Failed talking with device policy service", e);
877 }
878 }
879 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700880
Dianne Hackbornd6847842010-01-12 18:14:19 -0800881 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100882 * Retrieve the current minimum password quality for all admins of this user
883 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800884 * @param admin The name of the admin component to check, or null to aggregate
885 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800886 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800887 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700888 return getPasswordQuality(admin, UserHandle.myUserId());
889 }
890
891 /** @hide per-user version */
892 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800893 if (mService != null) {
894 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700895 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800896 } catch (RemoteException e) {
897 Log.w(TAG, "Failed talking with device policy service", e);
898 }
899 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800900 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800901 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700902
Dianne Hackbornd6847842010-01-12 18:14:19 -0800903 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800904 * Called by an application that is administering the device to set the
905 * minimum allowed password length. After setting this, the user
906 * will not be able to enter a new password that is not at least as
907 * restrictive as what has been set. Note that the current password
908 * will remain until the user has set a new one, so the change does not
909 * take place immediately. To prompt the user for a new password, use
910 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
911 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800912 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
913 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
914 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700915 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800916 * <p>The calling device admin must have requested
917 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
918 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700919 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800920 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800921 * @param length The new desired minimum password length. A value of 0
922 * means there is no restriction.
923 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800924 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800925 if (mService != null) {
926 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800927 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800928 } catch (RemoteException e) {
929 Log.w(TAG, "Failed talking with device policy service", e);
930 }
931 }
932 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700933
Dianne Hackbornd6847842010-01-12 18:14:19 -0800934 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100935 * Retrieve the current minimum password length for all admins of this
936 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800937 * @param admin The name of the admin component to check, or null to aggregate
938 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800939 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800940 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700941 return getPasswordMinimumLength(admin, UserHandle.myUserId());
942 }
943
944 /** @hide per-user version */
945 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800946 if (mService != null) {
947 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700948 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800949 } catch (RemoteException e) {
950 Log.w(TAG, "Failed talking with device policy service", e);
951 }
952 }
953 return 0;
954 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700955
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700956 /**
957 * Called by an application that is administering the device to set the
958 * minimum number of upper case letters required in the password. After
959 * setting this, the user will not be able to enter a new password that is
960 * not at least as restrictive as what has been set. Note that the current
961 * password will remain until the user has set a new one, so the change does
962 * not take place immediately. To prompt the user for a new password, use
963 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
964 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700965 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
966 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700967 * <p>
968 * The calling device admin must have requested
969 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
970 * this method; if it has not, a security exception will be thrown.
971 *
972 * @param admin Which {@link DeviceAdminReceiver} this request is associated
973 * with.
974 * @param length The new desired minimum number of upper case letters
975 * required in the password. A value of 0 means there is no
976 * restriction.
977 */
978 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
979 if (mService != null) {
980 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800981 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700982 } catch (RemoteException e) {
983 Log.w(TAG, "Failed talking with device policy service", e);
984 }
985 }
986 }
987
988 /**
989 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100990 * password for all admins of this user and its profiles or a particular one.
991 * This is the same value as set by
992 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700993 * and only applies when the password quality is
994 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700995 *
996 * @param admin The name of the admin component to check, or null to
997 * aggregate all admins.
998 * @return The minimum number of upper case letters required in the
999 * password.
1000 */
1001 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001002 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
1003 }
1004
1005 /** @hide per-user version */
1006 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001007 if (mService != null) {
1008 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001009 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001010 } catch (RemoteException e) {
1011 Log.w(TAG, "Failed talking with device policy service", e);
1012 }
1013 }
1014 return 0;
1015 }
1016
1017 /**
1018 * Called by an application that is administering the device to set the
1019 * minimum number of lower case letters required in the password. After
1020 * setting this, the user will not be able to enter a new password that is
1021 * not at least as restrictive as what has been set. Note that the current
1022 * password will remain until the user has set a new one, so the change does
1023 * not take place immediately. To prompt the user for a new password, use
1024 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1025 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001026 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1027 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001028 * <p>
1029 * The calling device admin must have requested
1030 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1031 * this method; if it has not, a security exception will be thrown.
1032 *
1033 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1034 * with.
1035 * @param length The new desired minimum number of lower case letters
1036 * required in the password. A value of 0 means there is no
1037 * restriction.
1038 */
1039 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
1040 if (mService != null) {
1041 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001042 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001043 } catch (RemoteException e) {
1044 Log.w(TAG, "Failed talking with device policy service", e);
1045 }
1046 }
1047 }
1048
1049 /**
1050 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001051 * password for all admins of this user and its profiles or a particular one.
1052 * This is the same value as set by
1053 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001054 * and only applies when the password quality is
1055 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001056 *
1057 * @param admin The name of the admin component to check, or null to
1058 * aggregate all admins.
1059 * @return The minimum number of lower case letters required in the
1060 * password.
1061 */
1062 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001063 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1064 }
1065
1066 /** @hide per-user version */
1067 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001068 if (mService != null) {
1069 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001070 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001071 } catch (RemoteException e) {
1072 Log.w(TAG, "Failed talking with device policy service", e);
1073 }
1074 }
1075 return 0;
1076 }
1077
1078 /**
1079 * Called by an application that is administering the device to set the
1080 * minimum number of letters required in the password. After setting this,
1081 * the user will not be able to enter a new password that is not at least as
1082 * restrictive as what has been set. Note that the current password will
1083 * remain until the user has set a new one, so the change does not take
1084 * place immediately. To prompt the user for a new password, use
1085 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1086 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001087 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1088 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001089 * <p>
1090 * The calling device admin must have requested
1091 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1092 * this method; if it has not, a security exception will be thrown.
1093 *
1094 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1095 * with.
1096 * @param length The new desired minimum number of letters required in the
1097 * password. A value of 0 means there is no restriction.
1098 */
1099 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1100 if (mService != null) {
1101 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001102 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001103 } catch (RemoteException e) {
1104 Log.w(TAG, "Failed talking with device policy service", e);
1105 }
1106 }
1107 }
1108
1109 /**
1110 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001111 * admins or a particular one. This is the same value as
1112 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1113 * and only applies when the password quality is
1114 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001115 *
1116 * @param admin The name of the admin component to check, or null to
1117 * aggregate all admins.
1118 * @return The minimum number of letters required in the password.
1119 */
1120 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001121 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1122 }
1123
1124 /** @hide per-user version */
1125 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001126 if (mService != null) {
1127 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001128 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001129 } catch (RemoteException e) {
1130 Log.w(TAG, "Failed talking with device policy service", e);
1131 }
1132 }
1133 return 0;
1134 }
1135
1136 /**
1137 * Called by an application that is administering the device to set the
1138 * minimum number of numerical digits required in the password. After
1139 * setting this, the user will not be able to enter a new password that is
1140 * not at least as restrictive as what has been set. Note that the current
1141 * password will remain until the user has set a new one, so the change does
1142 * not take place immediately. To prompt the user for a new password, use
1143 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1144 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001145 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1146 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001147 * <p>
1148 * The calling device admin must have requested
1149 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1150 * this method; if it has not, a security exception will be thrown.
1151 *
1152 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1153 * with.
1154 * @param length The new desired minimum number of numerical digits required
1155 * in the password. A value of 0 means there is no restriction.
1156 */
1157 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1158 if (mService != null) {
1159 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001160 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001161 } catch (RemoteException e) {
1162 Log.w(TAG, "Failed talking with device policy service", e);
1163 }
1164 }
1165 }
1166
1167 /**
1168 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001169 * for all admins of this user and its profiles or a particular one.
1170 * This is the same value as set by
1171 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001172 * and only applies when the password quality is
1173 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001174 *
1175 * @param admin The name of the admin component to check, or null to
1176 * aggregate all admins.
1177 * @return The minimum number of numerical digits required in the password.
1178 */
1179 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001180 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1181 }
1182
1183 /** @hide per-user version */
1184 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001185 if (mService != null) {
1186 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001187 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 } catch (RemoteException e) {
1189 Log.w(TAG, "Failed talking with device policy service", e);
1190 }
1191 }
1192 return 0;
1193 }
1194
1195 /**
1196 * Called by an application that is administering the device to set the
1197 * minimum number of symbols required in the password. After setting this,
1198 * the user will not be able to enter a new password that is not at least as
1199 * restrictive as what has been set. Note that the current password will
1200 * remain until the user has set a new one, so the change does not take
1201 * place immediately. To prompt the user for a new password, use
1202 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1203 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001204 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1205 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001206 * <p>
1207 * The calling device admin must have requested
1208 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1209 * this method; if it has not, a security exception will be thrown.
1210 *
1211 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1212 * with.
1213 * @param length The new desired minimum number of symbols required in the
1214 * password. A value of 0 means there is no restriction.
1215 */
1216 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1217 if (mService != null) {
1218 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001219 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001220 } catch (RemoteException e) {
1221 Log.w(TAG, "Failed talking with device policy service", e);
1222 }
1223 }
1224 }
1225
1226 /**
1227 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001228 * admins or a particular one. This is the same value as
1229 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1230 * and only applies when the password quality is
1231 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001232 *
1233 * @param admin The name of the admin component to check, or null to
1234 * aggregate all admins.
1235 * @return The minimum number of symbols required in the password.
1236 */
1237 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001238 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1239 }
1240
1241 /** @hide per-user version */
1242 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001243 if (mService != null) {
1244 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001245 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001246 } catch (RemoteException e) {
1247 Log.w(TAG, "Failed talking with device policy service", e);
1248 }
1249 }
1250 return 0;
1251 }
1252
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001253 /**
1254 * Called by an application that is administering the device to set the
1255 * minimum number of non-letter characters (numerical digits or symbols)
1256 * required in the password. After setting this, the user will not be able
1257 * to enter a new password that is not at least as restrictive as what has
1258 * been set. Note that the current password will remain until the user has
1259 * set a new one, so the change does not take place immediately. To prompt
1260 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1261 * setting this value. This constraint is only imposed if the administrator
1262 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1263 * {@link #setPasswordQuality}. The default value is 0.
1264 * <p>
1265 * The calling device admin must have requested
1266 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1267 * this method; if it has not, a security exception will be thrown.
1268 *
1269 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1270 * with.
1271 * @param length The new desired minimum number of letters required in the
1272 * password. A value of 0 means there is no restriction.
1273 */
1274 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1275 if (mService != null) {
1276 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001277 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001278 } catch (RemoteException e) {
1279 Log.w(TAG, "Failed talking with device policy service", e);
1280 }
1281 }
1282 }
1283
1284 /**
1285 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001286 * password for all admins of this user and its profiles or a particular one.
1287 * This is the same value as set by
1288 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001289 * and only applies when the password quality is
1290 * {@link #PASSWORD_QUALITY_COMPLEX}.
1291 *
1292 * @param admin The name of the admin component to check, or null to
1293 * aggregate all admins.
1294 * @return The minimum number of letters required in the password.
1295 */
1296 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001297 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1298 }
1299
1300 /** @hide per-user version */
1301 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001302 if (mService != null) {
1303 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001304 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001305 } catch (RemoteException e) {
1306 Log.w(TAG, "Failed talking with device policy service", e);
1307 }
1308 }
1309 return 0;
1310 }
1311
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001312 /**
1313 * Called by an application that is administering the device to set the length
1314 * of the password history. After setting this, the user will not be able to
1315 * enter a new password that is the same as any password in the history. Note
1316 * that the current password will remain until the user has set a new one, so
1317 * the change does not take place immediately. To prompt the user for a new
1318 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1319 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001320 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1321 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1322 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001323 *
1324 * <p>
1325 * The calling device admin must have requested
1326 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1327 * method; if it has not, a security exception will be thrown.
1328 *
1329 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1330 * with.
1331 * @param length The new desired length of password history. A value of 0
1332 * means there is no restriction.
1333 */
1334 public void setPasswordHistoryLength(ComponentName admin, int length) {
1335 if (mService != null) {
1336 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001337 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001338 } catch (RemoteException e) {
1339 Log.w(TAG, "Failed talking with device policy service", e);
1340 }
1341 }
1342 }
1343
1344 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001345 * Called by a device admin to set the password expiration timeout. Calling this method
1346 * will restart the countdown for password expiration for the given admin, as will changing
1347 * the device password (for all admins).
1348 *
1349 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1350 * For example, to have the password expire 5 days from now, timeout would be
1351 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1352 *
1353 * <p>To disable password expiration, a value of 0 may be used for timeout.
1354 *
Jim Millera4e28d12010-11-08 16:15:47 -08001355 * <p>The calling device admin must have requested
1356 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1357 * method; if it has not, a security exception will be thrown.
1358 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001359 * <p> Note that setting the password will automatically reset the expiration time for all
1360 * active admins. Active admins do not need to explicitly call this method in that case.
1361 *
Jim Millera4e28d12010-11-08 16:15:47 -08001362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1363 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1364 * means there is no restriction (unlimited).
1365 */
1366 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1367 if (mService != null) {
1368 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001369 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001370 } catch (RemoteException e) {
1371 Log.w(TAG, "Failed talking with device policy service", e);
1372 }
1373 }
1374 }
1375
1376 /**
Jim Miller6b857682011-02-16 16:27:41 -08001377 * Get the password expiration timeout for the given admin. The expiration timeout is the
1378 * recurring expiration timeout provided in the call to
1379 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1380 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001381 *
1382 * @param admin The name of the admin component to check, or null to aggregate all admins.
1383 * @return The timeout for the given admin or the minimum of all timeouts
1384 */
1385 public long getPasswordExpirationTimeout(ComponentName admin) {
1386 if (mService != null) {
1387 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001388 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001389 } catch (RemoteException e) {
1390 Log.w(TAG, "Failed talking with device policy service", e);
1391 }
1392 }
1393 return 0;
1394 }
1395
1396 /**
1397 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001398 * all admins of this user and its profiles if admin is null. If the password is
1399 * expired, this will return the time since the password expired as a negative number.
1400 * If admin is null, then a composite of all expiration timeouts is returned
1401 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001402 *
1403 * @param admin The name of the admin component to check, or null to aggregate all admins.
1404 * @return The password expiration time, in ms.
1405 */
1406 public long getPasswordExpiration(ComponentName admin) {
1407 if (mService != null) {
1408 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001409 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001410 } catch (RemoteException e) {
1411 Log.w(TAG, "Failed talking with device policy service", e);
1412 }
1413 }
1414 return 0;
1415 }
1416
1417 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001418 * Retrieve the current password history length for all admins of this
1419 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001420 * @param admin The name of the admin component to check, or null to aggregate
1421 * all admins.
1422 * @return The length of the password history
1423 */
1424 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001425 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1426 }
1427
1428 /** @hide per-user version */
1429 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001430 if (mService != null) {
1431 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001432 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001433 } catch (RemoteException e) {
1434 Log.w(TAG, "Failed talking with device policy service", e);
1435 }
1436 }
1437 return 0;
1438 }
1439
Dianne Hackbornd6847842010-01-12 18:14:19 -08001440 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001441 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001442 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001443 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001444 * @return Returns the maximum length that the user can enter.
1445 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001446 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001447 // Kind-of arbitrary.
1448 return 16;
1449 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001450
Dianne Hackborn254cb442010-01-27 19:23:59 -08001451 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001452 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001453 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001454 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001455 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001456 * <p>The calling device admin must have requested
1457 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1458 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001459 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001460 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001461 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001462 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001463 if (mService != null) {
1464 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001465 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001466 } catch (RemoteException e) {
1467 Log.w(TAG, "Failed talking with device policy service", e);
1468 }
1469 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001470 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001471 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001472
Dianne Hackbornd6847842010-01-12 18:14:19 -08001473 /**
1474 * Retrieve the number of times the user has failed at entering a
1475 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001476 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001477 * <p>The calling device admin must have requested
1478 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1479 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001480 */
1481 public int getCurrentFailedPasswordAttempts() {
1482 if (mService != null) {
1483 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001484 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001485 } catch (RemoteException e) {
1486 Log.w(TAG, "Failed talking with device policy service", e);
1487 }
1488 }
1489 return -1;
1490 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001491
1492 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001493 * Setting this to a value greater than zero enables a built-in policy
1494 * that will perform a device wipe after too many incorrect
1495 * device-unlock passwords have been entered. This built-in policy combines
1496 * watching for failed passwords and wiping the device, and requires
1497 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001498 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001499 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001500 * <p>To implement any other policy (e.g. wiping data for a particular
1501 * application only, erasing or revoking credentials, or reporting the
1502 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001503 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001504 * instead. Do not use this API, because if the maximum count is reached,
1505 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001506 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001508 * @param num The number of failed password attempts at which point the
1509 * device will wipe its data.
1510 */
1511 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1512 if (mService != null) {
1513 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001514 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001515 } catch (RemoteException e) {
1516 Log.w(TAG, "Failed talking with device policy service", e);
1517 }
1518 }
1519 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001520
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001521 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001522 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001523 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001524 * or a particular one.
1525 * @param admin The name of the admin component to check, or null to aggregate
1526 * all admins.
1527 */
1528 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001529 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1530 }
1531
1532 /** @hide per-user version */
1533 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001534 if (mService != null) {
1535 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001536 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001537 } catch (RemoteException e) {
1538 Log.w(TAG, "Failed talking with device policy service", e);
1539 }
1540 }
1541 return 0;
1542 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001543
Dianne Hackborn254cb442010-01-27 19:23:59 -08001544 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001545 * Returns the profile with the smallest maximum failed passwords for wipe,
1546 * for the given user. So for primary user, it might return the primary or
1547 * a managed profile. For a secondary user, it would be the same as the
1548 * user passed in.
1549 * @hide Used only by Keyguard
1550 */
1551 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1552 if (mService != null) {
1553 try {
1554 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1555 } catch (RemoteException e) {
1556 Log.w(TAG, "Failed talking with device policy service", e);
1557 }
1558 }
1559 return UserHandle.USER_NULL;
1560 }
1561
1562 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001563 * Flag for {@link #resetPassword}: don't allow other admins to change
1564 * the password again until the user has entered it.
1565 */
1566 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001567
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001568 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001569 * Force a new device unlock password (the password needed to access the
1570 * entire device, not for individual accounts) on the user. This takes
1571 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001572 * The given password must be sufficient for the
1573 * current password quality and length constraints as returned by
1574 * {@link #getPasswordQuality(ComponentName)} and
1575 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1576 * these constraints, then it will be rejected and false returned. Note
1577 * that the password may be a stronger quality (containing alphanumeric
1578 * characters when the requested quality is only numeric), in which case
1579 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001580 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001581 * <p>Calling with a null or empty password will clear any existing PIN,
1582 * pattern or password if the current password constraints allow it.
1583 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001584 * <p>The calling device admin must have requested
1585 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1586 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001587 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001588 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001589 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001590 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001591 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001592 * @return Returns true if the password was applied, or false if it is
1593 * not acceptable for the current constraints.
1594 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001595 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001596 if (mService != null) {
1597 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001598 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001599 } catch (RemoteException e) {
1600 Log.w(TAG, "Failed talking with device policy service", e);
1601 }
1602 }
1603 return false;
1604 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001605
Dianne Hackbornd6847842010-01-12 18:14:19 -08001606 /**
1607 * Called by an application that is administering the device to set the
1608 * maximum time for user activity until the device will lock. This limits
1609 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001610 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001611 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001612 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001613 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001614 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001615 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001616 * @param timeMs The new desired maximum time to lock in milliseconds.
1617 * A value of 0 means there is no restriction.
1618 */
1619 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1620 if (mService != null) {
1621 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001622 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001623 } catch (RemoteException e) {
1624 Log.w(TAG, "Failed talking with device policy service", e);
1625 }
1626 }
1627 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001628
Dianne Hackbornd6847842010-01-12 18:14:19 -08001629 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001630 * Retrieve the current maximum time to unlock for all admins of this user
1631 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001632 * @param admin The name of the admin component to check, or null to aggregate
1633 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001634 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001635 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001636 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001637 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001638 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1639 }
1640
1641 /** @hide per-user version */
1642 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001643 if (mService != null) {
1644 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001645 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001646 } catch (RemoteException e) {
1647 Log.w(TAG, "Failed talking with device policy service", e);
1648 }
1649 }
1650 return 0;
1651 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001652
Dianne Hackbornd6847842010-01-12 18:14:19 -08001653 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001654 * Make the device lock immediately, as if the lock screen timeout has
1655 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001656 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001657 * <p>The calling device admin must have requested
1658 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1659 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001660 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001661 public void lockNow() {
1662 if (mService != null) {
1663 try {
1664 mService.lockNow();
1665 } catch (RemoteException e) {
1666 Log.w(TAG, "Failed talking with device policy service", e);
1667 }
1668 }
1669 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001670
Dianne Hackbornd6847842010-01-12 18:14:19 -08001671 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001672 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001673 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001674 */
1675 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1676
1677 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001678 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1679 * data.
1680 *
Paul Crowley2934b262014-12-02 11:21:13 +00001681 * <p>This flag may only be set by device owner admins; if it is set by
1682 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001683 */
1684 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1685
1686 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001687 * Ask the user data be wiped. Wiping the primary user will cause the
1688 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001689 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001690 * <p>The calling device admin must have requested
1691 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1692 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001693 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001694 * @param flags Bit mask of additional options: currently supported flags
1695 * are {@link #WIPE_EXTERNAL_STORAGE} and
1696 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001697 */
1698 public void wipeData(int flags) {
1699 if (mService != null) {
1700 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001701 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001702 } catch (RemoteException e) {
1703 Log.w(TAG, "Failed talking with device policy service", e);
1704 }
1705 }
1706 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001707
Dianne Hackbornd6847842010-01-12 18:14:19 -08001708 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001709 * Called by an application that is administering the device to set the
1710 * global proxy and exclusion list.
1711 * <p>
1712 * The calling device admin must have requested
1713 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1714 * this method; if it has not, a security exception will be thrown.
1715 * Only the first device admin can set the proxy. If a second admin attempts
1716 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1717 * proxy will be returned. If successful in setting the proxy, null will
1718 * be returned.
1719 * The method can be called repeatedly by the device admin alrady setting the
1720 * proxy to update the proxy and exclusion list.
1721 *
1722 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1723 * with.
1724 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1725 * Pass Proxy.NO_PROXY to reset the proxy.
1726 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001727 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1728 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001729 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001730 */
1731 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1732 List<String> exclusionList ) {
1733 if (proxySpec == null) {
1734 throw new NullPointerException();
1735 }
1736 if (mService != null) {
1737 try {
1738 String hostSpec;
1739 String exclSpec;
1740 if (proxySpec.equals(Proxy.NO_PROXY)) {
1741 hostSpec = null;
1742 exclSpec = null;
1743 } else {
1744 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1745 throw new IllegalArgumentException();
1746 }
1747 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1748 String hostName = sa.getHostName();
1749 int port = sa.getPort();
1750 StringBuilder hostBuilder = new StringBuilder();
1751 hostSpec = hostBuilder.append(hostName)
1752 .append(":").append(Integer.toString(port)).toString();
1753 if (exclusionList == null) {
1754 exclSpec = "";
1755 } else {
1756 StringBuilder listBuilder = new StringBuilder();
1757 boolean firstDomain = true;
1758 for (String exclDomain : exclusionList) {
1759 if (!firstDomain) {
1760 listBuilder = listBuilder.append(",");
1761 } else {
1762 firstDomain = false;
1763 }
1764 listBuilder = listBuilder.append(exclDomain.trim());
1765 }
1766 exclSpec = listBuilder.toString();
1767 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001768 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1769 != android.net.Proxy.PROXY_VALID)
1770 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001771 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001772 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001773 } catch (RemoteException e) {
1774 Log.w(TAG, "Failed talking with device policy service", e);
1775 }
1776 }
1777 return null;
1778 }
1779
1780 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001781 * Set a network-independent global HTTP proxy. This is not normally what you want
1782 * for typical HTTP proxies - they are generally network dependent. However if you're
1783 * doing something unusual like general internal filtering this may be useful. On
1784 * a private network where the proxy is not accessible, you may break HTTP using this.
1785 *
1786 * <p>This method requires the caller to be the device owner.
1787 *
1788 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1789 * @see ProxyInfo
1790 *
1791 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1792 * with.
1793 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1794 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1795 */
1796 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1797 if (mService != null) {
1798 try {
1799 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1800 } catch (RemoteException e) {
1801 Log.w(TAG, "Failed talking with device policy service", e);
1802 }
1803 }
1804 }
1805
1806 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001807 * Returns the component name setting the global proxy.
1808 * @return ComponentName object of the device admin that set the global proxy, or
1809 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001810 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001811 */
1812 public ComponentName getGlobalProxyAdmin() {
1813 if (mService != null) {
1814 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001815 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001816 } catch (RemoteException e) {
1817 Log.w(TAG, "Failed talking with device policy service", e);
1818 }
1819 }
1820 return null;
1821 }
1822
1823 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001824 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001825 * indicating that encryption is not supported.
1826 */
1827 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1828
1829 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001830 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001831 * indicating that encryption is supported, but is not currently active.
1832 */
1833 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1834
1835 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001836 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001837 * indicating that encryption is not currently active, but is currently
1838 * being activated. This is only reported by devices that support
1839 * encryption of data and only when the storage is currently
1840 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1841 * to become encrypted will never return this value.
1842 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001843 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001844
1845 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001846 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001847 * indicating that encryption is active.
1848 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001849 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001850
1851 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001852 * Result code for {@link #getStorageEncryptionStatus}:
1853 * indicating that encryption is active, but an encryption key has not
1854 * been set by the user.
1855 */
1856 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1857
1858 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001859 * Activity action: begin the process of encrypting data on the device. This activity should
1860 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1861 * After resuming from this activity, use {@link #getStorageEncryption}
1862 * to check encryption status. However, on some devices this activity may never return, as
1863 * it may trigger a reboot and in some cases a complete data wipe of the device.
1864 */
1865 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1866 public static final String ACTION_START_ENCRYPTION
1867 = "android.app.action.START_ENCRYPTION";
1868
1869 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001870 * Widgets are enabled in keyguard
1871 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001872 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001873
1874 /**
Jim Miller50e62182014-04-23 17:25:00 -07001875 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001876 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001877 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1878
1879 /**
1880 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1881 */
1882 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1883
1884 /**
Jim Miller50e62182014-04-23 17:25:00 -07001885 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1886 */
1887 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1888
1889 /**
1890 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1891 */
1892 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1893
1894 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001895 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001896 * (e.g. PIN/Pattern/Password).
1897 */
1898 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1899
1900 /**
Jim Miller06e34502014-07-17 14:46:05 -07001901 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1902 */
1903 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1904
1905 /**
Jim Miller35207742012-11-02 15:33:20 -07001906 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001907 */
1908 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001909
1910 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001911 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001912 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001913 *
1914 * <p>When multiple device administrators attempt to control device
1915 * encryption, the most secure, supported setting will always be
1916 * used. If any device administrator requests device encryption,
1917 * it will be enabled; Conversely, if a device administrator
1918 * attempts to disable device encryption while another
1919 * device administrator has enabled it, the call to disable will
1920 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1921 *
1922 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001923 * written to other storage areas may or may not be encrypted, and this policy does not require
1924 * or control the encryption of any other storage areas.
1925 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1926 * {@code true}, then the directory returned by
1927 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1928 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001929 *
1930 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1931 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1932 * the encryption key may not be fully secured. For maximum security, the administrator should
1933 * also require (and check for) a pattern, PIN, or password.
1934 *
1935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1936 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001937 * @return the new request status (for all active admins) - will be one of
1938 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1939 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1940 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001941 */
1942 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1943 if (mService != null) {
1944 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001945 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001946 } catch (RemoteException e) {
1947 Log.w(TAG, "Failed talking with device policy service", e);
1948 }
1949 }
1950 return ENCRYPTION_STATUS_UNSUPPORTED;
1951 }
1952
1953 /**
1954 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001955 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001956 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001957 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1958 * this will return the requested encryption setting as an aggregate of all active
1959 * administrators.
1960 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001961 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001962 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001963 if (mService != null) {
1964 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001965 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001966 } catch (RemoteException e) {
1967 Log.w(TAG, "Failed talking with device policy service", e);
1968 }
1969 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001970 return false;
1971 }
1972
1973 /**
1974 * Called by an application that is administering the device to
1975 * determine the current encryption status of the device.
1976 *
1977 * Depending on the returned status code, the caller may proceed in different
1978 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1979 * storage system does not support encryption. If the
1980 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1981 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00001982 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
1983 * storage system has enabled encryption but no password is set so further action
1984 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08001985 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1986 *
Robin Lee7e678712014-07-24 16:41:31 +01001987 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001988 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00001989 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
1990 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08001991 */
1992 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001993 return getStorageEncryptionStatus(UserHandle.myUserId());
1994 }
1995
1996 /** @hide per-user version */
1997 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001998 if (mService != null) {
1999 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002000 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002001 } catch (RemoteException e) {
2002 Log.w(TAG, "Failed talking with device policy service", e);
2003 }
2004 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002005 return ENCRYPTION_STATUS_UNSUPPORTED;
2006 }
2007
2008 /**
Robin Lee7e678712014-07-24 16:41:31 +01002009 * Installs the given certificate as a user CA.
2010 *
Rubin Xuec32b562015-03-03 17:34:05 +00002011 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2012 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002013 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002014 *
2015 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002016 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002017 */
Robin Lee7e678712014-07-24 16:41:31 +01002018 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002019 if (mService != null) {
2020 try {
Robin Lee7e678712014-07-24 16:41:31 +01002021 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002022 } catch (RemoteException e) {
2023 Log.w(TAG, "Failed talking with device policy service", e);
2024 }
2025 }
2026 return false;
2027 }
2028
2029 /**
Robin Lee7e678712014-07-24 16:41:31 +01002030 * Uninstalls the given certificate from trusted user CAs, if present.
2031 *
Rubin Xuec32b562015-03-03 17:34:05 +00002032 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2033 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002034 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002035 */
Robin Lee7e678712014-07-24 16:41:31 +01002036 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002037 if (mService != null) {
2038 try {
Robin Lee306fe082014-06-19 14:04:24 +00002039 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01002040 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00002041 } catch (CertificateException e) {
2042 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002043 } catch (RemoteException e) {
2044 Log.w(TAG, "Failed talking with device policy service", e);
2045 }
2046 }
2047 }
2048
2049 /**
Robin Lee7e678712014-07-24 16:41:31 +01002050 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2051 * If a user has installed any certificates by other means than device policy these will be
2052 * included too.
2053 *
Rubin Xuec32b562015-03-03 17:34:05 +00002054 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2055 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002056 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002057 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002058 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002059 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002060 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002061 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002062 mService.enforceCanManageCaCerts(admin);
2063 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2064 for (String alias : certStore.userAliases()) {
2065 try {
2066 certs.add(certStore.getCertificate(alias).getEncoded());
2067 } catch (CertificateException ce) {
2068 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2069 }
2070 }
2071 } catch (RemoteException re) {
2072 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002073 }
2074 }
2075 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002076 }
2077
2078 /**
Robin Lee7e678712014-07-24 16:41:31 +01002079 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2080 * means other than device policy will also be removed, except for system CA certificates.
2081 *
Rubin Xuec32b562015-03-03 17:34:05 +00002082 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2083 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002084 */
2085 public void uninstallAllUserCaCerts(ComponentName admin) {
2086 if (mService != null) {
2087 for (String alias : new TrustedCertificateStore().userAliases()) {
2088 try {
2089 mService.uninstallCaCert(admin, alias);
2090 } catch (RemoteException re) {
2091 Log.w(TAG, "Failed talking with device policy service", re);
2092 }
2093 }
2094 }
2095 }
2096
2097 /**
2098 * Returns whether this certificate is installed as a trusted CA.
2099 *
Rubin Xuec32b562015-03-03 17:34:05 +00002100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use
2101 * <code>null</code> if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002102 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002103 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002104 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2105 if (mService != null) {
2106 try {
2107 mService.enforceCanManageCaCerts(admin);
2108 return getCaCertAlias(certBuffer) != null;
2109 } catch (RemoteException re) {
2110 Log.w(TAG, "Failed talking with device policy service", re);
2111 } catch (CertificateException ce) {
2112 Log.w(TAG, "Could not parse certificate", ce);
2113 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002114 }
2115 return false;
2116 }
2117
2118 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002119 * Called by a device or profile owner to install a certificate and private key pair. The
2120 * keypair will be visible to all apps within the profile.
2121 *
2122 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2123 * @param privKey The private key to install.
2124 * @param cert The certificate to install.
2125 * @param alias The private key alias under which to install the certificate. If a certificate
2126 * with that alias already exists, it will be overwritten.
2127 * @return {@code true} if the keys were installed, {@code false} otherwise.
2128 */
2129 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2130 String alias) {
2131 try {
2132 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002133 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2134 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2135 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002136 } catch (RemoteException e) {
2137 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002138 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2139 Log.w(TAG, "Failed to obtain private key material", e);
2140 } catch (CertificateException | IOException e) {
2141 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002142 }
2143 return false;
2144 }
2145
2146 /**
Robin Lee306fe082014-06-19 14:04:24 +00002147 * Returns the alias of a given CA certificate in the certificate store, or null if it
2148 * doesn't exist.
2149 */
2150 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2151 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2152 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2153 new ByteArrayInputStream(certBuffer));
2154 return new TrustedCertificateStore().getCertificateAlias(cert);
2155 }
2156
2157 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002158 * Called by a profile owner or device owner to grant access to privileged certificate
2159 * manipulation APIs to a third-party CA certificate installer app. Granted APIs include
2160 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
2161 * {@link #uninstallCaCert} and {@link #uninstallAllUserCaCerts}.
2162 * <p>
2163 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2164 * it is later cleared by calling this method with a null value or uninstallling the certificate
2165 * installer.
2166 *
2167 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2168 * @param installerPackage The package name of the certificate installer which will be given
2169 * access. If <code>null</code> is given the current package will be cleared.
2170 */
2171 public void setCertInstallerPackage(ComponentName who, String installerPackage)
2172 throws SecurityException {
2173 if (mService != null) {
2174 try {
2175 mService.setCertInstallerPackage(who, installerPackage);
2176 } catch (RemoteException e) {
2177 Log.w(TAG, "Failed talking with device policy service", e);
2178 }
2179 }
2180 }
2181
2182 /**
2183 * Called by a profile owner or device owner to retrieve the certificate installer for the
2184 * current user. null if none is set.
2185 *
2186 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2187 * @return The package name of the current delegated certificate installer. <code>null</code>
2188 * if none is set.
2189 */
2190 public String getCertInstallerPackage(ComponentName who) throws SecurityException {
2191 if (mService != null) {
2192 try {
2193 return mService.getCertInstallerPackage(who);
2194 } catch (RemoteException e) {
2195 Log.w(TAG, "Failed talking with device policy service", e);
2196 }
2197 }
2198 return null;
2199 }
2200
2201 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002202 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002203 * on the device, for this user. After setting this, no applications running as this user
2204 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002205 *
2206 * <p>The calling device admin must have requested
2207 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2208 * this method; if it has not, a security exception will be thrown.
2209 *
2210 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2211 * @param disabled Whether or not the camera should be disabled.
2212 */
2213 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2214 if (mService != null) {
2215 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002216 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002217 } catch (RemoteException e) {
2218 Log.w(TAG, "Failed talking with device policy service", e);
2219 }
2220 }
2221 }
2222
2223 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002224 * Determine whether or not the device's cameras have been disabled for this user,
2225 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002226 * @param admin The name of the admin component to check, or null to check if any admins
2227 * have disabled the camera
2228 */
2229 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002230 return getCameraDisabled(admin, UserHandle.myUserId());
2231 }
2232
2233 /** @hide per-user version */
2234 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002235 if (mService != null) {
2236 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002237 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002238 } catch (RemoteException e) {
2239 Log.w(TAG, "Failed talking with device policy service", e);
2240 }
2241 }
2242 return false;
2243 }
2244
2245 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002246 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2247 * screen capture also prevents the content from being shown on display devices that do not have
2248 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2249 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002250 *
2251 * <p>The calling device admin must be a device or profile owner. If it is not, a
2252 * security exception will be thrown.
2253 *
2254 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002255 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002256 */
2257 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2258 if (mService != null) {
2259 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002260 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002261 } catch (RemoteException e) {
2262 Log.w(TAG, "Failed talking with device policy service", e);
2263 }
2264 }
2265 }
2266
2267 /**
2268 * Determine whether or not screen capture has been disabled by the current
2269 * admin, if specified, or all admins.
2270 * @param admin The name of the admin component to check, or null to check if any admins
2271 * have disabled screen capture.
2272 */
2273 public boolean getScreenCaptureDisabled(ComponentName admin) {
2274 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2275 }
2276
2277 /** @hide per-user version */
2278 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2279 if (mService != null) {
2280 try {
2281 return mService.getScreenCaptureDisabled(admin, userHandle);
2282 } catch (RemoteException e) {
2283 Log.w(TAG, "Failed talking with device policy service", e);
2284 }
2285 }
2286 return false;
2287 }
2288
2289 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002290 * Called by a device owner to set whether auto time is required. If auto time is
2291 * required the user cannot set the date and time, but has to use network date and time.
2292 *
2293 * <p>Note: if auto time is required the user can still manually set the time zone.
2294 *
2295 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2296 * be thrown.
2297 *
2298 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2299 * @param required Whether auto time is set required or not.
2300 */
2301 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2302 if (mService != null) {
2303 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002304 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002305 } catch (RemoteException e) {
2306 Log.w(TAG, "Failed talking with device policy service", e);
2307 }
2308 }
2309 }
2310
2311 /**
2312 * @return true if auto time is required.
2313 */
2314 public boolean getAutoTimeRequired() {
2315 if (mService != null) {
2316 try {
2317 return mService.getAutoTimeRequired();
2318 } catch (RemoteException e) {
2319 Log.w(TAG, "Failed talking with device policy service", e);
2320 }
2321 }
2322 return false;
2323 }
2324
2325 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002326 * Called by an application that is administering the device to disable keyguard customizations,
2327 * such as widgets. After setting this, keyguard features will be disabled according to the
2328 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002329 *
2330 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002331 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002332 * this method; if it has not, a security exception will be thrown.
2333 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002334 * <p>Calling this from a managed profile will throw a security exception.
2335 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002336 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002337 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2338 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002339 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2340 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002341 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002342 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002343 if (mService != null) {
2344 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002345 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002346 } catch (RemoteException e) {
2347 Log.w(TAG, "Failed talking with device policy service", e);
2348 }
2349 }
2350 }
2351
2352 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002353 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002354 * admin, if specified, or all admins.
2355 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002356 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002357 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2358 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002359 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002360 public int getKeyguardDisabledFeatures(ComponentName admin) {
2361 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002362 }
2363
2364 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002365 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002366 if (mService != null) {
2367 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002368 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002369 } catch (RemoteException e) {
2370 Log.w(TAG, "Failed talking with device policy service", e);
2371 }
2372 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002373 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002374 }
2375
2376 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002377 * @hide
2378 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002379 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002380 if (mService != null) {
2381 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002382 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002383 } catch (RemoteException e) {
2384 Log.w(TAG, "Failed talking with device policy service", e);
2385 }
2386 }
2387 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002388
Dianne Hackbornd6847842010-01-12 18:14:19 -08002389 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002390 * @hide
2391 */
2392 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2393 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2394 }
2395
2396 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002397 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002398 * @hide
2399 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002400 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002401 ActivityInfo ai;
2402 try {
2403 ai = mContext.getPackageManager().getReceiverInfo(cn,
2404 PackageManager.GET_META_DATA);
2405 } catch (PackageManager.NameNotFoundException e) {
2406 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2407 return null;
2408 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002409
Dianne Hackbornd6847842010-01-12 18:14:19 -08002410 ResolveInfo ri = new ResolveInfo();
2411 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002412
Dianne Hackbornd6847842010-01-12 18:14:19 -08002413 try {
2414 return new DeviceAdminInfo(mContext, ri);
2415 } catch (XmlPullParserException e) {
2416 Log.w(TAG, "Unable to parse device policy " + cn, e);
2417 return null;
2418 } catch (IOException e) {
2419 Log.w(TAG, "Unable to parse device policy " + cn, e);
2420 return null;
2421 }
2422 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002423
Dianne Hackbornd6847842010-01-12 18:14:19 -08002424 /**
2425 * @hide
2426 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002427 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2428 if (mService != null) {
2429 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002430 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002431 } catch (RemoteException e) {
2432 Log.w(TAG, "Failed talking with device policy service", e);
2433 }
2434 }
2435 }
2436
2437 /**
2438 * @hide
2439 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002440 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002441 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002442 if (mService != null) {
2443 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002444 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002445 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002446 } catch (RemoteException e) {
2447 Log.w(TAG, "Failed talking with device policy service", e);
2448 }
2449 }
2450 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002451
Dianne Hackbornd6847842010-01-12 18:14:19 -08002452 /**
2453 * @hide
2454 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002455 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002456 if (mService != null) {
2457 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002458 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002459 } catch (RemoteException e) {
2460 Log.w(TAG, "Failed talking with device policy service", e);
2461 }
2462 }
2463 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002464
Dianne Hackbornd6847842010-01-12 18:14:19 -08002465 /**
2466 * @hide
2467 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002468 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002469 if (mService != null) {
2470 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002471 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002472 } catch (RemoteException e) {
2473 Log.w(TAG, "Failed talking with device policy service", e);
2474 }
2475 }
2476 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002477
2478 /**
2479 * @hide
2480 * Sets the given package as the device owner. The package must already be installed and there
2481 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2482 * method must be called before the device is provisioned.
2483 * @param packageName the package name of the application to be registered as the device owner.
2484 * @return whether the package was successfully registered as the device owner.
2485 * @throws IllegalArgumentException if the package name is null or invalid
2486 * @throws IllegalStateException if a device owner is already registered or the device has
2487 * already been provisioned.
2488 */
2489 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2490 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002491 return setDeviceOwner(packageName, null);
2492 }
2493
2494 /**
2495 * @hide
2496 * Sets the given package as the device owner. The package must already be installed and there
2497 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2498 * method must be called before the device is provisioned.
2499 * @param packageName the package name of the application to be registered as the device owner.
2500 * @param ownerName the human readable name of the institution that owns this device.
2501 * @return whether the package was successfully registered as the device owner.
2502 * @throws IllegalArgumentException if the package name is null or invalid
2503 * @throws IllegalStateException if a device owner is already registered or the device has
2504 * already been provisioned.
2505 */
2506 public boolean setDeviceOwner(String packageName, String ownerName)
2507 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002508 if (mService != null) {
2509 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002510 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002511 } catch (RemoteException re) {
2512 Log.w(TAG, "Failed to set device owner");
2513 }
2514 }
2515 return false;
2516 }
2517
2518 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002519 * Used to determine if a particular package has been registered as a Device Owner app.
2520 * A device owner app is a special device admin that cannot be deactivated by the user, once
2521 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2522 * package is currently registered as the device owner app, pass in the package name from
2523 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2524 * admin apps that want to check if they are also registered as the device owner app. The
2525 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2526 * the setup process.
2527 * @param packageName the package name of the app, to compare with the registered device owner
2528 * app, if any.
2529 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002530 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002531 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002532 if (mService != null) {
2533 try {
2534 return mService.isDeviceOwner(packageName);
2535 } catch (RemoteException re) {
2536 Log.w(TAG, "Failed to check device owner");
2537 }
2538 }
2539 return false;
2540 }
2541
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002542 /**
2543 * @hide
2544 * Redirect to isDeviceOwnerApp.
2545 */
2546 public boolean isDeviceOwner(String packageName) {
2547 return isDeviceOwnerApp(packageName);
2548 }
2549
Jason Monkb0dced82014-06-06 14:36:20 -04002550 /**
2551 * Clears the current device owner. The caller must be the device owner.
2552 *
2553 * This function should be used cautiously as once it is called it cannot
2554 * be undone. The device owner can only be set as a part of device setup
2555 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002556 *
2557 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002558 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002559 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002560 if (mService != null) {
2561 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002562 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002563 } catch (RemoteException re) {
2564 Log.w(TAG, "Failed to clear device owner");
2565 }
2566 }
2567 }
2568
Amith Yamasani71e6c692013-03-24 17:39:28 -07002569 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002570 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002571 public String getDeviceOwner() {
2572 if (mService != null) {
2573 try {
2574 return mService.getDeviceOwner();
2575 } catch (RemoteException re) {
2576 Log.w(TAG, "Failed to get device owner");
2577 }
2578 }
2579 return null;
2580 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002581
2582 /** @hide */
2583 public String getDeviceOwnerName() {
2584 if (mService != null) {
2585 try {
2586 return mService.getDeviceOwnerName();
2587 } catch (RemoteException re) {
2588 Log.w(TAG, "Failed to get device owner");
2589 }
2590 }
2591 return null;
2592 }
Adam Connors776c5552014-01-09 10:42:56 +00002593
2594 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002595 * Sets the given component as the device initializer. The package must already be installed and
2596 * set as an active device administrator, and there must not be an existing device initializer,
2597 * for this call to succeed. This method can only be called by an app holding the
2598 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2599 * device initializer app is granted device owner privileges during device initialization and
2600 * profile owner privileges during secondary user initialization.
2601 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2602 * called by the device owner.
2603 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2604 * @param initializerName The user-visible name of the device initializer.
2605 * @return whether the package was successfully registered as the device initializer.
2606 * @throws IllegalArgumentException if the package name is null or invalid
2607 * @throws IllegalStateException if the caller is not device owner or the device has
2608 * already been provisioned or a device initializer already exists.
2609 */
2610 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2611 String initializerName) throws IllegalArgumentException, IllegalStateException {
2612 if (mService != null) {
2613 try {
2614 return mService.setDeviceInitializer(who, initializer, initializerName);
2615 } catch (RemoteException re) {
2616 Log.w(TAG, "Failed to set device initializer");
2617 }
2618 }
2619 return false;
2620 }
2621
2622 /**
2623 * Used to determine if a particular package has been registered as the device initializer.
2624 *
2625 * @param packageName the package name of the app, to compare with the registered device
2626 * initializer app, if any.
2627 * @return whether or not the caller is registered as the device initializer app.
2628 */
2629 public boolean isDeviceInitializerApp(String packageName) {
2630 if (mService != null) {
2631 try {
2632 return mService.isDeviceInitializer(packageName);
2633 } catch (RemoteException re) {
2634 Log.w(TAG, "Failed to check device initializer");
2635 }
2636 }
2637 return false;
2638 }
2639
2640 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002641 * Removes the device initializer, so that it will not be invoked on user initialization for any
2642 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002643 * initializer itself. The caller must be an active administrator.
2644 *
2645 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002646 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002647 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002648 if (mService != null) {
2649 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002650 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002651 } catch (RemoteException re) {
2652 Log.w(TAG, "Failed to clear device initializer");
2653 }
2654 }
2655 }
2656
2657 /**
2658 * @hide
2659 * Gets the device initializer of the system.
2660 *
2661 * @return the package name of the device initializer.
2662 */
2663 @SystemApi
2664 public String getDeviceInitializerApp() {
2665 if (mService != null) {
2666 try {
2667 return mService.getDeviceInitializer();
2668 } catch (RemoteException re) {
2669 Log.w(TAG, "Failed to get device initializer");
2670 }
2671 }
2672 return null;
2673 }
2674
2675 /**
2676 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2677 * be used.
2678 *
2679 * <p>Device initializer must call this method to mark the user as functional.
2680 * Only the device initializer agent can call this.
2681 *
2682 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2683 * device initializer will no longer have elevated permissions to call methods in this class.
2684 * Additionally, it will be removed as an active administrator and its
2685 * {@link DeviceAdminReceiver} will be disabled.
2686 *
2687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2688 * @return whether the user is now enabled.
2689 */
2690 public boolean setUserEnabled(ComponentName admin) {
2691 if (mService != null) {
2692 try {
2693 return mService.setUserEnabled(admin);
2694 } catch (RemoteException e) {
2695 Log.w(TAG, "Failed talking with device policy service", e);
2696 }
2697 }
2698 return false;
2699 }
2700
2701 /**
Adam Connors776c5552014-01-09 10:42:56 +00002702 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002703 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302704 * Sets the given component as an active admin and registers the package as the profile
2705 * owner for this user. The package must already be installed and there shouldn't be
2706 * an existing profile owner registered for this user. Also, this method must be called
2707 * before the user setup has been completed.
2708 * <p>
2709 * This method can only be called by system apps that hold MANAGE_USERS permission and
2710 * MANAGE_DEVICE_ADMINS permission.
2711 * @param admin The component to register as an active admin and profile owner.
2712 * @param ownerName The user-visible name of the entity that is managing this user.
2713 * @return whether the admin was successfully registered as the profile owner.
2714 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2715 * the user has already been set up.
2716 */
Justin Morey80440cc2014-07-24 09:16:35 -05002717 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302718 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2719 throws IllegalArgumentException {
2720 if (mService != null) {
2721 try {
2722 final int myUserId = UserHandle.myUserId();
2723 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002724 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302725 } catch (RemoteException re) {
2726 Log.w(TAG, "Failed to set profile owner " + re);
2727 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2728 }
2729 }
2730 return false;
2731 }
2732
2733 /**
2734 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002735 * Clears the active profile owner and removes all user restrictions. The caller must
2736 * be from the same package as the active profile owner for this user, otherwise a
2737 * SecurityException will be thrown.
2738 *
2739 * @param admin The component to remove as the profile owner.
2740 * @return
2741 */
2742 @SystemApi
2743 public void clearProfileOwner(ComponentName admin) {
2744 if (mService != null) {
2745 try {
2746 mService.clearProfileOwner(admin);
2747 } catch (RemoteException re) {
2748 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2749 }
2750 }
2751 }
2752
2753 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002754 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002755 * Checks if the user was already setup.
2756 */
2757 public boolean hasUserSetupCompleted() {
2758 if (mService != null) {
2759 try {
2760 return mService.hasUserSetupCompleted();
2761 } catch (RemoteException re) {
2762 Log.w(TAG, "Failed to check if user setup has completed");
2763 }
2764 }
2765 return true;
2766 }
2767
2768 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002769 * @hide
2770 * Sets the given component as the profile owner of the given user profile. The package must
2771 * already be installed and there shouldn't be an existing profile owner registered for this
2772 * user. Only the system can call this API if the user has already completed setup.
2773 * @param admin the component name to be registered as profile owner.
2774 * @param ownerName the human readable name of the organisation associated with this DPM.
2775 * @param userHandle the userId to set the profile owner for.
2776 * @return whether the component was successfully registered as the profile owner.
2777 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2778 * the user has already been set up.
2779 */
2780 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2781 throws IllegalArgumentException {
2782 if (admin == null) {
2783 throw new NullPointerException("admin cannot be null");
2784 }
Adam Connors776c5552014-01-09 10:42:56 +00002785 if (mService != null) {
2786 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002787 if (ownerName == null) {
2788 ownerName = "";
2789 }
2790 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002791 } catch (RemoteException re) {
2792 Log.w(TAG, "Failed to set profile owner", re);
2793 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2794 }
2795 }
2796 return false;
2797 }
2798
2799 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002800 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2801 * be used. Only the profile owner can call this.
2802 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002803 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002804 *
2805 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2806 */
2807 public void setProfileEnabled(ComponentName admin) {
2808 if (mService != null) {
2809 try {
2810 mService.setProfileEnabled(admin);
2811 } catch (RemoteException e) {
2812 Log.w(TAG, "Failed talking with device policy service", e);
2813 }
2814 }
2815 }
2816
2817 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002818 * Sets the name of the profile. In the device owner case it sets the name of the user
2819 * 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 +01002820 * never called by the profile or device owner, the name will be set to default values.
2821 *
2822 * @see #isProfileOwnerApp
2823 * @see #isDeviceOwnerApp
2824 *
2825 * @param profileName The name of the profile.
2826 */
2827 public void setProfileName(ComponentName who, String profileName) {
2828 if (mService != null) {
2829 try {
2830 mService.setProfileName(who, profileName);
2831 } catch (RemoteException e) {
2832 Log.w(TAG, "Failed talking with device policy service", e);
2833 }
2834 }
2835}
2836
2837 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002838 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002839 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002840 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002841 *
2842 * @param packageName The package name of the app to compare with the registered profile owner.
2843 * @return Whether or not the package is registered as the profile owner.
2844 */
2845 public boolean isProfileOwnerApp(String packageName) {
2846 if (mService != null) {
2847 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002848 ComponentName profileOwner = mService.getProfileOwner(
2849 Process.myUserHandle().getIdentifier());
2850 return profileOwner != null
2851 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002852 } catch (RemoteException re) {
2853 Log.w(TAG, "Failed to check profile owner");
2854 }
2855 }
2856 return false;
2857 }
2858
2859 /**
2860 * @hide
2861 * @return the packageName of the owner of the given user profile or null if no profile
2862 * owner has been set for that user.
2863 * @throws IllegalArgumentException if the userId is invalid.
2864 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002865 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002866 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002867 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2868 }
2869
2870 /**
2871 * @see #getProfileOwner()
2872 * @hide
2873 */
2874 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002875 if (mService != null) {
2876 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002877 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002878 } catch (RemoteException re) {
2879 Log.w(TAG, "Failed to get profile owner");
2880 throw new IllegalArgumentException(
2881 "Requested profile owner for invalid userId", re);
2882 }
2883 }
2884 return null;
2885 }
2886
2887 /**
2888 * @hide
2889 * @return the human readable name of the organisation associated with this DPM or null if
2890 * one is not set.
2891 * @throws IllegalArgumentException if the userId is invalid.
2892 */
2893 public String getProfileOwnerName() throws IllegalArgumentException {
2894 if (mService != null) {
2895 try {
2896 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2897 } catch (RemoteException re) {
2898 Log.w(TAG, "Failed to get profile owner");
2899 throw new IllegalArgumentException(
2900 "Requested profile owner for invalid userId", re);
2901 }
2902 }
2903 return null;
2904 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002905
2906 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002907 * @hide
2908 * @param user The user for whom to fetch the profile owner name, if any.
2909 * @return the human readable name of the organisation associated with this profile owner or
2910 * null if one is not set.
2911 * @throws IllegalArgumentException if the userId is invalid.
2912 */
2913 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002914 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002915 if (mService != null) {
2916 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002917 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002918 } catch (RemoteException re) {
2919 Log.w(TAG, "Failed to get profile owner");
2920 throw new IllegalArgumentException(
2921 "Requested profile owner for invalid userId", re);
2922 }
2923 }
2924 return null;
2925 }
2926
2927 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002928 * Called by a profile owner or device owner to add a default intent handler activity for
2929 * intents that match a certain intent filter. This activity will remain the default intent
2930 * handler even if the set of potential event handlers for the intent filter changes and if
2931 * the intent preferences are reset.
2932 *
2933 * <p>The default disambiguation mechanism takes over if the activity is not installed
2934 * (anymore). When the activity is (re)installed, it is automatically reset as default
2935 * intent handler for the filter.
2936 *
2937 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2938 * security exception will be thrown.
2939 *
2940 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2941 * @param filter The IntentFilter for which a default handler is added.
2942 * @param activity The Activity that is added as default intent handler.
2943 */
2944 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2945 ComponentName activity) {
2946 if (mService != null) {
2947 try {
2948 mService.addPersistentPreferredActivity(admin, filter, activity);
2949 } catch (RemoteException e) {
2950 Log.w(TAG, "Failed talking with device policy service", e);
2951 }
2952 }
2953 }
2954
2955 /**
2956 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002957 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002958 *
2959 * <p>The calling device admin must be a profile owner. If it is not, a security
2960 * exception will be thrown.
2961 *
2962 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2963 * @param packageName The name of the package for which preferences are removed.
2964 */
2965 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2966 String packageName) {
2967 if (mService != null) {
2968 try {
2969 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2970 } catch (RemoteException e) {
2971 Log.w(TAG, "Failed talking with device policy service", e);
2972 }
2973 }
2974 }
Robin Lee66e5d962014-04-09 16:44:21 +01002975
2976 /**
2977 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002978 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002979 *
2980 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01002981 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01002982 *
2983 * <p>The application restrictions are only made visible to the target application and the
2984 * profile or device owner.
2985 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002986 * <p>If the restrictions are not available yet, but may be applied in the near future,
2987 * the admin can notify the target application of that by adding
2988 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
2989 *
Robin Lee66e5d962014-04-09 16:44:21 +01002990 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2991 * exception will be thrown.
2992 *
2993 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2994 * @param packageName The name of the package to update restricted settings for.
2995 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2996 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002997 *
2998 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01002999 */
3000 public void setApplicationRestrictions(ComponentName admin, String packageName,
3001 Bundle settings) {
3002 if (mService != null) {
3003 try {
3004 mService.setApplicationRestrictions(admin, packageName, settings);
3005 } catch (RemoteException e) {
3006 Log.w(TAG, "Failed talking with device policy service", e);
3007 }
3008 }
3009 }
3010
3011 /**
Jim Millere303bf42014-08-26 17:12:29 -07003012 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3013 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3014 * trust agents but those enabled by this function call. If flag
3015 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003016 *
3017 * <p>The calling device admin must have requested
3018 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003019 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003020 *
3021 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003022 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003023 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003024 * will be strictly disabled according to the state of the
3025 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3026 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3027 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3028 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003029 */
Jim Millere303bf42014-08-26 17:12:29 -07003030 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08003031 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003032 if (mService != null) {
3033 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003034 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003035 } catch (RemoteException e) {
3036 Log.w(TAG, "Failed talking with device policy service", e);
3037 }
3038 }
3039 }
3040
3041 /**
Jim Millere303bf42014-08-26 17:12:29 -07003042 * Gets configuration for the given trust agent based on aggregating all calls to
3043 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3044 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003045 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3047 * this function returns a list of configurations for all admins that declare
3048 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3049 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3050 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3051 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003052 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003053 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003054 */
Jim Millere303bf42014-08-26 17:12:29 -07003055 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3056 ComponentName agent) {
3057 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
3058 }
3059
3060 /** @hide per-user version */
3061 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
3062 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003063 if (mService != null) {
3064 try {
Jim Millere303bf42014-08-26 17:12:29 -07003065 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003066 } catch (RemoteException e) {
3067 Log.w(TAG, "Failed talking with device policy service", e);
3068 }
3069 }
Jim Millere303bf42014-08-26 17:12:29 -07003070 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003071 }
3072
3073 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003074 * Called by a profile owner of a managed profile to set whether caller-Id information from
3075 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003076 *
3077 * <p>The calling device admin must be a profile owner. If it is not, a
3078 * security exception will be thrown.
3079 *
3080 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3081 * @param disabled If true caller-Id information in the managed profile is not displayed.
3082 */
3083 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
3084 if (mService != null) {
3085 try {
3086 mService.setCrossProfileCallerIdDisabled(who, disabled);
3087 } catch (RemoteException e) {
3088 Log.w(TAG, "Failed talking with device policy service", e);
3089 }
3090 }
3091 }
3092
3093 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003094 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3095 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003096 *
3097 * <p>The calling device admin must be a profile owner. If it is not, a
3098 * security exception will be thrown.
3099 *
3100 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3101 */
3102 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3103 if (mService != null) {
3104 try {
3105 return mService.getCrossProfileCallerIdDisabled(who);
3106 } catch (RemoteException e) {
3107 Log.w(TAG, "Failed talking with device policy service", e);
3108 }
3109 }
3110 return false;
3111 }
3112
3113 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003114 * Determine whether or not caller-Id information has been disabled.
3115 *
3116 * @param userHandle The user for whom to check the caller-id permission
3117 * @hide
3118 */
3119 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3120 if (mService != null) {
3121 try {
3122 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3123 } catch (RemoteException e) {
3124 Log.w(TAG, "Failed talking with device policy service", e);
3125 }
3126 }
3127 return false;
3128 }
3129
3130 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003131 * Called by the profile owner of a managed profile so that some intents sent in the managed
3132 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003133 * Only activity intents are supported.
3134 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003135 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003136 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3137 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003138 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3139 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003140 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003141 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003142 if (mService != null) {
3143 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003144 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003145 } catch (RemoteException e) {
3146 Log.w(TAG, "Failed talking with device policy service", e);
3147 }
3148 }
3149 }
3150
3151 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003152 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3153 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003154 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3156 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003157 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003158 if (mService != null) {
3159 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003160 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003161 } catch (RemoteException e) {
3162 Log.w(TAG, "Failed talking with device policy service", e);
3163 }
3164 }
3165 }
3166
3167 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003168 * Called by a profile or device owner to set the permitted accessibility services. When
3169 * set by a device owner or profile owner the restriction applies to all profiles of the
3170 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003171 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003172 * By default the user can use any accessiblity service. When zero or more packages have
3173 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003174 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003175 *
3176 * <p> Calling with a null value for the list disables the restriction so that all services
3177 * can be used, calling with an empty list only allows the builtin system's services.
3178 *
3179 * <p> System accesibility services are always available to the user the list can't modify
3180 * this.
3181 *
3182 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3183 * @param packageNames List of accessibility service package names.
3184 *
3185 * @return true if setting the restriction succeeded. It fail if there is
3186 * one or more non-system accessibility services enabled, that are not in the list.
3187 */
3188 public boolean setPermittedAccessibilityServices(ComponentName admin,
3189 List<String> packageNames) {
3190 if (mService != null) {
3191 try {
3192 return mService.setPermittedAccessibilityServices(admin, packageNames);
3193 } catch (RemoteException e) {
3194 Log.w(TAG, "Failed talking with device policy service", e);
3195 }
3196 }
3197 return false;
3198 }
3199
3200 /**
3201 * Returns the list of permitted accessibility services set by this device or profile owner.
3202 *
3203 * <p>An empty list means no accessibility services except system services are allowed.
3204 * Null means all accessibility services are allowed.
3205 *
3206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3207 * @return List of accessiblity service package names.
3208 */
3209 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3210 if (mService != null) {
3211 try {
3212 return mService.getPermittedAccessibilityServices(admin);
3213 } catch (RemoteException e) {
3214 Log.w(TAG, "Failed talking with device policy service", e);
3215 }
3216 }
3217 return null;
3218 }
3219
3220 /**
3221 * Returns the list of accessibility services permitted by the device or profiles
3222 * owners of this user.
3223 *
3224 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3225 * it will contain the intersection of the permitted lists for any device or profile
3226 * owners that apply to this user. It will also include any system accessibility services.
3227 *
3228 * @param userId which user to check for.
3229 * @return List of accessiblity service package names.
3230 * @hide
3231 */
3232 @SystemApi
3233 public List<String> getPermittedAccessibilityServices(int userId) {
3234 if (mService != null) {
3235 try {
3236 return mService.getPermittedAccessibilityServicesForUser(userId);
3237 } catch (RemoteException e) {
3238 Log.w(TAG, "Failed talking with device policy service", e);
3239 }
3240 }
3241 return null;
3242 }
3243
3244 /**
3245 * Called by a profile or device owner to set the permitted input methods services. When
3246 * set by a device owner or profile owner the restriction applies to all profiles of the
3247 * user the device owner or profile owner is an admin for.
3248 *
3249 * By default the user can use any input method. When zero or more packages have
3250 * been added, input method that are not in the list and not part of the system
3251 * can not be enabled by the user.
3252 *
3253 * This method will fail if it is called for a admin that is not for the foreground user
3254 * or a profile of the foreground user.
3255 *
3256 * <p> Calling with a null value for the list disables the restriction so that all input methods
3257 * can be used, calling with an empty list disables all but the system's own input methods.
3258 *
3259 * <p> System input methods are always available to the user this method can't modify this.
3260 *
3261 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3262 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003263 * @return true if setting the restriction succeeded. It will fail if there are
3264 * one or more non-system input methods currently enabled that are not in
3265 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003266 */
3267 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3268 if (mService != null) {
3269 try {
3270 return mService.setPermittedInputMethods(admin, packageNames);
3271 } catch (RemoteException e) {
3272 Log.w(TAG, "Failed talking with device policy service", e);
3273 }
3274 }
3275 return false;
3276 }
3277
3278
3279 /**
3280 * Returns the list of permitted input methods set by this device or profile owner.
3281 *
3282 * <p>An empty list means no input methods except system input methods are allowed.
3283 * Null means all input methods are allowed.
3284 *
3285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3286 * @return List of input method package names.
3287 */
3288 public List<String> getPermittedInputMethods(ComponentName admin) {
3289 if (mService != null) {
3290 try {
3291 return mService.getPermittedInputMethods(admin);
3292 } catch (RemoteException e) {
3293 Log.w(TAG, "Failed talking with device policy service", e);
3294 }
3295 }
3296 return null;
3297 }
3298
3299 /**
3300 * Returns the list of input methods permitted by the device or profiles
3301 * owners of the current user.
3302 *
3303 * <p>Null means all input methods are allowed, if a non-null list is returned
3304 * it will contain the intersection of the permitted lists for any device or profile
3305 * owners that apply to this user. It will also include any system input methods.
3306 *
3307 * @return List of input method package names.
3308 * @hide
3309 */
3310 @SystemApi
3311 public List<String> getPermittedInputMethodsForCurrentUser() {
3312 if (mService != null) {
3313 try {
3314 return mService.getPermittedInputMethodsForCurrentUser();
3315 } catch (RemoteException e) {
3316 Log.w(TAG, "Failed talking with device policy service", e);
3317 }
3318 }
3319 return null;
3320 }
3321
3322 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003323 * Called by a device owner to create a user with the specified name. The UserHandle returned
3324 * by this method should not be persisted as user handles are recycled as users are removed and
3325 * created. If you need to persist an identifier for this user, use
3326 * {@link UserManager#getSerialNumberForUser}.
3327 *
3328 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3329 * @param name the user's name
3330 * @see UserHandle
3331 * @return the UserHandle object for the created user, or null if the user could not be created.
3332 */
3333 public UserHandle createUser(ComponentName admin, String name) {
3334 try {
3335 return mService.createUser(admin, name);
3336 } catch (RemoteException re) {
3337 Log.w(TAG, "Could not create a user", re);
3338 }
3339 return null;
3340 }
3341
3342 /**
Jason Monk03978a42014-06-10 15:05:30 -04003343 * Called by a device owner to create a user with the specified name. The UserHandle returned
3344 * by this method should not be persisted as user handles are recycled as users are removed and
3345 * created. If you need to persist an identifier for this user, use
3346 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3347 * immediately.
3348 *
3349 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3350 * as registered as an active admin on the new user. The profile owner package will be
3351 * installed on the new user if it already is installed on the device.
3352 *
3353 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3354 * profileOwnerComponent when onEnable is called.
3355 *
3356 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3357 * @param name the user's name
3358 * @param ownerName the human readable name of the organisation associated with this DPM.
3359 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3360 * the user.
3361 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3362 * on the new user.
3363 * @see UserHandle
3364 * @return the UserHandle object for the created user, or null if the user could not be created.
3365 */
3366 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3367 ComponentName profileOwnerComponent, Bundle adminExtras) {
3368 try {
3369 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3370 adminExtras);
3371 } catch (RemoteException re) {
3372 Log.w(TAG, "Could not create a user", re);
3373 }
3374 return null;
3375 }
3376
3377 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003378 * Called by a device owner to remove a user and all associated data. The primary user can
3379 * not be removed.
3380 *
3381 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3382 * @param userHandle the user to remove.
3383 * @return {@code true} if the user was removed, {@code false} otherwise.
3384 */
3385 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3386 try {
3387 return mService.removeUser(admin, userHandle);
3388 } catch (RemoteException re) {
3389 Log.w(TAG, "Could not remove user ", re);
3390 return false;
3391 }
3392 }
3393
3394 /**
Jason Monk582d9112014-07-09 19:57:08 -04003395 * Called by a device owner to switch the specified user to the foreground.
3396 *
3397 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3398 * @param userHandle the user to switch to; null will switch to primary.
3399 * @return {@code true} if the switch was successful, {@code false} otherwise.
3400 *
3401 * @see Intent#ACTION_USER_FOREGROUND
3402 */
3403 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3404 try {
3405 return mService.switchUser(admin, userHandle);
3406 } catch (RemoteException re) {
3407 Log.w(TAG, "Could not switch user ", re);
3408 return false;
3409 }
3410 }
3411
3412 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003413 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003414 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003415 *
3416 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3417 * exception will be thrown.
3418 *
3419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3420 * @param packageName The name of the package to fetch restricted settings of.
3421 * @return {@link Bundle} of settings corresponding to what was set last time
3422 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3423 * if no restrictions have been set.
3424 */
3425 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3426 if (mService != null) {
3427 try {
3428 return mService.getApplicationRestrictions(admin, packageName);
3429 } catch (RemoteException e) {
3430 Log.w(TAG, "Failed talking with device policy service", e);
3431 }
3432 }
3433 return null;
3434 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003435
3436 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003437 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003438 * <p>
3439 * The calling device admin must be a profile or device owner; if it is not,
3440 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003441 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003442 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3443 * with.
3444 * @param key The key of the restriction. See the constants in
3445 * {@link android.os.UserManager} for the list of keys.
3446 */
3447 public void addUserRestriction(ComponentName admin, String key) {
3448 if (mService != null) {
3449 try {
3450 mService.setUserRestriction(admin, key, true);
3451 } catch (RemoteException e) {
3452 Log.w(TAG, "Failed talking with device policy service", e);
3453 }
3454 }
3455 }
3456
3457 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003458 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003459 * <p>
3460 * The calling device admin must be a profile or device owner; if it is not,
3461 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003462 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003463 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3464 * with.
3465 * @param key The key of the restriction. See the constants in
3466 * {@link android.os.UserManager} for the list of keys.
3467 */
3468 public void clearUserRestriction(ComponentName admin, String key) {
3469 if (mService != null) {
3470 try {
3471 mService.setUserRestriction(admin, key, false);
3472 } catch (RemoteException e) {
3473 Log.w(TAG, "Failed talking with device policy service", e);
3474 }
3475 }
3476 }
Adam Connors010cfd42014-04-16 12:48:13 +01003477
3478 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003479 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003480 * is unavailable for use, but the data and actual package file remain.
3481 *
3482 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003483 * @param packageName The name of the package to hide or unhide.
3484 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3485 * unhidden.
3486 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003487 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003488 public boolean setApplicationHidden(ComponentName admin, String packageName,
3489 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003490 if (mService != null) {
3491 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003492 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003493 } catch (RemoteException e) {
3494 Log.w(TAG, "Failed talking with device policy service", e);
3495 }
3496 }
3497 return false;
3498 }
3499
3500 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003501 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003502 *
3503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003504 * @param packageName The name of the package to retrieve the hidden status of.
3505 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003506 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003507 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003508 if (mService != null) {
3509 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003510 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003511 } catch (RemoteException e) {
3512 Log.w(TAG, "Failed talking with device policy service", e);
3513 }
3514 }
3515 return false;
3516 }
3517
3518 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003519 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003520 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003521 *
3522 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3523 * @param packageName The package to be re-enabled in the current profile.
3524 */
3525 public void enableSystemApp(ComponentName admin, String packageName) {
3526 if (mService != null) {
3527 try {
3528 mService.enableSystemApp(admin, packageName);
3529 } catch (RemoteException e) {
3530 Log.w(TAG, "Failed to install package: " + packageName);
3531 }
3532 }
3533 }
3534
3535 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003536 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003537 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003538 *
3539 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3540 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3541 * intent will be re-enabled in the current profile.
3542 * @return int The number of activities that matched the intent and were installed.
3543 */
3544 public int enableSystemApp(ComponentName admin, Intent intent) {
3545 if (mService != null) {
3546 try {
3547 return mService.enableSystemAppWithIntent(admin, intent);
3548 } catch (RemoteException e) {
3549 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3550 }
3551 }
3552 return 0;
3553 }
3554
3555 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003556 * Called by a device owner or profile owner to disable account management for a specific type
3557 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003558 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003559 * <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 +01003560 * security exception will be thrown.
3561 *
3562 * <p>When account management is disabled for an account type, adding or removing an account
3563 * of that type will not be possible.
3564 *
3565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3566 * @param accountType For which account management is disabled or enabled.
3567 * @param disabled The boolean indicating that account management will be disabled (true) or
3568 * enabled (false).
3569 */
3570 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3571 boolean disabled) {
3572 if (mService != null) {
3573 try {
3574 mService.setAccountManagementDisabled(admin, accountType, disabled);
3575 } catch (RemoteException e) {
3576 Log.w(TAG, "Failed talking with device policy service", e);
3577 }
3578 }
3579 }
3580
3581 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003582 * Gets the array of accounts for which account management is disabled by the profile owner.
3583 *
3584 * <p> Account management can be disabled/enabled by calling
3585 * {@link #setAccountManagementDisabled}.
3586 *
3587 * @return a list of account types for which account management has been disabled.
3588 *
3589 * @see #setAccountManagementDisabled
3590 */
3591 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003592 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003593 }
3594
3595 /**
3596 * @see #getAccountTypesWithManagementDisabled()
3597 * @hide
3598 */
3599 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003600 if (mService != null) {
3601 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003602 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003603 } catch (RemoteException e) {
3604 Log.w(TAG, "Failed talking with device policy service", e);
3605 }
3606 }
3607
3608 return null;
3609 }
justinzhang511e0d82014-03-24 16:09:24 -04003610
3611 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003612 * Sets which packages may enter lock task mode.
3613 *
3614 * <p>Any packages that shares uid with an allowed package will also be allowed
3615 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003616 *
Jason Monkc5185f22014-06-24 11:12:42 -04003617 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003618 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003619 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003620 *
3621 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003622 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3623 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003624 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003625 */
Jason Monk48aacba2014-08-13 16:29:08 -04003626 public void setLockTaskPackages(ComponentName admin, String[] packages)
3627 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003628 if (mService != null) {
3629 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003630 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003631 } catch (RemoteException e) {
3632 Log.w(TAG, "Failed talking with device policy service", e);
3633 }
3634 }
3635 }
3636
3637 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003638 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003639 *
3640 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003641 * @hide
3642 */
Jason Monk48aacba2014-08-13 16:29:08 -04003643 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003644 if (mService != null) {
3645 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003646 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003647 } catch (RemoteException e) {
3648 Log.w(TAG, "Failed talking with device policy service", e);
3649 }
3650 }
3651 return null;
3652 }
3653
3654 /**
3655 * This function lets the caller know whether the given component is allowed to start the
3656 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003657 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003658 */
Jason Monkd7b86212014-06-16 13:15:38 -04003659 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003660 if (mService != null) {
3661 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003662 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003663 } catch (RemoteException e) {
3664 Log.w(TAG, "Failed talking with device policy service", e);
3665 }
3666 }
3667 return false;
3668 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003669
3670 /**
3671 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3672 * 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 -04003673 * <p>The settings that can be updated with this method are:
3674 * <ul>
3675 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3676 * <li>{@link Settings.Global#AUTO_TIME}</li>
3677 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003678 * <li>{@link Settings.Global#BLUETOOTH_ON}
3679 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3680 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3681 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003682 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3683 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3684 * <li>{@link Settings.Global#MODE_RINGER}</li>
3685 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3686 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003687 * <li>{@link Settings.Global#WIFI_ON}
3688 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3689 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003690 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003691 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3692 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3693 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003694 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003695 *
3696 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3697 * @param setting The name of the setting to update.
3698 * @param value The value to update the setting to.
3699 */
3700 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3701 if (mService != null) {
3702 try {
3703 mService.setGlobalSetting(admin, setting, value);
3704 } catch (RemoteException e) {
3705 Log.w(TAG, "Failed talking with device policy service", e);
3706 }
3707 }
3708 }
3709
3710 /**
3711 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3712 * that the value of the setting is in the correct form for the setting type should be performed
3713 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003714 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003715 * <ul>
3716 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003717 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003718 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3719 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003720 * <p>A device owner can additionally update the following settings:
3721 * <ul>
3722 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3723 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003724 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3725 * @param setting The name of the setting to update.
3726 * @param value The value to update the setting to.
3727 */
3728 public void setSecureSetting(ComponentName admin, String setting, String value) {
3729 if (mService != null) {
3730 try {
3731 mService.setSecureSetting(admin, setting, value);
3732 } catch (RemoteException e) {
3733 Log.w(TAG, "Failed talking with device policy service", e);
3734 }
3735 }
3736 }
3737
Amith Yamasanif20d6402014-05-24 15:34:37 -07003738 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003739 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003740 * making permission requests of a local or remote administrator of the user.
3741 * <p/>
3742 * Only a profile owner can designate the restrictions provider.
3743 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003744 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003745 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003746 * it removes the restrictions provider previously assigned.
3747 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003748 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003749 if (mService != null) {
3750 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003751 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003752 } catch (RemoteException re) {
3753 Log.w(TAG, "Failed to set permission provider on device policy service");
3754 }
3755 }
3756 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003757
3758 /**
3759 * Called by profile or device owners to set the master volume mute on or off.
3760 *
3761 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3762 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3763 */
3764 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3765 if (mService != null) {
3766 try {
3767 mService.setMasterVolumeMuted(admin, on);
3768 } catch (RemoteException re) {
3769 Log.w(TAG, "Failed to setMasterMute on device policy service");
3770 }
3771 }
3772 }
3773
3774 /**
3775 * Called by profile or device owners to check whether the master volume mute is on or off.
3776 *
3777 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3778 * @return {@code true} if master volume is muted, {@code false} if it's not.
3779 */
3780 public boolean isMasterVolumeMuted(ComponentName admin) {
3781 if (mService != null) {
3782 try {
3783 return mService.isMasterVolumeMuted(admin);
3784 } catch (RemoteException re) {
3785 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3786 }
3787 }
3788 return false;
3789 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003790
3791 /**
3792 * Called by profile or device owners to change whether a user can uninstall
3793 * a package.
3794 *
3795 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3796 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003797 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003798 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003799 public void setUninstallBlocked(ComponentName admin, String packageName,
3800 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003801 if (mService != null) {
3802 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003803 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003804 } catch (RemoteException re) {
3805 Log.w(TAG, "Failed to call block uninstall on device policy service");
3806 }
3807 }
3808 }
3809
3810 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003811 * Check whether the current user has been blocked by device policy from uninstalling a package.
3812 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00003813 * <p>
3814 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
3815 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
3816 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
3817 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01003818 *
Rubin Xua97855b2014-11-07 05:41:00 +00003819 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00003820 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003821 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003822 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003823 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003824 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003825 if (mService != null) {
3826 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003827 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003828 } catch (RemoteException re) {
3829 Log.w(TAG, "Failed to call block uninstall on device policy service");
3830 }
3831 }
3832 return false;
3833 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003834
3835 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003836 * Called by the profile owner of a managed profile to enable widget providers from a
3837 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003838 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003839 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003840 * a package may have zero or more provider components, where each component
3841 * provides a different widget type.
3842 * <p>
3843 * <strong>Note:</strong> By default no widget provider package is white-listed.
3844 * </p>
3845 *
3846 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3847 * @param packageName The package from which widget providers are white-listed.
3848 * @return Whether the package was added.
3849 *
3850 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3851 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3852 */
3853 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3854 if (mService != null) {
3855 try {
3856 return mService.addCrossProfileWidgetProvider(admin, packageName);
3857 } catch (RemoteException re) {
3858 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3859 }
3860 }
3861 return false;
3862 }
3863
3864 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003865 * Called by the profile owner of a managed profile to disable widget providers from a given
3866 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003867 * package should have been added via {@link #addCrossProfileWidgetProvider(
3868 * android.content.ComponentName, String)}.
3869 * <p>
3870 * <strong>Note:</strong> By default no widget provider package is white-listed.
3871 * </p>
3872 *
3873 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3874 * @param packageName The package from which widget providers are no longer
3875 * white-listed.
3876 * @return Whether the package was removed.
3877 *
3878 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3879 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3880 */
3881 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3882 if (mService != null) {
3883 try {
3884 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3885 } catch (RemoteException re) {
3886 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3887 }
3888 }
3889 return false;
3890 }
3891
3892 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003893 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003894 * available in the parent profile.
3895 *
3896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3897 * @return The white-listed package list.
3898 *
3899 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3900 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3901 */
3902 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3903 if (mService != null) {
3904 try {
3905 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3906 if (providers != null) {
3907 return providers;
3908 }
3909 } catch (RemoteException re) {
3910 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3911 }
3912 }
3913 return Collections.emptyList();
3914 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05003915
3916 /**
3917 * Called by profile or device owners to set the current user's photo.
3918 *
3919 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3920 * @param icon the bitmap to set as the photo.
3921 */
3922 public void setUserIcon(ComponentName admin, Bitmap icon) {
3923 try {
3924 mService.setUserIcon(admin, icon);
3925 } catch (RemoteException re) {
3926 Log.w(TAG, "Could not set the user icon ", re);
3927 }
3928 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003929}