blob: 99c97cec74470f5d44b0ae0b54dd92c6d2b532d0 [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 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100460 * This MIME type is used for starting the Device Owner provisioning.
461 *
462 * <p>During device owner provisioning a device admin app is set as the owner of the device.
463 * A device owner has full control over the device. The device owner can not be modified by the
464 * user and the only way of resetting the device is if the device owner app calls a factory
465 * reset.
466 *
467 * <p> A typical use case would be a device that is owned by a company, but used by either an
468 * employee or client.
469 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000470 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100471 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000472 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100473 * contains the following properties:
474 * <ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100475 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100476 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100477 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
478 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
479 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
480 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
481 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
482 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
483 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
484 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
485 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
486 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
487 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500488 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
489 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100490 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000491 * <p>
492 * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, it should also contain
493 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
494 * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain
495 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, (although
496 * specifying only {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
497 * This componentName must have been converted to a String via
498 * {@link android.content.ComponentName#flattenToString()}
499 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100500 * <p> When device owner provisioning has completed, an intent of the type
501 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
502 * device owner.
503 *
504 * <p>
505 * If provisioning fails, the device is factory reset.
506 *
507 * <p>Input: Nothing.</p>
508 * <p>Output: Nothing</p>
509 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100510 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100511 = "application/com.android.managedprovisioning";
512
513 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800514 * Activity action: ask the user to add a new device administrator to the system.
515 * The desired policy is the ComponentName of the policy in the
516 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
517 * bring the user through adding the device administrator to the system (or
518 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700519 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800520 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
521 * field to provide the user with additional explanation (in addition
522 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800523 *
524 * <p>If your administrator is already active, this will ordinarily return immediately (without
525 * user intervention). However, if your administrator has been updated and is requesting
526 * additional uses-policy flags, the user will be presented with the new list. New policies
527 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800528 */
529 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
530 public static final String ACTION_ADD_DEVICE_ADMIN
531 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700532
Dianne Hackbornd6847842010-01-12 18:14:19 -0800533 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700534 * @hide
535 * Activity action: ask the user to add a new device administrator as the profile owner
536 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
537 * permission can call this API.
538 *
539 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
540 * field. This will invoke a UI to bring the user through adding the profile owner admin
541 * to remotely control restrictions on the user.
542 *
543 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
544 * result of whether or not the user approved the action. If approved, the result will
545 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
546 * as a profile owner.
547 *
548 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
549 * field to provide the user with additional explanation (in addition
550 * to your component's description) about what is being added.
551 *
552 * <p>If there is already a profile owner active or the caller doesn't have the required
553 * permissions, the operation will return a failure result.
554 */
555 @SystemApi
556 public static final String ACTION_SET_PROFILE_OWNER
557 = "android.app.action.SET_PROFILE_OWNER";
558
559 /**
560 * @hide
561 * Name of the profile owner admin that controls the user.
562 */
563 @SystemApi
564 public static final String EXTRA_PROFILE_OWNER_NAME
565 = "android.app.extra.PROFILE_OWNER_NAME";
566
567 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700568 * Activity action: send when any policy admin changes a policy.
569 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700570 *
Jim Miller284b62e2010-06-08 14:27:42 -0700571 * @hide
572 */
573 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
574 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
575
576 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800577 * The ComponentName of the administrator component.
578 *
579 * @see #ACTION_ADD_DEVICE_ADMIN
580 */
581 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700582
Dianne Hackbornd6847842010-01-12 18:14:19 -0800583 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800584 * An optional CharSequence providing additional explanation for why the
585 * admin is being added.
586 *
587 * @see #ACTION_ADD_DEVICE_ADMIN
588 */
589 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700590
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800591 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700592 * Activity action: have the user enter a new password. This activity should
593 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
594 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
595 * enter a new password that meets the current requirements. You can use
596 * {@link #isActivePasswordSufficient()} to determine whether you need to
597 * have the user select a new password in order to meet the current
598 * constraints. Upon being resumed from this activity, you can check the new
599 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800600 */
601 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
602 public static final String ACTION_SET_NEW_PASSWORD
603 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700604
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000605 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000606 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
607 * the parent profile to access intents sent from the managed profile.
608 * That is, when an app in the managed profile calls
609 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
610 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000611 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100612 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000613
614 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000615 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
616 * the managed profile to access intents sent from the parent profile.
617 * That is, when an app in the parent profile calls
618 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
619 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000620 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100621 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700622
Dianne Hackbornd6847842010-01-12 18:14:19 -0800623 /**
624 * Return true if the given administrator component is currently
625 * active (enabled) in the system.
626 */
627 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100628 return isAdminActiveAsUser(who, UserHandle.myUserId());
629 }
630
631 /**
632 * @see #isAdminActive(ComponentName)
633 * @hide
634 */
635 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800636 if (mService != null) {
637 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100638 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800639 } catch (RemoteException e) {
640 Log.w(TAG, "Failed talking with device policy service", e);
641 }
642 }
643 return false;
644 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800645 /**
646 * Return true if the given administrator component is currently being removed
647 * for the user.
648 * @hide
649 */
650 public boolean isRemovingAdmin(ComponentName who, int userId) {
651 if (mService != null) {
652 try {
653 return mService.isRemovingAdmin(who, userId);
654 } catch (RemoteException e) {
655 Log.w(TAG, "Failed talking with device policy service", e);
656 }
657 }
658 return false;
659 }
660
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700661
Dianne Hackbornd6847842010-01-12 18:14:19 -0800662 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800663 * Return a list of all currently active device administrator's component
664 * names. Note that if there are no administrators than null may be
665 * returned.
666 */
667 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100668 return getActiveAdminsAsUser(UserHandle.myUserId());
669 }
670
671 /**
672 * @see #getActiveAdmins()
673 * @hide
674 */
675 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800676 if (mService != null) {
677 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100678 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800679 } catch (RemoteException e) {
680 Log.w(TAG, "Failed talking with device policy service", e);
681 }
682 }
683 return null;
684 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700685
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800686 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700687 * Used by package administration code to determine if a package can be stopped
688 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800689 * @hide
690 */
691 public boolean packageHasActiveAdmins(String packageName) {
692 if (mService != null) {
693 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700694 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800695 } catch (RemoteException e) {
696 Log.w(TAG, "Failed talking with device policy service", e);
697 }
698 }
699 return false;
700 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700701
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800702 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800703 * Remove a current administration component. This can only be called
704 * by the application that owns the administration component; if you
705 * try to remove someone else's component, a security exception will be
706 * thrown.
707 */
708 public void removeActiveAdmin(ComponentName who) {
709 if (mService != null) {
710 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700711 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800712 } catch (RemoteException e) {
713 Log.w(TAG, "Failed talking with device policy service", e);
714 }
715 }
716 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700717
Dianne Hackbornd6847842010-01-12 18:14:19 -0800718 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800719 * Returns true if an administrator has been granted a particular device policy. This can
720 * be used to check if the administrator was activated under an earlier set of policies,
721 * but requires additional policies after an upgrade.
722 *
723 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
724 * an active administrator, or an exception will be thrown.
725 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
726 */
727 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
728 if (mService != null) {
729 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700730 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800731 } catch (RemoteException e) {
732 Log.w(TAG, "Failed talking with device policy service", e);
733 }
734 }
735 return false;
736 }
737
738 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800739 * Constant for {@link #setPasswordQuality}: the policy has no requirements
740 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800741 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800742 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800743 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700744
Dianne Hackbornd6847842010-01-12 18:14:19 -0800745 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700746 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
747 * recognition technology. This implies technologies that can recognize the identity of
748 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
749 * Note that quality constants are ordered so that higher values are more restrictive.
750 */
751 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
752
753 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800754 * Constant for {@link #setPasswordQuality}: the policy requires some kind
755 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800756 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800757 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800758 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700759
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800760 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800761 * Constant for {@link #setPasswordQuality}: the user must have entered a
762 * password containing at least numeric characters. Note that quality
763 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800764 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800765 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700766
Dianne Hackbornd6847842010-01-12 18:14:19 -0800767 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800768 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800769 * password containing at least numeric characters with no repeating (4444)
770 * or ordered (1234, 4321, 2468) sequences. Note that quality
771 * constants are ordered so that higher values are more restrictive.
772 */
773 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
774
775 /**
776 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700777 * password containing at least alphabetic (or other symbol) characters.
778 * Note that quality constants are ordered so that higher values are more
779 * restrictive.
780 */
781 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700782
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700783 /**
784 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800785 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700786 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800787 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800788 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700789 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700790
Dianne Hackbornd6847842010-01-12 18:14:19 -0800791 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700792 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700793 * password containing at least a letter, a numerical digit and a special
794 * symbol, by default. With this password quality, passwords can be
795 * restricted to contain various sets of characters, like at least an
796 * uppercase letter, etc. These are specified using various methods,
797 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
798 * that quality constants are ordered so that higher values are more
799 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700800 */
801 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
802
803 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800804 * Called by an application that is administering the device to set the
805 * password restrictions it is imposing. After setting this, the user
806 * will not be able to enter a new password that is not at least as
807 * restrictive as what has been set. Note that the current password
808 * will remain until the user has set a new one, so the change does not
809 * take place immediately. To prompt the user for a new password, use
810 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700811 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800812 * <p>Quality constants are ordered so that higher values are more restrictive;
813 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800814 * the user's preference, and any other considerations) is the one that
815 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700816 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800817 * <p>The calling device admin must have requested
818 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
819 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700820 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800821 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800822 * @param quality The new desired quality. One of
823 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800824 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
825 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
826 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800828 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800829 if (mService != null) {
830 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800831 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800832 } catch (RemoteException e) {
833 Log.w(TAG, "Failed talking with device policy service", e);
834 }
835 }
836 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700837
Dianne Hackbornd6847842010-01-12 18:14:19 -0800838 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100839 * Retrieve the current minimum password quality for all admins of this user
840 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800841 * @param admin The name of the admin component to check, or null to aggregate
842 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800843 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800844 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700845 return getPasswordQuality(admin, UserHandle.myUserId());
846 }
847
848 /** @hide per-user version */
849 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800850 if (mService != null) {
851 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700852 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800853 } catch (RemoteException e) {
854 Log.w(TAG, "Failed talking with device policy service", e);
855 }
856 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800857 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800858 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700859
Dianne Hackbornd6847842010-01-12 18:14:19 -0800860 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800861 * Called by an application that is administering the device to set the
862 * minimum allowed password length. After setting this, the user
863 * will not be able to enter a new password that is not at least as
864 * restrictive as what has been set. Note that the current password
865 * will remain until the user has set a new one, so the change does not
866 * take place immediately. To prompt the user for a new password, use
867 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
868 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800869 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
870 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
871 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700872 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800873 * <p>The calling device admin must have requested
874 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
875 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700876 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800877 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800878 * @param length The new desired minimum password length. A value of 0
879 * means there is no restriction.
880 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800881 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800882 if (mService != null) {
883 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800884 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800885 } catch (RemoteException e) {
886 Log.w(TAG, "Failed talking with device policy service", e);
887 }
888 }
889 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700890
Dianne Hackbornd6847842010-01-12 18:14:19 -0800891 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100892 * Retrieve the current minimum password length for all admins of this
893 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800894 * @param admin The name of the admin component to check, or null to aggregate
895 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800896 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800897 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700898 return getPasswordMinimumLength(admin, UserHandle.myUserId());
899 }
900
901 /** @hide per-user version */
902 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800903 if (mService != null) {
904 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700905 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800906 } catch (RemoteException e) {
907 Log.w(TAG, "Failed talking with device policy service", e);
908 }
909 }
910 return 0;
911 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700912
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700913 /**
914 * Called by an application that is administering the device to set the
915 * minimum number of upper case letters required in the password. After
916 * setting this, the user will not be able to enter a new password that is
917 * not at least as restrictive as what has been set. Note that the current
918 * password will remain until the user has set a new one, so the change does
919 * not take place immediately. To prompt the user for a new password, use
920 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
921 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700922 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
923 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700924 * <p>
925 * The calling device admin must have requested
926 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
927 * this method; if it has not, a security exception will be thrown.
928 *
929 * @param admin Which {@link DeviceAdminReceiver} this request is associated
930 * with.
931 * @param length The new desired minimum number of upper case letters
932 * required in the password. A value of 0 means there is no
933 * restriction.
934 */
935 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
936 if (mService != null) {
937 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800938 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700939 } catch (RemoteException e) {
940 Log.w(TAG, "Failed talking with device policy service", e);
941 }
942 }
943 }
944
945 /**
946 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100947 * password for all admins of this user and its profiles or a particular one.
948 * This is the same value as set by
949 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700950 * and only applies when the password quality is
951 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700952 *
953 * @param admin The name of the admin component to check, or null to
954 * aggregate all admins.
955 * @return The minimum number of upper case letters required in the
956 * password.
957 */
958 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700959 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
960 }
961
962 /** @hide per-user version */
963 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700964 if (mService != null) {
965 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700966 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700967 } catch (RemoteException e) {
968 Log.w(TAG, "Failed talking with device policy service", e);
969 }
970 }
971 return 0;
972 }
973
974 /**
975 * Called by an application that is administering the device to set the
976 * minimum number of lower case letters required in the password. After
977 * setting this, the user will not be able to enter a new password that is
978 * not at least as restrictive as what has been set. Note that the current
979 * password will remain until the user has set a new one, so the change does
980 * not take place immediately. To prompt the user for a new password, use
981 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
982 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700983 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
984 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700985 * <p>
986 * The calling device admin must have requested
987 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
988 * this method; if it has not, a security exception will be thrown.
989 *
990 * @param admin Which {@link DeviceAdminReceiver} this request is associated
991 * with.
992 * @param length The new desired minimum number of lower case letters
993 * required in the password. A value of 0 means there is no
994 * restriction.
995 */
996 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
997 if (mService != null) {
998 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800999 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001000 } catch (RemoteException e) {
1001 Log.w(TAG, "Failed talking with device policy service", e);
1002 }
1003 }
1004 }
1005
1006 /**
1007 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001008 * password for all admins of this user and its profiles or a particular one.
1009 * This is the same value as set by
1010 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001011 * and only applies when the password quality is
1012 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001013 *
1014 * @param admin The name of the admin component to check, or null to
1015 * aggregate all admins.
1016 * @return The minimum number of lower case letters required in the
1017 * password.
1018 */
1019 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001020 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
1021 }
1022
1023 /** @hide per-user version */
1024 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001025 if (mService != null) {
1026 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001027 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001028 } catch (RemoteException e) {
1029 Log.w(TAG, "Failed talking with device policy service", e);
1030 }
1031 }
1032 return 0;
1033 }
1034
1035 /**
1036 * Called by an application that is administering the device to set the
1037 * minimum number of letters required in the password. After setting this,
1038 * the user will not be able to enter a new password that is not at least as
1039 * restrictive as what has been set. Note that the current password will
1040 * remain until the user has set a new one, so the change does not take
1041 * place immediately. To prompt the user for a new password, use
1042 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1043 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001044 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1045 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001046 * <p>
1047 * The calling device admin must have requested
1048 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1049 * this method; if it has not, a security exception will be thrown.
1050 *
1051 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1052 * with.
1053 * @param length The new desired minimum number of letters required in the
1054 * password. A value of 0 means there is no restriction.
1055 */
1056 public void setPasswordMinimumLetters(ComponentName admin, int length) {
1057 if (mService != null) {
1058 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001059 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001060 } catch (RemoteException e) {
1061 Log.w(TAG, "Failed talking with device policy service", e);
1062 }
1063 }
1064 }
1065
1066 /**
1067 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001068 * admins or a particular one. This is the same value as
1069 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1070 * and only applies when the password quality is
1071 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001072 *
1073 * @param admin The name of the admin component to check, or null to
1074 * aggregate all admins.
1075 * @return The minimum number of letters required in the password.
1076 */
1077 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001078 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
1079 }
1080
1081 /** @hide per-user version */
1082 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001083 if (mService != null) {
1084 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001085 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001086 } catch (RemoteException e) {
1087 Log.w(TAG, "Failed talking with device policy service", e);
1088 }
1089 }
1090 return 0;
1091 }
1092
1093 /**
1094 * Called by an application that is administering the device to set the
1095 * minimum number of numerical digits required in the password. After
1096 * setting this, the user will not be able to enter a new password that is
1097 * not at least as restrictive as what has been set. Note that the current
1098 * password will remain until the user has set a new one, so the change does
1099 * not take place immediately. To prompt the user for a new password, use
1100 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1101 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001102 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1103 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001104 * <p>
1105 * The calling device admin must have requested
1106 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1107 * this method; if it has not, a security exception will be thrown.
1108 *
1109 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1110 * with.
1111 * @param length The new desired minimum number of numerical digits required
1112 * in the password. A value of 0 means there is no restriction.
1113 */
1114 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1115 if (mService != null) {
1116 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001117 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001118 } catch (RemoteException e) {
1119 Log.w(TAG, "Failed talking with device policy service", e);
1120 }
1121 }
1122 }
1123
1124 /**
1125 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001126 * for all admins of this user and its profiles or a particular one.
1127 * This is the same value as set by
1128 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001129 * and only applies when the password quality is
1130 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001131 *
1132 * @param admin The name of the admin component to check, or null to
1133 * aggregate all admins.
1134 * @return The minimum number of numerical digits required in the password.
1135 */
1136 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001137 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1138 }
1139
1140 /** @hide per-user version */
1141 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001142 if (mService != null) {
1143 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001144 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001145 } catch (RemoteException e) {
1146 Log.w(TAG, "Failed talking with device policy service", e);
1147 }
1148 }
1149 return 0;
1150 }
1151
1152 /**
1153 * Called by an application that is administering the device to set the
1154 * minimum number of symbols required in the password. After setting this,
1155 * the user will not be able to enter a new password that is not at least as
1156 * restrictive as what has been set. Note that the current password will
1157 * remain until the user has set a new one, so the change does not take
1158 * place immediately. To prompt the user for a new password, use
1159 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1160 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001161 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1162 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001163 * <p>
1164 * The calling device admin must have requested
1165 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1166 * this method; if it has not, a security exception will be thrown.
1167 *
1168 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1169 * with.
1170 * @param length The new desired minimum number of symbols required in the
1171 * password. A value of 0 means there is no restriction.
1172 */
1173 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1174 if (mService != null) {
1175 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001176 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001177 } catch (RemoteException e) {
1178 Log.w(TAG, "Failed talking with device policy service", e);
1179 }
1180 }
1181 }
1182
1183 /**
1184 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001185 * admins or a particular one. This is the same value as
1186 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1187 * and only applies when the password quality is
1188 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001189 *
1190 * @param admin The name of the admin component to check, or null to
1191 * aggregate all admins.
1192 * @return The minimum number of symbols required in the password.
1193 */
1194 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001195 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1196 }
1197
1198 /** @hide per-user version */
1199 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001200 if (mService != null) {
1201 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001202 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001203 } catch (RemoteException e) {
1204 Log.w(TAG, "Failed talking with device policy service", e);
1205 }
1206 }
1207 return 0;
1208 }
1209
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001210 /**
1211 * Called by an application that is administering the device to set the
1212 * minimum number of non-letter characters (numerical digits or symbols)
1213 * required in the password. After setting this, the user will not be able
1214 * to enter a new password that is not at least as restrictive as what has
1215 * been set. Note that the current password will remain until the user has
1216 * set a new one, so the change does not take place immediately. To prompt
1217 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1218 * setting this value. This constraint is only imposed if the administrator
1219 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1220 * {@link #setPasswordQuality}. The default value is 0.
1221 * <p>
1222 * The calling device admin must have requested
1223 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1224 * this method; if it has not, a security exception will be thrown.
1225 *
1226 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1227 * with.
1228 * @param length The new desired minimum number of letters required in the
1229 * password. A value of 0 means there is no restriction.
1230 */
1231 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1232 if (mService != null) {
1233 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001234 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001235 } catch (RemoteException e) {
1236 Log.w(TAG, "Failed talking with device policy service", e);
1237 }
1238 }
1239 }
1240
1241 /**
1242 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001243 * password for all admins of this user and its profiles or a particular one.
1244 * This is the same value as set by
1245 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001246 * and only applies when the password quality is
1247 * {@link #PASSWORD_QUALITY_COMPLEX}.
1248 *
1249 * @param admin The name of the admin component to check, or null to
1250 * aggregate all admins.
1251 * @return The minimum number of letters required in the password.
1252 */
1253 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001254 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1255 }
1256
1257 /** @hide per-user version */
1258 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001259 if (mService != null) {
1260 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001261 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001262 } catch (RemoteException e) {
1263 Log.w(TAG, "Failed talking with device policy service", e);
1264 }
1265 }
1266 return 0;
1267 }
1268
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001269 /**
1270 * Called by an application that is administering the device to set the length
1271 * of the password history. After setting this, the user will not be able to
1272 * enter a new password that is the same as any password in the history. Note
1273 * that the current password will remain until the user has set a new one, so
1274 * the change does not take place immediately. To prompt the user for a new
1275 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1276 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001277 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1278 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1279 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001280 *
1281 * <p>
1282 * The calling device admin must have requested
1283 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1284 * method; if it has not, a security exception will be thrown.
1285 *
1286 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1287 * with.
1288 * @param length The new desired length of password history. A value of 0
1289 * means there is no restriction.
1290 */
1291 public void setPasswordHistoryLength(ComponentName admin, int length) {
1292 if (mService != null) {
1293 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001294 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001295 } catch (RemoteException e) {
1296 Log.w(TAG, "Failed talking with device policy service", e);
1297 }
1298 }
1299 }
1300
1301 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001302 * Called by a device admin to set the password expiration timeout. Calling this method
1303 * will restart the countdown for password expiration for the given admin, as will changing
1304 * the device password (for all admins).
1305 *
1306 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1307 * For example, to have the password expire 5 days from now, timeout would be
1308 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1309 *
1310 * <p>To disable password expiration, a value of 0 may be used for timeout.
1311 *
Jim Millera4e28d12010-11-08 16:15:47 -08001312 * <p>The calling device admin must have requested
1313 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1314 * method; if it has not, a security exception will be thrown.
1315 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001316 * <p> Note that setting the password will automatically reset the expiration time for all
1317 * active admins. Active admins do not need to explicitly call this method in that case.
1318 *
Jim Millera4e28d12010-11-08 16:15:47 -08001319 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1320 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1321 * means there is no restriction (unlimited).
1322 */
1323 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1324 if (mService != null) {
1325 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001326 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001327 } catch (RemoteException e) {
1328 Log.w(TAG, "Failed talking with device policy service", e);
1329 }
1330 }
1331 }
1332
1333 /**
Jim Miller6b857682011-02-16 16:27:41 -08001334 * Get the password expiration timeout for the given admin. The expiration timeout is the
1335 * recurring expiration timeout provided in the call to
1336 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1337 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001338 *
1339 * @param admin The name of the admin component to check, or null to aggregate all admins.
1340 * @return The timeout for the given admin or the minimum of all timeouts
1341 */
1342 public long getPasswordExpirationTimeout(ComponentName admin) {
1343 if (mService != null) {
1344 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001345 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001346 } catch (RemoteException e) {
1347 Log.w(TAG, "Failed talking with device policy service", e);
1348 }
1349 }
1350 return 0;
1351 }
1352
1353 /**
1354 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001355 * all admins of this user and its profiles if admin is null. If the password is
1356 * expired, this will return the time since the password expired as a negative number.
1357 * If admin is null, then a composite of all expiration timeouts is returned
1358 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001359 *
1360 * @param admin The name of the admin component to check, or null to aggregate all admins.
1361 * @return The password expiration time, in ms.
1362 */
1363 public long getPasswordExpiration(ComponentName admin) {
1364 if (mService != null) {
1365 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001366 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001367 } catch (RemoteException e) {
1368 Log.w(TAG, "Failed talking with device policy service", e);
1369 }
1370 }
1371 return 0;
1372 }
1373
1374 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001375 * Retrieve the current password history length for all admins of this
1376 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001377 * @param admin The name of the admin component to check, or null to aggregate
1378 * all admins.
1379 * @return The length of the password history
1380 */
1381 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001382 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1383 }
1384
1385 /** @hide per-user version */
1386 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001387 if (mService != null) {
1388 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001389 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001390 } catch (RemoteException e) {
1391 Log.w(TAG, "Failed talking with device policy service", e);
1392 }
1393 }
1394 return 0;
1395 }
1396
Dianne Hackbornd6847842010-01-12 18:14:19 -08001397 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001398 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001399 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001400 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001401 * @return Returns the maximum length that the user can enter.
1402 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001403 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001404 // Kind-of arbitrary.
1405 return 16;
1406 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001407
Dianne Hackborn254cb442010-01-27 19:23:59 -08001408 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001409 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001410 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001411 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001412 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001413 * <p>The calling device admin must have requested
1414 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1415 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001416 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001417 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001418 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001419 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001420 if (mService != null) {
1421 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001422 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001423 } catch (RemoteException e) {
1424 Log.w(TAG, "Failed talking with device policy service", e);
1425 }
1426 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001427 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001428 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001429
Dianne Hackbornd6847842010-01-12 18:14:19 -08001430 /**
1431 * Retrieve the number of times the user has failed at entering a
1432 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001433 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001434 * <p>The calling device admin must have requested
1435 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1436 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001437 */
1438 public int getCurrentFailedPasswordAttempts() {
1439 if (mService != null) {
1440 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001441 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001442 } catch (RemoteException e) {
1443 Log.w(TAG, "Failed talking with device policy service", e);
1444 }
1445 }
1446 return -1;
1447 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001448
1449 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001450 * Setting this to a value greater than zero enables a built-in policy
1451 * that will perform a device wipe after too many incorrect
1452 * device-unlock passwords have been entered. This built-in policy combines
1453 * watching for failed passwords and wiping the device, and requires
1454 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001455 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001456 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001457 * <p>To implement any other policy (e.g. wiping data for a particular
1458 * application only, erasing or revoking credentials, or reporting the
1459 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001460 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001461 * instead. Do not use this API, because if the maximum count is reached,
1462 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001463 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001464 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001465 * @param num The number of failed password attempts at which point the
1466 * device will wipe its data.
1467 */
1468 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1469 if (mService != null) {
1470 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001471 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001472 } catch (RemoteException e) {
1473 Log.w(TAG, "Failed talking with device policy service", e);
1474 }
1475 }
1476 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001477
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001478 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001479 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001480 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001481 * or a particular one.
1482 * @param admin The name of the admin component to check, or null to aggregate
1483 * all admins.
1484 */
1485 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001486 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1487 }
1488
1489 /** @hide per-user version */
1490 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001491 if (mService != null) {
1492 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001493 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001494 } catch (RemoteException e) {
1495 Log.w(TAG, "Failed talking with device policy service", e);
1496 }
1497 }
1498 return 0;
1499 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001500
Dianne Hackborn254cb442010-01-27 19:23:59 -08001501 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001502 * Returns the profile with the smallest maximum failed passwords for wipe,
1503 * for the given user. So for primary user, it might return the primary or
1504 * a managed profile. For a secondary user, it would be the same as the
1505 * user passed in.
1506 * @hide Used only by Keyguard
1507 */
1508 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1509 if (mService != null) {
1510 try {
1511 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1512 } catch (RemoteException e) {
1513 Log.w(TAG, "Failed talking with device policy service", e);
1514 }
1515 }
1516 return UserHandle.USER_NULL;
1517 }
1518
1519 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001520 * Flag for {@link #resetPassword}: don't allow other admins to change
1521 * the password again until the user has entered it.
1522 */
1523 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001524
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001525 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001526 * Force a new device unlock password (the password needed to access the
1527 * entire device, not for individual accounts) on the user. This takes
1528 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001529 * The given password must be sufficient for the
1530 * current password quality and length constraints as returned by
1531 * {@link #getPasswordQuality(ComponentName)} and
1532 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1533 * these constraints, then it will be rejected and false returned. Note
1534 * that the password may be a stronger quality (containing alphanumeric
1535 * characters when the requested quality is only numeric), in which case
1536 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001537 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001538 * <p>Calling with a null or empty password will clear any existing PIN,
1539 * pattern or password if the current password constraints allow it.
1540 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001541 * <p>The calling device admin must have requested
1542 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1543 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001544 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001545 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001546 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001547 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001548 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001549 * @return Returns true if the password was applied, or false if it is
1550 * not acceptable for the current constraints.
1551 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001552 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001553 if (mService != null) {
1554 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001555 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001556 } catch (RemoteException e) {
1557 Log.w(TAG, "Failed talking with device policy service", e);
1558 }
1559 }
1560 return false;
1561 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001562
Dianne Hackbornd6847842010-01-12 18:14:19 -08001563 /**
1564 * Called by an application that is administering the device to set the
1565 * maximum time for user activity until the device will lock. This limits
1566 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001567 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001568 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001569 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001570 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001571 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001572 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001573 * @param timeMs The new desired maximum time to lock in milliseconds.
1574 * A value of 0 means there is no restriction.
1575 */
1576 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1577 if (mService != null) {
1578 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001579 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001580 } catch (RemoteException e) {
1581 Log.w(TAG, "Failed talking with device policy service", e);
1582 }
1583 }
1584 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001585
Dianne Hackbornd6847842010-01-12 18:14:19 -08001586 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001587 * Retrieve the current maximum time to unlock for all admins of this user
1588 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001589 * @param admin The name of the admin component to check, or null to aggregate
1590 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001591 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001592 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001593 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001594 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001595 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1596 }
1597
1598 /** @hide per-user version */
1599 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001600 if (mService != null) {
1601 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001602 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001603 } catch (RemoteException e) {
1604 Log.w(TAG, "Failed talking with device policy service", e);
1605 }
1606 }
1607 return 0;
1608 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001609
Dianne Hackbornd6847842010-01-12 18:14:19 -08001610 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001611 * Make the device lock immediately, as if the lock screen timeout has
1612 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001613 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001614 * <p>The calling device admin must have requested
1615 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1616 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001617 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001618 public void lockNow() {
1619 if (mService != null) {
1620 try {
1621 mService.lockNow();
1622 } catch (RemoteException e) {
1623 Log.w(TAG, "Failed talking with device policy service", e);
1624 }
1625 }
1626 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001627
Dianne Hackbornd6847842010-01-12 18:14:19 -08001628 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001629 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001630 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001631 */
1632 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1633
1634 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001635 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1636 * data.
1637 *
Paul Crowley2934b262014-12-02 11:21:13 +00001638 * <p>This flag may only be set by device owner admins; if it is set by
1639 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001640 */
1641 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1642
1643 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001644 * Ask the user data be wiped. Wiping the primary user will cause the
1645 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001646 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001647 * <p>The calling device admin must have requested
1648 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1649 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001650 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001651 * @param flags Bit mask of additional options: currently supported flags
1652 * are {@link #WIPE_EXTERNAL_STORAGE} and
1653 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001654 */
1655 public void wipeData(int flags) {
1656 if (mService != null) {
1657 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001658 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001659 } catch (RemoteException e) {
1660 Log.w(TAG, "Failed talking with device policy service", e);
1661 }
1662 }
1663 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001664
Dianne Hackbornd6847842010-01-12 18:14:19 -08001665 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001666 * Called by an application that is administering the device to set the
1667 * global proxy and exclusion list.
1668 * <p>
1669 * The calling device admin must have requested
1670 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1671 * this method; if it has not, a security exception will be thrown.
1672 * Only the first device admin can set the proxy. If a second admin attempts
1673 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1674 * proxy will be returned. If successful in setting the proxy, null will
1675 * be returned.
1676 * The method can be called repeatedly by the device admin alrady setting the
1677 * proxy to update the proxy and exclusion list.
1678 *
1679 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1680 * with.
1681 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1682 * Pass Proxy.NO_PROXY to reset the proxy.
1683 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001684 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1685 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001686 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001687 */
1688 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1689 List<String> exclusionList ) {
1690 if (proxySpec == null) {
1691 throw new NullPointerException();
1692 }
1693 if (mService != null) {
1694 try {
1695 String hostSpec;
1696 String exclSpec;
1697 if (proxySpec.equals(Proxy.NO_PROXY)) {
1698 hostSpec = null;
1699 exclSpec = null;
1700 } else {
1701 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1702 throw new IllegalArgumentException();
1703 }
1704 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1705 String hostName = sa.getHostName();
1706 int port = sa.getPort();
1707 StringBuilder hostBuilder = new StringBuilder();
1708 hostSpec = hostBuilder.append(hostName)
1709 .append(":").append(Integer.toString(port)).toString();
1710 if (exclusionList == null) {
1711 exclSpec = "";
1712 } else {
1713 StringBuilder listBuilder = new StringBuilder();
1714 boolean firstDomain = true;
1715 for (String exclDomain : exclusionList) {
1716 if (!firstDomain) {
1717 listBuilder = listBuilder.append(",");
1718 } else {
1719 firstDomain = false;
1720 }
1721 listBuilder = listBuilder.append(exclDomain.trim());
1722 }
1723 exclSpec = listBuilder.toString();
1724 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001725 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1726 != android.net.Proxy.PROXY_VALID)
1727 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001728 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001729 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001730 } catch (RemoteException e) {
1731 Log.w(TAG, "Failed talking with device policy service", e);
1732 }
1733 }
1734 return null;
1735 }
1736
1737 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001738 * Set a network-independent global HTTP proxy. This is not normally what you want
1739 * for typical HTTP proxies - they are generally network dependent. However if you're
1740 * doing something unusual like general internal filtering this may be useful. On
1741 * a private network where the proxy is not accessible, you may break HTTP using this.
1742 *
1743 * <p>This method requires the caller to be the device owner.
1744 *
1745 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1746 * @see ProxyInfo
1747 *
1748 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1749 * with.
1750 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1751 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1752 */
1753 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1754 if (mService != null) {
1755 try {
1756 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1757 } catch (RemoteException e) {
1758 Log.w(TAG, "Failed talking with device policy service", e);
1759 }
1760 }
1761 }
1762
1763 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001764 * Returns the component name setting the global proxy.
1765 * @return ComponentName object of the device admin that set the global proxy, or
1766 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001767 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001768 */
1769 public ComponentName getGlobalProxyAdmin() {
1770 if (mService != null) {
1771 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001772 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
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 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001781 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001782 * indicating that encryption is not supported.
1783 */
1784 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1785
1786 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001787 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001788 * indicating that encryption is supported, but is not currently active.
1789 */
1790 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1791
1792 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001793 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001794 * indicating that encryption is not currently active, but is currently
1795 * being activated. This is only reported by devices that support
1796 * encryption of data and only when the storage is currently
1797 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1798 * to become encrypted will never return this value.
1799 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001800 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001801
1802 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001803 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001804 * indicating that encryption is active.
1805 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001806 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001807
1808 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001809 * Result code for {@link #getStorageEncryptionStatus}:
1810 * indicating that encryption is active, but an encryption key has not
1811 * been set by the user.
1812 */
1813 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1814
1815 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001816 * Activity action: begin the process of encrypting data on the device. This activity should
1817 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1818 * After resuming from this activity, use {@link #getStorageEncryption}
1819 * to check encryption status. However, on some devices this activity may never return, as
1820 * it may trigger a reboot and in some cases a complete data wipe of the device.
1821 */
1822 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1823 public static final String ACTION_START_ENCRYPTION
1824 = "android.app.action.START_ENCRYPTION";
1825
1826 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001827 * Widgets are enabled in keyguard
1828 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001829 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001830
1831 /**
Jim Miller50e62182014-04-23 17:25:00 -07001832 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001833 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001834 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1835
1836 /**
1837 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1838 */
1839 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1840
1841 /**
Jim Miller50e62182014-04-23 17:25:00 -07001842 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1843 */
1844 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1845
1846 /**
1847 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1848 */
1849 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1850
1851 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001852 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001853 * (e.g. PIN/Pattern/Password).
1854 */
1855 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1856
1857 /**
Jim Miller06e34502014-07-17 14:46:05 -07001858 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1859 */
1860 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1861
1862 /**
Jim Miller35207742012-11-02 15:33:20 -07001863 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001864 */
1865 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001866
1867 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001868 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001869 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001870 *
1871 * <p>When multiple device administrators attempt to control device
1872 * encryption, the most secure, supported setting will always be
1873 * used. If any device administrator requests device encryption,
1874 * it will be enabled; Conversely, if a device administrator
1875 * attempts to disable device encryption while another
1876 * device administrator has enabled it, the call to disable will
1877 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1878 *
1879 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001880 * written to other storage areas may or may not be encrypted, and this policy does not require
1881 * or control the encryption of any other storage areas.
1882 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1883 * {@code true}, then the directory returned by
1884 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1885 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001886 *
1887 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1888 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1889 * the encryption key may not be fully secured. For maximum security, the administrator should
1890 * also require (and check for) a pattern, PIN, or password.
1891 *
1892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1893 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001894 * @return the new request status (for all active admins) - will be one of
1895 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1896 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1897 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001898 */
1899 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1900 if (mService != null) {
1901 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001902 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001903 } catch (RemoteException e) {
1904 Log.w(TAG, "Failed talking with device policy service", e);
1905 }
1906 }
1907 return ENCRYPTION_STATUS_UNSUPPORTED;
1908 }
1909
1910 /**
1911 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001912 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001913 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001914 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1915 * this will return the requested encryption setting as an aggregate of all active
1916 * administrators.
1917 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001918 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001919 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001920 if (mService != null) {
1921 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001922 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001923 } catch (RemoteException e) {
1924 Log.w(TAG, "Failed talking with device policy service", e);
1925 }
1926 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001927 return false;
1928 }
1929
1930 /**
1931 * Called by an application that is administering the device to
1932 * determine the current encryption status of the device.
1933 *
1934 * Depending on the returned status code, the caller may proceed in different
1935 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1936 * storage system does not support encryption. If the
1937 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1938 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00001939 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
1940 * storage system has enabled encryption but no password is set so further action
1941 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08001942 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1943 *
Robin Lee7e678712014-07-24 16:41:31 +01001944 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001945 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00001946 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
1947 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08001948 */
1949 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001950 return getStorageEncryptionStatus(UserHandle.myUserId());
1951 }
1952
1953 /** @hide per-user version */
1954 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001955 if (mService != null) {
1956 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001957 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001958 } catch (RemoteException e) {
1959 Log.w(TAG, "Failed talking with device policy service", e);
1960 }
1961 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001962 return ENCRYPTION_STATUS_UNSUPPORTED;
1963 }
1964
1965 /**
Robin Lee7e678712014-07-24 16:41:31 +01001966 * Installs the given certificate as a user CA.
1967 *
1968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1969 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001970 *
1971 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001972 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001973 */
Robin Lee7e678712014-07-24 16:41:31 +01001974 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001975 if (mService != null) {
1976 try {
Robin Lee7e678712014-07-24 16:41:31 +01001977 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001978 } catch (RemoteException e) {
1979 Log.w(TAG, "Failed talking with device policy service", e);
1980 }
1981 }
1982 return false;
1983 }
1984
1985 /**
Robin Lee7e678712014-07-24 16:41:31 +01001986 * Uninstalls the given certificate from trusted user CAs, if present.
1987 *
1988 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1989 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001990 */
Robin Lee7e678712014-07-24 16:41:31 +01001991 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001992 if (mService != null) {
1993 try {
Robin Lee306fe082014-06-19 14:04:24 +00001994 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001995 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001996 } catch (CertificateException e) {
1997 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001998 } catch (RemoteException e) {
1999 Log.w(TAG, "Failed talking with device policy service", e);
2000 }
2001 }
2002 }
2003
2004 /**
Robin Lee7e678712014-07-24 16:41:31 +01002005 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2006 * If a user has installed any certificates by other means than device policy these will be
2007 * included too.
2008 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002009 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01002010 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002011 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002012 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002013 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002014 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002015 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002016 mService.enforceCanManageCaCerts(admin);
2017 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2018 for (String alias : certStore.userAliases()) {
2019 try {
2020 certs.add(certStore.getCertificate(alias).getEncoded());
2021 } catch (CertificateException ce) {
2022 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2023 }
2024 }
2025 } catch (RemoteException re) {
2026 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002027 }
2028 }
2029 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002030 }
2031
2032 /**
Robin Lee7e678712014-07-24 16:41:31 +01002033 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2034 * means other than device policy will also be removed, except for system CA certificates.
2035 *
2036 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2037 */
2038 public void uninstallAllUserCaCerts(ComponentName admin) {
2039 if (mService != null) {
2040 for (String alias : new TrustedCertificateStore().userAliases()) {
2041 try {
2042 mService.uninstallCaCert(admin, alias);
2043 } catch (RemoteException re) {
2044 Log.w(TAG, "Failed talking with device policy service", re);
2045 }
2046 }
2047 }
2048 }
2049
2050 /**
2051 * Returns whether this certificate is installed as a trusted CA.
2052 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002053 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01002054 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002055 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002056 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
2057 if (mService != null) {
2058 try {
2059 mService.enforceCanManageCaCerts(admin);
2060 return getCaCertAlias(certBuffer) != null;
2061 } catch (RemoteException re) {
2062 Log.w(TAG, "Failed talking with device policy service", re);
2063 } catch (CertificateException ce) {
2064 Log.w(TAG, "Could not parse certificate", ce);
2065 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002066 }
2067 return false;
2068 }
2069
2070 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002071 * Called by a device or profile owner to install a certificate and private key pair. The
2072 * keypair will be visible to all apps within the profile.
2073 *
2074 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2075 * @param privKey The private key to install.
2076 * @param cert The certificate to install.
2077 * @param alias The private key alias under which to install the certificate. If a certificate
2078 * with that alias already exists, it will be overwritten.
2079 * @return {@code true} if the keys were installed, {@code false} otherwise.
2080 */
2081 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
2082 String alias) {
2083 try {
2084 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002085 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2086 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
2087 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002088 } catch (RemoteException e) {
2089 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002090 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2091 Log.w(TAG, "Failed to obtain private key material", e);
2092 } catch (CertificateException | IOException e) {
2093 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002094 }
2095 return false;
2096 }
2097
2098 /**
Robin Lee306fe082014-06-19 14:04:24 +00002099 * Returns the alias of a given CA certificate in the certificate store, or null if it
2100 * doesn't exist.
2101 */
2102 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2103 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2104 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2105 new ByteArrayInputStream(certBuffer));
2106 return new TrustedCertificateStore().getCertificateAlias(cert);
2107 }
2108
2109 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002110 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002111 * on the device, for this user. After setting this, no applications running as this user
2112 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002113 *
2114 * <p>The calling device admin must have requested
2115 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2116 * this method; if it has not, a security exception will be thrown.
2117 *
2118 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2119 * @param disabled Whether or not the camera should be disabled.
2120 */
2121 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2122 if (mService != null) {
2123 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002124 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002125 } catch (RemoteException e) {
2126 Log.w(TAG, "Failed talking with device policy service", e);
2127 }
2128 }
2129 }
2130
2131 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002132 * Determine whether or not the device's cameras have been disabled for this user,
2133 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002134 * @param admin The name of the admin component to check, or null to check if any admins
2135 * have disabled the camera
2136 */
2137 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002138 return getCameraDisabled(admin, UserHandle.myUserId());
2139 }
2140
2141 /** @hide per-user version */
2142 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002143 if (mService != null) {
2144 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002145 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002146 } catch (RemoteException e) {
2147 Log.w(TAG, "Failed talking with device policy service", e);
2148 }
2149 }
2150 return false;
2151 }
2152
2153 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002154 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2155 * screen capture also prevents the content from being shown on display devices that do not have
2156 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2157 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002158 *
2159 * <p>The calling device admin must be a device or profile owner. If it is not, a
2160 * security exception will be thrown.
2161 *
2162 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002163 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002164 */
2165 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2166 if (mService != null) {
2167 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002168 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002169 } catch (RemoteException e) {
2170 Log.w(TAG, "Failed talking with device policy service", e);
2171 }
2172 }
2173 }
2174
2175 /**
2176 * Determine whether or not screen capture has been disabled by the current
2177 * admin, if specified, or all admins.
2178 * @param admin The name of the admin component to check, or null to check if any admins
2179 * have disabled screen capture.
2180 */
2181 public boolean getScreenCaptureDisabled(ComponentName admin) {
2182 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2183 }
2184
2185 /** @hide per-user version */
2186 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2187 if (mService != null) {
2188 try {
2189 return mService.getScreenCaptureDisabled(admin, userHandle);
2190 } catch (RemoteException e) {
2191 Log.w(TAG, "Failed talking with device policy service", e);
2192 }
2193 }
2194 return false;
2195 }
2196
2197 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002198 * Called by a device owner to set whether auto time is required. If auto time is
2199 * required the user cannot set the date and time, but has to use network date and time.
2200 *
2201 * <p>Note: if auto time is required the user can still manually set the time zone.
2202 *
2203 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2204 * be thrown.
2205 *
2206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2207 * @param required Whether auto time is set required or not.
2208 */
2209 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2210 if (mService != null) {
2211 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002212 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002213 } catch (RemoteException e) {
2214 Log.w(TAG, "Failed talking with device policy service", e);
2215 }
2216 }
2217 }
2218
2219 /**
2220 * @return true if auto time is required.
2221 */
2222 public boolean getAutoTimeRequired() {
2223 if (mService != null) {
2224 try {
2225 return mService.getAutoTimeRequired();
2226 } catch (RemoteException e) {
2227 Log.w(TAG, "Failed talking with device policy service", e);
2228 }
2229 }
2230 return false;
2231 }
2232
2233 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002234 * Called by an application that is administering the device to disable keyguard customizations,
2235 * such as widgets. After setting this, keyguard features will be disabled according to the
2236 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002237 *
2238 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002239 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002240 * this method; if it has not, a security exception will be thrown.
2241 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002242 * <p>Calling this from a managed profile will throw a security exception.
2243 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002244 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002245 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2246 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002247 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2248 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002249 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002250 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002251 if (mService != null) {
2252 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002253 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002254 } catch (RemoteException e) {
2255 Log.w(TAG, "Failed talking with device policy service", e);
2256 }
2257 }
2258 }
2259
2260 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002261 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002262 * admin, if specified, or all admins.
2263 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002264 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002265 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2266 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002267 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002268 public int getKeyguardDisabledFeatures(ComponentName admin) {
2269 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002270 }
2271
2272 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002273 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002274 if (mService != null) {
2275 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002276 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002277 } catch (RemoteException e) {
2278 Log.w(TAG, "Failed talking with device policy service", e);
2279 }
2280 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002281 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002282 }
2283
2284 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002285 * @hide
2286 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002287 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002288 if (mService != null) {
2289 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002290 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002291 } catch (RemoteException e) {
2292 Log.w(TAG, "Failed talking with device policy service", e);
2293 }
2294 }
2295 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002296
Dianne Hackbornd6847842010-01-12 18:14:19 -08002297 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002298 * @hide
2299 */
2300 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2301 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2302 }
2303
2304 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002305 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002306 * @hide
2307 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002308 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002309 ActivityInfo ai;
2310 try {
2311 ai = mContext.getPackageManager().getReceiverInfo(cn,
2312 PackageManager.GET_META_DATA);
2313 } catch (PackageManager.NameNotFoundException e) {
2314 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2315 return null;
2316 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002317
Dianne Hackbornd6847842010-01-12 18:14:19 -08002318 ResolveInfo ri = new ResolveInfo();
2319 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002320
Dianne Hackbornd6847842010-01-12 18:14:19 -08002321 try {
2322 return new DeviceAdminInfo(mContext, ri);
2323 } catch (XmlPullParserException e) {
2324 Log.w(TAG, "Unable to parse device policy " + cn, e);
2325 return null;
2326 } catch (IOException e) {
2327 Log.w(TAG, "Unable to parse device policy " + cn, e);
2328 return null;
2329 }
2330 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002331
Dianne Hackbornd6847842010-01-12 18:14:19 -08002332 /**
2333 * @hide
2334 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002335 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2336 if (mService != null) {
2337 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002338 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002339 } catch (RemoteException e) {
2340 Log.w(TAG, "Failed talking with device policy service", e);
2341 }
2342 }
2343 }
2344
2345 /**
2346 * @hide
2347 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002348 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002349 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002350 if (mService != null) {
2351 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002352 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002353 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002354 } catch (RemoteException e) {
2355 Log.w(TAG, "Failed talking with device policy service", e);
2356 }
2357 }
2358 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002359
Dianne Hackbornd6847842010-01-12 18:14:19 -08002360 /**
2361 * @hide
2362 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002363 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002364 if (mService != null) {
2365 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002366 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002367 } catch (RemoteException e) {
2368 Log.w(TAG, "Failed talking with device policy service", e);
2369 }
2370 }
2371 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002372
Dianne Hackbornd6847842010-01-12 18:14:19 -08002373 /**
2374 * @hide
2375 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002376 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002377 if (mService != null) {
2378 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002379 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002380 } catch (RemoteException e) {
2381 Log.w(TAG, "Failed talking with device policy service", e);
2382 }
2383 }
2384 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002385
2386 /**
2387 * @hide
2388 * Sets the given package as the device owner. The package must already be installed and there
2389 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2390 * method must be called before the device is provisioned.
2391 * @param packageName the package name of the application to be registered as the device owner.
2392 * @return whether the package was successfully registered as the device owner.
2393 * @throws IllegalArgumentException if the package name is null or invalid
2394 * @throws IllegalStateException if a device owner is already registered or the device has
2395 * already been provisioned.
2396 */
2397 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2398 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002399 return setDeviceOwner(packageName, null);
2400 }
2401
2402 /**
2403 * @hide
2404 * Sets the given package as the device owner. The package must already be installed and there
2405 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2406 * method must be called before the device is provisioned.
2407 * @param packageName the package name of the application to be registered as the device owner.
2408 * @param ownerName the human readable name of the institution that owns this device.
2409 * @return whether the package was successfully registered as the device owner.
2410 * @throws IllegalArgumentException if the package name is null or invalid
2411 * @throws IllegalStateException if a device owner is already registered or the device has
2412 * already been provisioned.
2413 */
2414 public boolean setDeviceOwner(String packageName, String ownerName)
2415 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002416 if (mService != null) {
2417 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002418 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002419 } catch (RemoteException re) {
2420 Log.w(TAG, "Failed to set device owner");
2421 }
2422 }
2423 return false;
2424 }
2425
2426 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002427 * Used to determine if a particular package has been registered as a Device Owner app.
2428 * A device owner app is a special device admin that cannot be deactivated by the user, once
2429 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2430 * package is currently registered as the device owner app, pass in the package name from
2431 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2432 * admin apps that want to check if they are also registered as the device owner app. The
2433 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2434 * the setup process.
2435 * @param packageName the package name of the app, to compare with the registered device owner
2436 * app, if any.
2437 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002438 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002439 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002440 if (mService != null) {
2441 try {
2442 return mService.isDeviceOwner(packageName);
2443 } catch (RemoteException re) {
2444 Log.w(TAG, "Failed to check device owner");
2445 }
2446 }
2447 return false;
2448 }
2449
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002450 /**
2451 * @hide
2452 * Redirect to isDeviceOwnerApp.
2453 */
2454 public boolean isDeviceOwner(String packageName) {
2455 return isDeviceOwnerApp(packageName);
2456 }
2457
Jason Monkb0dced82014-06-06 14:36:20 -04002458 /**
2459 * Clears the current device owner. The caller must be the device owner.
2460 *
2461 * This function should be used cautiously as once it is called it cannot
2462 * be undone. The device owner can only be set as a part of device setup
2463 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002464 *
2465 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002466 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002467 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002468 if (mService != null) {
2469 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002470 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002471 } catch (RemoteException re) {
2472 Log.w(TAG, "Failed to clear device owner");
2473 }
2474 }
2475 }
2476
Amith Yamasani71e6c692013-03-24 17:39:28 -07002477 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002478 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002479 public String getDeviceOwner() {
2480 if (mService != null) {
2481 try {
2482 return mService.getDeviceOwner();
2483 } catch (RemoteException re) {
2484 Log.w(TAG, "Failed to get device owner");
2485 }
2486 }
2487 return null;
2488 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002489
2490 /** @hide */
2491 public String getDeviceOwnerName() {
2492 if (mService != null) {
2493 try {
2494 return mService.getDeviceOwnerName();
2495 } catch (RemoteException re) {
2496 Log.w(TAG, "Failed to get device owner");
2497 }
2498 }
2499 return null;
2500 }
Adam Connors776c5552014-01-09 10:42:56 +00002501
2502 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05002503 * Sets the given component as the device initializer. The package must already be installed and
2504 * set as an active device administrator, and there must not be an existing device initializer,
2505 * for this call to succeed. This method can only be called by an app holding the
2506 * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A
2507 * device initializer app is granted device owner privileges during device initialization and
2508 * profile owner privileges during secondary user initialization.
2509 * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not
2510 * called by the device owner.
2511 * @param initializer Which {@link DeviceAdminReceiver} to make device initializer.
2512 * @param initializerName The user-visible name of the device initializer.
2513 * @return whether the package was successfully registered as the device initializer.
2514 * @throws IllegalArgumentException if the package name is null or invalid
2515 * @throws IllegalStateException if the caller is not device owner or the device has
2516 * already been provisioned or a device initializer already exists.
2517 */
2518 public boolean setDeviceInitializer(ComponentName who, ComponentName initializer,
2519 String initializerName) throws IllegalArgumentException, IllegalStateException {
2520 if (mService != null) {
2521 try {
2522 return mService.setDeviceInitializer(who, initializer, initializerName);
2523 } catch (RemoteException re) {
2524 Log.w(TAG, "Failed to set device initializer");
2525 }
2526 }
2527 return false;
2528 }
2529
2530 /**
2531 * Used to determine if a particular package has been registered as the device initializer.
2532 *
2533 * @param packageName the package name of the app, to compare with the registered device
2534 * initializer app, if any.
2535 * @return whether or not the caller is registered as the device initializer app.
2536 */
2537 public boolean isDeviceInitializerApp(String packageName) {
2538 if (mService != null) {
2539 try {
2540 return mService.isDeviceInitializer(packageName);
2541 } catch (RemoteException re) {
2542 Log.w(TAG, "Failed to check device initializer");
2543 }
2544 }
2545 return false;
2546 }
2547
2548 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002549 * Removes the device initializer, so that it will not be invoked on user initialization for any
2550 * subsequently created users. This method can be called by either the device owner or device
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002551 * initializer itself. The caller must be an active administrator.
2552 *
2553 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
Julia Reynolds20118f12015-02-11 12:34:08 -05002554 */
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002555 public void clearDeviceInitializerApp(ComponentName who) {
Julia Reynolds20118f12015-02-11 12:34:08 -05002556 if (mService != null) {
2557 try {
Julia Reynolds1c3754a2015-03-05 10:06:41 -05002558 mService.clearDeviceInitializer(who);
Julia Reynolds20118f12015-02-11 12:34:08 -05002559 } catch (RemoteException re) {
2560 Log.w(TAG, "Failed to clear device initializer");
2561 }
2562 }
2563 }
2564
2565 /**
2566 * @hide
2567 * Gets the device initializer of the system.
2568 *
2569 * @return the package name of the device initializer.
2570 */
2571 @SystemApi
2572 public String getDeviceInitializerApp() {
2573 if (mService != null) {
2574 try {
2575 return mService.getDeviceInitializer();
2576 } catch (RemoteException re) {
2577 Log.w(TAG, "Failed to get device initializer");
2578 }
2579 }
2580 return null;
2581 }
2582
2583 /**
2584 * Sets the enabled state of the user. A user should be enabled only once it is ready to
2585 * be used.
2586 *
2587 * <p>Device initializer must call this method to mark the user as functional.
2588 * Only the device initializer agent can call this.
2589 *
2590 * <p>When the user is enabled, if the device initializer is not also the device owner, the
2591 * device initializer will no longer have elevated permissions to call methods in this class.
2592 * Additionally, it will be removed as an active administrator and its
2593 * {@link DeviceAdminReceiver} will be disabled.
2594 *
2595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2596 * @return whether the user is now enabled.
2597 */
2598 public boolean setUserEnabled(ComponentName admin) {
2599 if (mService != null) {
2600 try {
2601 return mService.setUserEnabled(admin);
2602 } catch (RemoteException e) {
2603 Log.w(TAG, "Failed talking with device policy service", e);
2604 }
2605 }
2606 return false;
2607 }
2608
2609 /**
Adam Connors776c5552014-01-09 10:42:56 +00002610 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002611 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302612 * Sets the given component as an active admin and registers the package as the profile
2613 * owner for this user. The package must already be installed and there shouldn't be
2614 * an existing profile owner registered for this user. Also, this method must be called
2615 * before the user setup has been completed.
2616 * <p>
2617 * This method can only be called by system apps that hold MANAGE_USERS permission and
2618 * MANAGE_DEVICE_ADMINS permission.
2619 * @param admin The component to register as an active admin and profile owner.
2620 * @param ownerName The user-visible name of the entity that is managing this user.
2621 * @return whether the admin was successfully registered as the profile owner.
2622 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2623 * the user has already been set up.
2624 */
Justin Morey80440cc2014-07-24 09:16:35 -05002625 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302626 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2627 throws IllegalArgumentException {
2628 if (mService != null) {
2629 try {
2630 final int myUserId = UserHandle.myUserId();
2631 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002632 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302633 } catch (RemoteException re) {
2634 Log.w(TAG, "Failed to set profile owner " + re);
2635 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2636 }
2637 }
2638 return false;
2639 }
2640
2641 /**
2642 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002643 * Clears the active profile owner and removes all user restrictions. The caller must
2644 * be from the same package as the active profile owner for this user, otherwise a
2645 * SecurityException will be thrown.
2646 *
2647 * @param admin The component to remove as the profile owner.
2648 * @return
2649 */
2650 @SystemApi
2651 public void clearProfileOwner(ComponentName admin) {
2652 if (mService != null) {
2653 try {
2654 mService.clearProfileOwner(admin);
2655 } catch (RemoteException re) {
2656 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2657 }
2658 }
2659 }
2660
2661 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002662 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002663 * Checks if the user was already setup.
2664 */
2665 public boolean hasUserSetupCompleted() {
2666 if (mService != null) {
2667 try {
2668 return mService.hasUserSetupCompleted();
2669 } catch (RemoteException re) {
2670 Log.w(TAG, "Failed to check if user setup has completed");
2671 }
2672 }
2673 return true;
2674 }
2675
2676 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002677 * @hide
2678 * Sets the given component as the profile owner of the given user profile. The package must
2679 * already be installed and there shouldn't be an existing profile owner registered for this
2680 * user. Only the system can call this API if the user has already completed setup.
2681 * @param admin the component name to be registered as profile owner.
2682 * @param ownerName the human readable name of the organisation associated with this DPM.
2683 * @param userHandle the userId to set the profile owner for.
2684 * @return whether the component was successfully registered as the profile owner.
2685 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2686 * the user has already been set up.
2687 */
2688 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2689 throws IllegalArgumentException {
2690 if (admin == null) {
2691 throw new NullPointerException("admin cannot be null");
2692 }
Adam Connors776c5552014-01-09 10:42:56 +00002693 if (mService != null) {
2694 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002695 if (ownerName == null) {
2696 ownerName = "";
2697 }
2698 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002699 } catch (RemoteException re) {
2700 Log.w(TAG, "Failed to set profile owner", re);
2701 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2702 }
2703 }
2704 return false;
2705 }
2706
2707 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002708 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2709 * be used. Only the profile owner can call this.
2710 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002711 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002712 *
2713 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2714 */
2715 public void setProfileEnabled(ComponentName admin) {
2716 if (mService != null) {
2717 try {
2718 mService.setProfileEnabled(admin);
2719 } catch (RemoteException e) {
2720 Log.w(TAG, "Failed talking with device policy service", e);
2721 }
2722 }
2723 }
2724
2725 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002726 * Sets the name of the profile. In the device owner case it sets the name of the user
2727 * 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 +01002728 * never called by the profile or device owner, the name will be set to default values.
2729 *
2730 * @see #isProfileOwnerApp
2731 * @see #isDeviceOwnerApp
2732 *
2733 * @param profileName The name of the profile.
2734 */
2735 public void setProfileName(ComponentName who, String profileName) {
2736 if (mService != null) {
2737 try {
2738 mService.setProfileName(who, profileName);
2739 } catch (RemoteException e) {
2740 Log.w(TAG, "Failed talking with device policy service", e);
2741 }
2742 }
2743}
2744
2745 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002746 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002747 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002748 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002749 *
2750 * @param packageName The package name of the app to compare with the registered profile owner.
2751 * @return Whether or not the package is registered as the profile owner.
2752 */
2753 public boolean isProfileOwnerApp(String packageName) {
2754 if (mService != null) {
2755 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002756 ComponentName profileOwner = mService.getProfileOwner(
2757 Process.myUserHandle().getIdentifier());
2758 return profileOwner != null
2759 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002760 } catch (RemoteException re) {
2761 Log.w(TAG, "Failed to check profile owner");
2762 }
2763 }
2764 return false;
2765 }
2766
2767 /**
2768 * @hide
2769 * @return the packageName of the owner of the given user profile or null if no profile
2770 * owner has been set for that user.
2771 * @throws IllegalArgumentException if the userId is invalid.
2772 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002773 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002774 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002775 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2776 }
2777
2778 /**
2779 * @see #getProfileOwner()
2780 * @hide
2781 */
2782 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002783 if (mService != null) {
2784 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002785 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002786 } catch (RemoteException re) {
2787 Log.w(TAG, "Failed to get profile owner");
2788 throw new IllegalArgumentException(
2789 "Requested profile owner for invalid userId", re);
2790 }
2791 }
2792 return null;
2793 }
2794
2795 /**
2796 * @hide
2797 * @return the human readable name of the organisation associated with this DPM or null if
2798 * one is not set.
2799 * @throws IllegalArgumentException if the userId is invalid.
2800 */
2801 public String getProfileOwnerName() throws IllegalArgumentException {
2802 if (mService != null) {
2803 try {
2804 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2805 } catch (RemoteException re) {
2806 Log.w(TAG, "Failed to get profile owner");
2807 throw new IllegalArgumentException(
2808 "Requested profile owner for invalid userId", re);
2809 }
2810 }
2811 return null;
2812 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002813
2814 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002815 * @hide
2816 * @param user The user for whom to fetch the profile owner name, if any.
2817 * @return the human readable name of the organisation associated with this profile owner or
2818 * null if one is not set.
2819 * @throws IllegalArgumentException if the userId is invalid.
2820 */
2821 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002822 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002823 if (mService != null) {
2824 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002825 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002826 } catch (RemoteException re) {
2827 Log.w(TAG, "Failed to get profile owner");
2828 throw new IllegalArgumentException(
2829 "Requested profile owner for invalid userId", re);
2830 }
2831 }
2832 return null;
2833 }
2834
2835 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002836 * Called by a profile owner or device owner to add a default intent handler activity for
2837 * intents that match a certain intent filter. This activity will remain the default intent
2838 * handler even if the set of potential event handlers for the intent filter changes and if
2839 * the intent preferences are reset.
2840 *
2841 * <p>The default disambiguation mechanism takes over if the activity is not installed
2842 * (anymore). When the activity is (re)installed, it is automatically reset as default
2843 * intent handler for the filter.
2844 *
2845 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2846 * security exception will be thrown.
2847 *
2848 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2849 * @param filter The IntentFilter for which a default handler is added.
2850 * @param activity The Activity that is added as default intent handler.
2851 */
2852 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2853 ComponentName activity) {
2854 if (mService != null) {
2855 try {
2856 mService.addPersistentPreferredActivity(admin, filter, activity);
2857 } catch (RemoteException e) {
2858 Log.w(TAG, "Failed talking with device policy service", e);
2859 }
2860 }
2861 }
2862
2863 /**
2864 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002865 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002866 *
2867 * <p>The calling device admin must be a profile owner. If it is not, a security
2868 * exception will be thrown.
2869 *
2870 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2871 * @param packageName The name of the package for which preferences are removed.
2872 */
2873 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2874 String packageName) {
2875 if (mService != null) {
2876 try {
2877 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2878 } catch (RemoteException e) {
2879 Log.w(TAG, "Failed talking with device policy service", e);
2880 }
2881 }
2882 }
Robin Lee66e5d962014-04-09 16:44:21 +01002883
2884 /**
2885 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002886 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002887 *
2888 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01002889 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01002890 *
2891 * <p>The application restrictions are only made visible to the target application and the
2892 * profile or device owner.
2893 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002894 * <p>If the restrictions are not available yet, but may be applied in the near future,
2895 * the admin can notify the target application of that by adding
2896 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
2897 *
Robin Lee66e5d962014-04-09 16:44:21 +01002898 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2899 * exception will be thrown.
2900 *
2901 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2902 * @param packageName The name of the package to update restricted settings for.
2903 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2904 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002905 *
2906 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01002907 */
2908 public void setApplicationRestrictions(ComponentName admin, String packageName,
2909 Bundle settings) {
2910 if (mService != null) {
2911 try {
2912 mService.setApplicationRestrictions(admin, packageName, settings);
2913 } catch (RemoteException e) {
2914 Log.w(TAG, "Failed talking with device policy service", e);
2915 }
2916 }
2917 }
2918
2919 /**
Jim Millere303bf42014-08-26 17:12:29 -07002920 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
2921 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
2922 * trust agents but those enabled by this function call. If flag
2923 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07002924 *
2925 * <p>The calling device admin must have requested
2926 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07002927 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07002928 *
2929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07002930 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08002931 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07002932 * will be strictly disabled according to the state of the
2933 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
2934 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
2935 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
2936 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07002937 */
Jim Millere303bf42014-08-26 17:12:29 -07002938 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08002939 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07002940 if (mService != null) {
2941 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002942 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07002943 } catch (RemoteException e) {
2944 Log.w(TAG, "Failed talking with device policy service", e);
2945 }
2946 }
2947 }
2948
2949 /**
Jim Millere303bf42014-08-26 17:12:29 -07002950 * Gets configuration for the given trust agent based on aggregating all calls to
2951 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
2952 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07002953 *
Jim Millerb5db57a2015-01-14 18:17:19 -08002954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2955 * this function returns a list of configurations for all admins that declare
2956 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
2957 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
2958 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
2959 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07002960 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07002961 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07002962 */
Jim Millere303bf42014-08-26 17:12:29 -07002963 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2964 ComponentName agent) {
2965 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
2966 }
2967
2968 /** @hide per-user version */
2969 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2970 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07002971 if (mService != null) {
2972 try {
Jim Millere303bf42014-08-26 17:12:29 -07002973 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07002974 } catch (RemoteException e) {
2975 Log.w(TAG, "Failed talking with device policy service", e);
2976 }
2977 }
Jim Millere303bf42014-08-26 17:12:29 -07002978 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07002979 }
2980
2981 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002982 * Called by a profile owner of a managed profile to set whether caller-Id information from
2983 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01002984 *
2985 * <p>The calling device admin must be a profile owner. If it is not, a
2986 * security exception will be thrown.
2987 *
2988 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2989 * @param disabled If true caller-Id information in the managed profile is not displayed.
2990 */
2991 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2992 if (mService != null) {
2993 try {
2994 mService.setCrossProfileCallerIdDisabled(who, disabled);
2995 } catch (RemoteException e) {
2996 Log.w(TAG, "Failed talking with device policy service", e);
2997 }
2998 }
2999 }
3000
3001 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003002 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3003 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003004 *
3005 * <p>The calling device admin must be a profile owner. If it is not, a
3006 * security exception will be thrown.
3007 *
3008 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
3009 */
3010 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
3011 if (mService != null) {
3012 try {
3013 return mService.getCrossProfileCallerIdDisabled(who);
3014 } catch (RemoteException e) {
3015 Log.w(TAG, "Failed talking with device policy service", e);
3016 }
3017 }
3018 return false;
3019 }
3020
3021 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003022 * Determine whether or not caller-Id information has been disabled.
3023 *
3024 * @param userHandle The user for whom to check the caller-id permission
3025 * @hide
3026 */
3027 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3028 if (mService != null) {
3029 try {
3030 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3031 } catch (RemoteException e) {
3032 Log.w(TAG, "Failed talking with device policy service", e);
3033 }
3034 }
3035 return false;
3036 }
3037
3038 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003039 * Called by the profile owner of a managed profile so that some intents sent in the managed
3040 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003041 * Only activity intents are supported.
3042 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003043 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003044 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3045 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003046 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3047 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003048 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003049 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003050 if (mService != null) {
3051 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003052 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003053 } catch (RemoteException e) {
3054 Log.w(TAG, "Failed talking with device policy service", e);
3055 }
3056 }
3057 }
3058
3059 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003060 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3061 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003062 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3064 */
Nicolas Prevot81948992014-05-16 18:25:26 +01003065 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003066 if (mService != null) {
3067 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003068 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003069 } catch (RemoteException e) {
3070 Log.w(TAG, "Failed talking with device policy service", e);
3071 }
3072 }
3073 }
3074
3075 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003076 * Called by a profile or device owner to set the permitted accessibility services. When
3077 * set by a device owner or profile owner the restriction applies to all profiles of the
3078 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003079 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003080 * By default the user can use any accessiblity service. When zero or more packages have
3081 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003082 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003083 *
3084 * <p> Calling with a null value for the list disables the restriction so that all services
3085 * can be used, calling with an empty list only allows the builtin system's services.
3086 *
3087 * <p> System accesibility services are always available to the user the list can't modify
3088 * this.
3089 *
3090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3091 * @param packageNames List of accessibility service package names.
3092 *
3093 * @return true if setting the restriction succeeded. It fail if there is
3094 * one or more non-system accessibility services enabled, that are not in the list.
3095 */
3096 public boolean setPermittedAccessibilityServices(ComponentName admin,
3097 List<String> packageNames) {
3098 if (mService != null) {
3099 try {
3100 return mService.setPermittedAccessibilityServices(admin, packageNames);
3101 } catch (RemoteException e) {
3102 Log.w(TAG, "Failed talking with device policy service", e);
3103 }
3104 }
3105 return false;
3106 }
3107
3108 /**
3109 * Returns the list of permitted accessibility services set by this device or profile owner.
3110 *
3111 * <p>An empty list means no accessibility services except system services are allowed.
3112 * Null means all accessibility services are allowed.
3113 *
3114 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3115 * @return List of accessiblity service package names.
3116 */
3117 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
3118 if (mService != null) {
3119 try {
3120 return mService.getPermittedAccessibilityServices(admin);
3121 } catch (RemoteException e) {
3122 Log.w(TAG, "Failed talking with device policy service", e);
3123 }
3124 }
3125 return null;
3126 }
3127
3128 /**
3129 * Returns the list of accessibility services permitted by the device or profiles
3130 * owners of this user.
3131 *
3132 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3133 * it will contain the intersection of the permitted lists for any device or profile
3134 * owners that apply to this user. It will also include any system accessibility services.
3135 *
3136 * @param userId which user to check for.
3137 * @return List of accessiblity service package names.
3138 * @hide
3139 */
3140 @SystemApi
3141 public List<String> getPermittedAccessibilityServices(int userId) {
3142 if (mService != null) {
3143 try {
3144 return mService.getPermittedAccessibilityServicesForUser(userId);
3145 } catch (RemoteException e) {
3146 Log.w(TAG, "Failed talking with device policy service", e);
3147 }
3148 }
3149 return null;
3150 }
3151
3152 /**
3153 * Called by a profile or device owner to set the permitted input methods services. When
3154 * set by a device owner or profile owner the restriction applies to all profiles of the
3155 * user the device owner or profile owner is an admin for.
3156 *
3157 * By default the user can use any input method. When zero or more packages have
3158 * been added, input method that are not in the list and not part of the system
3159 * can not be enabled by the user.
3160 *
3161 * This method will fail if it is called for a admin that is not for the foreground user
3162 * or a profile of the foreground user.
3163 *
3164 * <p> Calling with a null value for the list disables the restriction so that all input methods
3165 * can be used, calling with an empty list disables all but the system's own input methods.
3166 *
3167 * <p> System input methods are always available to the user this method can't modify this.
3168 *
3169 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3170 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003171 * @return true if setting the restriction succeeded. It will fail if there are
3172 * one or more non-system input methods currently enabled that are not in
3173 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003174 */
3175 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
3176 if (mService != null) {
3177 try {
3178 return mService.setPermittedInputMethods(admin, packageNames);
3179 } catch (RemoteException e) {
3180 Log.w(TAG, "Failed talking with device policy service", e);
3181 }
3182 }
3183 return false;
3184 }
3185
3186
3187 /**
3188 * Returns the list of permitted input methods set by this device or profile owner.
3189 *
3190 * <p>An empty list means no input methods except system input methods are allowed.
3191 * Null means all input methods are allowed.
3192 *
3193 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3194 * @return List of input method package names.
3195 */
3196 public List<String> getPermittedInputMethods(ComponentName admin) {
3197 if (mService != null) {
3198 try {
3199 return mService.getPermittedInputMethods(admin);
3200 } catch (RemoteException e) {
3201 Log.w(TAG, "Failed talking with device policy service", e);
3202 }
3203 }
3204 return null;
3205 }
3206
3207 /**
3208 * Returns the list of input methods permitted by the device or profiles
3209 * owners of the current user.
3210 *
3211 * <p>Null means all input methods are allowed, if a non-null list is returned
3212 * it will contain the intersection of the permitted lists for any device or profile
3213 * owners that apply to this user. It will also include any system input methods.
3214 *
3215 * @return List of input method package names.
3216 * @hide
3217 */
3218 @SystemApi
3219 public List<String> getPermittedInputMethodsForCurrentUser() {
3220 if (mService != null) {
3221 try {
3222 return mService.getPermittedInputMethodsForCurrentUser();
3223 } catch (RemoteException e) {
3224 Log.w(TAG, "Failed talking with device policy service", e);
3225 }
3226 }
3227 return null;
3228 }
3229
3230 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003231 * Called by a device owner to create a user with the specified name. The UserHandle returned
3232 * by this method should not be persisted as user handles are recycled as users are removed and
3233 * created. If you need to persist an identifier for this user, use
3234 * {@link UserManager#getSerialNumberForUser}.
3235 *
3236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3237 * @param name the user's name
3238 * @see UserHandle
3239 * @return the UserHandle object for the created user, or null if the user could not be created.
3240 */
3241 public UserHandle createUser(ComponentName admin, String name) {
3242 try {
3243 return mService.createUser(admin, name);
3244 } catch (RemoteException re) {
3245 Log.w(TAG, "Could not create a user", re);
3246 }
3247 return null;
3248 }
3249
3250 /**
Jason Monk03978a42014-06-10 15:05:30 -04003251 * Called by a device owner to create a user with the specified name. The UserHandle returned
3252 * by this method should not be persisted as user handles are recycled as users are removed and
3253 * created. If you need to persist an identifier for this user, use
3254 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3255 * immediately.
3256 *
3257 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3258 * as registered as an active admin on the new user. The profile owner package will be
3259 * installed on the new user if it already is installed on the device.
3260 *
3261 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3262 * profileOwnerComponent when onEnable is called.
3263 *
3264 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3265 * @param name the user's name
3266 * @param ownerName the human readable name of the organisation associated with this DPM.
3267 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3268 * the user.
3269 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3270 * on the new user.
3271 * @see UserHandle
3272 * @return the UserHandle object for the created user, or null if the user could not be created.
3273 */
3274 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3275 ComponentName profileOwnerComponent, Bundle adminExtras) {
3276 try {
3277 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3278 adminExtras);
3279 } catch (RemoteException re) {
3280 Log.w(TAG, "Could not create a user", re);
3281 }
3282 return null;
3283 }
3284
3285 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003286 * Called by a device owner to remove a user and all associated data. The primary user can
3287 * not be removed.
3288 *
3289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3290 * @param userHandle the user to remove.
3291 * @return {@code true} if the user was removed, {@code false} otherwise.
3292 */
3293 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3294 try {
3295 return mService.removeUser(admin, userHandle);
3296 } catch (RemoteException re) {
3297 Log.w(TAG, "Could not remove user ", re);
3298 return false;
3299 }
3300 }
3301
3302 /**
Jason Monk582d9112014-07-09 19:57:08 -04003303 * Called by a device owner to switch the specified user to the foreground.
3304 *
3305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3306 * @param userHandle the user to switch to; null will switch to primary.
3307 * @return {@code true} if the switch was successful, {@code false} otherwise.
3308 *
3309 * @see Intent#ACTION_USER_FOREGROUND
3310 */
3311 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3312 try {
3313 return mService.switchUser(admin, userHandle);
3314 } catch (RemoteException re) {
3315 Log.w(TAG, "Could not switch user ", re);
3316 return false;
3317 }
3318 }
3319
3320 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003321 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003322 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003323 *
3324 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3325 * exception will be thrown.
3326 *
3327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3328 * @param packageName The name of the package to fetch restricted settings of.
3329 * @return {@link Bundle} of settings corresponding to what was set last time
3330 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3331 * if no restrictions have been set.
3332 */
3333 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3334 if (mService != null) {
3335 try {
3336 return mService.getApplicationRestrictions(admin, packageName);
3337 } catch (RemoteException e) {
3338 Log.w(TAG, "Failed talking with device policy service", e);
3339 }
3340 }
3341 return null;
3342 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003343
3344 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003345 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003346 * <p>
3347 * The calling device admin must be a profile or device owner; if it is not,
3348 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003349 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003350 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3351 * with.
3352 * @param key The key of the restriction. See the constants in
3353 * {@link android.os.UserManager} for the list of keys.
3354 */
3355 public void addUserRestriction(ComponentName admin, String key) {
3356 if (mService != null) {
3357 try {
3358 mService.setUserRestriction(admin, key, true);
3359 } catch (RemoteException e) {
3360 Log.w(TAG, "Failed talking with device policy service", e);
3361 }
3362 }
3363 }
3364
3365 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003366 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003367 * <p>
3368 * The calling device admin must be a profile or device owner; if it is not,
3369 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003370 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003371 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3372 * with.
3373 * @param key The key of the restriction. See the constants in
3374 * {@link android.os.UserManager} for the list of keys.
3375 */
3376 public void clearUserRestriction(ComponentName admin, String key) {
3377 if (mService != null) {
3378 try {
3379 mService.setUserRestriction(admin, key, false);
3380 } catch (RemoteException e) {
3381 Log.w(TAG, "Failed talking with device policy service", e);
3382 }
3383 }
3384 }
Adam Connors010cfd42014-04-16 12:48:13 +01003385
3386 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003387 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003388 * is unavailable for use, but the data and actual package file remain.
3389 *
3390 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003391 * @param packageName The name of the package to hide or unhide.
3392 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3393 * unhidden.
3394 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003395 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003396 public boolean setApplicationHidden(ComponentName admin, String packageName,
3397 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003398 if (mService != null) {
3399 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003400 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003401 } catch (RemoteException e) {
3402 Log.w(TAG, "Failed talking with device policy service", e);
3403 }
3404 }
3405 return false;
3406 }
3407
3408 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003409 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003410 *
3411 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003412 * @param packageName The name of the package to retrieve the hidden status of.
3413 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003414 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003415 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003416 if (mService != null) {
3417 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003418 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003419 } catch (RemoteException e) {
3420 Log.w(TAG, "Failed talking with device policy service", e);
3421 }
3422 }
3423 return false;
3424 }
3425
3426 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003427 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003428 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003429 *
3430 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3431 * @param packageName The package to be re-enabled in the current profile.
3432 */
3433 public void enableSystemApp(ComponentName admin, String packageName) {
3434 if (mService != null) {
3435 try {
3436 mService.enableSystemApp(admin, packageName);
3437 } catch (RemoteException e) {
3438 Log.w(TAG, "Failed to install package: " + packageName);
3439 }
3440 }
3441 }
3442
3443 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003444 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003445 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003446 *
3447 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3448 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3449 * intent will be re-enabled in the current profile.
3450 * @return int The number of activities that matched the intent and were installed.
3451 */
3452 public int enableSystemApp(ComponentName admin, Intent intent) {
3453 if (mService != null) {
3454 try {
3455 return mService.enableSystemAppWithIntent(admin, intent);
3456 } catch (RemoteException e) {
3457 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3458 }
3459 }
3460 return 0;
3461 }
3462
3463 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003464 * Called by a device owner or profile owner to disable account management for a specific type
3465 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003466 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003467 * <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 +01003468 * security exception will be thrown.
3469 *
3470 * <p>When account management is disabled for an account type, adding or removing an account
3471 * of that type will not be possible.
3472 *
3473 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3474 * @param accountType For which account management is disabled or enabled.
3475 * @param disabled The boolean indicating that account management will be disabled (true) or
3476 * enabled (false).
3477 */
3478 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3479 boolean disabled) {
3480 if (mService != null) {
3481 try {
3482 mService.setAccountManagementDisabled(admin, accountType, disabled);
3483 } catch (RemoteException e) {
3484 Log.w(TAG, "Failed talking with device policy service", e);
3485 }
3486 }
3487 }
3488
3489 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003490 * Gets the array of accounts for which account management is disabled by the profile owner.
3491 *
3492 * <p> Account management can be disabled/enabled by calling
3493 * {@link #setAccountManagementDisabled}.
3494 *
3495 * @return a list of account types for which account management has been disabled.
3496 *
3497 * @see #setAccountManagementDisabled
3498 */
3499 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003500 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003501 }
3502
3503 /**
3504 * @see #getAccountTypesWithManagementDisabled()
3505 * @hide
3506 */
3507 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003508 if (mService != null) {
3509 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003510 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003511 } catch (RemoteException e) {
3512 Log.w(TAG, "Failed talking with device policy service", e);
3513 }
3514 }
3515
3516 return null;
3517 }
justinzhang511e0d82014-03-24 16:09:24 -04003518
3519 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003520 * Sets which packages may enter lock task mode.
3521 *
3522 * <p>Any packages that shares uid with an allowed package will also be allowed
3523 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003524 *
Jason Monkc5185f22014-06-24 11:12:42 -04003525 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003526 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003527 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003528 *
3529 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003530 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3531 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003532 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003533 */
Jason Monk48aacba2014-08-13 16:29:08 -04003534 public void setLockTaskPackages(ComponentName admin, String[] packages)
3535 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003536 if (mService != null) {
3537 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003538 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003539 } catch (RemoteException e) {
3540 Log.w(TAG, "Failed talking with device policy service", e);
3541 }
3542 }
3543 }
3544
3545 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003546 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003547 *
3548 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003549 * @hide
3550 */
Jason Monk48aacba2014-08-13 16:29:08 -04003551 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003552 if (mService != null) {
3553 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003554 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003555 } catch (RemoteException e) {
3556 Log.w(TAG, "Failed talking with device policy service", e);
3557 }
3558 }
3559 return null;
3560 }
3561
3562 /**
3563 * This function lets the caller know whether the given component is allowed to start the
3564 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003565 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003566 */
Jason Monkd7b86212014-06-16 13:15:38 -04003567 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003568 if (mService != null) {
3569 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003570 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003571 } catch (RemoteException e) {
3572 Log.w(TAG, "Failed talking with device policy service", e);
3573 }
3574 }
3575 return false;
3576 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003577
3578 /**
3579 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3580 * 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 -04003581 * <p>The settings that can be updated with this method are:
3582 * <ul>
3583 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3584 * <li>{@link Settings.Global#AUTO_TIME}</li>
3585 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003586 * <li>{@link Settings.Global#BLUETOOTH_ON}
3587 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3588 * {@link android.bluetooth.BluetoothAdapter#enable()} and
3589 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003590 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3591 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3592 * <li>{@link Settings.Global#MODE_RINGER}</li>
3593 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3594 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Nicolas Prevot41916d42015-02-24 18:41:50 +00003595 * <li>{@link Settings.Global#WIFI_ON}
3596 * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use
3597 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003598 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00003599 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
3600 * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards
3601 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003602 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003603 *
3604 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3605 * @param setting The name of the setting to update.
3606 * @param value The value to update the setting to.
3607 */
3608 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3609 if (mService != null) {
3610 try {
3611 mService.setGlobalSetting(admin, setting, value);
3612 } catch (RemoteException e) {
3613 Log.w(TAG, "Failed talking with device policy service", e);
3614 }
3615 }
3616 }
3617
3618 /**
3619 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3620 * that the value of the setting is in the correct form for the setting type should be performed
3621 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003622 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003623 * <ul>
3624 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003625 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003626 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3627 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003628 * <p>A device owner can additionally update the following settings:
3629 * <ul>
3630 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3631 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003632 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3633 * @param setting The name of the setting to update.
3634 * @param value The value to update the setting to.
3635 */
3636 public void setSecureSetting(ComponentName admin, String setting, String value) {
3637 if (mService != null) {
3638 try {
3639 mService.setSecureSetting(admin, setting, value);
3640 } catch (RemoteException e) {
3641 Log.w(TAG, "Failed talking with device policy service", e);
3642 }
3643 }
3644 }
3645
Amith Yamasanif20d6402014-05-24 15:34:37 -07003646 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003647 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003648 * making permission requests of a local or remote administrator of the user.
3649 * <p/>
3650 * Only a profile owner can designate the restrictions provider.
3651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003652 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003653 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003654 * it removes the restrictions provider previously assigned.
3655 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003656 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003657 if (mService != null) {
3658 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003659 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003660 } catch (RemoteException re) {
3661 Log.w(TAG, "Failed to set permission provider on device policy service");
3662 }
3663 }
3664 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003665
3666 /**
3667 * Called by profile or device owners to set the master volume mute on or off.
3668 *
3669 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3670 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3671 */
3672 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3673 if (mService != null) {
3674 try {
3675 mService.setMasterVolumeMuted(admin, on);
3676 } catch (RemoteException re) {
3677 Log.w(TAG, "Failed to setMasterMute on device policy service");
3678 }
3679 }
3680 }
3681
3682 /**
3683 * Called by profile or device owners to check whether the master volume mute is on or off.
3684 *
3685 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3686 * @return {@code true} if master volume is muted, {@code false} if it's not.
3687 */
3688 public boolean isMasterVolumeMuted(ComponentName admin) {
3689 if (mService != null) {
3690 try {
3691 return mService.isMasterVolumeMuted(admin);
3692 } catch (RemoteException re) {
3693 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3694 }
3695 }
3696 return false;
3697 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003698
3699 /**
3700 * Called by profile or device owners to change whether a user can uninstall
3701 * a package.
3702 *
3703 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3704 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003705 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003706 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003707 public void setUninstallBlocked(ComponentName admin, String packageName,
3708 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003709 if (mService != null) {
3710 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003711 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003712 } catch (RemoteException re) {
3713 Log.w(TAG, "Failed to call block uninstall on device policy service");
3714 }
3715 }
3716 }
3717
3718 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003719 * Check whether the current user has been blocked by device policy from uninstalling a package.
3720 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00003721 * <p>
3722 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
3723 * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code>
3724 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
3725 * <code>null</code> will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01003726 *
Rubin Xua97855b2014-11-07 05:41:00 +00003727 * @param admin The name of the admin component whose blocking policy will be checked, or null
Rubin Xue1e6faa2015-03-10 10:51:59 +00003728 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003729 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003730 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003731 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003732 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003733 if (mService != null) {
3734 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003735 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003736 } catch (RemoteException re) {
3737 Log.w(TAG, "Failed to call block uninstall on device policy service");
3738 }
3739 }
3740 return false;
3741 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003742
3743 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003744 * Called by the profile owner of a managed profile to enable widget providers from a
3745 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003746 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003747 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003748 * a package may have zero or more provider components, where each component
3749 * provides a different widget type.
3750 * <p>
3751 * <strong>Note:</strong> By default no widget provider package is white-listed.
3752 * </p>
3753 *
3754 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3755 * @param packageName The package from which widget providers are white-listed.
3756 * @return Whether the package was added.
3757 *
3758 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3759 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3760 */
3761 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3762 if (mService != null) {
3763 try {
3764 return mService.addCrossProfileWidgetProvider(admin, packageName);
3765 } catch (RemoteException re) {
3766 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3767 }
3768 }
3769 return false;
3770 }
3771
3772 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003773 * Called by the profile owner of a managed profile to disable widget providers from a given
3774 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003775 * package should have been added via {@link #addCrossProfileWidgetProvider(
3776 * android.content.ComponentName, String)}.
3777 * <p>
3778 * <strong>Note:</strong> By default no widget provider package is white-listed.
3779 * </p>
3780 *
3781 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3782 * @param packageName The package from which widget providers are no longer
3783 * white-listed.
3784 * @return Whether the package was removed.
3785 *
3786 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3787 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3788 */
3789 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3790 if (mService != null) {
3791 try {
3792 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3793 } catch (RemoteException re) {
3794 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3795 }
3796 }
3797 return false;
3798 }
3799
3800 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003801 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003802 * available in the parent profile.
3803 *
3804 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3805 * @return The white-listed package list.
3806 *
3807 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3808 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3809 */
3810 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3811 if (mService != null) {
3812 try {
3813 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3814 if (providers != null) {
3815 return providers;
3816 }
3817 } catch (RemoteException re) {
3818 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3819 }
3820 }
3821 return Collections.emptyList();
3822 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05003823
3824 /**
3825 * Called by profile or device owners to set the current user's photo.
3826 *
3827 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3828 * @param icon the bitmap to set as the photo.
3829 */
3830 public void setUserIcon(ComponentName admin, Bitmap icon) {
3831 try {
3832 mService.setUserIcon(admin, icon);
3833 } catch (RemoteException re) {
3834 Log.w(TAG, "Could not set the user icon ", re);
3835 }
3836 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003837}