blob: d7b904ff06adf9b8d39a05e29a1973828ced4f86 [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 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800343 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000344 * 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 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001686 * Result code for {@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 /**
Robin Lee3795fb02015-02-16 14:17:23 +00001702 * Result code for {@link #getStorageEncryptionStatus}:
1703 * indicating that encryption is active, but an encryption key has not
1704 * been set by the user.
1705 */
1706 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
1707
1708 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001709 * Activity action: begin the process of encrypting data on the device. This activity should
1710 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1711 * After resuming from this activity, use {@link #getStorageEncryption}
1712 * to check encryption status. However, on some devices this activity may never return, as
1713 * it may trigger a reboot and in some cases a complete data wipe of the device.
1714 */
1715 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1716 public static final String ACTION_START_ENCRYPTION
1717 = "android.app.action.START_ENCRYPTION";
1718
1719 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001720 * Widgets are enabled in keyguard
1721 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001722 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001723
1724 /**
Jim Miller50e62182014-04-23 17:25:00 -07001725 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001726 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001727 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1728
1729 /**
1730 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1731 */
1732 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1733
1734 /**
Jim Miller50e62182014-04-23 17:25:00 -07001735 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1736 */
1737 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1738
1739 /**
1740 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1741 */
1742 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1743
1744 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001745 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001746 * (e.g. PIN/Pattern/Password).
1747 */
1748 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1749
1750 /**
Jim Miller06e34502014-07-17 14:46:05 -07001751 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1752 */
1753 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1754
1755 /**
Jim Miller35207742012-11-02 15:33:20 -07001756 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001757 */
1758 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001759
1760 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001761 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001762 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001763 *
1764 * <p>When multiple device administrators attempt to control device
1765 * encryption, the most secure, supported setting will always be
1766 * used. If any device administrator requests device encryption,
1767 * it will be enabled; Conversely, if a device administrator
1768 * attempts to disable device encryption while another
1769 * device administrator has enabled it, the call to disable will
1770 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1771 *
1772 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001773 * written to other storage areas may or may not be encrypted, and this policy does not require
1774 * or control the encryption of any other storage areas.
1775 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1776 * {@code true}, then the directory returned by
1777 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1778 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001779 *
1780 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1781 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1782 * the encryption key may not be fully secured. For maximum security, the administrator should
1783 * also require (and check for) a pattern, PIN, or password.
1784 *
1785 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1786 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001787 * @return the new request status (for all active admins) - will be one of
1788 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1789 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1790 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001791 */
1792 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1793 if (mService != null) {
1794 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001795 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001796 } catch (RemoteException e) {
1797 Log.w(TAG, "Failed talking with device policy service", e);
1798 }
1799 }
1800 return ENCRYPTION_STATUS_UNSUPPORTED;
1801 }
1802
1803 /**
1804 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001805 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001806 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001807 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1808 * this will return the requested encryption setting as an aggregate of all active
1809 * administrators.
1810 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001811 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001812 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001813 if (mService != null) {
1814 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001815 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001816 } catch (RemoteException e) {
1817 Log.w(TAG, "Failed talking with device policy service", e);
1818 }
1819 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001820 return false;
1821 }
1822
1823 /**
1824 * Called by an application that is administering the device to
1825 * determine the current encryption status of the device.
1826 *
1827 * Depending on the returned status code, the caller may proceed in different
1828 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1829 * storage system does not support encryption. If the
1830 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1831 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00001832 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
1833 * storage system has enabled encryption but no password is set so further action
1834 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08001835 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1836 *
Robin Lee7e678712014-07-24 16:41:31 +01001837 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001838 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00001839 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
1840 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08001841 */
1842 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001843 return getStorageEncryptionStatus(UserHandle.myUserId());
1844 }
1845
1846 /** @hide per-user version */
1847 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001848 if (mService != null) {
1849 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001850 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001851 } catch (RemoteException e) {
1852 Log.w(TAG, "Failed talking with device policy service", e);
1853 }
1854 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001855 return ENCRYPTION_STATUS_UNSUPPORTED;
1856 }
1857
1858 /**
Robin Lee7e678712014-07-24 16:41:31 +01001859 * Installs the given certificate as a user CA.
1860 *
1861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1862 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001863 *
1864 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001865 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001866 */
Robin Lee7e678712014-07-24 16:41:31 +01001867 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001868 if (mService != null) {
1869 try {
Robin Lee7e678712014-07-24 16:41:31 +01001870 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001871 } catch (RemoteException e) {
1872 Log.w(TAG, "Failed talking with device policy service", e);
1873 }
1874 }
1875 return false;
1876 }
1877
1878 /**
Robin Lee7e678712014-07-24 16:41:31 +01001879 * Uninstalls the given certificate from trusted user CAs, if present.
1880 *
1881 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1882 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001883 */
Robin Lee7e678712014-07-24 16:41:31 +01001884 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001885 if (mService != null) {
1886 try {
Robin Lee306fe082014-06-19 14:04:24 +00001887 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001888 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001889 } catch (CertificateException e) {
1890 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001891 } catch (RemoteException e) {
1892 Log.w(TAG, "Failed talking with device policy service", e);
1893 }
1894 }
1895 }
1896
1897 /**
Robin Lee7e678712014-07-24 16:41:31 +01001898 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1899 * If a user has installed any certificates by other means than device policy these will be
1900 * included too.
1901 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001902 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001903 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001904 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001905 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01001906 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001907 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01001908 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001909 mService.enforceCanManageCaCerts(admin);
1910 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1911 for (String alias : certStore.userAliases()) {
1912 try {
1913 certs.add(certStore.getCertificate(alias).getEncoded());
1914 } catch (CertificateException ce) {
1915 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1916 }
1917 }
1918 } catch (RemoteException re) {
1919 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01001920 }
1921 }
1922 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001923 }
1924
1925 /**
Robin Lee7e678712014-07-24 16:41:31 +01001926 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1927 * means other than device policy will also be removed, except for system CA certificates.
1928 *
1929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1930 */
1931 public void uninstallAllUserCaCerts(ComponentName admin) {
1932 if (mService != null) {
1933 for (String alias : new TrustedCertificateStore().userAliases()) {
1934 try {
1935 mService.uninstallCaCert(admin, alias);
1936 } catch (RemoteException re) {
1937 Log.w(TAG, "Failed talking with device policy service", re);
1938 }
1939 }
1940 }
1941 }
1942
1943 /**
1944 * Returns whether this certificate is installed as a trusted CA.
1945 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001946 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001947 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001948 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001949 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
1950 if (mService != null) {
1951 try {
1952 mService.enforceCanManageCaCerts(admin);
1953 return getCaCertAlias(certBuffer) != null;
1954 } catch (RemoteException re) {
1955 Log.w(TAG, "Failed talking with device policy service", re);
1956 } catch (CertificateException ce) {
1957 Log.w(TAG, "Could not parse certificate", ce);
1958 }
Maggie Benthallda51e682013-08-08 22:35:44 -04001959 }
1960 return false;
1961 }
1962
1963 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001964 * Called by a device or profile owner to install a certificate and private key pair. The
1965 * keypair will be visible to all apps within the profile.
1966 *
1967 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
1968 * @param privKey The private key to install.
1969 * @param cert The certificate to install.
1970 * @param alias The private key alias under which to install the certificate. If a certificate
1971 * with that alias already exists, it will be overwritten.
1972 * @return {@code true} if the keys were installed, {@code false} otherwise.
1973 */
1974 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
1975 String alias) {
1976 try {
1977 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01001978 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
1979 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
1980 return mService.installKeyPair(who, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001981 } catch (RemoteException e) {
1982 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01001983 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
1984 Log.w(TAG, "Failed to obtain private key material", e);
1985 } catch (CertificateException | IOException e) {
1986 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001987 }
1988 return false;
1989 }
1990
1991 /**
Robin Lee306fe082014-06-19 14:04:24 +00001992 * Returns the alias of a given CA certificate in the certificate store, or null if it
1993 * doesn't exist.
1994 */
1995 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1996 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1997 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1998 new ByteArrayInputStream(certBuffer));
1999 return new TrustedCertificateStore().getCertificateAlias(cert);
2000 }
2001
2002 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002003 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002004 * on the device, for this user. After setting this, no applications running as this user
2005 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002006 *
2007 * <p>The calling device admin must have requested
2008 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2009 * this method; if it has not, a security exception will be thrown.
2010 *
2011 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2012 * @param disabled Whether or not the camera should be disabled.
2013 */
2014 public void setCameraDisabled(ComponentName admin, boolean disabled) {
2015 if (mService != null) {
2016 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002017 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002018 } catch (RemoteException e) {
2019 Log.w(TAG, "Failed talking with device policy service", e);
2020 }
2021 }
2022 }
2023
2024 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002025 * Determine whether or not the device's cameras have been disabled for this user,
2026 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07002027 * @param admin The name of the admin component to check, or null to check if any admins
2028 * have disabled the camera
2029 */
2030 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002031 return getCameraDisabled(admin, UserHandle.myUserId());
2032 }
2033
2034 /** @hide per-user version */
2035 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002036 if (mService != null) {
2037 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002038 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002039 } catch (RemoteException e) {
2040 Log.w(TAG, "Failed talking with device policy service", e);
2041 }
2042 }
2043 return false;
2044 }
2045
2046 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002047 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2048 * screen capture also prevents the content from being shown on display devices that do not have
2049 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2050 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002051 *
2052 * <p>The calling device admin must be a device or profile owner. If it is not, a
2053 * security exception will be thrown.
2054 *
2055 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002056 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002057 */
2058 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2059 if (mService != null) {
2060 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002061 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002062 } catch (RemoteException e) {
2063 Log.w(TAG, "Failed talking with device policy service", e);
2064 }
2065 }
2066 }
2067
2068 /**
2069 * Determine whether or not screen capture has been disabled by the current
2070 * admin, if specified, or all admins.
2071 * @param admin The name of the admin component to check, or null to check if any admins
2072 * have disabled screen capture.
2073 */
2074 public boolean getScreenCaptureDisabled(ComponentName admin) {
2075 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2076 }
2077
2078 /** @hide per-user version */
2079 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2080 if (mService != null) {
2081 try {
2082 return mService.getScreenCaptureDisabled(admin, userHandle);
2083 } catch (RemoteException e) {
2084 Log.w(TAG, "Failed talking with device policy service", e);
2085 }
2086 }
2087 return false;
2088 }
2089
2090 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002091 * Called by a device owner to set whether auto time is required. If auto time is
2092 * required the user cannot set the date and time, but has to use network date and time.
2093 *
2094 * <p>Note: if auto time is required the user can still manually set the time zone.
2095 *
2096 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2097 * be thrown.
2098 *
2099 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2100 * @param required Whether auto time is set required or not.
2101 */
2102 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2103 if (mService != null) {
2104 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002105 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002106 } catch (RemoteException e) {
2107 Log.w(TAG, "Failed talking with device policy service", e);
2108 }
2109 }
2110 }
2111
2112 /**
2113 * @return true if auto time is required.
2114 */
2115 public boolean getAutoTimeRequired() {
2116 if (mService != null) {
2117 try {
2118 return mService.getAutoTimeRequired();
2119 } catch (RemoteException e) {
2120 Log.w(TAG, "Failed talking with device policy service", e);
2121 }
2122 }
2123 return false;
2124 }
2125
2126 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002127 * Called by an application that is administering the device to disable keyguard customizations,
2128 * such as widgets. After setting this, keyguard features will be disabled according to the
2129 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002130 *
2131 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002132 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002133 * this method; if it has not, a security exception will be thrown.
2134 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002135 * <p>Calling this from a managed profile will throw a security exception.
2136 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002138 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2139 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002140 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2141 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002142 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002143 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002144 if (mService != null) {
2145 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002146 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002147 } catch (RemoteException e) {
2148 Log.w(TAG, "Failed talking with device policy service", e);
2149 }
2150 }
2151 }
2152
2153 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002154 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002155 * admin, if specified, or all admins.
2156 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002157 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002158 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2159 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002160 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002161 public int getKeyguardDisabledFeatures(ComponentName admin) {
2162 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002163 }
2164
2165 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002166 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002167 if (mService != null) {
2168 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002169 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002170 } catch (RemoteException e) {
2171 Log.w(TAG, "Failed talking with device policy service", e);
2172 }
2173 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002174 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002175 }
2176
2177 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002178 * @hide
2179 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002180 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002181 if (mService != null) {
2182 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002183 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002184 } catch (RemoteException e) {
2185 Log.w(TAG, "Failed talking with device policy service", e);
2186 }
2187 }
2188 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002189
Dianne Hackbornd6847842010-01-12 18:14:19 -08002190 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002191 * @hide
2192 */
2193 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2194 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2195 }
2196
2197 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002198 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002199 * @hide
2200 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002201 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002202 ActivityInfo ai;
2203 try {
2204 ai = mContext.getPackageManager().getReceiverInfo(cn,
2205 PackageManager.GET_META_DATA);
2206 } catch (PackageManager.NameNotFoundException e) {
2207 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2208 return null;
2209 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002210
Dianne Hackbornd6847842010-01-12 18:14:19 -08002211 ResolveInfo ri = new ResolveInfo();
2212 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002213
Dianne Hackbornd6847842010-01-12 18:14:19 -08002214 try {
2215 return new DeviceAdminInfo(mContext, ri);
2216 } catch (XmlPullParserException e) {
2217 Log.w(TAG, "Unable to parse device policy " + cn, e);
2218 return null;
2219 } catch (IOException e) {
2220 Log.w(TAG, "Unable to parse device policy " + cn, e);
2221 return null;
2222 }
2223 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002224
Dianne Hackbornd6847842010-01-12 18:14:19 -08002225 /**
2226 * @hide
2227 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002228 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2229 if (mService != null) {
2230 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002231 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002232 } catch (RemoteException e) {
2233 Log.w(TAG, "Failed talking with device policy service", e);
2234 }
2235 }
2236 }
2237
2238 /**
2239 * @hide
2240 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002241 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002242 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002243 if (mService != null) {
2244 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002245 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002246 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002247 } catch (RemoteException e) {
2248 Log.w(TAG, "Failed talking with device policy service", e);
2249 }
2250 }
2251 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002252
Dianne Hackbornd6847842010-01-12 18:14:19 -08002253 /**
2254 * @hide
2255 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002256 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002257 if (mService != null) {
2258 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002259 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002260 } catch (RemoteException e) {
2261 Log.w(TAG, "Failed talking with device policy service", e);
2262 }
2263 }
2264 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002265
Dianne Hackbornd6847842010-01-12 18:14:19 -08002266 /**
2267 * @hide
2268 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002269 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002270 if (mService != null) {
2271 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002272 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002273 } catch (RemoteException e) {
2274 Log.w(TAG, "Failed talking with device policy service", e);
2275 }
2276 }
2277 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002278
2279 /**
2280 * @hide
2281 * Sets the given package as the device owner. The package must already be installed and there
2282 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2283 * method must be called before the device is provisioned.
2284 * @param packageName the package name of the application to be registered as the device owner.
2285 * @return whether the package was successfully registered as the device owner.
2286 * @throws IllegalArgumentException if the package name is null or invalid
2287 * @throws IllegalStateException if a device owner is already registered or the device has
2288 * already been provisioned.
2289 */
2290 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2291 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002292 return setDeviceOwner(packageName, null);
2293 }
2294
2295 /**
2296 * @hide
2297 * Sets the given package as the device owner. The package must already be installed and there
2298 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2299 * method must be called before the device is provisioned.
2300 * @param packageName the package name of the application to be registered as the device owner.
2301 * @param ownerName the human readable name of the institution that owns this device.
2302 * @return whether the package was successfully registered as the device owner.
2303 * @throws IllegalArgumentException if the package name is null or invalid
2304 * @throws IllegalStateException if a device owner is already registered or the device has
2305 * already been provisioned.
2306 */
2307 public boolean setDeviceOwner(String packageName, String ownerName)
2308 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002309 if (mService != null) {
2310 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002311 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002312 } catch (RemoteException re) {
2313 Log.w(TAG, "Failed to set device owner");
2314 }
2315 }
2316 return false;
2317 }
2318
2319 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002320 * Used to determine if a particular package has been registered as a Device Owner app.
2321 * A device owner app is a special device admin that cannot be deactivated by the user, once
2322 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2323 * package is currently registered as the device owner app, pass in the package name from
2324 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2325 * admin apps that want to check if they are also registered as the device owner app. The
2326 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2327 * the setup process.
2328 * @param packageName the package name of the app, to compare with the registered device owner
2329 * app, if any.
2330 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002331 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002332 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002333 if (mService != null) {
2334 try {
2335 return mService.isDeviceOwner(packageName);
2336 } catch (RemoteException re) {
2337 Log.w(TAG, "Failed to check device owner");
2338 }
2339 }
2340 return false;
2341 }
2342
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002343 /**
2344 * @hide
2345 * Redirect to isDeviceOwnerApp.
2346 */
2347 public boolean isDeviceOwner(String packageName) {
2348 return isDeviceOwnerApp(packageName);
2349 }
2350
Jason Monkb0dced82014-06-06 14:36:20 -04002351 /**
2352 * Clears the current device owner. The caller must be the device owner.
2353 *
2354 * This function should be used cautiously as once it is called it cannot
2355 * be undone. The device owner can only be set as a part of device setup
2356 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002357 *
2358 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002359 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002360 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002361 if (mService != null) {
2362 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002363 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002364 } catch (RemoteException re) {
2365 Log.w(TAG, "Failed to clear device owner");
2366 }
2367 }
2368 }
2369
Amith Yamasani71e6c692013-03-24 17:39:28 -07002370 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002371 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002372 public String getDeviceOwner() {
2373 if (mService != null) {
2374 try {
2375 return mService.getDeviceOwner();
2376 } catch (RemoteException re) {
2377 Log.w(TAG, "Failed to get device owner");
2378 }
2379 }
2380 return null;
2381 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002382
2383 /** @hide */
2384 public String getDeviceOwnerName() {
2385 if (mService != null) {
2386 try {
2387 return mService.getDeviceOwnerName();
2388 } catch (RemoteException re) {
2389 Log.w(TAG, "Failed to get device owner");
2390 }
2391 }
2392 return null;
2393 }
Adam Connors776c5552014-01-09 10:42:56 +00002394
2395 /**
2396 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002397 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302398 * Sets the given component as an active admin and registers the package as the profile
2399 * owner for this user. The package must already be installed and there shouldn't be
2400 * an existing profile owner registered for this user. Also, this method must be called
2401 * before the user setup has been completed.
2402 * <p>
2403 * This method can only be called by system apps that hold MANAGE_USERS permission and
2404 * MANAGE_DEVICE_ADMINS permission.
2405 * @param admin The component to register as an active admin and profile owner.
2406 * @param ownerName The user-visible name of the entity that is managing this user.
2407 * @return whether the admin was successfully registered as the profile owner.
2408 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2409 * the user has already been set up.
2410 */
Justin Morey80440cc2014-07-24 09:16:35 -05002411 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302412 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2413 throws IllegalArgumentException {
2414 if (mService != null) {
2415 try {
2416 final int myUserId = UserHandle.myUserId();
2417 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002418 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302419 } catch (RemoteException re) {
2420 Log.w(TAG, "Failed to set profile owner " + re);
2421 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2422 }
2423 }
2424 return false;
2425 }
2426
2427 /**
2428 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002429 * Clears the active profile owner and removes all user restrictions. The caller must
2430 * be from the same package as the active profile owner for this user, otherwise a
2431 * SecurityException will be thrown.
2432 *
2433 * @param admin The component to remove as the profile owner.
2434 * @return
2435 */
2436 @SystemApi
2437 public void clearProfileOwner(ComponentName admin) {
2438 if (mService != null) {
2439 try {
2440 mService.clearProfileOwner(admin);
2441 } catch (RemoteException re) {
2442 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2443 }
2444 }
2445 }
2446
2447 /**
2448 * @hide
2449 * Checks if the user was already setup.
2450 */
2451 public boolean hasUserSetupCompleted() {
2452 if (mService != null) {
2453 try {
2454 return mService.hasUserSetupCompleted();
2455 } catch (RemoteException re) {
2456 Log.w(TAG, "Failed to check if user setup has completed");
2457 }
2458 }
2459 return true;
2460 }
2461
2462 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002463 * @hide
2464 * Sets the given component as the profile owner of the given user profile. The package must
2465 * already be installed and there shouldn't be an existing profile owner registered for this
2466 * user. Only the system can call this API if the user has already completed setup.
2467 * @param admin the component name to be registered as profile owner.
2468 * @param ownerName the human readable name of the organisation associated with this DPM.
2469 * @param userHandle the userId to set the profile owner for.
2470 * @return whether the component was successfully registered as the profile owner.
2471 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2472 * the user has already been set up.
2473 */
2474 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2475 throws IllegalArgumentException {
2476 if (admin == null) {
2477 throw new NullPointerException("admin cannot be null");
2478 }
Adam Connors776c5552014-01-09 10:42:56 +00002479 if (mService != null) {
2480 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002481 if (ownerName == null) {
2482 ownerName = "";
2483 }
2484 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002485 } catch (RemoteException re) {
2486 Log.w(TAG, "Failed to set profile owner", re);
2487 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2488 }
2489 }
2490 return false;
2491 }
2492
2493 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002494 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2495 * be used. Only the profile owner can call this.
2496 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002497 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002498 *
2499 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2500 */
2501 public void setProfileEnabled(ComponentName admin) {
2502 if (mService != null) {
2503 try {
2504 mService.setProfileEnabled(admin);
2505 } catch (RemoteException e) {
2506 Log.w(TAG, "Failed talking with device policy service", e);
2507 }
2508 }
2509 }
2510
2511 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002512 * Sets the name of the profile. In the device owner case it sets the name of the user
2513 * 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 +01002514 * never called by the profile or device owner, the name will be set to default values.
2515 *
2516 * @see #isProfileOwnerApp
2517 * @see #isDeviceOwnerApp
2518 *
2519 * @param profileName The name of the profile.
2520 */
2521 public void setProfileName(ComponentName who, String profileName) {
2522 if (mService != null) {
2523 try {
2524 mService.setProfileName(who, profileName);
2525 } catch (RemoteException e) {
2526 Log.w(TAG, "Failed talking with device policy service", e);
2527 }
2528 }
2529}
2530
2531 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002532 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002533 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002534 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002535 *
2536 * @param packageName The package name of the app to compare with the registered profile owner.
2537 * @return Whether or not the package is registered as the profile owner.
2538 */
2539 public boolean isProfileOwnerApp(String packageName) {
2540 if (mService != null) {
2541 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002542 ComponentName profileOwner = mService.getProfileOwner(
2543 Process.myUserHandle().getIdentifier());
2544 return profileOwner != null
2545 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002546 } catch (RemoteException re) {
2547 Log.w(TAG, "Failed to check profile owner");
2548 }
2549 }
2550 return false;
2551 }
2552
2553 /**
2554 * @hide
2555 * @return the packageName of the owner of the given user profile or null if no profile
2556 * owner has been set for that user.
2557 * @throws IllegalArgumentException if the userId is invalid.
2558 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002559 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002560 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002561 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2562 }
2563
2564 /**
2565 * @see #getProfileOwner()
2566 * @hide
2567 */
2568 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002569 if (mService != null) {
2570 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002571 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002572 } catch (RemoteException re) {
2573 Log.w(TAG, "Failed to get profile owner");
2574 throw new IllegalArgumentException(
2575 "Requested profile owner for invalid userId", re);
2576 }
2577 }
2578 return null;
2579 }
2580
2581 /**
2582 * @hide
2583 * @return the human readable name of the organisation associated with this DPM or null if
2584 * one is not set.
2585 * @throws IllegalArgumentException if the userId is invalid.
2586 */
2587 public String getProfileOwnerName() throws IllegalArgumentException {
2588 if (mService != null) {
2589 try {
2590 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2591 } catch (RemoteException re) {
2592 Log.w(TAG, "Failed to get profile owner");
2593 throw new IllegalArgumentException(
2594 "Requested profile owner for invalid userId", re);
2595 }
2596 }
2597 return null;
2598 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002599
2600 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002601 * @hide
2602 * @param user The user for whom to fetch the profile owner name, if any.
2603 * @return the human readable name of the organisation associated with this profile owner or
2604 * null if one is not set.
2605 * @throws IllegalArgumentException if the userId is invalid.
2606 */
2607 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002608 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002609 if (mService != null) {
2610 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002611 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002612 } catch (RemoteException re) {
2613 Log.w(TAG, "Failed to get profile owner");
2614 throw new IllegalArgumentException(
2615 "Requested profile owner for invalid userId", re);
2616 }
2617 }
2618 return null;
2619 }
2620
2621 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002622 * Called by a profile owner or device owner to add a default intent handler activity for
2623 * intents that match a certain intent filter. This activity will remain the default intent
2624 * handler even if the set of potential event handlers for the intent filter changes and if
2625 * the intent preferences are reset.
2626 *
2627 * <p>The default disambiguation mechanism takes over if the activity is not installed
2628 * (anymore). When the activity is (re)installed, it is automatically reset as default
2629 * intent handler for the filter.
2630 *
2631 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2632 * security exception will be thrown.
2633 *
2634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2635 * @param filter The IntentFilter for which a default handler is added.
2636 * @param activity The Activity that is added as default intent handler.
2637 */
2638 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2639 ComponentName activity) {
2640 if (mService != null) {
2641 try {
2642 mService.addPersistentPreferredActivity(admin, filter, activity);
2643 } catch (RemoteException e) {
2644 Log.w(TAG, "Failed talking with device policy service", e);
2645 }
2646 }
2647 }
2648
2649 /**
2650 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002651 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002652 *
2653 * <p>The calling device admin must be a profile owner. If it is not, a security
2654 * exception will be thrown.
2655 *
2656 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2657 * @param packageName The name of the package for which preferences are removed.
2658 */
2659 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2660 String packageName) {
2661 if (mService != null) {
2662 try {
2663 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2664 } catch (RemoteException e) {
2665 Log.w(TAG, "Failed talking with device policy service", e);
2666 }
2667 }
2668 }
Robin Lee66e5d962014-04-09 16:44:21 +01002669
2670 /**
2671 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002672 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002673 *
2674 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01002675 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01002676 *
2677 * <p>The application restrictions are only made visible to the target application and the
2678 * profile or device owner.
2679 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002680 * <p>If the restrictions are not available yet, but may be applied in the near future,
2681 * the admin can notify the target application of that by adding
2682 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
2683 *
Robin Lee66e5d962014-04-09 16:44:21 +01002684 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2685 * exception will be thrown.
2686 *
2687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2688 * @param packageName The name of the package to update restricted settings for.
2689 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2690 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002691 *
2692 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01002693 */
2694 public void setApplicationRestrictions(ComponentName admin, String packageName,
2695 Bundle settings) {
2696 if (mService != null) {
2697 try {
2698 mService.setApplicationRestrictions(admin, packageName, settings);
2699 } catch (RemoteException e) {
2700 Log.w(TAG, "Failed talking with device policy service", e);
2701 }
2702 }
2703 }
2704
2705 /**
Jim Millere303bf42014-08-26 17:12:29 -07002706 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
2707 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
2708 * trust agents but those enabled by this function call. If flag
2709 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07002710 *
2711 * <p>The calling device admin must have requested
2712 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07002713 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07002714 *
2715 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07002716 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08002717 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07002718 * will be strictly disabled according to the state of the
2719 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
2720 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
2721 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
2722 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07002723 */
Jim Millere303bf42014-08-26 17:12:29 -07002724 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
Jim Millerb5db57a2015-01-14 18:17:19 -08002725 PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07002726 if (mService != null) {
2727 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002728 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07002729 } catch (RemoteException e) {
2730 Log.w(TAG, "Failed talking with device policy service", e);
2731 }
2732 }
2733 }
2734
2735 /**
Jim Millere303bf42014-08-26 17:12:29 -07002736 * Gets configuration for the given trust agent based on aggregating all calls to
2737 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
2738 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07002739 *
Jim Millerb5db57a2015-01-14 18:17:19 -08002740 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2741 * this function returns a list of configurations for all admins that declare
2742 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
2743 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
2744 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
2745 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07002746 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07002747 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07002748 */
Jim Millere303bf42014-08-26 17:12:29 -07002749 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2750 ComponentName agent) {
2751 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
2752 }
2753
2754 /** @hide per-user version */
2755 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2756 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07002757 if (mService != null) {
2758 try {
Jim Millere303bf42014-08-26 17:12:29 -07002759 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07002760 } catch (RemoteException e) {
2761 Log.w(TAG, "Failed talking with device policy service", e);
2762 }
2763 }
Jim Millere303bf42014-08-26 17:12:29 -07002764 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07002765 }
2766
2767 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002768 * Called by a profile owner of a managed profile to set whether caller-Id information from
2769 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01002770 *
2771 * <p>The calling device admin must be a profile owner. If it is not, a
2772 * security exception will be thrown.
2773 *
2774 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2775 * @param disabled If true caller-Id information in the managed profile is not displayed.
2776 */
2777 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2778 if (mService != null) {
2779 try {
2780 mService.setCrossProfileCallerIdDisabled(who, disabled);
2781 } catch (RemoteException e) {
2782 Log.w(TAG, "Failed talking with device policy service", e);
2783 }
2784 }
2785 }
2786
2787 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002788 * Called by a profile owner of a managed profile to determine whether or not caller-Id
2789 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01002790 *
2791 * <p>The calling device admin must be a profile owner. If it is not, a
2792 * security exception will be thrown.
2793 *
2794 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2795 */
2796 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2797 if (mService != null) {
2798 try {
2799 return mService.getCrossProfileCallerIdDisabled(who);
2800 } catch (RemoteException e) {
2801 Log.w(TAG, "Failed talking with device policy service", e);
2802 }
2803 }
2804 return false;
2805 }
2806
2807 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002808 * Determine whether or not caller-Id information has been disabled.
2809 *
2810 * @param userHandle The user for whom to check the caller-id permission
2811 * @hide
2812 */
2813 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2814 if (mService != null) {
2815 try {
2816 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2817 } catch (RemoteException e) {
2818 Log.w(TAG, "Failed talking with device policy service", e);
2819 }
2820 }
2821 return false;
2822 }
2823
2824 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002825 * Called by the profile owner of a managed profile so that some intents sent in the managed
2826 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00002827 * Only activity intents are supported.
2828 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002830 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2831 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002832 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2833 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002834 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002835 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002836 if (mService != null) {
2837 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002838 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002839 } catch (RemoteException e) {
2840 Log.w(TAG, "Failed talking with device policy service", e);
2841 }
2842 }
2843 }
2844
2845 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002846 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
2847 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002848 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2850 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002851 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002852 if (mService != null) {
2853 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002854 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002855 } catch (RemoteException e) {
2856 Log.w(TAG, "Failed talking with device policy service", e);
2857 }
2858 }
2859 }
2860
2861 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002862 * Called by a profile or device owner to set the permitted accessibility services. When
2863 * set by a device owner or profile owner the restriction applies to all profiles of the
2864 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07002865 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002866 * By default the user can use any accessiblity service. When zero or more packages have
2867 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07002868 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002869 *
2870 * <p> Calling with a null value for the list disables the restriction so that all services
2871 * can be used, calling with an empty list only allows the builtin system's services.
2872 *
2873 * <p> System accesibility services are always available to the user the list can't modify
2874 * this.
2875 *
2876 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2877 * @param packageNames List of accessibility service package names.
2878 *
2879 * @return true if setting the restriction succeeded. It fail if there is
2880 * one or more non-system accessibility services enabled, that are not in the list.
2881 */
2882 public boolean setPermittedAccessibilityServices(ComponentName admin,
2883 List<String> packageNames) {
2884 if (mService != null) {
2885 try {
2886 return mService.setPermittedAccessibilityServices(admin, packageNames);
2887 } catch (RemoteException e) {
2888 Log.w(TAG, "Failed talking with device policy service", e);
2889 }
2890 }
2891 return false;
2892 }
2893
2894 /**
2895 * Returns the list of permitted accessibility services set by this device or profile owner.
2896 *
2897 * <p>An empty list means no accessibility services except system services are allowed.
2898 * Null means all accessibility services are allowed.
2899 *
2900 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2901 * @return List of accessiblity service package names.
2902 */
2903 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2904 if (mService != null) {
2905 try {
2906 return mService.getPermittedAccessibilityServices(admin);
2907 } catch (RemoteException e) {
2908 Log.w(TAG, "Failed talking with device policy service", e);
2909 }
2910 }
2911 return null;
2912 }
2913
2914 /**
2915 * Returns the list of accessibility services permitted by the device or profiles
2916 * owners of this user.
2917 *
2918 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2919 * it will contain the intersection of the permitted lists for any device or profile
2920 * owners that apply to this user. It will also include any system accessibility services.
2921 *
2922 * @param userId which user to check for.
2923 * @return List of accessiblity service package names.
2924 * @hide
2925 */
2926 @SystemApi
2927 public List<String> getPermittedAccessibilityServices(int userId) {
2928 if (mService != null) {
2929 try {
2930 return mService.getPermittedAccessibilityServicesForUser(userId);
2931 } catch (RemoteException e) {
2932 Log.w(TAG, "Failed talking with device policy service", e);
2933 }
2934 }
2935 return null;
2936 }
2937
2938 /**
2939 * Called by a profile or device owner to set the permitted input methods services. When
2940 * set by a device owner or profile owner the restriction applies to all profiles of the
2941 * user the device owner or profile owner is an admin for.
2942 *
2943 * By default the user can use any input method. When zero or more packages have
2944 * been added, input method that are not in the list and not part of the system
2945 * can not be enabled by the user.
2946 *
2947 * This method will fail if it is called for a admin that is not for the foreground user
2948 * or a profile of the foreground user.
2949 *
2950 * <p> Calling with a null value for the list disables the restriction so that all input methods
2951 * can be used, calling with an empty list disables all but the system's own input methods.
2952 *
2953 * <p> System input methods are always available to the user this method can't modify this.
2954 *
2955 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2956 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00002957 * @return true if setting the restriction succeeded. It will fail if there are
2958 * one or more non-system input methods currently enabled that are not in
2959 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002960 */
2961 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2962 if (mService != null) {
2963 try {
2964 return mService.setPermittedInputMethods(admin, packageNames);
2965 } catch (RemoteException e) {
2966 Log.w(TAG, "Failed talking with device policy service", e);
2967 }
2968 }
2969 return false;
2970 }
2971
2972
2973 /**
2974 * Returns the list of permitted input methods set by this device or profile owner.
2975 *
2976 * <p>An empty list means no input methods except system input methods are allowed.
2977 * Null means all input methods are allowed.
2978 *
2979 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2980 * @return List of input method package names.
2981 */
2982 public List<String> getPermittedInputMethods(ComponentName admin) {
2983 if (mService != null) {
2984 try {
2985 return mService.getPermittedInputMethods(admin);
2986 } catch (RemoteException e) {
2987 Log.w(TAG, "Failed talking with device policy service", e);
2988 }
2989 }
2990 return null;
2991 }
2992
2993 /**
2994 * Returns the list of input methods permitted by the device or profiles
2995 * owners of the current user.
2996 *
2997 * <p>Null means all input methods are allowed, if a non-null list is returned
2998 * it will contain the intersection of the permitted lists for any device or profile
2999 * owners that apply to this user. It will also include any system input methods.
3000 *
3001 * @return List of input method package names.
3002 * @hide
3003 */
3004 @SystemApi
3005 public List<String> getPermittedInputMethodsForCurrentUser() {
3006 if (mService != null) {
3007 try {
3008 return mService.getPermittedInputMethodsForCurrentUser();
3009 } catch (RemoteException e) {
3010 Log.w(TAG, "Failed talking with device policy service", e);
3011 }
3012 }
3013 return null;
3014 }
3015
3016 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003017 * Called by a device owner to create a user with the specified name. The UserHandle returned
3018 * by this method should not be persisted as user handles are recycled as users are removed and
3019 * created. If you need to persist an identifier for this user, use
3020 * {@link UserManager#getSerialNumberForUser}.
3021 *
3022 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3023 * @param name the user's name
3024 * @see UserHandle
3025 * @return the UserHandle object for the created user, or null if the user could not be created.
3026 */
3027 public UserHandle createUser(ComponentName admin, String name) {
3028 try {
3029 return mService.createUser(admin, name);
3030 } catch (RemoteException re) {
3031 Log.w(TAG, "Could not create a user", re);
3032 }
3033 return null;
3034 }
3035
3036 /**
Jason Monk03978a42014-06-10 15:05:30 -04003037 * Called by a device owner to create a user with the specified name. The UserHandle returned
3038 * by this method should not be persisted as user handles are recycled as users are removed and
3039 * created. If you need to persist an identifier for this user, use
3040 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3041 * immediately.
3042 *
3043 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3044 * as registered as an active admin on the new user. The profile owner package will be
3045 * installed on the new user if it already is installed on the device.
3046 *
3047 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3048 * profileOwnerComponent when onEnable is called.
3049 *
3050 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3051 * @param name the user's name
3052 * @param ownerName the human readable name of the organisation associated with this DPM.
3053 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3054 * the user.
3055 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3056 * on the new user.
3057 * @see UserHandle
3058 * @return the UserHandle object for the created user, or null if the user could not be created.
3059 */
3060 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3061 ComponentName profileOwnerComponent, Bundle adminExtras) {
3062 try {
3063 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3064 adminExtras);
3065 } catch (RemoteException re) {
3066 Log.w(TAG, "Could not create a user", re);
3067 }
3068 return null;
3069 }
3070
3071 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003072 * Called by a device owner to remove a user and all associated data. The primary user can
3073 * not be removed.
3074 *
3075 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3076 * @param userHandle the user to remove.
3077 * @return {@code true} if the user was removed, {@code false} otherwise.
3078 */
3079 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3080 try {
3081 return mService.removeUser(admin, userHandle);
3082 } catch (RemoteException re) {
3083 Log.w(TAG, "Could not remove user ", re);
3084 return false;
3085 }
3086 }
3087
3088 /**
Jason Monk582d9112014-07-09 19:57:08 -04003089 * Called by a device owner to switch the specified user to the foreground.
3090 *
3091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3092 * @param userHandle the user to switch to; null will switch to primary.
3093 * @return {@code true} if the switch was successful, {@code false} otherwise.
3094 *
3095 * @see Intent#ACTION_USER_FOREGROUND
3096 */
3097 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3098 try {
3099 return mService.switchUser(admin, userHandle);
3100 } catch (RemoteException re) {
3101 Log.w(TAG, "Could not switch user ", re);
3102 return false;
3103 }
3104 }
3105
3106 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003107 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003108 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003109 *
3110 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3111 * exception will be thrown.
3112 *
3113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3114 * @param packageName The name of the package to fetch restricted settings of.
3115 * @return {@link Bundle} of settings corresponding to what was set last time
3116 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3117 * if no restrictions have been set.
3118 */
3119 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3120 if (mService != null) {
3121 try {
3122 return mService.getApplicationRestrictions(admin, packageName);
3123 } catch (RemoteException e) {
3124 Log.w(TAG, "Failed talking with device policy service", e);
3125 }
3126 }
3127 return null;
3128 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003129
3130 /**
3131 * Called by a profile or device owner to set a user restriction specified
3132 * by the key.
3133 * <p>
3134 * The calling device admin must be a profile or device owner; if it is not,
3135 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003136 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003137 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3138 * with.
3139 * @param key The key of the restriction. See the constants in
3140 * {@link android.os.UserManager} for the list of keys.
3141 */
3142 public void addUserRestriction(ComponentName admin, String key) {
3143 if (mService != null) {
3144 try {
3145 mService.setUserRestriction(admin, key, true);
3146 } catch (RemoteException e) {
3147 Log.w(TAG, "Failed talking with device policy service", e);
3148 }
3149 }
3150 }
3151
3152 /**
3153 * Called by a profile or device owner to clear a user restriction specified
3154 * by the key.
3155 * <p>
3156 * The calling device admin must be a profile or device owner; if it is not,
3157 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003158 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003159 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3160 * with.
3161 * @param key The key of the restriction. See the constants in
3162 * {@link android.os.UserManager} for the list of keys.
3163 */
3164 public void clearUserRestriction(ComponentName admin, String key) {
3165 if (mService != null) {
3166 try {
3167 mService.setUserRestriction(admin, key, false);
3168 } catch (RemoteException e) {
3169 Log.w(TAG, "Failed talking with device policy service", e);
3170 }
3171 }
3172 }
Adam Connors010cfd42014-04-16 12:48:13 +01003173
3174 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003175 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003176 * is unavailable for use, but the data and actual package file remain.
3177 *
3178 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003179 * @param packageName The name of the package to hide or unhide.
3180 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3181 * unhidden.
3182 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003183 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003184 public boolean setApplicationHidden(ComponentName admin, String packageName,
3185 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003186 if (mService != null) {
3187 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003188 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003189 } catch (RemoteException e) {
3190 Log.w(TAG, "Failed talking with device policy service", e);
3191 }
3192 }
3193 return false;
3194 }
3195
3196 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003197 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003198 *
3199 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003200 * @param packageName The name of the package to retrieve the hidden status of.
3201 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003202 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003203 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003204 if (mService != null) {
3205 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003206 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003207 } catch (RemoteException e) {
3208 Log.w(TAG, "Failed talking with device policy service", e);
3209 }
3210 }
3211 return false;
3212 }
3213
3214 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003215 * Called by profile or device owner to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003216 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003217 *
3218 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3219 * @param packageName The package to be re-enabled in the current profile.
3220 */
3221 public void enableSystemApp(ComponentName admin, String packageName) {
3222 if (mService != null) {
3223 try {
3224 mService.enableSystemApp(admin, packageName);
3225 } catch (RemoteException e) {
3226 Log.w(TAG, "Failed to install package: " + packageName);
3227 }
3228 }
3229 }
3230
3231 /**
3232 * Called by profile or device owner to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003233 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003234 *
3235 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3236 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3237 * intent will be re-enabled in the current profile.
3238 * @return int The number of activities that matched the intent and were installed.
3239 */
3240 public int enableSystemApp(ComponentName admin, Intent intent) {
3241 if (mService != null) {
3242 try {
3243 return mService.enableSystemAppWithIntent(admin, intent);
3244 } catch (RemoteException e) {
3245 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3246 }
3247 }
3248 return 0;
3249 }
3250
3251 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003252 * Called by a device owner or profile owner to disable account management for a specific type
3253 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003254 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003255 * <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 +01003256 * security exception will be thrown.
3257 *
3258 * <p>When account management is disabled for an account type, adding or removing an account
3259 * of that type will not be possible.
3260 *
3261 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3262 * @param accountType For which account management is disabled or enabled.
3263 * @param disabled The boolean indicating that account management will be disabled (true) or
3264 * enabled (false).
3265 */
3266 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3267 boolean disabled) {
3268 if (mService != null) {
3269 try {
3270 mService.setAccountManagementDisabled(admin, accountType, disabled);
3271 } catch (RemoteException e) {
3272 Log.w(TAG, "Failed talking with device policy service", e);
3273 }
3274 }
3275 }
3276
3277 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003278 * Gets the array of accounts for which account management is disabled by the profile owner.
3279 *
3280 * <p> Account management can be disabled/enabled by calling
3281 * {@link #setAccountManagementDisabled}.
3282 *
3283 * @return a list of account types for which account management has been disabled.
3284 *
3285 * @see #setAccountManagementDisabled
3286 */
3287 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003288 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003289 }
3290
3291 /**
3292 * @see #getAccountTypesWithManagementDisabled()
3293 * @hide
3294 */
3295 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003296 if (mService != null) {
3297 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003298 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003299 } catch (RemoteException e) {
3300 Log.w(TAG, "Failed talking with device policy service", e);
3301 }
3302 }
3303
3304 return null;
3305 }
justinzhang511e0d82014-03-24 16:09:24 -04003306
3307 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003308 * Sets which packages may enter lock task mode.
3309 *
3310 * <p>Any packages that shares uid with an allowed package will also be allowed
3311 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003312 *
Jason Monkc5185f22014-06-24 11:12:42 -04003313 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003314 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003315 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003316 *
3317 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003318 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3319 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003320 */
Jason Monk48aacba2014-08-13 16:29:08 -04003321 public void setLockTaskPackages(ComponentName admin, String[] packages)
3322 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003323 if (mService != null) {
3324 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003325 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003326 } catch (RemoteException e) {
3327 Log.w(TAG, "Failed talking with device policy service", e);
3328 }
3329 }
3330 }
3331
3332 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003333 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003334 *
3335 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003336 * @hide
3337 */
Jason Monk48aacba2014-08-13 16:29:08 -04003338 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003339 if (mService != null) {
3340 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003341 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003342 } catch (RemoteException e) {
3343 Log.w(TAG, "Failed talking with device policy service", e);
3344 }
3345 }
3346 return null;
3347 }
3348
3349 /**
3350 * This function lets the caller know whether the given component is allowed to start the
3351 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003352 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003353 */
Jason Monkd7b86212014-06-16 13:15:38 -04003354 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003355 if (mService != null) {
3356 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003357 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003358 } catch (RemoteException e) {
3359 Log.w(TAG, "Failed talking with device policy service", e);
3360 }
3361 }
3362 return false;
3363 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003364
3365 /**
3366 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3367 * 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 -04003368 * <p>The settings that can be updated with this method are:
3369 * <ul>
3370 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3371 * <li>{@link Settings.Global#AUTO_TIME}</li>
3372 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
3373 * <li>{@link Settings.Global#BLUETOOTH_ON}</li>
3374 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3375 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3376 * <li>{@link Settings.Global#MODE_RINGER}</li>
3377 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3378 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
3379 * <li>{@link Settings.Global#WIFI_ON}</li>
3380 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3381 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003382 *
3383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3384 * @param setting The name of the setting to update.
3385 * @param value The value to update the setting to.
3386 */
3387 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3388 if (mService != null) {
3389 try {
3390 mService.setGlobalSetting(admin, setting, value);
3391 } catch (RemoteException e) {
3392 Log.w(TAG, "Failed talking with device policy service", e);
3393 }
3394 }
3395 }
3396
3397 /**
3398 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3399 * that the value of the setting is in the correct form for the setting type should be performed
3400 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003401 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003402 * <ul>
3403 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003404 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003405 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3406 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003407 * <p>A device owner can additionally update the following settings:
3408 * <ul>
3409 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3410 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003411 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3412 * @param setting The name of the setting to update.
3413 * @param value The value to update the setting to.
3414 */
3415 public void setSecureSetting(ComponentName admin, String setting, String value) {
3416 if (mService != null) {
3417 try {
3418 mService.setSecureSetting(admin, setting, value);
3419 } catch (RemoteException e) {
3420 Log.w(TAG, "Failed talking with device policy service", e);
3421 }
3422 }
3423 }
3424
Amith Yamasanif20d6402014-05-24 15:34:37 -07003425 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003426 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003427 * making permission requests of a local or remote administrator of the user.
3428 * <p/>
3429 * Only a profile owner can designate the restrictions provider.
3430 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003431 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003432 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003433 * it removes the restrictions provider previously assigned.
3434 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003435 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003436 if (mService != null) {
3437 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003438 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003439 } catch (RemoteException re) {
3440 Log.w(TAG, "Failed to set permission provider on device policy service");
3441 }
3442 }
3443 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003444
3445 /**
3446 * Called by profile or device owners to set the master volume mute on or off.
3447 *
3448 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3449 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3450 */
3451 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3452 if (mService != null) {
3453 try {
3454 mService.setMasterVolumeMuted(admin, on);
3455 } catch (RemoteException re) {
3456 Log.w(TAG, "Failed to setMasterMute on device policy service");
3457 }
3458 }
3459 }
3460
3461 /**
3462 * Called by profile or device owners to check whether the master volume mute is on or off.
3463 *
3464 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3465 * @return {@code true} if master volume is muted, {@code false} if it's not.
3466 */
3467 public boolean isMasterVolumeMuted(ComponentName admin) {
3468 if (mService != null) {
3469 try {
3470 return mService.isMasterVolumeMuted(admin);
3471 } catch (RemoteException re) {
3472 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3473 }
3474 }
3475 return false;
3476 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003477
3478 /**
3479 * Called by profile or device owners to change whether a user can uninstall
3480 * a package.
3481 *
3482 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3483 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003484 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003485 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003486 public void setUninstallBlocked(ComponentName admin, String packageName,
3487 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003488 if (mService != null) {
3489 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003490 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003491 } catch (RemoteException re) {
3492 Log.w(TAG, "Failed to call block uninstall on device policy service");
3493 }
3494 }
3495 }
3496
3497 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003498 * Check whether the current user has been blocked by device policy from uninstalling a package.
3499 * Requires the caller to be the profile owner if checking a specific admin's policy.
Kenny Guyc13053b2014-05-29 14:17:17 +01003500 *
Rubin Xua97855b2014-11-07 05:41:00 +00003501 * @param admin The name of the admin component whose blocking policy will be checked, or null
3502 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003503 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003504 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003505 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003506 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003507 if (mService != null) {
3508 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003509 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003510 } catch (RemoteException re) {
3511 Log.w(TAG, "Failed to call block uninstall on device policy service");
3512 }
3513 }
3514 return false;
3515 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003516
3517 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003518 * Called by the profile owner of a managed profile to enable widget providers from a
3519 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003520 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003521 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003522 * a package may have zero or more provider components, where each component
3523 * provides a different widget type.
3524 * <p>
3525 * <strong>Note:</strong> By default no widget provider package is white-listed.
3526 * </p>
3527 *
3528 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3529 * @param packageName The package from which widget providers are white-listed.
3530 * @return Whether the package was added.
3531 *
3532 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3533 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3534 */
3535 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3536 if (mService != null) {
3537 try {
3538 return mService.addCrossProfileWidgetProvider(admin, packageName);
3539 } catch (RemoteException re) {
3540 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3541 }
3542 }
3543 return false;
3544 }
3545
3546 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003547 * Called by the profile owner of a managed profile to disable widget providers from a given
3548 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003549 * package should have been added via {@link #addCrossProfileWidgetProvider(
3550 * android.content.ComponentName, String)}.
3551 * <p>
3552 * <strong>Note:</strong> By default no widget provider package is white-listed.
3553 * </p>
3554 *
3555 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3556 * @param packageName The package from which widget providers are no longer
3557 * white-listed.
3558 * @return Whether the package was removed.
3559 *
3560 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3561 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3562 */
3563 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3564 if (mService != null) {
3565 try {
3566 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3567 } catch (RemoteException re) {
3568 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3569 }
3570 }
3571 return false;
3572 }
3573
3574 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003575 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003576 * available in the parent profile.
3577 *
3578 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3579 * @return The white-listed package list.
3580 *
3581 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3582 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3583 */
3584 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3585 if (mService != null) {
3586 try {
3587 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3588 if (providers != null) {
3589 return providers;
3590 }
3591 } catch (RemoteException re) {
3592 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3593 }
3594 }
3595 return Collections.emptyList();
3596 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003597}