blob: a10b1331ca726e38d7655d3bb33a2bbb4b2dbffd [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;
Jason Monk03bc9912014-05-13 09:44:57 -040031import android.net.ProxyInfo;
Robin Lee66e5d962014-04-09 16:44:21 +010032import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.os.Handler;
Jim Millere303bf42014-08-26 17:12:29 -070034import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000035import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080036import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.os.RemoteException;
38import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070039import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040040import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040041import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010042import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070043import android.service.restrictions.RestrictionsReceiver;
Jim Millere303bf42014-08-26 17:12:29 -070044import android.service.trust.TrustAgentService;
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
71 * <a href={@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
72 * 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 *
108 * <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
111 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100112 * <p>This intent must contain the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000113 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000114 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
115 * in the provisioning intent. The
116 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
117 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
118 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100119 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100120 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
121 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000122 *
123 * <p>Input: Nothing.</p>
124 * <p>Output: Nothing</p>
125 */
126 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
127 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100128 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000129
130 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700131 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
132 * a mobile device management application that starts managed profile provisioning to pass data
133 * to itself on the managed profile when provisioning completes. The mobile device management
134 * application sends this extra in an intent with the action
135 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
136 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
137 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
138 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100139 */
140 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100141 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100142
143 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100144 * A String extra holding the package name of the mobile device management application that
145 * will be set as the profile owner or device owner.
146 *
147 * <p>If an application starts provisioning directly via an intent with action
148 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
149 * application that started provisioning. The package will be set as profile owner in that case.
150 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000151 * <p>This package is set as device owner when device owner provisioning is started by an NFC
152 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000153 */
154 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100155 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000156
157 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000158 * An {@link android.accounts.Account} extra holding the account to migrate during managed
159 * profile provisioning. If the account supplied is present in the primary user, it will be
160 * copied, along with its credentials to the managed profile and removed from the primary user.
161 *
162 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
163 */
164
165 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
166 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
167
168 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100169 * A String extra that, holds the email address of the account which a managed profile is
170 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
171 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100172 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100173 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
174 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100175 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
176 * contains this extra, it is forwarded in the
177 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
178 * device management application that was set as the profile owner during provisioning.
179 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100180 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100181 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
182 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100183
184 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000185 * A Boolean extra that can be used by the mobile device management application to skip the
186 * disabling of system apps during provisioning when set to <code>true</code>.
187 *
188 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
189 * provisioning via an NFC bump.
190 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000191 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
192 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000193
194 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100195 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
196 * will be set to.
197 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000198 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
199 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100200 */
201 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100202 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100203
204 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100205 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
206 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100207 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000208 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
209 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100210 */
211 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100212 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100213
214 /**
215 * A String extra holding the {@link java.util.Locale} that the device will be set to.
216 * Format: xx_yy, where xx is the language code, and yy the country code.
217 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000218 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
219 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100220 */
221 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100222 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100223
224 /**
225 * A String extra holding the ssid of the wifi network that should be used during nfc device
226 * owner provisioning for downloading the mobile device management application.
227 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000228 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
229 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100230 */
231 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100232 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100233
234 /**
235 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
236 * is hidden or not.
237 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000238 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
239 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100240 */
241 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100242 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100243
244 /**
245 * A String extra indicating the security type of the wifi network in
246 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
247 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000248 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
249 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100250 */
251 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100252 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100253
254 /**
255 * A String extra holding the password of the wifi network in
256 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
257 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000258 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
259 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100260 */
261 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100262 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100263
264 /**
265 * A String extra holding the proxy host for the wifi network in
266 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
267 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000268 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
269 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100270 */
271 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100272 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100273
274 /**
275 * An int extra holding the proxy port for the wifi network in
276 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
277 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000278 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
279 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100280 */
281 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100282 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100283
284 /**
285 * A String extra holding the proxy bypass for the wifi network in
286 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
287 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000288 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
289 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100290 */
291 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100292 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100293
294 /**
295 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
296 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
297 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000298 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
299 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100300 */
301 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100302 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100303
304 /**
305 * A String extra holding a url that specifies the download location of the device admin
306 * package. When not provided it is assumed that the device admin package is already installed.
307 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000308 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
309 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100310 */
311 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100312 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100313
314 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100315 * A String extra holding a http cookie header which should be used in the http request to the
316 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
317 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000318 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
319 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100320 */
321 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100322 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100323
324 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100325 * A String extra holding the SHA-1 checksum of the file at download location specified in
326 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
327 * the file at the download location an error will be shown to the user and the user will be
328 * asked to factory reset the device.
329 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000330 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
331 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100332 */
333 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100334 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100335
336 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000337 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
338 * has completed successfully.
339 *
340 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
341 * intent (@see #ACTION_PROVISION_MANAGED_PROFILE).
342 *
343 * <p>This intent will contain the extra {@link EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
344 * corresponds to the account requested to be migrated at provisioning time, if any.
345 */
346 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
347 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
348 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
349
350 /**
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500351 * A boolean extra indicating whether device encryption is required as part of Device Owner
352 * provisioning.
353 *
354 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
355 * provisioning via an NFC bump.
356 */
357 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
358 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
359
360 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100361 * This MIME type is used for starting the Device Owner provisioning.
362 *
363 * <p>During device owner provisioning a device admin app is set as the owner of the device.
364 * A device owner has full control over the device. The device owner can not be modified by the
365 * user and the only way of resetting the device is if the device owner app calls a factory
366 * reset.
367 *
368 * <p> A typical use case would be a device that is owned by a company, but used by either an
369 * employee or client.
370 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000371 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100372 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000373 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100374 * contains the following properties:
375 * <ul>
376 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
377 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100378 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100379 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
380 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
381 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
382 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
383 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
384 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
385 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
386 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
387 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
388 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
389 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500390 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
391 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100392 *
393 * <p> When device owner provisioning has completed, an intent of the type
394 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
395 * device owner.
396 *
397 * <p>
398 * If provisioning fails, the device is factory reset.
399 *
400 * <p>Input: Nothing.</p>
401 * <p>Output: Nothing</p>
402 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100403 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100404 = "application/com.android.managedprovisioning";
405
406 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800407 * Activity action: ask the user to add a new device administrator to the system.
408 * The desired policy is the ComponentName of the policy in the
409 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
410 * bring the user through adding the device administrator to the system (or
411 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700412 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800413 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
414 * field to provide the user with additional explanation (in addition
415 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800416 *
417 * <p>If your administrator is already active, this will ordinarily return immediately (without
418 * user intervention). However, if your administrator has been updated and is requesting
419 * additional uses-policy flags, the user will be presented with the new list. New policies
420 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800421 */
422 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
423 public static final String ACTION_ADD_DEVICE_ADMIN
424 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700425
Dianne Hackbornd6847842010-01-12 18:14:19 -0800426 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700427 * @hide
428 * Activity action: ask the user to add a new device administrator as the profile owner
429 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
430 * permission can call this API.
431 *
432 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
433 * field. This will invoke a UI to bring the user through adding the profile owner admin
434 * to remotely control restrictions on the user.
435 *
436 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
437 * result of whether or not the user approved the action. If approved, the result will
438 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
439 * as a profile owner.
440 *
441 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
442 * field to provide the user with additional explanation (in addition
443 * to your component's description) about what is being added.
444 *
445 * <p>If there is already a profile owner active or the caller doesn't have the required
446 * permissions, the operation will return a failure result.
447 */
448 @SystemApi
449 public static final String ACTION_SET_PROFILE_OWNER
450 = "android.app.action.SET_PROFILE_OWNER";
451
452 /**
453 * @hide
454 * Name of the profile owner admin that controls the user.
455 */
456 @SystemApi
457 public static final String EXTRA_PROFILE_OWNER_NAME
458 = "android.app.extra.PROFILE_OWNER_NAME";
459
460 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700461 * Activity action: send when any policy admin changes a policy.
462 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700463 *
Jim Miller284b62e2010-06-08 14:27:42 -0700464 * @hide
465 */
466 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
467 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
468
469 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800470 * The ComponentName of the administrator component.
471 *
472 * @see #ACTION_ADD_DEVICE_ADMIN
473 */
474 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700475
Dianne Hackbornd6847842010-01-12 18:14:19 -0800476 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800477 * An optional CharSequence providing additional explanation for why the
478 * admin is being added.
479 *
480 * @see #ACTION_ADD_DEVICE_ADMIN
481 */
482 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700483
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800484 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700485 * Activity action: have the user enter a new password. This activity should
486 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
487 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
488 * enter a new password that meets the current requirements. You can use
489 * {@link #isActivePasswordSufficient()} to determine whether you need to
490 * have the user select a new password in order to meet the current
491 * constraints. Upon being resumed from this activity, you can check the new
492 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800493 */
494 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
495 public static final String ACTION_SET_NEW_PASSWORD
496 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700497
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000498 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000499 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
500 * the parent profile to access intents sent from the managed profile.
501 * That is, when an app in the managed profile calls
502 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
503 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000504 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100505 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000506
507 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000508 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
509 * the managed profile to access intents sent from the parent profile.
510 * That is, when an app in the parent profile calls
511 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
512 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000513 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100514 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700515
Dianne Hackbornd6847842010-01-12 18:14:19 -0800516 /**
517 * Return true if the given administrator component is currently
518 * active (enabled) in the system.
519 */
520 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100521 return isAdminActiveAsUser(who, UserHandle.myUserId());
522 }
523
524 /**
525 * @see #isAdminActive(ComponentName)
526 * @hide
527 */
528 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800529 if (mService != null) {
530 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100531 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800532 } catch (RemoteException e) {
533 Log.w(TAG, "Failed talking with device policy service", e);
534 }
535 }
536 return false;
537 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800538 /**
539 * Return true if the given administrator component is currently being removed
540 * for the user.
541 * @hide
542 */
543 public boolean isRemovingAdmin(ComponentName who, int userId) {
544 if (mService != null) {
545 try {
546 return mService.isRemovingAdmin(who, userId);
547 } catch (RemoteException e) {
548 Log.w(TAG, "Failed talking with device policy service", e);
549 }
550 }
551 return false;
552 }
553
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700554
Dianne Hackbornd6847842010-01-12 18:14:19 -0800555 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800556 * Return a list of all currently active device administrator's component
557 * names. Note that if there are no administrators than null may be
558 * returned.
559 */
560 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100561 return getActiveAdminsAsUser(UserHandle.myUserId());
562 }
563
564 /**
565 * @see #getActiveAdmins()
566 * @hide
567 */
568 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800569 if (mService != null) {
570 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100571 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800572 } catch (RemoteException e) {
573 Log.w(TAG, "Failed talking with device policy service", e);
574 }
575 }
576 return null;
577 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700578
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800579 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700580 * Used by package administration code to determine if a package can be stopped
581 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800582 * @hide
583 */
584 public boolean packageHasActiveAdmins(String packageName) {
585 if (mService != null) {
586 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700587 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800588 } catch (RemoteException e) {
589 Log.w(TAG, "Failed talking with device policy service", e);
590 }
591 }
592 return false;
593 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700594
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800595 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800596 * Remove a current administration component. This can only be called
597 * by the application that owns the administration component; if you
598 * try to remove someone else's component, a security exception will be
599 * thrown.
600 */
601 public void removeActiveAdmin(ComponentName who) {
602 if (mService != null) {
603 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700604 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800605 } catch (RemoteException e) {
606 Log.w(TAG, "Failed talking with device policy service", e);
607 }
608 }
609 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700610
Dianne Hackbornd6847842010-01-12 18:14:19 -0800611 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800612 * Returns true if an administrator has been granted a particular device policy. This can
613 * be used to check if the administrator was activated under an earlier set of policies,
614 * but requires additional policies after an upgrade.
615 *
616 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
617 * an active administrator, or an exception will be thrown.
618 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
619 */
620 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
621 if (mService != null) {
622 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700623 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800624 } catch (RemoteException e) {
625 Log.w(TAG, "Failed talking with device policy service", e);
626 }
627 }
628 return false;
629 }
630
631 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800632 * Constant for {@link #setPasswordQuality}: the policy has no requirements
633 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800634 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800635 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800636 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700637
Dianne Hackbornd6847842010-01-12 18:14:19 -0800638 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700639 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
640 * recognition technology. This implies technologies that can recognize the identity of
641 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
642 * Note that quality constants are ordered so that higher values are more restrictive.
643 */
644 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
645
646 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800647 * Constant for {@link #setPasswordQuality}: the policy requires some kind
648 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800649 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800650 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800651 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700652
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800653 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800654 * Constant for {@link #setPasswordQuality}: the user must have entered a
655 * password containing at least numeric characters. Note that quality
656 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800657 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800658 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700659
Dianne Hackbornd6847842010-01-12 18:14:19 -0800660 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800661 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800662 * password containing at least numeric characters with no repeating (4444)
663 * or ordered (1234, 4321, 2468) sequences. Note that quality
664 * constants are ordered so that higher values are more restrictive.
665 */
666 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
667
668 /**
669 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700670 * password containing at least alphabetic (or other symbol) characters.
671 * Note that quality constants are ordered so that higher values are more
672 * restrictive.
673 */
674 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700675
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700676 /**
677 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800678 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700679 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800680 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800681 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700682 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700683
Dianne Hackbornd6847842010-01-12 18:14:19 -0800684 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700685 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700686 * password containing at least a letter, a numerical digit and a special
687 * symbol, by default. With this password quality, passwords can be
688 * restricted to contain various sets of characters, like at least an
689 * uppercase letter, etc. These are specified using various methods,
690 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
691 * that quality constants are ordered so that higher values are more
692 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700693 */
694 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
695
696 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800697 * Called by an application that is administering the device to set the
698 * password restrictions it is imposing. After setting this, the user
699 * will not be able to enter a new password that is not at least as
700 * restrictive as what has been set. Note that the current password
701 * will remain until the user has set a new one, so the change does not
702 * take place immediately. To prompt the user for a new password, use
703 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700704 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800705 * <p>Quality constants are ordered so that higher values are more restrictive;
706 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800707 * the user's preference, and any other considerations) is the one that
708 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700709 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800710 * <p>The calling device admin must have requested
711 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
712 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700713 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800714 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800715 * @param quality The new desired quality. One of
716 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800717 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
718 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
719 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800720 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800721 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800722 if (mService != null) {
723 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800724 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800725 } catch (RemoteException e) {
726 Log.w(TAG, "Failed talking with device policy service", e);
727 }
728 }
729 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700730
Dianne Hackbornd6847842010-01-12 18:14:19 -0800731 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100732 * Retrieve the current minimum password quality for all admins of this user
733 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800734 * @param admin The name of the admin component to check, or null to aggregate
735 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800736 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800737 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700738 return getPasswordQuality(admin, UserHandle.myUserId());
739 }
740
741 /** @hide per-user version */
742 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800743 if (mService != null) {
744 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700745 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800746 } catch (RemoteException e) {
747 Log.w(TAG, "Failed talking with device policy service", e);
748 }
749 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800750 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800751 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700752
Dianne Hackbornd6847842010-01-12 18:14:19 -0800753 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800754 * Called by an application that is administering the device to set the
755 * minimum allowed password length. After setting this, the user
756 * will not be able to enter a new password that is not at least as
757 * restrictive as what has been set. Note that the current password
758 * will remain until the user has set a new one, so the change does not
759 * take place immediately. To prompt the user for a new password, use
760 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
761 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800762 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
763 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
764 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700765 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800766 * <p>The calling device admin must have requested
767 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
768 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700769 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800771 * @param length The new desired minimum password length. A value of 0
772 * means there is no restriction.
773 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800774 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800775 if (mService != null) {
776 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800777 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800778 } catch (RemoteException e) {
779 Log.w(TAG, "Failed talking with device policy service", e);
780 }
781 }
782 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700783
Dianne Hackbornd6847842010-01-12 18:14:19 -0800784 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100785 * Retrieve the current minimum password length for all admins of this
786 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800787 * @param admin The name of the admin component to check, or null to aggregate
788 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800789 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800790 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700791 return getPasswordMinimumLength(admin, UserHandle.myUserId());
792 }
793
794 /** @hide per-user version */
795 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800796 if (mService != null) {
797 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700798 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800799 } catch (RemoteException e) {
800 Log.w(TAG, "Failed talking with device policy service", e);
801 }
802 }
803 return 0;
804 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700805
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700806 /**
807 * Called by an application that is administering the device to set the
808 * minimum number of upper case letters required in the password. After
809 * setting this, the user will not be able to enter a new password that is
810 * not at least as restrictive as what has been set. Note that the current
811 * password will remain until the user has set a new one, so the change does
812 * not take place immediately. To prompt the user for a new password, use
813 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
814 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700815 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
816 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700817 * <p>
818 * The calling device admin must have requested
819 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
820 * this method; if it has not, a security exception will be thrown.
821 *
822 * @param admin Which {@link DeviceAdminReceiver} this request is associated
823 * with.
824 * @param length The new desired minimum number of upper case letters
825 * required in the password. A value of 0 means there is no
826 * restriction.
827 */
828 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
829 if (mService != null) {
830 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800831 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700832 } catch (RemoteException e) {
833 Log.w(TAG, "Failed talking with device policy service", e);
834 }
835 }
836 }
837
838 /**
839 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100840 * password for all admins of this user and its profiles or a particular one.
841 * This is the same value as set by
842 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700843 * and only applies when the password quality is
844 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700845 *
846 * @param admin The name of the admin component to check, or null to
847 * aggregate all admins.
848 * @return The minimum number of upper case letters required in the
849 * password.
850 */
851 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700852 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
853 }
854
855 /** @hide per-user version */
856 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700857 if (mService != null) {
858 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700859 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700860 } catch (RemoteException e) {
861 Log.w(TAG, "Failed talking with device policy service", e);
862 }
863 }
864 return 0;
865 }
866
867 /**
868 * Called by an application that is administering the device to set the
869 * minimum number of lower case letters required in the password. After
870 * setting this, the user will not be able to enter a new password that is
871 * not at least as restrictive as what has been set. Note that the current
872 * password will remain until the user has set a new one, so the change does
873 * not take place immediately. To prompt the user for a new password, use
874 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
875 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700876 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
877 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700878 * <p>
879 * The calling device admin must have requested
880 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
881 * this method; if it has not, a security exception will be thrown.
882 *
883 * @param admin Which {@link DeviceAdminReceiver} this request is associated
884 * with.
885 * @param length The new desired minimum number of lower case letters
886 * required in the password. A value of 0 means there is no
887 * restriction.
888 */
889 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
890 if (mService != null) {
891 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800892 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700893 } catch (RemoteException e) {
894 Log.w(TAG, "Failed talking with device policy service", e);
895 }
896 }
897 }
898
899 /**
900 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100901 * password for all admins of this user and its profiles or a particular one.
902 * This is the same value as set by
903 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700904 * and only applies when the password quality is
905 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700906 *
907 * @param admin The name of the admin component to check, or null to
908 * aggregate all admins.
909 * @return The minimum number of lower case letters required in the
910 * password.
911 */
912 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700913 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
914 }
915
916 /** @hide per-user version */
917 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700918 if (mService != null) {
919 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700920 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700921 } catch (RemoteException e) {
922 Log.w(TAG, "Failed talking with device policy service", e);
923 }
924 }
925 return 0;
926 }
927
928 /**
929 * Called by an application that is administering the device to set the
930 * minimum number of letters required in the password. After setting this,
931 * the user will not be able to enter a new password that is not at least as
932 * restrictive as what has been set. Note that the current password will
933 * remain until the user has set a new one, so the change does not take
934 * place immediately. To prompt the user for a new password, use
935 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
936 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700937 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
938 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700939 * <p>
940 * The calling device admin must have requested
941 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
942 * this method; if it has not, a security exception will be thrown.
943 *
944 * @param admin Which {@link DeviceAdminReceiver} this request is associated
945 * with.
946 * @param length The new desired minimum number of letters required in the
947 * password. A value of 0 means there is no restriction.
948 */
949 public void setPasswordMinimumLetters(ComponentName admin, int length) {
950 if (mService != null) {
951 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -0800952 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700953 } catch (RemoteException e) {
954 Log.w(TAG, "Failed talking with device policy service", e);
955 }
956 }
957 }
958
959 /**
960 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700961 * admins or a particular one. This is the same value as
962 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
963 * and only applies when the password quality is
964 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700965 *
966 * @param admin The name of the admin component to check, or null to
967 * aggregate all admins.
968 * @return The minimum number of letters required in the password.
969 */
970 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700971 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
972 }
973
974 /** @hide per-user version */
975 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700976 if (mService != null) {
977 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700978 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700979 } catch (RemoteException e) {
980 Log.w(TAG, "Failed talking with device policy service", e);
981 }
982 }
983 return 0;
984 }
985
986 /**
987 * Called by an application that is administering the device to set the
988 * minimum number of numerical digits required in the password. After
989 * setting this, the user will not be able to enter a new password that is
990 * not at least as restrictive as what has been set. Note that the current
991 * password will remain until the user has set a new one, so the change does
992 * not take place immediately. To prompt the user for a new password, use
993 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
994 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700995 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
996 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700997 * <p>
998 * The calling device admin must have requested
999 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1000 * this method; if it has not, a security exception will be thrown.
1001 *
1002 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1003 * with.
1004 * @param length The new desired minimum number of numerical digits required
1005 * in the password. A value of 0 means there is no restriction.
1006 */
1007 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
1008 if (mService != null) {
1009 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001010 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001011 } catch (RemoteException e) {
1012 Log.w(TAG, "Failed talking with device policy service", e);
1013 }
1014 }
1015 }
1016
1017 /**
1018 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001019 * for all admins of this user and its profiles or a particular one.
1020 * This is the same value as set by
1021 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001022 * and only applies when the password quality is
1023 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001024 *
1025 * @param admin The name of the admin component to check, or null to
1026 * aggregate all admins.
1027 * @return The minimum number of numerical digits required in the password.
1028 */
1029 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001030 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1031 }
1032
1033 /** @hide per-user version */
1034 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001035 if (mService != null) {
1036 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001037 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001038 } catch (RemoteException e) {
1039 Log.w(TAG, "Failed talking with device policy service", e);
1040 }
1041 }
1042 return 0;
1043 }
1044
1045 /**
1046 * Called by an application that is administering the device to set the
1047 * minimum number of symbols required in the password. After setting this,
1048 * the user will not be able to enter a new password that is not at least as
1049 * restrictive as what has been set. Note that the current password will
1050 * remain until the user has set a new one, so the change does not take
1051 * place immediately. To prompt the user for a new password, use
1052 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1053 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001054 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1055 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001056 * <p>
1057 * The calling device admin must have requested
1058 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1059 * this method; if it has not, a security exception will be thrown.
1060 *
1061 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1062 * with.
1063 * @param length The new desired minimum number of symbols required in the
1064 * password. A value of 0 means there is no restriction.
1065 */
1066 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1067 if (mService != null) {
1068 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001069 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001070 } catch (RemoteException e) {
1071 Log.w(TAG, "Failed talking with device policy service", e);
1072 }
1073 }
1074 }
1075
1076 /**
1077 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001078 * admins or a particular one. This is the same value as
1079 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1080 * and only applies when the password quality is
1081 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001082 *
1083 * @param admin The name of the admin component to check, or null to
1084 * aggregate all admins.
1085 * @return The minimum number of symbols required in the password.
1086 */
1087 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001088 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1089 }
1090
1091 /** @hide per-user version */
1092 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001093 if (mService != null) {
1094 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001095 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001096 } catch (RemoteException e) {
1097 Log.w(TAG, "Failed talking with device policy service", e);
1098 }
1099 }
1100 return 0;
1101 }
1102
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001103 /**
1104 * Called by an application that is administering the device to set the
1105 * minimum number of non-letter characters (numerical digits or symbols)
1106 * required in the password. After setting this, the user will not be able
1107 * to enter a new password that is not at least as restrictive as what has
1108 * been set. Note that the current password will remain until the user has
1109 * set a new one, so the change does not take place immediately. To prompt
1110 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1111 * setting this value. This constraint is only imposed if the administrator
1112 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1113 * {@link #setPasswordQuality}. The default value is 0.
1114 * <p>
1115 * The calling device admin must have requested
1116 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1117 * this method; if it has not, a security exception will be thrown.
1118 *
1119 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1120 * with.
1121 * @param length The new desired minimum number of letters required in the
1122 * password. A value of 0 means there is no restriction.
1123 */
1124 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1125 if (mService != null) {
1126 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001127 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001128 } catch (RemoteException e) {
1129 Log.w(TAG, "Failed talking with device policy service", e);
1130 }
1131 }
1132 }
1133
1134 /**
1135 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001136 * password for all admins of this user and its profiles or a particular one.
1137 * This is the same value as set by
1138 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001139 * and only applies when the password quality is
1140 * {@link #PASSWORD_QUALITY_COMPLEX}.
1141 *
1142 * @param admin The name of the admin component to check, or null to
1143 * aggregate all admins.
1144 * @return The minimum number of letters required in the password.
1145 */
1146 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001147 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1148 }
1149
1150 /** @hide per-user version */
1151 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001152 if (mService != null) {
1153 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001154 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001155 } catch (RemoteException e) {
1156 Log.w(TAG, "Failed talking with device policy service", e);
1157 }
1158 }
1159 return 0;
1160 }
1161
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001162 /**
1163 * Called by an application that is administering the device to set the length
1164 * of the password history. After setting this, the user will not be able to
1165 * enter a new password that is the same as any password in the history. Note
1166 * that the current password will remain until the user has set a new one, so
1167 * the change does not take place immediately. To prompt the user for a new
1168 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1169 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001170 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1171 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1172 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001173 *
1174 * <p>
1175 * The calling device admin must have requested
1176 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1177 * method; if it has not, a security exception will be thrown.
1178 *
1179 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1180 * with.
1181 * @param length The new desired length of password history. A value of 0
1182 * means there is no restriction.
1183 */
1184 public void setPasswordHistoryLength(ComponentName admin, int length) {
1185 if (mService != null) {
1186 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001187 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001188 } catch (RemoteException e) {
1189 Log.w(TAG, "Failed talking with device policy service", e);
1190 }
1191 }
1192 }
1193
1194 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001195 * Called by a device admin to set the password expiration timeout. Calling this method
1196 * will restart the countdown for password expiration for the given admin, as will changing
1197 * the device password (for all admins).
1198 *
1199 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1200 * For example, to have the password expire 5 days from now, timeout would be
1201 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1202 *
1203 * <p>To disable password expiration, a value of 0 may be used for timeout.
1204 *
Jim Millera4e28d12010-11-08 16:15:47 -08001205 * <p>The calling device admin must have requested
1206 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1207 * method; if it has not, a security exception will be thrown.
1208 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001209 * <p> Note that setting the password will automatically reset the expiration time for all
1210 * active admins. Active admins do not need to explicitly call this method in that case.
1211 *
Jim Millera4e28d12010-11-08 16:15:47 -08001212 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1213 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1214 * means there is no restriction (unlimited).
1215 */
1216 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1217 if (mService != null) {
1218 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001219 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001220 } catch (RemoteException e) {
1221 Log.w(TAG, "Failed talking with device policy service", e);
1222 }
1223 }
1224 }
1225
1226 /**
Jim Miller6b857682011-02-16 16:27:41 -08001227 * Get the password expiration timeout for the given admin. The expiration timeout is the
1228 * recurring expiration timeout provided in the call to
1229 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1230 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001231 *
1232 * @param admin The name of the admin component to check, or null to aggregate all admins.
1233 * @return The timeout for the given admin or the minimum of all timeouts
1234 */
1235 public long getPasswordExpirationTimeout(ComponentName admin) {
1236 if (mService != null) {
1237 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001238 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001239 } catch (RemoteException e) {
1240 Log.w(TAG, "Failed talking with device policy service", e);
1241 }
1242 }
1243 return 0;
1244 }
1245
1246 /**
1247 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001248 * all admins of this user and its profiles if admin is null. If the password is
1249 * expired, this will return the time since the password expired as a negative number.
1250 * If admin is null, then a composite of all expiration timeouts is returned
1251 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001252 *
1253 * @param admin The name of the admin component to check, or null to aggregate all admins.
1254 * @return The password expiration time, in ms.
1255 */
1256 public long getPasswordExpiration(ComponentName admin) {
1257 if (mService != null) {
1258 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001259 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001260 } catch (RemoteException e) {
1261 Log.w(TAG, "Failed talking with device policy service", e);
1262 }
1263 }
1264 return 0;
1265 }
1266
1267 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001268 * Retrieve the current password history length for all admins of this
1269 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001270 * @param admin The name of the admin component to check, or null to aggregate
1271 * all admins.
1272 * @return The length of the password history
1273 */
1274 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001275 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1276 }
1277
1278 /** @hide per-user version */
1279 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001280 if (mService != null) {
1281 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001282 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001283 } catch (RemoteException e) {
1284 Log.w(TAG, "Failed talking with device policy service", e);
1285 }
1286 }
1287 return 0;
1288 }
1289
Dianne Hackbornd6847842010-01-12 18:14:19 -08001290 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001291 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001292 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001293 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001294 * @return Returns the maximum length that the user can enter.
1295 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001296 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001297 // Kind-of arbitrary.
1298 return 16;
1299 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001300
Dianne Hackborn254cb442010-01-27 19:23:59 -08001301 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001302 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001303 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001304 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001305 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001306 * <p>The calling device admin must have requested
1307 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1308 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001309 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001310 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001311 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001312 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001313 if (mService != null) {
1314 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001315 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001316 } catch (RemoteException e) {
1317 Log.w(TAG, "Failed talking with device policy service", e);
1318 }
1319 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001320 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001321 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001322
Dianne Hackbornd6847842010-01-12 18:14:19 -08001323 /**
1324 * Retrieve the number of times the user has failed at entering a
1325 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001326 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001327 * <p>The calling device admin must have requested
1328 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1329 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001330 */
1331 public int getCurrentFailedPasswordAttempts() {
1332 if (mService != null) {
1333 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001334 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001335 } catch (RemoteException e) {
1336 Log.w(TAG, "Failed talking with device policy service", e);
1337 }
1338 }
1339 return -1;
1340 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001341
1342 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001343 * Setting this to a value greater than zero enables a built-in policy
1344 * that will perform a device wipe after too many incorrect
1345 * device-unlock passwords have been entered. This built-in policy combines
1346 * watching for failed passwords and wiping the device, and requires
1347 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001348 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001349 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001350 * <p>To implement any other policy (e.g. wiping data for a particular
1351 * application only, erasing or revoking credentials, or reporting the
1352 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001353 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001354 * instead. Do not use this API, because if the maximum count is reached,
1355 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001356 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001357 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001358 * @param num The number of failed password attempts at which point the
1359 * device will wipe its data.
1360 */
1361 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1362 if (mService != null) {
1363 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001364 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001365 } catch (RemoteException e) {
1366 Log.w(TAG, "Failed talking with device policy service", e);
1367 }
1368 }
1369 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001370
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001371 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001372 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001373 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001374 * or a particular one.
1375 * @param admin The name of the admin component to check, or null to aggregate
1376 * all admins.
1377 */
1378 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001379 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1380 }
1381
1382 /** @hide per-user version */
1383 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001384 if (mService != null) {
1385 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001386 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001387 } catch (RemoteException e) {
1388 Log.w(TAG, "Failed talking with device policy service", e);
1389 }
1390 }
1391 return 0;
1392 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001393
Dianne Hackborn254cb442010-01-27 19:23:59 -08001394 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001395 * Returns the profile with the smallest maximum failed passwords for wipe,
1396 * for the given user. So for primary user, it might return the primary or
1397 * a managed profile. For a secondary user, it would be the same as the
1398 * user passed in.
1399 * @hide Used only by Keyguard
1400 */
1401 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1402 if (mService != null) {
1403 try {
1404 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1405 } catch (RemoteException e) {
1406 Log.w(TAG, "Failed talking with device policy service", e);
1407 }
1408 }
1409 return UserHandle.USER_NULL;
1410 }
1411
1412 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001413 * Flag for {@link #resetPassword}: don't allow other admins to change
1414 * the password again until the user has entered it.
1415 */
1416 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001417
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001418 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001419 * Force a new device unlock password (the password needed to access the
1420 * entire device, not for individual accounts) on the user. This takes
1421 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001422 * The given password must be sufficient for the
1423 * current password quality and length constraints as returned by
1424 * {@link #getPasswordQuality(ComponentName)} and
1425 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1426 * these constraints, then it will be rejected and false returned. Note
1427 * that the password may be a stronger quality (containing alphanumeric
1428 * characters when the requested quality is only numeric), in which case
1429 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001430 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001431 * <p>Calling with a null or empty password will clear any existing PIN,
1432 * pattern or password if the current password constraints allow it.
1433 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001434 * <p>The calling device admin must have requested
1435 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1436 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001437 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001438 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001439 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001440 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001441 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001442 * @return Returns true if the password was applied, or false if it is
1443 * not acceptable for the current constraints.
1444 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001445 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001446 if (mService != null) {
1447 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001448 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001449 } catch (RemoteException e) {
1450 Log.w(TAG, "Failed talking with device policy service", e);
1451 }
1452 }
1453 return false;
1454 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001455
Dianne Hackbornd6847842010-01-12 18:14:19 -08001456 /**
1457 * Called by an application that is administering the device to set the
1458 * maximum time for user activity until the device will lock. This limits
1459 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001460 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001461 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001462 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001463 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001464 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001465 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001466 * @param timeMs The new desired maximum time to lock in milliseconds.
1467 * A value of 0 means there is no restriction.
1468 */
1469 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1470 if (mService != null) {
1471 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001472 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001473 } catch (RemoteException e) {
1474 Log.w(TAG, "Failed talking with device policy service", e);
1475 }
1476 }
1477 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001478
Dianne Hackbornd6847842010-01-12 18:14:19 -08001479 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001480 * Retrieve the current maximum time to unlock for all admins of this user
1481 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001482 * @param admin The name of the admin component to check, or null to aggregate
1483 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001484 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001485 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001486 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001487 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001488 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1489 }
1490
1491 /** @hide per-user version */
1492 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001493 if (mService != null) {
1494 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001495 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001496 } catch (RemoteException e) {
1497 Log.w(TAG, "Failed talking with device policy service", e);
1498 }
1499 }
1500 return 0;
1501 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001502
Dianne Hackbornd6847842010-01-12 18:14:19 -08001503 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001504 * Make the device lock immediately, as if the lock screen timeout has
1505 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001506 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001507 * <p>The calling device admin must have requested
1508 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1509 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001510 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001511 public void lockNow() {
1512 if (mService != null) {
1513 try {
1514 mService.lockNow();
1515 } catch (RemoteException e) {
1516 Log.w(TAG, "Failed talking with device policy service", e);
1517 }
1518 }
1519 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001520
Dianne Hackbornd6847842010-01-12 18:14:19 -08001521 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001522 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001523 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001524 */
1525 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1526
1527 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001528 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1529 * data.
1530 *
Paul Crowley2934b262014-12-02 11:21:13 +00001531 * <p>This flag may only be set by device owner admins; if it is set by
1532 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001533 */
1534 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1535
1536 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001537 * Ask the user data be wiped. Wiping the primary user will cause the
1538 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001539 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001540 * <p>The calling device admin must have requested
1541 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1542 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001543 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001544 * @param flags Bit mask of additional options: currently supported flags
1545 * are {@link #WIPE_EXTERNAL_STORAGE} and
1546 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001547 */
1548 public void wipeData(int flags) {
1549 if (mService != null) {
1550 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001551 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001552 } catch (RemoteException e) {
1553 Log.w(TAG, "Failed talking with device policy service", e);
1554 }
1555 }
1556 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001557
Dianne Hackbornd6847842010-01-12 18:14:19 -08001558 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001559 * Called by an application that is administering the device to set the
1560 * global proxy and exclusion list.
1561 * <p>
1562 * The calling device admin must have requested
1563 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1564 * this method; if it has not, a security exception will be thrown.
1565 * Only the first device admin can set the proxy. If a second admin attempts
1566 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1567 * proxy will be returned. If successful in setting the proxy, null will
1568 * be returned.
1569 * The method can be called repeatedly by the device admin alrady setting the
1570 * proxy to update the proxy and exclusion list.
1571 *
1572 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1573 * with.
1574 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1575 * Pass Proxy.NO_PROXY to reset the proxy.
1576 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001577 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1578 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001579 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001580 */
1581 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1582 List<String> exclusionList ) {
1583 if (proxySpec == null) {
1584 throw new NullPointerException();
1585 }
1586 if (mService != null) {
1587 try {
1588 String hostSpec;
1589 String exclSpec;
1590 if (proxySpec.equals(Proxy.NO_PROXY)) {
1591 hostSpec = null;
1592 exclSpec = null;
1593 } else {
1594 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1595 throw new IllegalArgumentException();
1596 }
1597 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1598 String hostName = sa.getHostName();
1599 int port = sa.getPort();
1600 StringBuilder hostBuilder = new StringBuilder();
1601 hostSpec = hostBuilder.append(hostName)
1602 .append(":").append(Integer.toString(port)).toString();
1603 if (exclusionList == null) {
1604 exclSpec = "";
1605 } else {
1606 StringBuilder listBuilder = new StringBuilder();
1607 boolean firstDomain = true;
1608 for (String exclDomain : exclusionList) {
1609 if (!firstDomain) {
1610 listBuilder = listBuilder.append(",");
1611 } else {
1612 firstDomain = false;
1613 }
1614 listBuilder = listBuilder.append(exclDomain.trim());
1615 }
1616 exclSpec = listBuilder.toString();
1617 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001618 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1619 != android.net.Proxy.PROXY_VALID)
1620 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001621 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001622 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001623 } catch (RemoteException e) {
1624 Log.w(TAG, "Failed talking with device policy service", e);
1625 }
1626 }
1627 return null;
1628 }
1629
1630 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001631 * Set a network-independent global HTTP proxy. This is not normally what you want
1632 * for typical HTTP proxies - they are generally network dependent. However if you're
1633 * doing something unusual like general internal filtering this may be useful. On
1634 * a private network where the proxy is not accessible, you may break HTTP using this.
1635 *
1636 * <p>This method requires the caller to be the device owner.
1637 *
1638 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1639 * @see ProxyInfo
1640 *
1641 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1642 * with.
1643 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1644 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1645 */
1646 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1647 if (mService != null) {
1648 try {
1649 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1650 } catch (RemoteException e) {
1651 Log.w(TAG, "Failed talking with device policy service", e);
1652 }
1653 }
1654 }
1655
1656 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001657 * Returns the component name setting the global proxy.
1658 * @return ComponentName object of the device admin that set the global proxy, or
1659 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001660 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001661 */
1662 public ComponentName getGlobalProxyAdmin() {
1663 if (mService != null) {
1664 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001665 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001666 } catch (RemoteException e) {
1667 Log.w(TAG, "Failed talking with device policy service", e);
1668 }
1669 }
1670 return null;
1671 }
1672
1673 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001674 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001675 * indicating that encryption is not supported.
1676 */
1677 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1678
1679 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001680 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001681 * indicating that encryption is supported, but is not currently active.
1682 */
1683 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1684
1685 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001686 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001687 * indicating that encryption is not currently active, but is currently
1688 * being activated. This is only reported by devices that support
1689 * encryption of data and only when the storage is currently
1690 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1691 * to become encrypted will never return this value.
1692 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001693 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001694
1695 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001696 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001697 * indicating that encryption is active.
1698 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001699 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001700
1701 /**
1702 * Activity action: begin the process of encrypting data on the device. This activity should
1703 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1704 * After resuming from this activity, use {@link #getStorageEncryption}
1705 * to check encryption status. However, on some devices this activity may never return, as
1706 * it may trigger a reboot and in some cases a complete data wipe of the device.
1707 */
1708 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1709 public static final String ACTION_START_ENCRYPTION
1710 = "android.app.action.START_ENCRYPTION";
1711
1712 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001713 * Widgets are enabled in keyguard
1714 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001715 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001716
1717 /**
Jim Miller50e62182014-04-23 17:25:00 -07001718 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001719 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001720 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1721
1722 /**
1723 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1724 */
1725 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1726
1727 /**
Jim Miller50e62182014-04-23 17:25:00 -07001728 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1729 */
1730 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1731
1732 /**
1733 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1734 */
1735 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1736
1737 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001738 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001739 * (e.g. PIN/Pattern/Password).
1740 */
1741 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1742
1743 /**
Jim Miller06e34502014-07-17 14:46:05 -07001744 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1745 */
1746 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1747
1748 /**
Jim Miller35207742012-11-02 15:33:20 -07001749 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001750 */
1751 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001752
1753 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001754 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001755 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001756 *
1757 * <p>When multiple device administrators attempt to control device
1758 * encryption, the most secure, supported setting will always be
1759 * used. If any device administrator requests device encryption,
1760 * it will be enabled; Conversely, if a device administrator
1761 * attempts to disable device encryption while another
1762 * device administrator has enabled it, the call to disable will
1763 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1764 *
1765 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001766 * written to other storage areas may or may not be encrypted, and this policy does not require
1767 * or control the encryption of any other storage areas.
1768 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1769 * {@code true}, then the directory returned by
1770 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1771 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001772 *
1773 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1774 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1775 * the encryption key may not be fully secured. For maximum security, the administrator should
1776 * also require (and check for) a pattern, PIN, or password.
1777 *
1778 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1779 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001780 * @return the new request status (for all active admins) - will be one of
1781 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1782 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1783 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001784 */
1785 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1786 if (mService != null) {
1787 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001788 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001789 } catch (RemoteException e) {
1790 Log.w(TAG, "Failed talking with device policy service", e);
1791 }
1792 }
1793 return ENCRYPTION_STATUS_UNSUPPORTED;
1794 }
1795
1796 /**
1797 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001798 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001799 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1801 * this will return the requested encryption setting as an aggregate of all active
1802 * administrators.
1803 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001804 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001805 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001806 if (mService != null) {
1807 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001808 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001809 } catch (RemoteException e) {
1810 Log.w(TAG, "Failed talking with device policy service", e);
1811 }
1812 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001813 return false;
1814 }
1815
1816 /**
1817 * Called by an application that is administering the device to
1818 * determine the current encryption status of the device.
1819 *
1820 * Depending on the returned status code, the caller may proceed in different
1821 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1822 * storage system does not support encryption. If the
1823 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1824 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1825 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1826 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1827 *
Robin Lee7e678712014-07-24 16:41:31 +01001828 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001829 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1830 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1831 */
1832 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001833 return getStorageEncryptionStatus(UserHandle.myUserId());
1834 }
1835
1836 /** @hide per-user version */
1837 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001838 if (mService != null) {
1839 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001840 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001841 } catch (RemoteException e) {
1842 Log.w(TAG, "Failed talking with device policy service", e);
1843 }
1844 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001845 return ENCRYPTION_STATUS_UNSUPPORTED;
1846 }
1847
1848 /**
Robin Lee7e678712014-07-24 16:41:31 +01001849 * Installs the given certificate as a user CA.
1850 *
1851 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1852 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001853 *
1854 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001855 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001856 */
Robin Lee7e678712014-07-24 16:41:31 +01001857 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001858 if (mService != null) {
1859 try {
Robin Lee7e678712014-07-24 16:41:31 +01001860 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001861 } catch (RemoteException e) {
1862 Log.w(TAG, "Failed talking with device policy service", e);
1863 }
1864 }
1865 return false;
1866 }
1867
1868 /**
Robin Lee7e678712014-07-24 16:41:31 +01001869 * Uninstalls the given certificate from trusted user CAs, if present.
1870 *
1871 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1872 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001873 */
Robin Lee7e678712014-07-24 16:41:31 +01001874 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001875 if (mService != null) {
1876 try {
Robin Lee306fe082014-06-19 14:04:24 +00001877 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001878 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001879 } catch (CertificateException e) {
1880 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001881 } catch (RemoteException e) {
1882 Log.w(TAG, "Failed talking with device policy service", e);
1883 }
1884 }
1885 }
1886
1887 /**
Robin Lee7e678712014-07-24 16:41:31 +01001888 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1889 * If a user has installed any certificates by other means than device policy these will be
1890 * included too.
1891 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001893 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001894 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001895 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01001896 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001897 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01001898 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001899 mService.enforceCanManageCaCerts(admin);
1900 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1901 for (String alias : certStore.userAliases()) {
1902 try {
1903 certs.add(certStore.getCertificate(alias).getEncoded());
1904 } catch (CertificateException ce) {
1905 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1906 }
1907 }
1908 } catch (RemoteException re) {
1909 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01001910 }
1911 }
1912 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001913 }
1914
1915 /**
Robin Lee7e678712014-07-24 16:41:31 +01001916 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1917 * means other than device policy will also be removed, except for system CA certificates.
1918 *
1919 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1920 */
1921 public void uninstallAllUserCaCerts(ComponentName admin) {
1922 if (mService != null) {
1923 for (String alias : new TrustedCertificateStore().userAliases()) {
1924 try {
1925 mService.uninstallCaCert(admin, alias);
1926 } catch (RemoteException re) {
1927 Log.w(TAG, "Failed talking with device policy service", re);
1928 }
1929 }
1930 }
1931 }
1932
1933 /**
1934 * Returns whether this certificate is installed as a trusted CA.
1935 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001936 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001937 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001938 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001939 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
1940 if (mService != null) {
1941 try {
1942 mService.enforceCanManageCaCerts(admin);
1943 return getCaCertAlias(certBuffer) != null;
1944 } catch (RemoteException re) {
1945 Log.w(TAG, "Failed talking with device policy service", re);
1946 } catch (CertificateException ce) {
1947 Log.w(TAG, "Could not parse certificate", ce);
1948 }
Maggie Benthallda51e682013-08-08 22:35:44 -04001949 }
1950 return false;
1951 }
1952
1953 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001954 * Called by a device or profile owner to install a certificate and private key pair. The
1955 * keypair will be visible to all apps within the profile.
1956 *
1957 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
1958 * @param privKey The private key to install.
1959 * @param cert The certificate to install.
1960 * @param alias The private key alias under which to install the certificate. If a certificate
1961 * with that alias already exists, it will be overwritten.
1962 * @return {@code true} if the keys were installed, {@code false} otherwise.
1963 */
1964 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
1965 String alias) {
1966 try {
1967 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01001968 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
1969 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
1970 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001971 } catch (RemoteException e) {
1972 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01001973 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
1974 Log.w(TAG, "Failed to obtain private key material", e);
1975 } catch (CertificateException | IOException e) {
1976 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001977 }
1978 return false;
1979 }
1980
1981 /**
Robin Lee306fe082014-06-19 14:04:24 +00001982 * Returns the alias of a given CA certificate in the certificate store, or null if it
1983 * doesn't exist.
1984 */
1985 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1986 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1987 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1988 new ByteArrayInputStream(certBuffer));
1989 return new TrustedCertificateStore().getCertificateAlias(cert);
1990 }
1991
1992 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001993 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07001994 * on the device, for this user. After setting this, no applications running as this user
1995 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07001996 *
1997 * <p>The calling device admin must have requested
1998 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1999 * this method; if it has not, a security exception will be thrown.
2000 *
2001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2002 * @param disabled Whether or not the camera should be disabled.
2003 */
2004 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2005 if (mService != null) {
2006 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002007 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002008 } catch (RemoteException e) {
2009 Log.w(TAG, "Failed talking with device policy service", e);
2010 }
2011 }
2012 }
2013
2014 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002015 * Determine whether or not the device's cameras have been disabled for this user,
2016 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002017 * @param admin The name of the admin component to check, or null to check if any admins
2018 * have disabled the camera
2019 */
2020 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002021 return getCameraDisabled(admin, UserHandle.myUserId());
2022 }
2023
2024 /** @hide per-user version */
2025 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002026 if (mService != null) {
2027 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002028 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002029 } catch (RemoteException e) {
2030 Log.w(TAG, "Failed talking with device policy service", e);
2031 }
2032 }
2033 return false;
2034 }
2035
2036 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002037 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2038 * screen capture also prevents the content from being shown on display devices that do not have
2039 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2040 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002041 *
2042 * <p>The calling device admin must be a device or profile owner. If it is not, a
2043 * security exception will be thrown.
2044 *
2045 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002046 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002047 */
2048 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2049 if (mService != null) {
2050 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002051 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002052 } catch (RemoteException e) {
2053 Log.w(TAG, "Failed talking with device policy service", e);
2054 }
2055 }
2056 }
2057
2058 /**
2059 * Determine whether or not screen capture has been disabled by the current
2060 * admin, if specified, or all admins.
2061 * @param admin The name of the admin component to check, or null to check if any admins
2062 * have disabled screen capture.
2063 */
2064 public boolean getScreenCaptureDisabled(ComponentName admin) {
2065 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2066 }
2067
2068 /** @hide per-user version */
2069 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2070 if (mService != null) {
2071 try {
2072 return mService.getScreenCaptureDisabled(admin, userHandle);
2073 } catch (RemoteException e) {
2074 Log.w(TAG, "Failed talking with device policy service", e);
2075 }
2076 }
2077 return false;
2078 }
2079
2080 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002081 * Called by a device owner to set whether auto time is required. If auto time is
2082 * required the user cannot set the date and time, but has to use network date and time.
2083 *
2084 * <p>Note: if auto time is required the user can still manually set the time zone.
2085 *
2086 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2087 * be thrown.
2088 *
2089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2090 * @param required Whether auto time is set required or not.
2091 */
2092 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2093 if (mService != null) {
2094 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002095 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002096 } catch (RemoteException e) {
2097 Log.w(TAG, "Failed talking with device policy service", e);
2098 }
2099 }
2100 }
2101
2102 /**
2103 * @return true if auto time is required.
2104 */
2105 public boolean getAutoTimeRequired() {
2106 if (mService != null) {
2107 try {
2108 return mService.getAutoTimeRequired();
2109 } catch (RemoteException e) {
2110 Log.w(TAG, "Failed talking with device policy service", e);
2111 }
2112 }
2113 return false;
2114 }
2115
2116 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002117 * Called by an application that is administering the device to disable keyguard customizations,
2118 * such as widgets. After setting this, keyguard features will be disabled according to the
2119 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002120 *
2121 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002122 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002123 * this method; if it has not, a security exception will be thrown.
2124 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002125 * <p>Calling this from a managed profile will throw a security exception.
2126 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002127 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002128 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2129 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002130 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2131 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002132 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002133 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002134 if (mService != null) {
2135 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002136 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002137 } catch (RemoteException e) {
2138 Log.w(TAG, "Failed talking with device policy service", e);
2139 }
2140 }
2141 }
2142
2143 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002144 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002145 * admin, if specified, or all admins.
2146 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002147 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002148 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2149 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002150 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002151 public int getKeyguardDisabledFeatures(ComponentName admin) {
2152 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002153 }
2154
2155 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002156 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002157 if (mService != null) {
2158 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002159 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002160 } catch (RemoteException e) {
2161 Log.w(TAG, "Failed talking with device policy service", e);
2162 }
2163 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002164 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002165 }
2166
2167 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002168 * @hide
2169 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002170 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002171 if (mService != null) {
2172 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002173 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002174 } catch (RemoteException e) {
2175 Log.w(TAG, "Failed talking with device policy service", e);
2176 }
2177 }
2178 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002179
Dianne Hackbornd6847842010-01-12 18:14:19 -08002180 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002181 * @hide
2182 */
2183 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2184 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2185 }
2186
2187 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002188 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002189 * @hide
2190 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002191 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002192 ActivityInfo ai;
2193 try {
2194 ai = mContext.getPackageManager().getReceiverInfo(cn,
2195 PackageManager.GET_META_DATA);
2196 } catch (PackageManager.NameNotFoundException e) {
2197 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2198 return null;
2199 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002200
Dianne Hackbornd6847842010-01-12 18:14:19 -08002201 ResolveInfo ri = new ResolveInfo();
2202 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002203
Dianne Hackbornd6847842010-01-12 18:14:19 -08002204 try {
2205 return new DeviceAdminInfo(mContext, ri);
2206 } catch (XmlPullParserException e) {
2207 Log.w(TAG, "Unable to parse device policy " + cn, e);
2208 return null;
2209 } catch (IOException e) {
2210 Log.w(TAG, "Unable to parse device policy " + cn, e);
2211 return null;
2212 }
2213 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002214
Dianne Hackbornd6847842010-01-12 18:14:19 -08002215 /**
2216 * @hide
2217 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002218 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2219 if (mService != null) {
2220 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002221 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002222 } catch (RemoteException e) {
2223 Log.w(TAG, "Failed talking with device policy service", e);
2224 }
2225 }
2226 }
2227
2228 /**
2229 * @hide
2230 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002231 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002232 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002233 if (mService != null) {
2234 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002235 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002236 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002237 } catch (RemoteException e) {
2238 Log.w(TAG, "Failed talking with device policy service", e);
2239 }
2240 }
2241 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002242
Dianne Hackbornd6847842010-01-12 18:14:19 -08002243 /**
2244 * @hide
2245 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002246 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002247 if (mService != null) {
2248 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002249 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002250 } catch (RemoteException e) {
2251 Log.w(TAG, "Failed talking with device policy service", e);
2252 }
2253 }
2254 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002255
Dianne Hackbornd6847842010-01-12 18:14:19 -08002256 /**
2257 * @hide
2258 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002259 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002260 if (mService != null) {
2261 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002262 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002263 } catch (RemoteException e) {
2264 Log.w(TAG, "Failed talking with device policy service", e);
2265 }
2266 }
2267 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002268
2269 /**
2270 * @hide
2271 * Sets the given package as the device owner. The package must already be installed and there
2272 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2273 * method must be called before the device is provisioned.
2274 * @param packageName the package name of the application to be registered as the device owner.
2275 * @return whether the package was successfully registered as the device owner.
2276 * @throws IllegalArgumentException if the package name is null or invalid
2277 * @throws IllegalStateException if a device owner is already registered or the device has
2278 * already been provisioned.
2279 */
2280 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2281 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002282 return setDeviceOwner(packageName, null);
2283 }
2284
2285 /**
2286 * @hide
2287 * Sets the given package as the device owner. The package must already be installed and there
2288 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2289 * method must be called before the device is provisioned.
2290 * @param packageName the package name of the application to be registered as the device owner.
2291 * @param ownerName the human readable name of the institution that owns this device.
2292 * @return whether the package was successfully registered as the device owner.
2293 * @throws IllegalArgumentException if the package name is null or invalid
2294 * @throws IllegalStateException if a device owner is already registered or the device has
2295 * already been provisioned.
2296 */
2297 public boolean setDeviceOwner(String packageName, String ownerName)
2298 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002299 if (mService != null) {
2300 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002301 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002302 } catch (RemoteException re) {
2303 Log.w(TAG, "Failed to set device owner");
2304 }
2305 }
2306 return false;
2307 }
2308
2309 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002310 * Used to determine if a particular package has been registered as a Device Owner app.
2311 * A device owner app is a special device admin that cannot be deactivated by the user, once
2312 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2313 * package is currently registered as the device owner app, pass in the package name from
2314 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2315 * admin apps that want to check if they are also registered as the device owner app. The
2316 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2317 * the setup process.
2318 * @param packageName the package name of the app, to compare with the registered device owner
2319 * app, if any.
2320 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002321 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002322 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002323 if (mService != null) {
2324 try {
2325 return mService.isDeviceOwner(packageName);
2326 } catch (RemoteException re) {
2327 Log.w(TAG, "Failed to check device owner");
2328 }
2329 }
2330 return false;
2331 }
2332
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002333 /**
2334 * @hide
2335 * Redirect to isDeviceOwnerApp.
2336 */
2337 public boolean isDeviceOwner(String packageName) {
2338 return isDeviceOwnerApp(packageName);
2339 }
2340
Jason Monkb0dced82014-06-06 14:36:20 -04002341 /**
2342 * Clears the current device owner. The caller must be the device owner.
2343 *
2344 * This function should be used cautiously as once it is called it cannot
2345 * be undone. The device owner can only be set as a part of device setup
2346 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002347 *
2348 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002349 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002350 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002351 if (mService != null) {
2352 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002353 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002354 } catch (RemoteException re) {
2355 Log.w(TAG, "Failed to clear device owner");
2356 }
2357 }
2358 }
2359
Amith Yamasani71e6c692013-03-24 17:39:28 -07002360 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002361 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002362 public String getDeviceOwner() {
2363 if (mService != null) {
2364 try {
2365 return mService.getDeviceOwner();
2366 } catch (RemoteException re) {
2367 Log.w(TAG, "Failed to get device owner");
2368 }
2369 }
2370 return null;
2371 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002372
2373 /** @hide */
2374 public String getDeviceOwnerName() {
2375 if (mService != null) {
2376 try {
2377 return mService.getDeviceOwnerName();
2378 } catch (RemoteException re) {
2379 Log.w(TAG, "Failed to get device owner");
2380 }
2381 }
2382 return null;
2383 }
Adam Connors776c5552014-01-09 10:42:56 +00002384
2385 /**
2386 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002387 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302388 * Sets the given component as an active admin and registers the package as the profile
2389 * owner for this user. The package must already be installed and there shouldn't be
2390 * an existing profile owner registered for this user. Also, this method must be called
2391 * before the user setup has been completed.
2392 * <p>
2393 * This method can only be called by system apps that hold MANAGE_USERS permission and
2394 * MANAGE_DEVICE_ADMINS permission.
2395 * @param admin The component to register as an active admin and profile owner.
2396 * @param ownerName The user-visible name of the entity that is managing this user.
2397 * @return whether the admin was successfully registered as the profile owner.
2398 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2399 * the user has already been set up.
2400 */
Justin Morey80440cc2014-07-24 09:16:35 -05002401 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302402 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2403 throws IllegalArgumentException {
2404 if (mService != null) {
2405 try {
2406 final int myUserId = UserHandle.myUserId();
2407 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002408 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302409 } catch (RemoteException re) {
2410 Log.w(TAG, "Failed to set profile owner " + re);
2411 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2412 }
2413 }
2414 return false;
2415 }
2416
2417 /**
2418 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002419 * Clears the active profile owner and removes all user restrictions. The caller must
2420 * be from the same package as the active profile owner for this user, otherwise a
2421 * SecurityException will be thrown.
2422 *
2423 * @param admin The component to remove as the profile owner.
2424 * @return
2425 */
2426 @SystemApi
2427 public void clearProfileOwner(ComponentName admin) {
2428 if (mService != null) {
2429 try {
2430 mService.clearProfileOwner(admin);
2431 } catch (RemoteException re) {
2432 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2433 }
2434 }
2435 }
2436
2437 /**
2438 * @hide
2439 * Checks if the user was already setup.
2440 */
2441 public boolean hasUserSetupCompleted() {
2442 if (mService != null) {
2443 try {
2444 return mService.hasUserSetupCompleted();
2445 } catch (RemoteException re) {
2446 Log.w(TAG, "Failed to check if user setup has completed");
2447 }
2448 }
2449 return true;
2450 }
2451
2452 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002453 * @hide
2454 * Sets the given component as the profile owner of the given user profile. The package must
2455 * already be installed and there shouldn't be an existing profile owner registered for this
2456 * user. Only the system can call this API if the user has already completed setup.
2457 * @param admin the component name to be registered as profile owner.
2458 * @param ownerName the human readable name of the organisation associated with this DPM.
2459 * @param userHandle the userId to set the profile owner for.
2460 * @return whether the component was successfully registered as the profile owner.
2461 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2462 * the user has already been set up.
2463 */
2464 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2465 throws IllegalArgumentException {
2466 if (admin == null) {
2467 throw new NullPointerException("admin cannot be null");
2468 }
Adam Connors776c5552014-01-09 10:42:56 +00002469 if (mService != null) {
2470 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002471 if (ownerName == null) {
2472 ownerName = "";
2473 }
2474 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002475 } catch (RemoteException re) {
2476 Log.w(TAG, "Failed to set profile owner", re);
2477 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2478 }
2479 }
2480 return false;
2481 }
2482
2483 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002484 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2485 * be used. Only the profile owner can call this.
2486 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002487 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002488 *
2489 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2490 */
2491 public void setProfileEnabled(ComponentName admin) {
2492 if (mService != null) {
2493 try {
2494 mService.setProfileEnabled(admin);
2495 } catch (RemoteException e) {
2496 Log.w(TAG, "Failed talking with device policy service", e);
2497 }
2498 }
2499 }
2500
2501 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002502 * Sets the name of the profile. In the device owner case it sets the name of the user
2503 * 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 +01002504 * never called by the profile or device owner, the name will be set to default values.
2505 *
2506 * @see #isProfileOwnerApp
2507 * @see #isDeviceOwnerApp
2508 *
2509 * @param profileName The name of the profile.
2510 */
2511 public void setProfileName(ComponentName who, String profileName) {
2512 if (mService != null) {
2513 try {
2514 mService.setProfileName(who, profileName);
2515 } catch (RemoteException e) {
2516 Log.w(TAG, "Failed talking with device policy service", e);
2517 }
2518 }
2519}
2520
2521 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002522 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002523 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002524 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002525 *
2526 * @param packageName The package name of the app to compare with the registered profile owner.
2527 * @return Whether or not the package is registered as the profile owner.
2528 */
2529 public boolean isProfileOwnerApp(String packageName) {
2530 if (mService != null) {
2531 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002532 ComponentName profileOwner = mService.getProfileOwner(
2533 Process.myUserHandle().getIdentifier());
2534 return profileOwner != null
2535 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002536 } catch (RemoteException re) {
2537 Log.w(TAG, "Failed to check profile owner");
2538 }
2539 }
2540 return false;
2541 }
2542
2543 /**
2544 * @hide
2545 * @return the packageName of the owner of the given user profile or null if no profile
2546 * owner has been set for that user.
2547 * @throws IllegalArgumentException if the userId is invalid.
2548 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002549 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002550 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002551 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2552 }
2553
2554 /**
2555 * @see #getProfileOwner()
2556 * @hide
2557 */
2558 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002559 if (mService != null) {
2560 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002561 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002562 } catch (RemoteException re) {
2563 Log.w(TAG, "Failed to get profile owner");
2564 throw new IllegalArgumentException(
2565 "Requested profile owner for invalid userId", re);
2566 }
2567 }
2568 return null;
2569 }
2570
2571 /**
2572 * @hide
2573 * @return the human readable name of the organisation associated with this DPM or null if
2574 * one is not set.
2575 * @throws IllegalArgumentException if the userId is invalid.
2576 */
2577 public String getProfileOwnerName() throws IllegalArgumentException {
2578 if (mService != null) {
2579 try {
2580 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2581 } catch (RemoteException re) {
2582 Log.w(TAG, "Failed to get profile owner");
2583 throw new IllegalArgumentException(
2584 "Requested profile owner for invalid userId", re);
2585 }
2586 }
2587 return null;
2588 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002589
2590 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002591 * @hide
2592 * @param user The user for whom to fetch the profile owner name, if any.
2593 * @return the human readable name of the organisation associated with this profile owner or
2594 * null if one is not set.
2595 * @throws IllegalArgumentException if the userId is invalid.
2596 */
2597 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002598 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002599 if (mService != null) {
2600 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002601 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002602 } catch (RemoteException re) {
2603 Log.w(TAG, "Failed to get profile owner");
2604 throw new IllegalArgumentException(
2605 "Requested profile owner for invalid userId", re);
2606 }
2607 }
2608 return null;
2609 }
2610
2611 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002612 * Called by a profile owner or device owner to add a default intent handler activity for
2613 * intents that match a certain intent filter. This activity will remain the default intent
2614 * handler even if the set of potential event handlers for the intent filter changes and if
2615 * the intent preferences are reset.
2616 *
2617 * <p>The default disambiguation mechanism takes over if the activity is not installed
2618 * (anymore). When the activity is (re)installed, it is automatically reset as default
2619 * intent handler for the filter.
2620 *
2621 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2622 * security exception will be thrown.
2623 *
2624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2625 * @param filter The IntentFilter for which a default handler is added.
2626 * @param activity The Activity that is added as default intent handler.
2627 */
2628 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2629 ComponentName activity) {
2630 if (mService != null) {
2631 try {
2632 mService.addPersistentPreferredActivity(admin, filter, activity);
2633 } catch (RemoteException e) {
2634 Log.w(TAG, "Failed talking with device policy service", e);
2635 }
2636 }
2637 }
2638
2639 /**
2640 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002641 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002642 *
2643 * <p>The calling device admin must be a profile owner. If it is not, a security
2644 * exception will be thrown.
2645 *
2646 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2647 * @param packageName The name of the package for which preferences are removed.
2648 */
2649 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2650 String packageName) {
2651 if (mService != null) {
2652 try {
2653 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2654 } catch (RemoteException e) {
2655 Log.w(TAG, "Failed talking with device policy service", e);
2656 }
2657 }
2658 }
Robin Lee66e5d962014-04-09 16:44:21 +01002659
2660 /**
2661 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002662 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002663 *
2664 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01002665 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01002666 *
2667 * <p>The application restrictions are only made visible to the target application and the
2668 * profile or device owner.
2669 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002670 * <p>If the restrictions are not available yet, but may be applied in the near future,
2671 * the admin can notify the target application of that by adding
2672 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
2673 *
Robin Lee66e5d962014-04-09 16:44:21 +01002674 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2675 * exception will be thrown.
2676 *
2677 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2678 * @param packageName The name of the package to update restricted settings for.
2679 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2680 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002681 *
2682 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01002683 */
2684 public void setApplicationRestrictions(ComponentName admin, String packageName,
2685 Bundle settings) {
2686 if (mService != null) {
2687 try {
2688 mService.setApplicationRestrictions(admin, packageName, settings);
2689 } catch (RemoteException e) {
2690 Log.w(TAG, "Failed talking with device policy service", e);
2691 }
2692 }
2693 }
2694
2695 /**
Jim Millere303bf42014-08-26 17:12:29 -07002696 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
2697 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
2698 * trust agents but those enabled by this function call. If flag
2699 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07002700 *
2701 * <p>The calling device admin must have requested
2702 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07002703 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07002704 *
2705 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07002706 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08002707 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07002708 * will be strictly disabled according to the state of the
2709 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
2710 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
2711 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
2712 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07002713 */
Jim Millere303bf42014-08-26 17:12:29 -07002714 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08002715 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07002716 if (mService != null) {
2717 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002718 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07002719 } catch (RemoteException e) {
2720 Log.w(TAG, "Failed talking with device policy service", e);
2721 }
2722 }
2723 }
2724
2725 /**
Jim Millere303bf42014-08-26 17:12:29 -07002726 * Gets configuration for the given trust agent based on aggregating all calls to
2727 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
2728 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07002729 *
Jim Millerb5db57a2015-01-14 18:17:19 -08002730 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2731 * this function returns a list of configurations for all admins that declare
2732 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
2733 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
2734 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
2735 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07002736 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07002737 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07002738 */
Jim Millere303bf42014-08-26 17:12:29 -07002739 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2740 ComponentName agent) {
2741 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
2742 }
2743
2744 /** @hide per-user version */
2745 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2746 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07002747 if (mService != null) {
2748 try {
Jim Millere303bf42014-08-26 17:12:29 -07002749 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07002750 } catch (RemoteException e) {
2751 Log.w(TAG, "Failed talking with device policy service", e);
2752 }
2753 }
Jim Millere303bf42014-08-26 17:12:29 -07002754 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07002755 }
2756
2757 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002758 * Called by a profile owner of a managed profile to set whether caller-Id information from
2759 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01002760 *
2761 * <p>The calling device admin must be a profile owner. If it is not, a
2762 * security exception will be thrown.
2763 *
2764 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2765 * @param disabled If true caller-Id information in the managed profile is not displayed.
2766 */
2767 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2768 if (mService != null) {
2769 try {
2770 mService.setCrossProfileCallerIdDisabled(who, disabled);
2771 } catch (RemoteException e) {
2772 Log.w(TAG, "Failed talking with device policy service", e);
2773 }
2774 }
2775 }
2776
2777 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002778 * Called by a profile owner of a managed profile to determine whether or not caller-Id
2779 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01002780 *
2781 * <p>The calling device admin must be a profile owner. If it is not, a
2782 * security exception will be thrown.
2783 *
2784 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2785 */
2786 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2787 if (mService != null) {
2788 try {
2789 return mService.getCrossProfileCallerIdDisabled(who);
2790 } catch (RemoteException e) {
2791 Log.w(TAG, "Failed talking with device policy service", e);
2792 }
2793 }
2794 return false;
2795 }
2796
2797 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002798 * Determine whether or not caller-Id information has been disabled.
2799 *
2800 * @param userHandle The user for whom to check the caller-id permission
2801 * @hide
2802 */
2803 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2804 if (mService != null) {
2805 try {
2806 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2807 } catch (RemoteException e) {
2808 Log.w(TAG, "Failed talking with device policy service", e);
2809 }
2810 }
2811 return false;
2812 }
2813
2814 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002815 * Called by the profile owner of a managed profile so that some intents sent in the managed
2816 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00002817 * Only activity intents are supported.
2818 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002819 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002820 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2821 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002822 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2823 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002824 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002825 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002826 if (mService != null) {
2827 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002828 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002829 } catch (RemoteException e) {
2830 Log.w(TAG, "Failed talking with device policy service", e);
2831 }
2832 }
2833 }
2834
2835 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002836 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
2837 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002838 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2840 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002841 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002842 if (mService != null) {
2843 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002844 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002845 } catch (RemoteException e) {
2846 Log.w(TAG, "Failed talking with device policy service", e);
2847 }
2848 }
2849 }
2850
2851 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002852 * Called by a profile or device owner to set the permitted accessibility services. When
2853 * set by a device owner or profile owner the restriction applies to all profiles of the
2854 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07002855 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002856 * By default the user can use any accessiblity service. When zero or more packages have
2857 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07002858 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002859 *
2860 * <p> Calling with a null value for the list disables the restriction so that all services
2861 * can be used, calling with an empty list only allows the builtin system's services.
2862 *
2863 * <p> System accesibility services are always available to the user the list can't modify
2864 * this.
2865 *
2866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2867 * @param packageNames List of accessibility service package names.
2868 *
2869 * @return true if setting the restriction succeeded. It fail if there is
2870 * one or more non-system accessibility services enabled, that are not in the list.
2871 */
2872 public boolean setPermittedAccessibilityServices(ComponentName admin,
2873 List<String> packageNames) {
2874 if (mService != null) {
2875 try {
2876 return mService.setPermittedAccessibilityServices(admin, packageNames);
2877 } catch (RemoteException e) {
2878 Log.w(TAG, "Failed talking with device policy service", e);
2879 }
2880 }
2881 return false;
2882 }
2883
2884 /**
2885 * Returns the list of permitted accessibility services set by this device or profile owner.
2886 *
2887 * <p>An empty list means no accessibility services except system services are allowed.
2888 * Null means all accessibility services are allowed.
2889 *
2890 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2891 * @return List of accessiblity service package names.
2892 */
2893 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2894 if (mService != null) {
2895 try {
2896 return mService.getPermittedAccessibilityServices(admin);
2897 } catch (RemoteException e) {
2898 Log.w(TAG, "Failed talking with device policy service", e);
2899 }
2900 }
2901 return null;
2902 }
2903
2904 /**
2905 * Returns the list of accessibility services permitted by the device or profiles
2906 * owners of this user.
2907 *
2908 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2909 * it will contain the intersection of the permitted lists for any device or profile
2910 * owners that apply to this user. It will also include any system accessibility services.
2911 *
2912 * @param userId which user to check for.
2913 * @return List of accessiblity service package names.
2914 * @hide
2915 */
2916 @SystemApi
2917 public List<String> getPermittedAccessibilityServices(int userId) {
2918 if (mService != null) {
2919 try {
2920 return mService.getPermittedAccessibilityServicesForUser(userId);
2921 } catch (RemoteException e) {
2922 Log.w(TAG, "Failed talking with device policy service", e);
2923 }
2924 }
2925 return null;
2926 }
2927
2928 /**
2929 * Called by a profile or device owner to set the permitted input methods services. When
2930 * set by a device owner or profile owner the restriction applies to all profiles of the
2931 * user the device owner or profile owner is an admin for.
2932 *
2933 * By default the user can use any input method. When zero or more packages have
2934 * been added, input method that are not in the list and not part of the system
2935 * can not be enabled by the user.
2936 *
2937 * This method will fail if it is called for a admin that is not for the foreground user
2938 * or a profile of the foreground user.
2939 *
2940 * <p> Calling with a null value for the list disables the restriction so that all input methods
2941 * can be used, calling with an empty list disables all but the system's own input methods.
2942 *
2943 * <p> System input methods are always available to the user this method can't modify this.
2944 *
2945 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2946 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00002947 * @return true if setting the restriction succeeded. It will fail if there are
2948 * one or more non-system input methods currently enabled that are not in
2949 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002950 */
2951 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2952 if (mService != null) {
2953 try {
2954 return mService.setPermittedInputMethods(admin, packageNames);
2955 } catch (RemoteException e) {
2956 Log.w(TAG, "Failed talking with device policy service", e);
2957 }
2958 }
2959 return false;
2960 }
2961
2962
2963 /**
2964 * Returns the list of permitted input methods set by this device or profile owner.
2965 *
2966 * <p>An empty list means no input methods except system input methods are allowed.
2967 * Null means all input methods are allowed.
2968 *
2969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2970 * @return List of input method package names.
2971 */
2972 public List<String> getPermittedInputMethods(ComponentName admin) {
2973 if (mService != null) {
2974 try {
2975 return mService.getPermittedInputMethods(admin);
2976 } catch (RemoteException e) {
2977 Log.w(TAG, "Failed talking with device policy service", e);
2978 }
2979 }
2980 return null;
2981 }
2982
2983 /**
2984 * Returns the list of input methods permitted by the device or profiles
2985 * owners of the current user.
2986 *
2987 * <p>Null means all input methods are allowed, if a non-null list is returned
2988 * it will contain the intersection of the permitted lists for any device or profile
2989 * owners that apply to this user. It will also include any system input methods.
2990 *
2991 * @return List of input method package names.
2992 * @hide
2993 */
2994 @SystemApi
2995 public List<String> getPermittedInputMethodsForCurrentUser() {
2996 if (mService != null) {
2997 try {
2998 return mService.getPermittedInputMethodsForCurrentUser();
2999 } catch (RemoteException e) {
3000 Log.w(TAG, "Failed talking with device policy service", e);
3001 }
3002 }
3003 return null;
3004 }
3005
3006 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003007 * Called by a device owner to create a user with the specified name. The UserHandle returned
3008 * by this method should not be persisted as user handles are recycled as users are removed and
3009 * created. If you need to persist an identifier for this user, use
3010 * {@link UserManager#getSerialNumberForUser}.
3011 *
3012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3013 * @param name the user's name
3014 * @see UserHandle
3015 * @return the UserHandle object for the created user, or null if the user could not be created.
3016 */
3017 public UserHandle createUser(ComponentName admin, String name) {
3018 try {
3019 return mService.createUser(admin, name);
3020 } catch (RemoteException re) {
3021 Log.w(TAG, "Could not create a user", re);
3022 }
3023 return null;
3024 }
3025
3026 /**
Jason Monk03978a42014-06-10 15:05:30 -04003027 * Called by a device owner to create a user with the specified name. The UserHandle returned
3028 * by this method should not be persisted as user handles are recycled as users are removed and
3029 * created. If you need to persist an identifier for this user, use
3030 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3031 * immediately.
3032 *
3033 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3034 * as registered as an active admin on the new user. The profile owner package will be
3035 * installed on the new user if it already is installed on the device.
3036 *
3037 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3038 * profileOwnerComponent when onEnable is called.
3039 *
3040 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3041 * @param name the user's name
3042 * @param ownerName the human readable name of the organisation associated with this DPM.
3043 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3044 * the user.
3045 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3046 * on the new user.
3047 * @see UserHandle
3048 * @return the UserHandle object for the created user, or null if the user could not be created.
3049 */
3050 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3051 ComponentName profileOwnerComponent, Bundle adminExtras) {
3052 try {
3053 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3054 adminExtras);
3055 } catch (RemoteException re) {
3056 Log.w(TAG, "Could not create a user", re);
3057 }
3058 return null;
3059 }
3060
3061 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003062 * Called by a device owner to remove a user and all associated data. The primary user can
3063 * not be removed.
3064 *
3065 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3066 * @param userHandle the user to remove.
3067 * @return {@code true} if the user was removed, {@code false} otherwise.
3068 */
3069 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3070 try {
3071 return mService.removeUser(admin, userHandle);
3072 } catch (RemoteException re) {
3073 Log.w(TAG, "Could not remove user ", re);
3074 return false;
3075 }
3076 }
3077
3078 /**
Jason Monk582d9112014-07-09 19:57:08 -04003079 * Called by a device owner to switch the specified user to the foreground.
3080 *
3081 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3082 * @param userHandle the user to switch to; null will switch to primary.
3083 * @return {@code true} if the switch was successful, {@code false} otherwise.
3084 *
3085 * @see Intent#ACTION_USER_FOREGROUND
3086 */
3087 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3088 try {
3089 return mService.switchUser(admin, userHandle);
3090 } catch (RemoteException re) {
3091 Log.w(TAG, "Could not switch user ", re);
3092 return false;
3093 }
3094 }
3095
3096 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003097 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003098 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003099 *
3100 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3101 * exception will be thrown.
3102 *
3103 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3104 * @param packageName The name of the package to fetch restricted settings of.
3105 * @return {@link Bundle} of settings corresponding to what was set last time
3106 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3107 * if no restrictions have been set.
3108 */
3109 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3110 if (mService != null) {
3111 try {
3112 return mService.getApplicationRestrictions(admin, packageName);
3113 } catch (RemoteException e) {
3114 Log.w(TAG, "Failed talking with device policy service", e);
3115 }
3116 }
3117 return null;
3118 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003119
3120 /**
3121 * Called by a profile or device owner to set a user restriction specified
3122 * by the key.
3123 * <p>
3124 * The calling device admin must be a profile or device owner; if it is not,
3125 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003126 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003127 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3128 * with.
3129 * @param key The key of the restriction. See the constants in
3130 * {@link android.os.UserManager} for the list of keys.
3131 */
3132 public void addUserRestriction(ComponentName admin, String key) {
3133 if (mService != null) {
3134 try {
3135 mService.setUserRestriction(admin, key, true);
3136 } catch (RemoteException e) {
3137 Log.w(TAG, "Failed talking with device policy service", e);
3138 }
3139 }
3140 }
3141
3142 /**
3143 * Called by a profile or device owner to clear a user restriction specified
3144 * by the key.
3145 * <p>
3146 * The calling device admin must be a profile or device owner; if it is not,
3147 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003148 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003149 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3150 * with.
3151 * @param key The key of the restriction. See the constants in
3152 * {@link android.os.UserManager} for the list of keys.
3153 */
3154 public void clearUserRestriction(ComponentName admin, String key) {
3155 if (mService != null) {
3156 try {
3157 mService.setUserRestriction(admin, key, false);
3158 } catch (RemoteException e) {
3159 Log.w(TAG, "Failed talking with device policy service", e);
3160 }
3161 }
3162 }
Adam Connors010cfd42014-04-16 12:48:13 +01003163
3164 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003165 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003166 * is unavailable for use, but the data and actual package file remain.
3167 *
3168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003169 * @param packageName The name of the package to hide or unhide.
3170 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3171 * unhidden.
3172 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003173 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003174 public boolean setApplicationHidden(ComponentName admin, String packageName,
3175 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003176 if (mService != null) {
3177 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003178 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003179 } catch (RemoteException e) {
3180 Log.w(TAG, "Failed talking with device policy service", e);
3181 }
3182 }
3183 return false;
3184 }
3185
3186 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003187 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003188 *
3189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003190 * @param packageName The name of the package to retrieve the hidden status of.
3191 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003192 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003193 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003194 if (mService != null) {
3195 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003196 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003197 } catch (RemoteException e) {
3198 Log.w(TAG, "Failed talking with device policy service", e);
3199 }
3200 }
3201 return false;
3202 }
3203
3204 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003205 * Called by profile or device owner to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003206 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003207 *
3208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3209 * @param packageName The package to be re-enabled in the current profile.
3210 */
3211 public void enableSystemApp(ComponentName admin, String packageName) {
3212 if (mService != null) {
3213 try {
3214 mService.enableSystemApp(admin, packageName);
3215 } catch (RemoteException e) {
3216 Log.w(TAG, "Failed to install package: " + packageName);
3217 }
3218 }
3219 }
3220
3221 /**
3222 * Called by profile or device owner to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003223 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003224 *
3225 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3226 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3227 * intent will be re-enabled in the current profile.
3228 * @return int The number of activities that matched the intent and were installed.
3229 */
3230 public int enableSystemApp(ComponentName admin, Intent intent) {
3231 if (mService != null) {
3232 try {
3233 return mService.enableSystemAppWithIntent(admin, intent);
3234 } catch (RemoteException e) {
3235 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3236 }
3237 }
3238 return 0;
3239 }
3240
3241 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003242 * Called by a device owner or profile owner to disable account management for a specific type
3243 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003244 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003245 * <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 +01003246 * security exception will be thrown.
3247 *
3248 * <p>When account management is disabled for an account type, adding or removing an account
3249 * of that type will not be possible.
3250 *
3251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3252 * @param accountType For which account management is disabled or enabled.
3253 * @param disabled The boolean indicating that account management will be disabled (true) or
3254 * enabled (false).
3255 */
3256 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3257 boolean disabled) {
3258 if (mService != null) {
3259 try {
3260 mService.setAccountManagementDisabled(admin, accountType, disabled);
3261 } catch (RemoteException e) {
3262 Log.w(TAG, "Failed talking with device policy service", e);
3263 }
3264 }
3265 }
3266
3267 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003268 * Gets the array of accounts for which account management is disabled by the profile owner.
3269 *
3270 * <p> Account management can be disabled/enabled by calling
3271 * {@link #setAccountManagementDisabled}.
3272 *
3273 * @return a list of account types for which account management has been disabled.
3274 *
3275 * @see #setAccountManagementDisabled
3276 */
3277 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003278 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003279 }
3280
3281 /**
3282 * @see #getAccountTypesWithManagementDisabled()
3283 * @hide
3284 */
3285 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003286 if (mService != null) {
3287 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003288 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003289 } catch (RemoteException e) {
3290 Log.w(TAG, "Failed talking with device policy service", e);
3291 }
3292 }
3293
3294 return null;
3295 }
justinzhang511e0d82014-03-24 16:09:24 -04003296
3297 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003298 * Sets which packages may enter lock task mode.
3299 *
3300 * <p>Any packages that shares uid with an allowed package will also be allowed
3301 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003302 *
Jason Monkc5185f22014-06-24 11:12:42 -04003303 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003304 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003306 *
3307 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003308 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3309 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003310 */
Jason Monk48aacba2014-08-13 16:29:08 -04003311 public void setLockTaskPackages(ComponentName admin, String[] packages)
3312 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003313 if (mService != null) {
3314 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003315 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003316 } catch (RemoteException e) {
3317 Log.w(TAG, "Failed talking with device policy service", e);
3318 }
3319 }
3320 }
3321
3322 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003323 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003324 *
3325 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003326 * @hide
3327 */
Jason Monk48aacba2014-08-13 16:29:08 -04003328 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003329 if (mService != null) {
3330 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003331 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003332 } catch (RemoteException e) {
3333 Log.w(TAG, "Failed talking with device policy service", e);
3334 }
3335 }
3336 return null;
3337 }
3338
3339 /**
3340 * This function lets the caller know whether the given component is allowed to start the
3341 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003342 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003343 */
Jason Monkd7b86212014-06-16 13:15:38 -04003344 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003345 if (mService != null) {
3346 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003347 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003348 } catch (RemoteException e) {
3349 Log.w(TAG, "Failed talking with device policy service", e);
3350 }
3351 }
3352 return false;
3353 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003354
3355 /**
3356 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3357 * 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 -04003358 * <p>The settings that can be updated with this method are:
3359 * <ul>
3360 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3361 * <li>{@link Settings.Global#AUTO_TIME}</li>
3362 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
3363 * <li>{@link Settings.Global#BLUETOOTH_ON}</li>
3364 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3365 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3366 * <li>{@link Settings.Global#MODE_RINGER}</li>
3367 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3368 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
3369 * <li>{@link Settings.Global#WIFI_ON}</li>
3370 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3371 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003372 *
3373 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3374 * @param setting The name of the setting to update.
3375 * @param value The value to update the setting to.
3376 */
3377 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3378 if (mService != null) {
3379 try {
3380 mService.setGlobalSetting(admin, setting, value);
3381 } catch (RemoteException e) {
3382 Log.w(TAG, "Failed talking with device policy service", e);
3383 }
3384 }
3385 }
3386
3387 /**
3388 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3389 * that the value of the setting is in the correct form for the setting type should be performed
3390 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003391 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003392 * <ul>
3393 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003394 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003395 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3396 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003397 * <p>A device owner can additionally update the following settings:
3398 * <ul>
3399 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3400 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3402 * @param setting The name of the setting to update.
3403 * @param value The value to update the setting to.
3404 */
3405 public void setSecureSetting(ComponentName admin, String setting, String value) {
3406 if (mService != null) {
3407 try {
3408 mService.setSecureSetting(admin, setting, value);
3409 } catch (RemoteException e) {
3410 Log.w(TAG, "Failed talking with device policy service", e);
3411 }
3412 }
3413 }
3414
Amith Yamasanif20d6402014-05-24 15:34:37 -07003415 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003416 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003417 * making permission requests of a local or remote administrator of the user.
3418 * <p/>
3419 * Only a profile owner can designate the restrictions provider.
3420 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003421 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003422 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003423 * it removes the restrictions provider previously assigned.
3424 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003425 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003426 if (mService != null) {
3427 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003428 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003429 } catch (RemoteException re) {
3430 Log.w(TAG, "Failed to set permission provider on device policy service");
3431 }
3432 }
3433 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003434
3435 /**
3436 * Called by profile or device owners to set the master volume mute on or off.
3437 *
3438 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3439 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3440 */
3441 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3442 if (mService != null) {
3443 try {
3444 mService.setMasterVolumeMuted(admin, on);
3445 } catch (RemoteException re) {
3446 Log.w(TAG, "Failed to setMasterMute on device policy service");
3447 }
3448 }
3449 }
3450
3451 /**
3452 * Called by profile or device owners to check whether the master volume mute is on or off.
3453 *
3454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3455 * @return {@code true} if master volume is muted, {@code false} if it's not.
3456 */
3457 public boolean isMasterVolumeMuted(ComponentName admin) {
3458 if (mService != null) {
3459 try {
3460 return mService.isMasterVolumeMuted(admin);
3461 } catch (RemoteException re) {
3462 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3463 }
3464 }
3465 return false;
3466 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003467
3468 /**
3469 * Called by profile or device owners to change whether a user can uninstall
3470 * a package.
3471 *
3472 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3473 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003474 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003475 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003476 public void setUninstallBlocked(ComponentName admin, String packageName,
3477 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003478 if (mService != null) {
3479 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003480 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003481 } catch (RemoteException re) {
3482 Log.w(TAG, "Failed to call block uninstall on device policy service");
3483 }
3484 }
3485 }
3486
3487 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003488 * Check whether the current user has been blocked by device policy from uninstalling a package.
3489 * Requires the caller to be the profile owner if checking a specific admin's policy.
Kenny Guyc13053b2014-05-29 14:17:17 +01003490 *
Rubin Xua97855b2014-11-07 05:41:00 +00003491 * @param admin The name of the admin component whose blocking policy will be checked, or null
3492 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003493 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003494 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003495 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003496 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003497 if (mService != null) {
3498 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003499 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003500 } catch (RemoteException re) {
3501 Log.w(TAG, "Failed to call block uninstall on device policy service");
3502 }
3503 }
3504 return false;
3505 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003506
3507 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003508 * Called by the profile owner of a managed profile to enable widget providers from a
3509 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003510 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003511 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003512 * a package may have zero or more provider components, where each component
3513 * provides a different widget type.
3514 * <p>
3515 * <strong>Note:</strong> By default no widget provider package is white-listed.
3516 * </p>
3517 *
3518 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3519 * @param packageName The package from which widget providers are white-listed.
3520 * @return Whether the package was added.
3521 *
3522 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3523 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3524 */
3525 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3526 if (mService != null) {
3527 try {
3528 return mService.addCrossProfileWidgetProvider(admin, packageName);
3529 } catch (RemoteException re) {
3530 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3531 }
3532 }
3533 return false;
3534 }
3535
3536 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003537 * Called by the profile owner of a managed profile to disable widget providers from a given
3538 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003539 * package should have been added via {@link #addCrossProfileWidgetProvider(
3540 * android.content.ComponentName, String)}.
3541 * <p>
3542 * <strong>Note:</strong> By default no widget provider package is white-listed.
3543 * </p>
3544 *
3545 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3546 * @param packageName The package from which widget providers are no longer
3547 * white-listed.
3548 * @return Whether the package was removed.
3549 *
3550 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3551 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3552 */
3553 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3554 if (mService != null) {
3555 try {
3556 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3557 } catch (RemoteException re) {
3558 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3559 }
3560 }
3561 return false;
3562 }
3563
3564 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003565 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003566 * available in the parent profile.
3567 *
3568 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3569 * @return The white-listed package list.
3570 *
3571 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3572 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3573 */
3574 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3575 if (mService != null) {
3576 try {
3577 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3578 if (providers != null) {
3579 return providers;
3580 }
3581 } catch (RemoteException re) {
3582 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3583 }
3584 }
3585 return Collections.emptyList();
3586 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003587}