blob: ead89b302ecd2f6e8490da6e6b931319d6fce219 [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;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010055import java.security.PrivateKey;
56import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040057import java.security.cert.CertificateException;
58import java.security.cert.CertificateFactory;
59import java.security.cert.X509Certificate;
Jim Miller604e7552014-07-18 19:00:02 -070060import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070061import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080062import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080063
64/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000065 * Public interface for managing policies enforced on a device. Most clients of this class must be
66 * registered with the system as a
67 * <a href={@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
68 * a device administrator may be registered as either a profile or device owner. A given method is
69 * accessible to all device administrators unless the documentation for that method specifies that
70 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080071 *
72 * <div class="special reference">
73 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000074 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080075 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
76 * developer guide.</p>
77 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080078 */
79public class DevicePolicyManager {
80 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080081
82 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080083 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070084
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080085 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080086 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080087 mService = IDevicePolicyManager.Stub.asInterface(
88 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
89 }
90
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080091 /** @hide */
92 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080093 DevicePolicyManager me = new DevicePolicyManager(context, handler);
94 return me.mService != null ? me : null;
95 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070096
Dianne Hackbornd6847842010-01-12 18:14:19 -080097 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +000098 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +000099 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100100 * <p>A managed profile allows data separation for example for the usage of a
101 * device as a personal and corporate device. The user which provisioning is started from and
102 * the managed profile share a launcher.
103 *
104 * <p>This intent will typically be sent by a mobile device management application (mdm).
105 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
106 * control over the profile
107 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100108 * <p>This intent must contain the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000109 *
110 * <p> When managed provisioning has completed, an intent of the type
111 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100112 * managed profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100113 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100114 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
115 * previous state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 *
117 * <p>Input: Nothing.</p>
118 * <p>Output: Nothing</p>
119 */
120 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
121 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100122 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000123
124 /**
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700125 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows
126 * a mobile device management application that starts managed profile provisioning to pass data
127 * to itself on the managed profile when provisioning completes. The mobile device management
128 * application sends this extra in an intent with the action
129 * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in
130 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
131 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
132 * during the managed profile provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100133 */
134 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100135 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100136
137 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100138 * A String extra holding the package name of the mobile device management application that
139 * will be set as the profile owner or device owner.
140 *
141 * <p>If an application starts provisioning directly via an intent with action
142 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
143 * application that started provisioning. The package will be set as profile owner in that case.
144 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000145 * <p>This package is set as device owner when device owner provisioning is started by an NFC
146 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000147 */
148 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100149 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000150
151 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000152 * An {@link android.accounts.Account} extra holding the account to migrate during managed
153 * profile provisioning. If the account supplied is present in the primary user, it will be
154 * copied, along with its credentials to the managed profile and removed from the primary user.
155 *
156 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
157 */
158
159 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
160 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
161
162 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100163 * A String extra that, holds the email address of the account which a managed profile is
164 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
165 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100166 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100167 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
168 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100169 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
170 * contains this extra, it is forwarded in the
171 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
172 * device management application that was set as the profile owner during provisioning.
173 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100174 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100175 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
176 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100177
178 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000179 * A Boolean extra that can be used by the mobile device management application to skip the
180 * disabling of system apps during provisioning when set to <code>true</code>.
181 *
182 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
183 * provisioning via an NFC bump.
184 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000185 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
186 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000187
188 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100189 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
190 * will be set to.
191 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000192 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
193 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100194 */
195 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100196 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100197
198 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100199 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
200 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100201 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000202 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
203 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100204 */
205 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100206 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100207
208 /**
209 * A String extra holding the {@link java.util.Locale} that the device will be set to.
210 * Format: xx_yy, where xx is the language code, and yy the country code.
211 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000212 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
213 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100214 */
215 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100216 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100217
218 /**
219 * A String extra holding the ssid of the wifi network that should be used during nfc device
220 * owner provisioning for downloading the mobile device management application.
221 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000222 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
223 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100224 */
225 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100226 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100227
228 /**
229 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
230 * is hidden or not.
231 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000232 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
233 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100234 */
235 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100236 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100237
238 /**
239 * A String extra indicating the security type of the wifi network in
240 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
241 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000242 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
243 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100244 */
245 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100246 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100247
248 /**
249 * A String extra holding the password of the wifi network in
250 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
251 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000252 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
253 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100254 */
255 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100256 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100257
258 /**
259 * A String extra holding the proxy host for the wifi network in
260 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
261 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000262 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
263 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100264 */
265 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100266 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100267
268 /**
269 * An int extra holding the proxy port for the wifi network in
270 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
271 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000272 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
273 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100274 */
275 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100276 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100277
278 /**
279 * A String extra holding the proxy bypass for the wifi network in
280 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
281 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000282 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
283 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100284 */
285 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100286 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100287
288 /**
289 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
290 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
291 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000292 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
293 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100294 */
295 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100296 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100297
298 /**
299 * A String extra holding a url that specifies the download location of the device admin
300 * package. When not provided it is assumed that the device admin package is already installed.
301 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000302 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
303 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100304 */
305 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100306 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100307
308 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100309 * A String extra holding a http cookie header which should be used in the http request to the
310 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
311 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000312 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
313 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100314 */
315 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100316 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100317
318 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100319 * A String extra holding the SHA-1 checksum of the file at download location specified in
320 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match
321 * the file at the download location an error will be shown to the user and the user will be
322 * asked to factory reset the device.
323 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000324 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
325 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100326 */
327 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100328 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329
330 /**
331 * This MIME type is used for starting the Device Owner provisioning.
332 *
333 * <p>During device owner provisioning a device admin app is set as the owner of the device.
334 * A device owner has full control over the device. The device owner can not be modified by the
335 * user and the only way of resetting the device is if the device owner app calls a factory
336 * reset.
337 *
338 * <p> A typical use case would be a device that is owned by a company, but used by either an
339 * employee or client.
340 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000341 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100342 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000343 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100344 * contains the following properties:
345 * <ul>
346 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
347 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100348 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100349 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li>
350 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
351 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
352 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
353 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
354 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
355 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
356 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
357 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
358 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
359 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
360 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul>
361 *
362 * <p> When device owner provisioning has completed, an intent of the type
363 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
364 * device owner.
365 *
366 * <p>
367 * If provisioning fails, the device is factory reset.
368 *
369 * <p>Input: Nothing.</p>
370 * <p>Output: Nothing</p>
371 */
Esteban Talaveraf057f062014-08-20 14:27:45 +0100372 public static final String MIME_TYPE_PROVISIONING_NFC
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 = "application/com.android.managedprovisioning";
374
375 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800376 * Activity action: ask the user to add a new device administrator to the system.
377 * The desired policy is the ComponentName of the policy in the
378 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
379 * bring the user through adding the device administrator to the system (or
380 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700381 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800382 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
383 * field to provide the user with additional explanation (in addition
384 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800385 *
386 * <p>If your administrator is already active, this will ordinarily return immediately (without
387 * user intervention). However, if your administrator has been updated and is requesting
388 * additional uses-policy flags, the user will be presented with the new list. New policies
389 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800390 */
391 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
392 public static final String ACTION_ADD_DEVICE_ADMIN
393 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700394
Dianne Hackbornd6847842010-01-12 18:14:19 -0800395 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700396 * @hide
397 * Activity action: ask the user to add a new device administrator as the profile owner
398 * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS
399 * permission can call this API.
400 *
401 * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra
402 * field. This will invoke a UI to bring the user through adding the profile owner admin
403 * to remotely control restrictions on the user.
404 *
405 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
406 * result of whether or not the user approved the action. If approved, the result will
407 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
408 * as a profile owner.
409 *
410 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
411 * field to provide the user with additional explanation (in addition
412 * to your component's description) about what is being added.
413 *
414 * <p>If there is already a profile owner active or the caller doesn't have the required
415 * permissions, the operation will return a failure result.
416 */
417 @SystemApi
418 public static final String ACTION_SET_PROFILE_OWNER
419 = "android.app.action.SET_PROFILE_OWNER";
420
421 /**
422 * @hide
423 * Name of the profile owner admin that controls the user.
424 */
425 @SystemApi
426 public static final String EXTRA_PROFILE_OWNER_NAME
427 = "android.app.extra.PROFILE_OWNER_NAME";
428
429 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700430 * Activity action: send when any policy admin changes a policy.
431 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700432 *
Jim Miller284b62e2010-06-08 14:27:42 -0700433 * @hide
434 */
435 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
436 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
437
438 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800439 * The ComponentName of the administrator component.
440 *
441 * @see #ACTION_ADD_DEVICE_ADMIN
442 */
443 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700444
Dianne Hackbornd6847842010-01-12 18:14:19 -0800445 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800446 * An optional CharSequence providing additional explanation for why the
447 * admin is being added.
448 *
449 * @see #ACTION_ADD_DEVICE_ADMIN
450 */
451 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700452
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800453 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700454 * Activity action: have the user enter a new password. This activity should
455 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
456 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
457 * enter a new password that meets the current requirements. You can use
458 * {@link #isActivePasswordSufficient()} to determine whether you need to
459 * have the user select a new password in order to meet the current
460 * constraints. Upon being resumed from this activity, you can check the new
461 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800462 */
463 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
464 public static final String ACTION_SET_NEW_PASSWORD
465 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700466
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000467 /**
Jeff Sharkey97978802014-10-14 10:48:18 -0700468 * Flag used by {@link #addCrossProfileIntentFilter} to allow access
469 * <em>from</em> a managed profile <em>to</em> its parent. That is, any
470 * matching activities in the parent profile are included in the
471 * disambiguation list shown when an app in the managed profile calls
472 * {@link Activity#startActivity(Intent)}.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000473 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100474 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000475
476 /**
Jeff Sharkey97978802014-10-14 10:48:18 -0700477 * Flag used by {@link #addCrossProfileIntentFilter} to allow access
478 * <em>from</em> a parent <em>to</em> its managed profile. That is, any
479 * matching activities in the managed profile are included in the
480 * disambiguation list shown when an app in the parent profile calls
481 * {@link Activity#startActivity(Intent)}.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000482 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100483 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700484
Dianne Hackbornd6847842010-01-12 18:14:19 -0800485 /**
486 * Return true if the given administrator component is currently
487 * active (enabled) in the system.
488 */
489 public boolean isAdminActive(ComponentName who) {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100490 return isAdminActiveAsUser(who, UserHandle.myUserId());
491 }
492
493 /**
494 * @see #isAdminActive(ComponentName)
495 * @hide
496 */
497 public boolean isAdminActiveAsUser(ComponentName who, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800498 if (mService != null) {
499 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100500 return mService.isAdminActive(who, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800501 } catch (RemoteException e) {
502 Log.w(TAG, "Failed talking with device policy service", e);
503 }
504 }
505 return false;
506 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800507 /**
508 * Return true if the given administrator component is currently being removed
509 * for the user.
510 * @hide
511 */
512 public boolean isRemovingAdmin(ComponentName who, int userId) {
513 if (mService != null) {
514 try {
515 return mService.isRemovingAdmin(who, userId);
516 } catch (RemoteException e) {
517 Log.w(TAG, "Failed talking with device policy service", e);
518 }
519 }
520 return false;
521 }
522
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700523
Dianne Hackbornd6847842010-01-12 18:14:19 -0800524 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800525 * Return a list of all currently active device administrator's component
526 * names. Note that if there are no administrators than null may be
527 * returned.
528 */
529 public List<ComponentName> getActiveAdmins() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100530 return getActiveAdminsAsUser(UserHandle.myUserId());
531 }
532
533 /**
534 * @see #getActiveAdmins()
535 * @hide
536 */
537 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800538 if (mService != null) {
539 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100540 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800541 } catch (RemoteException e) {
542 Log.w(TAG, "Failed talking with device policy service", e);
543 }
544 }
545 return null;
546 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700547
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800548 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700549 * Used by package administration code to determine if a package can be stopped
550 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800551 * @hide
552 */
553 public boolean packageHasActiveAdmins(String packageName) {
554 if (mService != null) {
555 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700556 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800557 } catch (RemoteException e) {
558 Log.w(TAG, "Failed talking with device policy service", e);
559 }
560 }
561 return false;
562 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700563
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800564 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800565 * Remove a current administration component. This can only be called
566 * by the application that owns the administration component; if you
567 * try to remove someone else's component, a security exception will be
568 * thrown.
569 */
570 public void removeActiveAdmin(ComponentName who) {
571 if (mService != null) {
572 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700573 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800574 } catch (RemoteException e) {
575 Log.w(TAG, "Failed talking with device policy service", e);
576 }
577 }
578 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700579
Dianne Hackbornd6847842010-01-12 18:14:19 -0800580 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800581 * Returns true if an administrator has been granted a particular device policy. This can
582 * be used to check if the administrator was activated under an earlier set of policies,
583 * but requires additional policies after an upgrade.
584 *
585 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
586 * an active administrator, or an exception will be thrown.
587 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
588 */
589 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
590 if (mService != null) {
591 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700592 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800593 } catch (RemoteException e) {
594 Log.w(TAG, "Failed talking with device policy service", e);
595 }
596 }
597 return false;
598 }
599
600 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800601 * Constant for {@link #setPasswordQuality}: the policy has no requirements
602 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800603 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800604 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800605 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700606
Dianne Hackbornd6847842010-01-12 18:14:19 -0800607 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700608 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
609 * recognition technology. This implies technologies that can recognize the identity of
610 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
611 * Note that quality constants are ordered so that higher values are more restrictive.
612 */
613 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
614
615 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800616 * Constant for {@link #setPasswordQuality}: the policy requires some kind
617 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800618 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800619 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800620 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700621
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800622 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800623 * Constant for {@link #setPasswordQuality}: the user must have entered a
624 * password containing at least numeric characters. Note that quality
625 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800626 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800627 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700628
Dianne Hackbornd6847842010-01-12 18:14:19 -0800629 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800630 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800631 * password containing at least numeric characters with no repeating (4444)
632 * or ordered (1234, 4321, 2468) sequences. Note that quality
633 * constants are ordered so that higher values are more restrictive.
634 */
635 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
636
637 /**
638 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700639 * password containing at least alphabetic (or other symbol) characters.
640 * Note that quality constants are ordered so that higher values are more
641 * restrictive.
642 */
643 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700644
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700645 /**
646 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800647 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700648 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800649 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800650 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700651 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700652
Dianne Hackbornd6847842010-01-12 18:14:19 -0800653 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700654 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700655 * password containing at least a letter, a numerical digit and a special
656 * symbol, by default. With this password quality, passwords can be
657 * restricted to contain various sets of characters, like at least an
658 * uppercase letter, etc. These are specified using various methods,
659 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
660 * that quality constants are ordered so that higher values are more
661 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700662 */
663 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
664
665 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800666 * Called by an application that is administering the device to set the
667 * password restrictions it is imposing. After setting this, the user
668 * will not be able to enter a new password that is not at least as
669 * restrictive as what has been set. Note that the current password
670 * will remain until the user has set a new one, so the change does not
671 * take place immediately. To prompt the user for a new password, use
672 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700673 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800674 * <p>Quality constants are ordered so that higher values are more restrictive;
675 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800676 * the user's preference, and any other considerations) is the one that
677 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700678 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800679 * <p>The calling device admin must have requested
680 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
681 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700682 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800683 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800684 * @param quality The new desired quality. One of
685 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -0800686 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
687 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
688 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800689 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800690 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800691 if (mService != null) {
692 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700693 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800694 } catch (RemoteException e) {
695 Log.w(TAG, "Failed talking with device policy service", e);
696 }
697 }
698 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700699
Dianne Hackbornd6847842010-01-12 18:14:19 -0800700 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100701 * Retrieve the current minimum password quality for all admins of this user
702 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800703 * @param admin The name of the admin component to check, or null to aggregate
704 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800705 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800706 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700707 return getPasswordQuality(admin, UserHandle.myUserId());
708 }
709
710 /** @hide per-user version */
711 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800712 if (mService != null) {
713 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700714 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800715 } catch (RemoteException e) {
716 Log.w(TAG, "Failed talking with device policy service", e);
717 }
718 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800719 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800720 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700721
Dianne Hackbornd6847842010-01-12 18:14:19 -0800722 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800723 * Called by an application that is administering the device to set the
724 * minimum allowed password length. After setting this, the user
725 * will not be able to enter a new password that is not at least as
726 * restrictive as what has been set. Note that the current password
727 * will remain until the user has set a new one, so the change does not
728 * take place immediately. To prompt the user for a new password, use
729 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
730 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -0800731 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
732 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
733 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700734 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800735 * <p>The calling device admin must have requested
736 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
737 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700738 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800739 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800740 * @param length The new desired minimum password length. A value of 0
741 * means there is no restriction.
742 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800743 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800744 if (mService != null) {
745 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700746 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800747 } catch (RemoteException e) {
748 Log.w(TAG, "Failed talking with device policy service", e);
749 }
750 }
751 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700752
Dianne Hackbornd6847842010-01-12 18:14:19 -0800753 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100754 * Retrieve the current minimum password length for all admins of this
755 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800756 * @param admin The name of the admin component to check, or null to aggregate
757 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800758 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800759 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700760 return getPasswordMinimumLength(admin, UserHandle.myUserId());
761 }
762
763 /** @hide per-user version */
764 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800765 if (mService != null) {
766 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700767 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800768 } catch (RemoteException e) {
769 Log.w(TAG, "Failed talking with device policy service", e);
770 }
771 }
772 return 0;
773 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700774
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700775 /**
776 * Called by an application that is administering the device to set the
777 * minimum number of upper case letters required in the password. After
778 * setting this, the user will not be able to enter a new password that is
779 * not at least as restrictive as what has been set. Note that the current
780 * password will remain until the user has set a new one, so the change does
781 * not take place immediately. To prompt the user for a new password, use
782 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
783 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700784 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
785 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700786 * <p>
787 * The calling device admin must have requested
788 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
789 * this method; if it has not, a security exception will be thrown.
790 *
791 * @param admin Which {@link DeviceAdminReceiver} this request is associated
792 * with.
793 * @param length The new desired minimum number of upper case letters
794 * required in the password. A value of 0 means there is no
795 * restriction.
796 */
797 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
798 if (mService != null) {
799 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700800 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700801 } catch (RemoteException e) {
802 Log.w(TAG, "Failed talking with device policy service", e);
803 }
804 }
805 }
806
807 /**
808 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100809 * password for all admins of this user and its profiles or a particular one.
810 * This is the same value as set by
811 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700812 * and only applies when the password quality is
813 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700814 *
815 * @param admin The name of the admin component to check, or null to
816 * aggregate all admins.
817 * @return The minimum number of upper case letters required in the
818 * password.
819 */
820 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700821 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
822 }
823
824 /** @hide per-user version */
825 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700826 if (mService != null) {
827 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700828 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700829 } catch (RemoteException e) {
830 Log.w(TAG, "Failed talking with device policy service", e);
831 }
832 }
833 return 0;
834 }
835
836 /**
837 * Called by an application that is administering the device to set the
838 * minimum number of lower case letters required in the password. After
839 * setting this, the user will not be able to enter a new password that is
840 * not at least as restrictive as what has been set. Note that the current
841 * password will remain until the user has set a new one, so the change does
842 * not take place immediately. To prompt the user for a new password, use
843 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
844 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700845 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
846 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700847 * <p>
848 * The calling device admin must have requested
849 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
850 * this method; if it has not, a security exception will be thrown.
851 *
852 * @param admin Which {@link DeviceAdminReceiver} this request is associated
853 * with.
854 * @param length The new desired minimum number of lower case letters
855 * required in the password. A value of 0 means there is no
856 * restriction.
857 */
858 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
859 if (mService != null) {
860 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700861 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700862 } catch (RemoteException e) {
863 Log.w(TAG, "Failed talking with device policy service", e);
864 }
865 }
866 }
867
868 /**
869 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100870 * password for all admins of this user and its profiles or a particular one.
871 * This is the same value as set by
872 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700873 * and only applies when the password quality is
874 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700875 *
876 * @param admin The name of the admin component to check, or null to
877 * aggregate all admins.
878 * @return The minimum number of lower case letters required in the
879 * password.
880 */
881 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700882 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
883 }
884
885 /** @hide per-user version */
886 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700887 if (mService != null) {
888 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700889 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700890 } catch (RemoteException e) {
891 Log.w(TAG, "Failed talking with device policy service", e);
892 }
893 }
894 return 0;
895 }
896
897 /**
898 * Called by an application that is administering the device to set the
899 * minimum number of letters required in the password. After setting this,
900 * the user will not be able to enter a new password that is not at least as
901 * restrictive as what has been set. Note that the current password will
902 * remain until the user has set a new one, so the change does not take
903 * place immediately. To prompt the user for a new password, use
904 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
905 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700906 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
907 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700908 * <p>
909 * The calling device admin must have requested
910 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
911 * this method; if it has not, a security exception will be thrown.
912 *
913 * @param admin Which {@link DeviceAdminReceiver} this request is associated
914 * with.
915 * @param length The new desired minimum number of letters required in the
916 * password. A value of 0 means there is no restriction.
917 */
918 public void setPasswordMinimumLetters(ComponentName admin, int length) {
919 if (mService != null) {
920 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700921 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700922 } catch (RemoteException e) {
923 Log.w(TAG, "Failed talking with device policy service", e);
924 }
925 }
926 }
927
928 /**
929 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700930 * admins or a particular one. This is the same value as
931 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
932 * and only applies when the password quality is
933 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700934 *
935 * @param admin The name of the admin component to check, or null to
936 * aggregate all admins.
937 * @return The minimum number of letters required in the password.
938 */
939 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700940 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
941 }
942
943 /** @hide per-user version */
944 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700945 if (mService != null) {
946 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700947 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700948 } catch (RemoteException e) {
949 Log.w(TAG, "Failed talking with device policy service", e);
950 }
951 }
952 return 0;
953 }
954
955 /**
956 * Called by an application that is administering the device to set the
957 * minimum number of numerical digits required in the password. After
958 * setting this, the user will not be able to enter a new password that is
959 * not at least as restrictive as what has been set. Note that the current
960 * password will remain until the user has set a new one, so the change does
961 * not take place immediately. To prompt the user for a new password, use
962 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
963 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700964 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
965 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700966 * <p>
967 * The calling device admin must have requested
968 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
969 * this method; if it has not, a security exception will be thrown.
970 *
971 * @param admin Which {@link DeviceAdminReceiver} this request is associated
972 * with.
973 * @param length The new desired minimum number of numerical digits required
974 * in the password. A value of 0 means there is no restriction.
975 */
976 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
977 if (mService != null) {
978 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700979 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700980 } catch (RemoteException e) {
981 Log.w(TAG, "Failed talking with device policy service", e);
982 }
983 }
984 }
985
986 /**
987 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100988 * for all admins of this user and its profiles or a particular one.
989 * This is the same value as set by
990 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700991 * and only applies when the password quality is
992 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700993 *
994 * @param admin The name of the admin component to check, or null to
995 * aggregate all admins.
996 * @return The minimum number of numerical digits required in the password.
997 */
998 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700999 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
1000 }
1001
1002 /** @hide per-user version */
1003 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001004 if (mService != null) {
1005 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001006 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001007 } catch (RemoteException e) {
1008 Log.w(TAG, "Failed talking with device policy service", e);
1009 }
1010 }
1011 return 0;
1012 }
1013
1014 /**
1015 * Called by an application that is administering the device to set the
1016 * minimum number of symbols required in the password. After setting this,
1017 * the user will not be able to enter a new password that is not at least as
1018 * restrictive as what has been set. Note that the current password will
1019 * remain until the user has set a new one, so the change does not take
1020 * place immediately. To prompt the user for a new password, use
1021 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1022 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001023 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1024 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001025 * <p>
1026 * The calling device admin must have requested
1027 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1028 * this method; if it has not, a security exception will be thrown.
1029 *
1030 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1031 * with.
1032 * @param length The new desired minimum number of symbols required in the
1033 * password. A value of 0 means there is no restriction.
1034 */
1035 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
1036 if (mService != null) {
1037 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001038 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001039 } catch (RemoteException e) {
1040 Log.w(TAG, "Failed talking with device policy service", e);
1041 }
1042 }
1043 }
1044
1045 /**
1046 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001047 * admins or a particular one. This is the same value as
1048 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1049 * and only applies when the password quality is
1050 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001051 *
1052 * @param admin The name of the admin component to check, or null to
1053 * aggregate all admins.
1054 * @return The minimum number of symbols required in the password.
1055 */
1056 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001057 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
1058 }
1059
1060 /** @hide per-user version */
1061 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001062 if (mService != null) {
1063 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001064 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001065 } catch (RemoteException e) {
1066 Log.w(TAG, "Failed talking with device policy service", e);
1067 }
1068 }
1069 return 0;
1070 }
1071
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001072 /**
1073 * Called by an application that is administering the device to set the
1074 * minimum number of non-letter characters (numerical digits or symbols)
1075 * required in the password. After setting this, the user will not be able
1076 * to enter a new password that is not at least as restrictive as what has
1077 * been set. Note that the current password will remain until the user has
1078 * set a new one, so the change does not take place immediately. To prompt
1079 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1080 * setting this value. This constraint is only imposed if the administrator
1081 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1082 * {@link #setPasswordQuality}. The default value is 0.
1083 * <p>
1084 * The calling device admin must have requested
1085 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1086 * this method; if it has not, a security exception will be thrown.
1087 *
1088 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1089 * with.
1090 * @param length The new desired minimum number of letters required in the
1091 * password. A value of 0 means there is no restriction.
1092 */
1093 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
1094 if (mService != null) {
1095 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001096 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001097 } catch (RemoteException e) {
1098 Log.w(TAG, "Failed talking with device policy service", e);
1099 }
1100 }
1101 }
1102
1103 /**
1104 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001105 * password for all admins of this user and its profiles or a particular one.
1106 * This is the same value as set by
1107 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001108 * and only applies when the password quality is
1109 * {@link #PASSWORD_QUALITY_COMPLEX}.
1110 *
1111 * @param admin The name of the admin component to check, or null to
1112 * aggregate all admins.
1113 * @return The minimum number of letters required in the password.
1114 */
1115 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001116 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
1117 }
1118
1119 /** @hide per-user version */
1120 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001121 if (mService != null) {
1122 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001123 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001124 } catch (RemoteException e) {
1125 Log.w(TAG, "Failed talking with device policy service", e);
1126 }
1127 }
1128 return 0;
1129 }
1130
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001131 /**
1132 * Called by an application that is administering the device to set the length
1133 * of the password history. After setting this, the user will not be able to
1134 * enter a new password that is the same as any password in the history. Note
1135 * that the current password will remain until the user has set a new one, so
1136 * the change does not take place immediately. To prompt the user for a new
1137 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1138 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001139 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1140 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1141 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001142 *
1143 * <p>
1144 * The calling device admin must have requested
1145 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1146 * method; if it has not, a security exception will be thrown.
1147 *
1148 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1149 * with.
1150 * @param length The new desired length of password history. A value of 0
1151 * means there is no restriction.
1152 */
1153 public void setPasswordHistoryLength(ComponentName admin, int length) {
1154 if (mService != null) {
1155 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001156 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001157 } catch (RemoteException e) {
1158 Log.w(TAG, "Failed talking with device policy service", e);
1159 }
1160 }
1161 }
1162
1163 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001164 * Called by a device admin to set the password expiration timeout. Calling this method
1165 * will restart the countdown for password expiration for the given admin, as will changing
1166 * the device password (for all admins).
1167 *
1168 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1169 * For example, to have the password expire 5 days from now, timeout would be
1170 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1171 *
1172 * <p>To disable password expiration, a value of 0 may be used for timeout.
1173 *
Jim Millera4e28d12010-11-08 16:15:47 -08001174 * <p>The calling device admin must have requested
1175 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1176 * method; if it has not, a security exception will be thrown.
1177 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001178 * <p> Note that setting the password will automatically reset the expiration time for all
1179 * active admins. Active admins do not need to explicitly call this method in that case.
1180 *
Jim Millera4e28d12010-11-08 16:15:47 -08001181 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1182 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1183 * means there is no restriction (unlimited).
1184 */
1185 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
1186 if (mService != null) {
1187 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001188 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001189 } catch (RemoteException e) {
1190 Log.w(TAG, "Failed talking with device policy service", e);
1191 }
1192 }
1193 }
1194
1195 /**
Jim Miller6b857682011-02-16 16:27:41 -08001196 * Get the password expiration timeout for the given admin. The expiration timeout is the
1197 * recurring expiration timeout provided in the call to
1198 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
1199 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001200 *
1201 * @param admin The name of the admin component to check, or null to aggregate all admins.
1202 * @return The timeout for the given admin or the minimum of all timeouts
1203 */
1204 public long getPasswordExpirationTimeout(ComponentName admin) {
1205 if (mService != null) {
1206 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001207 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001208 } catch (RemoteException e) {
1209 Log.w(TAG, "Failed talking with device policy service", e);
1210 }
1211 }
1212 return 0;
1213 }
1214
1215 /**
1216 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001217 * all admins of this user and its profiles if admin is null. If the password is
1218 * expired, this will return the time since the password expired as a negative number.
1219 * If admin is null, then a composite of all expiration timeouts is returned
1220 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001221 *
1222 * @param admin The name of the admin component to check, or null to aggregate all admins.
1223 * @return The password expiration time, in ms.
1224 */
1225 public long getPasswordExpiration(ComponentName admin) {
1226 if (mService != null) {
1227 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001228 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001229 } catch (RemoteException e) {
1230 Log.w(TAG, "Failed talking with device policy service", e);
1231 }
1232 }
1233 return 0;
1234 }
1235
1236 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001237 * Retrieve the current password history length for all admins of this
1238 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001239 * @param admin The name of the admin component to check, or null to aggregate
1240 * all admins.
1241 * @return The length of the password history
1242 */
1243 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001244 return getPasswordHistoryLength(admin, UserHandle.myUserId());
1245 }
1246
1247 /** @hide per-user version */
1248 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001249 if (mService != null) {
1250 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001251 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001252 } catch (RemoteException e) {
1253 Log.w(TAG, "Failed talking with device policy service", e);
1254 }
1255 }
1256 return 0;
1257 }
1258
Dianne Hackbornd6847842010-01-12 18:14:19 -08001259 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001260 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001261 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001262 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001263 * @return Returns the maximum length that the user can enter.
1264 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001265 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001266 // Kind-of arbitrary.
1267 return 16;
1268 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001269
Dianne Hackborn254cb442010-01-27 19:23:59 -08001270 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001271 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001272 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001273 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001274 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001275 * <p>The calling device admin must have requested
1276 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1277 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001278 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001279 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001280 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001281 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001282 if (mService != null) {
1283 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001284 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001285 } catch (RemoteException e) {
1286 Log.w(TAG, "Failed talking with device policy service", e);
1287 }
1288 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001289 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001290 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001291
Dianne Hackbornd6847842010-01-12 18:14:19 -08001292 /**
1293 * Retrieve the number of times the user has failed at entering a
1294 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001295 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001296 * <p>The calling device admin must have requested
1297 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1298 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001299 */
1300 public int getCurrentFailedPasswordAttempts() {
1301 if (mService != null) {
1302 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001303 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001304 } catch (RemoteException e) {
1305 Log.w(TAG, "Failed talking with device policy service", e);
1306 }
1307 }
1308 return -1;
1309 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001310
1311 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001312 * Setting this to a value greater than zero enables a built-in policy
1313 * that will perform a device wipe after too many incorrect
1314 * device-unlock passwords have been entered. This built-in policy combines
1315 * watching for failed passwords and wiping the device, and requires
1316 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001317 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001318 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001319 * <p>To implement any other policy (e.g. wiping data for a particular
1320 * application only, erasing or revoking credentials, or reporting the
1321 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001322 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001323 * instead. Do not use this API, because if the maximum count is reached,
1324 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001325 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001326 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001327 * @param num The number of failed password attempts at which point the
1328 * device will wipe its data.
1329 */
1330 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1331 if (mService != null) {
1332 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001333 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001334 } catch (RemoteException e) {
1335 Log.w(TAG, "Failed talking with device policy service", e);
1336 }
1337 }
1338 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001339
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001340 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001341 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001342 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001343 * or a particular one.
1344 * @param admin The name of the admin component to check, or null to aggregate
1345 * all admins.
1346 */
1347 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001348 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1349 }
1350
1351 /** @hide per-user version */
1352 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001353 if (mService != null) {
1354 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001355 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001356 } catch (RemoteException e) {
1357 Log.w(TAG, "Failed talking with device policy service", e);
1358 }
1359 }
1360 return 0;
1361 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001362
Dianne Hackborn254cb442010-01-27 19:23:59 -08001363 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001364 * Returns the profile with the smallest maximum failed passwords for wipe,
1365 * for the given user. So for primary user, it might return the primary or
1366 * a managed profile. For a secondary user, it would be the same as the
1367 * user passed in.
1368 * @hide Used only by Keyguard
1369 */
1370 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1371 if (mService != null) {
1372 try {
1373 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1374 } catch (RemoteException e) {
1375 Log.w(TAG, "Failed talking with device policy service", e);
1376 }
1377 }
1378 return UserHandle.USER_NULL;
1379 }
1380
1381 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001382 * Flag for {@link #resetPassword}: don't allow other admins to change
1383 * the password again until the user has entered it.
1384 */
1385 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001386
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001387 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001388 * Force a new device unlock password (the password needed to access the
1389 * entire device, not for individual accounts) on the user. This takes
1390 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001391 * The given password must be sufficient for the
1392 * current password quality and length constraints as returned by
1393 * {@link #getPasswordQuality(ComponentName)} and
1394 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1395 * these constraints, then it will be rejected and false returned. Note
1396 * that the password may be a stronger quality (containing alphanumeric
1397 * characters when the requested quality is only numeric), in which case
1398 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001399 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001400 * <p>Calling with a null or empty password will clear any existing PIN,
1401 * pattern or password if the current password constraints allow it.
1402 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001403 * <p>The calling device admin must have requested
1404 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1405 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001406 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07001407 * <p>Calling this from a managed profile will throw a security exception.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001408 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001409 * @param password The new password for the user. Null or empty clears the password.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001410 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001411 * @return Returns true if the password was applied, or false if it is
1412 * not acceptable for the current constraints.
1413 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001414 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001415 if (mService != null) {
1416 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001417 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001418 } catch (RemoteException e) {
1419 Log.w(TAG, "Failed talking with device policy service", e);
1420 }
1421 }
1422 return false;
1423 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001424
Dianne Hackbornd6847842010-01-12 18:14:19 -08001425 /**
1426 * Called by an application that is administering the device to set the
1427 * maximum time for user activity until the device will lock. This limits
1428 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001429 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001430 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001431 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001432 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001433 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001434 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001435 * @param timeMs The new desired maximum time to lock in milliseconds.
1436 * A value of 0 means there is no restriction.
1437 */
1438 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1439 if (mService != null) {
1440 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001441 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001442 } catch (RemoteException e) {
1443 Log.w(TAG, "Failed talking with device policy service", e);
1444 }
1445 }
1446 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001447
Dianne Hackbornd6847842010-01-12 18:14:19 -08001448 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001449 * Retrieve the current maximum time to unlock for all admins of this user
1450 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001451 * @param admin The name of the admin component to check, or null to aggregate
1452 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001453 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001454 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001455 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001456 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001457 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1458 }
1459
1460 /** @hide per-user version */
1461 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001462 if (mService != null) {
1463 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001464 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001465 } catch (RemoteException e) {
1466 Log.w(TAG, "Failed talking with device policy service", e);
1467 }
1468 }
1469 return 0;
1470 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001471
Dianne Hackbornd6847842010-01-12 18:14:19 -08001472 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001473 * Make the device lock immediately, as if the lock screen timeout has
1474 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001475 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001476 * <p>The calling device admin must have requested
1477 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1478 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001479 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001480 public void lockNow() {
1481 if (mService != null) {
1482 try {
1483 mService.lockNow();
1484 } catch (RemoteException e) {
1485 Log.w(TAG, "Failed talking with device policy service", e);
1486 }
1487 }
1488 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001489
Dianne Hackbornd6847842010-01-12 18:14:19 -08001490 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001491 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001492 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001493 */
1494 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1495
1496 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001497 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1498 * data.
1499 *
Paul Crowley2934b262014-12-02 11:21:13 +00001500 * <p>This flag may only be set by device owner admins; if it is set by
1501 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001502 */
1503 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1504
1505 /**
Paul Quei2450a0e2013-09-20 09:26:21 +08001506 * Ask the user data be wiped. This will cause the device to reboot,
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001507 * erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001508 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001509 * <p>The calling device admin must have requested
1510 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1511 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001512 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001513 * @param flags Bit mask of additional options: currently supported flags
1514 * are {@link #WIPE_EXTERNAL_STORAGE} and
1515 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001516 */
1517 public void wipeData(int flags) {
1518 if (mService != null) {
1519 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001520 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001521 } catch (RemoteException e) {
1522 Log.w(TAG, "Failed talking with device policy service", e);
1523 }
1524 }
1525 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001526
Dianne Hackbornd6847842010-01-12 18:14:19 -08001527 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001528 * Called by an application that is administering the device to set the
1529 * global proxy and exclusion list.
1530 * <p>
1531 * The calling device admin must have requested
1532 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1533 * this method; if it has not, a security exception will be thrown.
1534 * Only the first device admin can set the proxy. If a second admin attempts
1535 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1536 * proxy will be returned. If successful in setting the proxy, null will
1537 * be returned.
1538 * The method can be called repeatedly by the device admin alrady setting the
1539 * proxy to update the proxy and exclusion list.
1540 *
1541 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1542 * with.
1543 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1544 * Pass Proxy.NO_PROXY to reset the proxy.
1545 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001546 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1547 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001548 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001549 */
1550 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1551 List<String> exclusionList ) {
1552 if (proxySpec == null) {
1553 throw new NullPointerException();
1554 }
1555 if (mService != null) {
1556 try {
1557 String hostSpec;
1558 String exclSpec;
1559 if (proxySpec.equals(Proxy.NO_PROXY)) {
1560 hostSpec = null;
1561 exclSpec = null;
1562 } else {
1563 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1564 throw new IllegalArgumentException();
1565 }
1566 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1567 String hostName = sa.getHostName();
1568 int port = sa.getPort();
1569 StringBuilder hostBuilder = new StringBuilder();
1570 hostSpec = hostBuilder.append(hostName)
1571 .append(":").append(Integer.toString(port)).toString();
1572 if (exclusionList == null) {
1573 exclSpec = "";
1574 } else {
1575 StringBuilder listBuilder = new StringBuilder();
1576 boolean firstDomain = true;
1577 for (String exclDomain : exclusionList) {
1578 if (!firstDomain) {
1579 listBuilder = listBuilder.append(",");
1580 } else {
1581 firstDomain = false;
1582 }
1583 listBuilder = listBuilder.append(exclDomain.trim());
1584 }
1585 exclSpec = listBuilder.toString();
1586 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001587 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1588 != android.net.Proxy.PROXY_VALID)
1589 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001590 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001591 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001592 } catch (RemoteException e) {
1593 Log.w(TAG, "Failed talking with device policy service", e);
1594 }
1595 }
1596 return null;
1597 }
1598
1599 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001600 * Set a network-independent global HTTP proxy. This is not normally what you want
1601 * for typical HTTP proxies - they are generally network dependent. However if you're
1602 * doing something unusual like general internal filtering this may be useful. On
1603 * a private network where the proxy is not accessible, you may break HTTP using this.
1604 *
1605 * <p>This method requires the caller to be the device owner.
1606 *
1607 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1608 * @see ProxyInfo
1609 *
1610 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1611 * with.
1612 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1613 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1614 */
1615 public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) {
1616 if (mService != null) {
1617 try {
1618 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1619 } catch (RemoteException e) {
1620 Log.w(TAG, "Failed talking with device policy service", e);
1621 }
1622 }
1623 }
1624
1625 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001626 * Returns the component name setting the global proxy.
1627 * @return ComponentName object of the device admin that set the global proxy, or
1628 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001629 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001630 */
1631 public ComponentName getGlobalProxyAdmin() {
1632 if (mService != null) {
1633 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001634 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001635 } catch (RemoteException e) {
1636 Log.w(TAG, "Failed talking with device policy service", e);
1637 }
1638 }
1639 return null;
1640 }
1641
1642 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001643 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001644 * indicating that encryption is not supported.
1645 */
1646 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1647
1648 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001649 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001650 * indicating that encryption is supported, but is not currently active.
1651 */
1652 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1653
1654 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001655 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001656 * indicating that encryption is not currently active, but is currently
1657 * being activated. This is only reported by devices that support
1658 * encryption of data and only when the storage is currently
1659 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1660 * to become encrypted will never return this value.
1661 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001662 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001663
1664 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001665 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001666 * indicating that encryption is active.
1667 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001668 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001669
1670 /**
1671 * Activity action: begin the process of encrypting data on the device. This activity should
1672 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1673 * After resuming from this activity, use {@link #getStorageEncryption}
1674 * to check encryption status. However, on some devices this activity may never return, as
1675 * it may trigger a reboot and in some cases a complete data wipe of the device.
1676 */
1677 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1678 public static final String ACTION_START_ENCRYPTION
1679 = "android.app.action.START_ENCRYPTION";
1680
1681 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001682 * Widgets are enabled in keyguard
1683 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001684 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001685
1686 /**
Jim Miller50e62182014-04-23 17:25:00 -07001687 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001688 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001689 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1690
1691 /**
1692 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1693 */
1694 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1695
1696 /**
Jim Miller50e62182014-04-23 17:25:00 -07001697 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1698 */
1699 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1700
1701 /**
1702 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1703 */
1704 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1705
1706 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02001707 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07001708 * (e.g. PIN/Pattern/Password).
1709 */
1710 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1711
1712 /**
Jim Miller06e34502014-07-17 14:46:05 -07001713 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
1714 */
1715 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
1716
1717 /**
Jim Miller35207742012-11-02 15:33:20 -07001718 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001719 */
1720 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001721
1722 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001723 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001724 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001725 *
1726 * <p>When multiple device administrators attempt to control device
1727 * encryption, the most secure, supported setting will always be
1728 * used. If any device administrator requests device encryption,
1729 * it will be enabled; Conversely, if a device administrator
1730 * attempts to disable device encryption while another
1731 * device administrator has enabled it, the call to disable will
1732 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1733 *
1734 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001735 * written to other storage areas may or may not be encrypted, and this policy does not require
1736 * or control the encryption of any other storage areas.
1737 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1738 * {@code true}, then the directory returned by
1739 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1740 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001741 *
1742 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1743 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1744 * the encryption key may not be fully secured. For maximum security, the administrator should
1745 * also require (and check for) a pattern, PIN, or password.
1746 *
1747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1748 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001749 * @return the new request status (for all active admins) - will be one of
1750 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1751 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1752 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001753 */
1754 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1755 if (mService != null) {
1756 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001757 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001758 } catch (RemoteException e) {
1759 Log.w(TAG, "Failed talking with device policy service", e);
1760 }
1761 }
1762 return ENCRYPTION_STATUS_UNSUPPORTED;
1763 }
1764
1765 /**
1766 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001767 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001768 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001769 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1770 * this will return the requested encryption setting as an aggregate of all active
1771 * administrators.
1772 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001773 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001774 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001775 if (mService != null) {
1776 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001777 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001778 } catch (RemoteException e) {
1779 Log.w(TAG, "Failed talking with device policy service", e);
1780 }
1781 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001782 return false;
1783 }
1784
1785 /**
1786 * Called by an application that is administering the device to
1787 * determine the current encryption status of the device.
1788 *
1789 * Depending on the returned status code, the caller may proceed in different
1790 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1791 * storage system does not support encryption. If the
1792 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1793 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1794 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1795 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1796 *
Robin Lee7e678712014-07-24 16:41:31 +01001797 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08001798 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1799 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1800 */
1801 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001802 return getStorageEncryptionStatus(UserHandle.myUserId());
1803 }
1804
1805 /** @hide per-user version */
1806 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001807 if (mService != null) {
1808 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001809 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001810 } catch (RemoteException e) {
1811 Log.w(TAG, "Failed talking with device policy service", e);
1812 }
1813 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001814 return ENCRYPTION_STATUS_UNSUPPORTED;
1815 }
1816
1817 /**
Robin Lee7e678712014-07-24 16:41:31 +01001818 * Installs the given certificate as a user CA.
1819 *
1820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1821 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04001822 *
1823 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01001824 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04001825 */
Robin Lee7e678712014-07-24 16:41:31 +01001826 public boolean installCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001827 if (mService != null) {
1828 try {
Robin Lee7e678712014-07-24 16:41:31 +01001829 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04001830 } catch (RemoteException e) {
1831 Log.w(TAG, "Failed talking with device policy service", e);
1832 }
1833 }
1834 return false;
1835 }
1836
1837 /**
Robin Lee7e678712014-07-24 16:41:31 +01001838 * Uninstalls the given certificate from trusted user CAs, if present.
1839 *
1840 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1841 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04001842 */
Robin Lee7e678712014-07-24 16:41:31 +01001843 public void uninstallCaCert(ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04001844 if (mService != null) {
1845 try {
Robin Lee306fe082014-06-19 14:04:24 +00001846 final String alias = getCaCertAlias(certBuffer);
Robin Lee7e678712014-07-24 16:41:31 +01001847 mService.uninstallCaCert(admin, alias);
Robin Lee306fe082014-06-19 14:04:24 +00001848 } catch (CertificateException e) {
1849 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04001850 } catch (RemoteException e) {
1851 Log.w(TAG, "Failed talking with device policy service", e);
1852 }
1853 }
1854 }
1855
1856 /**
Robin Lee7e678712014-07-24 16:41:31 +01001857 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
1858 * If a user has installed any certificates by other means than device policy these will be
1859 * included too.
1860 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001862 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04001863 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001864 public List<byte[]> getInstalledCaCerts(ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01001865 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001866 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01001867 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001868 mService.enforceCanManageCaCerts(admin);
1869 final TrustedCertificateStore certStore = new TrustedCertificateStore();
1870 for (String alias : certStore.userAliases()) {
1871 try {
1872 certs.add(certStore.getCertificate(alias).getEncoded());
1873 } catch (CertificateException ce) {
1874 Log.w(TAG, "Could not encode certificate: " + alias, ce);
1875 }
1876 }
1877 } catch (RemoteException re) {
1878 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01001879 }
1880 }
1881 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04001882 }
1883
1884 /**
Robin Lee7e678712014-07-24 16:41:31 +01001885 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
1886 * means other than device policy will also be removed, except for system CA certificates.
1887 *
1888 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1889 */
1890 public void uninstallAllUserCaCerts(ComponentName admin) {
1891 if (mService != null) {
1892 for (String alias : new TrustedCertificateStore().userAliases()) {
1893 try {
1894 mService.uninstallCaCert(admin, alias);
1895 } catch (RemoteException re) {
1896 Log.w(TAG, "Failed talking with device policy service", re);
1897 }
1898 }
1899 }
1900 }
1901
1902 /**
1903 * Returns whether this certificate is installed as a trusted CA.
1904 *
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Robin Lee7e678712014-07-24 16:41:31 +01001906 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04001907 */
Esteban Talavera808f6ef2014-08-28 17:15:54 +01001908 public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) {
1909 if (mService != null) {
1910 try {
1911 mService.enforceCanManageCaCerts(admin);
1912 return getCaCertAlias(certBuffer) != null;
1913 } catch (RemoteException re) {
1914 Log.w(TAG, "Failed talking with device policy service", re);
1915 } catch (CertificateException ce) {
1916 Log.w(TAG, "Could not parse certificate", ce);
1917 }
Maggie Benthallda51e682013-08-08 22:35:44 -04001918 }
1919 return false;
1920 }
1921
1922 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01001923 * Called by a device or profile owner to install a certificate and private key pair. The
1924 * keypair will be visible to all apps within the profile.
1925 *
1926 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
1927 * @param privKey The private key to install.
1928 * @param cert The certificate to install.
1929 * @param alias The private key alias under which to install the certificate. If a certificate
1930 * with that alias already exists, it will be overwritten.
1931 * @return {@code true} if the keys were installed, {@code false} otherwise.
1932 */
1933 public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert,
1934 String alias) {
1935 try {
1936 final byte[] pemCert = Credentials.convertToPem(cert);
1937 return mService.installKeyPair(who, privKey.getEncoded(), pemCert, alias);
1938 } catch (CertificateException e) {
1939 Log.w(TAG, "Error encoding certificate", e);
1940 } catch (IOException e) {
1941 Log.w(TAG, "Error writing certificate", e);
1942 } catch (RemoteException e) {
1943 Log.w(TAG, "Failed talking with device policy service", e);
1944 }
1945 return false;
1946 }
1947
1948 /**
Robin Lee306fe082014-06-19 14:04:24 +00001949 * Returns the alias of a given CA certificate in the certificate store, or null if it
1950 * doesn't exist.
1951 */
1952 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
1953 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1954 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1955 new ByteArrayInputStream(certBuffer));
1956 return new TrustedCertificateStore().getCertificateAlias(cert);
1957 }
1958
1959 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001960 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07001961 * on the device, for this user. After setting this, no applications running as this user
1962 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07001963 *
1964 * <p>The calling device admin must have requested
1965 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1966 * this method; if it has not, a security exception will be thrown.
1967 *
1968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1969 * @param disabled Whether or not the camera should be disabled.
1970 */
1971 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1972 if (mService != null) {
1973 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001974 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001975 } catch (RemoteException e) {
1976 Log.w(TAG, "Failed talking with device policy service", e);
1977 }
1978 }
1979 }
1980
1981 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07001982 * Determine whether or not the device's cameras have been disabled for this user,
1983 * either by the current admin, if specified, or all admins.
Ben Komalo2447edd2011-05-09 16:05:33 -07001984 * @param admin The name of the admin component to check, or null to check if any admins
1985 * have disabled the camera
1986 */
1987 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001988 return getCameraDisabled(admin, UserHandle.myUserId());
1989 }
1990
1991 /** @hide per-user version */
1992 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001993 if (mService != null) {
1994 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001995 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001996 } catch (RemoteException e) {
1997 Log.w(TAG, "Failed talking with device policy service", e);
1998 }
1999 }
2000 return false;
2001 }
2002
2003 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002004 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2005 * screen capture also prevents the content from being shown on display devices that do not have
2006 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2007 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002008 *
2009 * <p>The calling device admin must be a device or profile owner. If it is not, a
2010 * security exception will be thrown.
2011 *
2012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002013 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002014 */
2015 public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) {
2016 if (mService != null) {
2017 try {
2018 mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled);
2019 } catch (RemoteException e) {
2020 Log.w(TAG, "Failed talking with device policy service", e);
2021 }
2022 }
2023 }
2024
2025 /**
2026 * Determine whether or not screen capture has been disabled by the current
2027 * admin, if specified, or all admins.
2028 * @param admin The name of the admin component to check, or null to check if any admins
2029 * have disabled screen capture.
2030 */
2031 public boolean getScreenCaptureDisabled(ComponentName admin) {
2032 return getScreenCaptureDisabled(admin, UserHandle.myUserId());
2033 }
2034
2035 /** @hide per-user version */
2036 public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) {
2037 if (mService != null) {
2038 try {
2039 return mService.getScreenCaptureDisabled(admin, userHandle);
2040 } catch (RemoteException e) {
2041 Log.w(TAG, "Failed talking with device policy service", e);
2042 }
2043 }
2044 return false;
2045 }
2046
2047 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002048 * Called by a device owner to set whether auto time is required. If auto time is
2049 * required the user cannot set the date and time, but has to use network date and time.
2050 *
2051 * <p>Note: if auto time is required the user can still manually set the time zone.
2052 *
2053 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2054 * be thrown.
2055 *
2056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2057 * @param required Whether auto time is set required or not.
2058 */
2059 public void setAutoTimeRequired(ComponentName admin, boolean required) {
2060 if (mService != null) {
2061 try {
2062 mService.setAutoTimeRequired(admin, UserHandle.myUserId(), required);
2063 } catch (RemoteException e) {
2064 Log.w(TAG, "Failed talking with device policy service", e);
2065 }
2066 }
2067 }
2068
2069 /**
2070 * @return true if auto time is required.
2071 */
2072 public boolean getAutoTimeRequired() {
2073 if (mService != null) {
2074 try {
2075 return mService.getAutoTimeRequired();
2076 } catch (RemoteException e) {
2077 Log.w(TAG, "Failed talking with device policy service", e);
2078 }
2079 }
2080 return false;
2081 }
2082
2083 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002084 * Called by an application that is administering the device to disable keyguard customizations,
2085 * such as widgets. After setting this, keyguard features will be disabled according to the
2086 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002087 *
2088 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002089 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002090 * this method; if it has not, a security exception will be thrown.
2091 *
Amith Yamasani242f4b12014-10-14 16:06:13 -07002092 * <p>Calling this from a managed profile will throw a security exception.
2093 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002094 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002095 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2096 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002097 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
2098 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002099 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002100 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002101 if (mService != null) {
2102 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002103 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07002104 } catch (RemoteException e) {
2105 Log.w(TAG, "Failed talking with device policy service", e);
2106 }
2107 }
2108 }
2109
2110 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002111 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002112 * admin, if specified, or all admins.
2113 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002114 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002115 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2116 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002117 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002118 public int getKeyguardDisabledFeatures(ComponentName admin) {
2119 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002120 }
2121
2122 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002123 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002124 if (mService != null) {
2125 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002126 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002127 } catch (RemoteException e) {
2128 Log.w(TAG, "Failed talking with device policy service", e);
2129 }
2130 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002131 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002132 }
2133
2134 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002135 * @hide
2136 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01002137 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002138 if (mService != null) {
2139 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002140 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002141 } catch (RemoteException e) {
2142 Log.w(TAG, "Failed talking with device policy service", e);
2143 }
2144 }
2145 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002146
Dianne Hackbornd6847842010-01-12 18:14:19 -08002147 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002148 * @hide
2149 */
2150 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
2151 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
2152 }
2153
2154 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08002155 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002156 * @hide
2157 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08002158 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002159 ActivityInfo ai;
2160 try {
2161 ai = mContext.getPackageManager().getReceiverInfo(cn,
2162 PackageManager.GET_META_DATA);
2163 } catch (PackageManager.NameNotFoundException e) {
2164 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2165 return null;
2166 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002167
Dianne Hackbornd6847842010-01-12 18:14:19 -08002168 ResolveInfo ri = new ResolveInfo();
2169 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002170
Dianne Hackbornd6847842010-01-12 18:14:19 -08002171 try {
2172 return new DeviceAdminInfo(mContext, ri);
2173 } catch (XmlPullParserException e) {
2174 Log.w(TAG, "Unable to parse device policy " + cn, e);
2175 return null;
2176 } catch (IOException e) {
2177 Log.w(TAG, "Unable to parse device policy " + cn, e);
2178 return null;
2179 }
2180 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002181
Dianne Hackbornd6847842010-01-12 18:14:19 -08002182 /**
2183 * @hide
2184 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002185 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
2186 if (mService != null) {
2187 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002188 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002189 } catch (RemoteException e) {
2190 Log.w(TAG, "Failed talking with device policy service", e);
2191 }
2192 }
2193 }
2194
2195 /**
2196 * @hide
2197 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002198 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002199 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002200 if (mService != null) {
2201 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002202 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002203 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002204 } catch (RemoteException e) {
2205 Log.w(TAG, "Failed talking with device policy service", e);
2206 }
2207 }
2208 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002209
Dianne Hackbornd6847842010-01-12 18:14:19 -08002210 /**
2211 * @hide
2212 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002213 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002214 if (mService != null) {
2215 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002216 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002217 } catch (RemoteException e) {
2218 Log.w(TAG, "Failed talking with device policy service", e);
2219 }
2220 }
2221 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002222
Dianne Hackbornd6847842010-01-12 18:14:19 -08002223 /**
2224 * @hide
2225 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002226 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002227 if (mService != null) {
2228 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002229 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002230 } catch (RemoteException e) {
2231 Log.w(TAG, "Failed talking with device policy service", e);
2232 }
2233 }
2234 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002235
2236 /**
2237 * @hide
2238 * Sets the given package as the device owner. The package must already be installed and there
2239 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2240 * method must be called before the device is provisioned.
2241 * @param packageName the package name of the application to be registered as the device owner.
2242 * @return whether the package was successfully registered as the device owner.
2243 * @throws IllegalArgumentException if the package name is null or invalid
2244 * @throws IllegalStateException if a device owner is already registered or the device has
2245 * already been provisioned.
2246 */
2247 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
2248 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002249 return setDeviceOwner(packageName, null);
2250 }
2251
2252 /**
2253 * @hide
2254 * Sets the given package as the device owner. The package must already be installed and there
2255 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
2256 * method must be called before the device is provisioned.
2257 * @param packageName the package name of the application to be registered as the device owner.
2258 * @param ownerName the human readable name of the institution that owns this device.
2259 * @return whether the package was successfully registered as the device owner.
2260 * @throws IllegalArgumentException if the package name is null or invalid
2261 * @throws IllegalStateException if a device owner is already registered or the device has
2262 * already been provisioned.
2263 */
2264 public boolean setDeviceOwner(String packageName, String ownerName)
2265 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002266 if (mService != null) {
2267 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002268 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002269 } catch (RemoteException re) {
2270 Log.w(TAG, "Failed to set device owner");
2271 }
2272 }
2273 return false;
2274 }
2275
2276 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002277 * Used to determine if a particular package has been registered as a Device Owner app.
2278 * A device owner app is a special device admin that cannot be deactivated by the user, once
2279 * activated as a device admin. It also cannot be uninstalled. To check if a particular
2280 * package is currently registered as the device owner app, pass in the package name from
2281 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
2282 * admin apps that want to check if they are also registered as the device owner app. The
2283 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2284 * the setup process.
2285 * @param packageName the package name of the app, to compare with the registered device owner
2286 * app, if any.
2287 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002288 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002289 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002290 if (mService != null) {
2291 try {
2292 return mService.isDeviceOwner(packageName);
2293 } catch (RemoteException re) {
2294 Log.w(TAG, "Failed to check device owner");
2295 }
2296 }
2297 return false;
2298 }
2299
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002300 /**
2301 * @hide
2302 * Redirect to isDeviceOwnerApp.
2303 */
2304 public boolean isDeviceOwner(String packageName) {
2305 return isDeviceOwnerApp(packageName);
2306 }
2307
Jason Monkb0dced82014-06-06 14:36:20 -04002308 /**
2309 * Clears the current device owner. The caller must be the device owner.
2310 *
2311 * This function should be used cautiously as once it is called it cannot
2312 * be undone. The device owner can only be set as a part of device setup
2313 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002314 *
2315 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002316 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002317 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002318 if (mService != null) {
2319 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002320 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002321 } catch (RemoteException re) {
2322 Log.w(TAG, "Failed to clear device owner");
2323 }
2324 }
2325 }
2326
Amith Yamasani71e6c692013-03-24 17:39:28 -07002327 /** @hide */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002328 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002329 public String getDeviceOwner() {
2330 if (mService != null) {
2331 try {
2332 return mService.getDeviceOwner();
2333 } catch (RemoteException re) {
2334 Log.w(TAG, "Failed to get device owner");
2335 }
2336 }
2337 return null;
2338 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002339
2340 /** @hide */
2341 public String getDeviceOwnerName() {
2342 if (mService != null) {
2343 try {
2344 return mService.getDeviceOwnerName();
2345 } catch (RemoteException re) {
2346 Log.w(TAG, "Failed to get device owner");
2347 }
2348 }
2349 return null;
2350 }
Adam Connors776c5552014-01-09 10:42:56 +00002351
2352 /**
2353 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002354 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302355 * Sets the given component as an active admin and registers the package as the profile
2356 * owner for this user. The package must already be installed and there shouldn't be
2357 * an existing profile owner registered for this user. Also, this method must be called
2358 * before the user setup has been completed.
2359 * <p>
2360 * This method can only be called by system apps that hold MANAGE_USERS permission and
2361 * MANAGE_DEVICE_ADMINS permission.
2362 * @param admin The component to register as an active admin and profile owner.
2363 * @param ownerName The user-visible name of the entity that is managing this user.
2364 * @return whether the admin was successfully registered as the profile owner.
2365 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2366 * the user has already been set up.
2367 */
Justin Morey80440cc2014-07-24 09:16:35 -05002368 @SystemApi
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302369 public boolean setActiveProfileOwner(ComponentName admin, String ownerName)
2370 throws IllegalArgumentException {
2371 if (mService != null) {
2372 try {
2373 final int myUserId = UserHandle.myUserId();
2374 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002375 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302376 } catch (RemoteException re) {
2377 Log.w(TAG, "Failed to set profile owner " + re);
2378 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2379 }
2380 }
2381 return false;
2382 }
2383
2384 /**
2385 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002386 * Clears the active profile owner and removes all user restrictions. The caller must
2387 * be from the same package as the active profile owner for this user, otherwise a
2388 * SecurityException will be thrown.
2389 *
2390 * @param admin The component to remove as the profile owner.
2391 * @return
2392 */
2393 @SystemApi
2394 public void clearProfileOwner(ComponentName admin) {
2395 if (mService != null) {
2396 try {
2397 mService.clearProfileOwner(admin);
2398 } catch (RemoteException re) {
2399 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2400 }
2401 }
2402 }
2403
2404 /**
2405 * @hide
2406 * Checks if the user was already setup.
2407 */
2408 public boolean hasUserSetupCompleted() {
2409 if (mService != null) {
2410 try {
2411 return mService.hasUserSetupCompleted();
2412 } catch (RemoteException re) {
2413 Log.w(TAG, "Failed to check if user setup has completed");
2414 }
2415 }
2416 return true;
2417 }
2418
2419 /**
2420 * @deprecated Use setProfileOwner(ComponentName ...)
2421 * @hide
Adam Connors776c5552014-01-09 10:42:56 +00002422 * Sets the given package as the profile owner of the given user profile. The package must
2423 * already be installed and there shouldn't be an existing profile owner registered for this
2424 * user. Also, this method must be called before the user has been used for the first time.
2425 * @param packageName the package name of the application to be registered as profile owner.
2426 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00002427 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00002428 * @return whether the package was successfully registered as the profile owner.
2429 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2430 * the user has already been set up.
2431 */
Adam Connors661ec472014-02-11 13:59:46 +00002432 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00002433 throws IllegalArgumentException {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002434 if (packageName == null) {
2435 throw new NullPointerException("packageName cannot be null");
2436 }
2437 return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle);
2438 }
2439
2440 /**
2441 * @hide
2442 * Sets the given component as the profile owner of the given user profile. The package must
2443 * already be installed and there shouldn't be an existing profile owner registered for this
2444 * user. Only the system can call this API if the user has already completed setup.
2445 * @param admin the component name to be registered as profile owner.
2446 * @param ownerName the human readable name of the organisation associated with this DPM.
2447 * @param userHandle the userId to set the profile owner for.
2448 * @return whether the component was successfully registered as the profile owner.
2449 * @throws IllegalArgumentException if admin is null, the package isn't installed, or
2450 * the user has already been set up.
2451 */
2452 public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle)
2453 throws IllegalArgumentException {
2454 if (admin == null) {
2455 throw new NullPointerException("admin cannot be null");
2456 }
Adam Connors776c5552014-01-09 10:42:56 +00002457 if (mService != null) {
2458 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002459 if (ownerName == null) {
2460 ownerName = "";
2461 }
2462 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002463 } catch (RemoteException re) {
2464 Log.w(TAG, "Failed to set profile owner", re);
2465 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2466 }
2467 }
2468 return false;
2469 }
2470
2471 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002472 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
2473 * be used. Only the profile owner can call this.
2474 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01002475 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002476 *
2477 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2478 */
2479 public void setProfileEnabled(ComponentName admin) {
2480 if (mService != null) {
2481 try {
2482 mService.setProfileEnabled(admin);
2483 } catch (RemoteException e) {
2484 Log.w(TAG, "Failed talking with device policy service", e);
2485 }
2486 }
2487 }
2488
2489 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002490 * Sets the name of the profile. In the device owner case it sets the name of the user
2491 * 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 +01002492 * never called by the profile or device owner, the name will be set to default values.
2493 *
2494 * @see #isProfileOwnerApp
2495 * @see #isDeviceOwnerApp
2496 *
2497 * @param profileName The name of the profile.
2498 */
2499 public void setProfileName(ComponentName who, String profileName) {
2500 if (mService != null) {
2501 try {
2502 mService.setProfileName(who, profileName);
2503 } catch (RemoteException e) {
2504 Log.w(TAG, "Failed talking with device policy service", e);
2505 }
2506 }
2507}
2508
2509 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002510 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01002511 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002512 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00002513 *
2514 * @param packageName The package name of the app to compare with the registered profile owner.
2515 * @return Whether or not the package is registered as the profile owner.
2516 */
2517 public boolean isProfileOwnerApp(String packageName) {
2518 if (mService != null) {
2519 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01002520 ComponentName profileOwner = mService.getProfileOwner(
2521 Process.myUserHandle().getIdentifier());
2522 return profileOwner != null
2523 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00002524 } catch (RemoteException re) {
2525 Log.w(TAG, "Failed to check profile owner");
2526 }
2527 }
2528 return false;
2529 }
2530
2531 /**
2532 * @hide
2533 * @return the packageName of the owner of the given user profile or null if no profile
2534 * owner has been set for that user.
2535 * @throws IllegalArgumentException if the userId is invalid.
2536 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002537 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002538 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002539 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
2540 }
2541
2542 /**
2543 * @see #getProfileOwner()
2544 * @hide
2545 */
2546 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002547 if (mService != null) {
2548 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01002549 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00002550 } catch (RemoteException re) {
2551 Log.w(TAG, "Failed to get profile owner");
2552 throw new IllegalArgumentException(
2553 "Requested profile owner for invalid userId", re);
2554 }
2555 }
2556 return null;
2557 }
2558
2559 /**
2560 * @hide
2561 * @return the human readable name of the organisation associated with this DPM or null if
2562 * one is not set.
2563 * @throws IllegalArgumentException if the userId is invalid.
2564 */
2565 public String getProfileOwnerName() throws IllegalArgumentException {
2566 if (mService != null) {
2567 try {
2568 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
2569 } catch (RemoteException re) {
2570 Log.w(TAG, "Failed to get profile owner");
2571 throw new IllegalArgumentException(
2572 "Requested profile owner for invalid userId", re);
2573 }
2574 }
2575 return null;
2576 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002577
2578 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07002579 * @hide
2580 * @param user The user for whom to fetch the profile owner name, if any.
2581 * @return the human readable name of the organisation associated with this profile owner or
2582 * null if one is not set.
2583 * @throws IllegalArgumentException if the userId is invalid.
2584 */
2585 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02002586 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07002587 if (mService != null) {
2588 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02002589 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07002590 } catch (RemoteException re) {
2591 Log.w(TAG, "Failed to get profile owner");
2592 throw new IllegalArgumentException(
2593 "Requested profile owner for invalid userId", re);
2594 }
2595 }
2596 return null;
2597 }
2598
2599 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002600 * Called by a profile owner or device owner to add a default intent handler activity for
2601 * intents that match a certain intent filter. This activity will remain the default intent
2602 * handler even if the set of potential event handlers for the intent filter changes and if
2603 * the intent preferences are reset.
2604 *
2605 * <p>The default disambiguation mechanism takes over if the activity is not installed
2606 * (anymore). When the activity is (re)installed, it is automatically reset as default
2607 * intent handler for the filter.
2608 *
2609 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
2610 * security exception will be thrown.
2611 *
2612 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2613 * @param filter The IntentFilter for which a default handler is added.
2614 * @param activity The Activity that is added as default intent handler.
2615 */
2616 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
2617 ComponentName activity) {
2618 if (mService != null) {
2619 try {
2620 mService.addPersistentPreferredActivity(admin, filter, activity);
2621 } catch (RemoteException e) {
2622 Log.w(TAG, "Failed talking with device policy service", e);
2623 }
2624 }
2625 }
2626
2627 /**
2628 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00002629 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00002630 *
2631 * <p>The calling device admin must be a profile owner. If it is not, a security
2632 * exception will be thrown.
2633 *
2634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2635 * @param packageName The name of the package for which preferences are removed.
2636 */
2637 public void clearPackagePersistentPreferredActivities(ComponentName admin,
2638 String packageName) {
2639 if (mService != null) {
2640 try {
2641 mService.clearPackagePersistentPreferredActivities(admin, packageName);
2642 } catch (RemoteException e) {
2643 Log.w(TAG, "Failed talking with device policy service", e);
2644 }
2645 }
2646 }
Robin Lee66e5d962014-04-09 16:44:21 +01002647
2648 /**
2649 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002650 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01002651 *
2652 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
Kenny Guyd00cfc52014-09-18 16:24:31 +01002653 * boolean, int, String, or String[].
Robin Lee66e5d962014-04-09 16:44:21 +01002654 *
2655 * <p>The application restrictions are only made visible to the target application and the
2656 * profile or device owner.
2657 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002658 * <p>If the restrictions are not available yet, but may be applied in the near future,
2659 * the admin can notify the target application of that by adding
2660 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
2661 *
Robin Lee66e5d962014-04-09 16:44:21 +01002662 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2663 * exception will be thrown.
2664 *
2665 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2666 * @param packageName The name of the package to update restricted settings for.
2667 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2668 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00002669 *
2670 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01002671 */
2672 public void setApplicationRestrictions(ComponentName admin, String packageName,
2673 Bundle settings) {
2674 if (mService != null) {
2675 try {
2676 mService.setApplicationRestrictions(admin, packageName, settings);
2677 } catch (RemoteException e) {
2678 Log.w(TAG, "Failed talking with device policy service", e);
2679 }
2680 }
2681 }
2682
2683 /**
Jim Millere303bf42014-08-26 17:12:29 -07002684 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
2685 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
2686 * trust agents but those enabled by this function call. If flag
2687 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07002688 *
2689 * <p>The calling device admin must have requested
2690 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07002691 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07002692 *
2693 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07002694 * @param target Component name of the agent to be enabled.
2695 * @param options TrustAgent-specific feature bundle. If null for any admin, agent
2696 * will be strictly disabled according to the state of the
2697 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
2698 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
2699 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
2700 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07002701 */
Jim Millere303bf42014-08-26 17:12:29 -07002702 public void setTrustAgentConfiguration(ComponentName admin, ComponentName target,
2703 PersistableBundle options) {
Jim Miller604e7552014-07-18 19:00:02 -07002704 if (mService != null) {
2705 try {
Jim Millere303bf42014-08-26 17:12:29 -07002706 mService.setTrustAgentConfiguration(admin, target, options, UserHandle.myUserId());
Jim Miller604e7552014-07-18 19:00:02 -07002707 } catch (RemoteException e) {
2708 Log.w(TAG, "Failed talking with device policy service", e);
2709 }
2710 }
2711 }
2712
2713 /**
Jim Millere303bf42014-08-26 17:12:29 -07002714 * Gets configuration for the given trust agent based on aggregating all calls to
2715 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
2716 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07002717 *
2718 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2719 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07002720 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07002721 */
Jim Millere303bf42014-08-26 17:12:29 -07002722 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2723 ComponentName agent) {
2724 return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId());
2725 }
2726
2727 /** @hide per-user version */
2728 public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin,
2729 ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07002730 if (mService != null) {
2731 try {
Jim Millere303bf42014-08-26 17:12:29 -07002732 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07002733 } catch (RemoteException e) {
2734 Log.w(TAG, "Failed talking with device policy service", e);
2735 }
2736 }
Jim Millere303bf42014-08-26 17:12:29 -07002737 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07002738 }
2739
2740 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002741 * Called by a profile owner of a managed profile to set whether caller-Id information from
2742 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01002743 *
2744 * <p>The calling device admin must be a profile owner. If it is not, a
2745 * security exception will be thrown.
2746 *
2747 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2748 * @param disabled If true caller-Id information in the managed profile is not displayed.
2749 */
2750 public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) {
2751 if (mService != null) {
2752 try {
2753 mService.setCrossProfileCallerIdDisabled(who, disabled);
2754 } catch (RemoteException e) {
2755 Log.w(TAG, "Failed talking with device policy service", e);
2756 }
2757 }
2758 }
2759
2760 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002761 * Called by a profile owner of a managed profile to determine whether or not caller-Id
2762 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01002763 *
2764 * <p>The calling device admin must be a profile owner. If it is not, a
2765 * security exception will be thrown.
2766 *
2767 * @param who Which {@link DeviceAdminReceiver} this request is associated with.
2768 */
2769 public boolean getCrossProfileCallerIdDisabled(ComponentName who) {
2770 if (mService != null) {
2771 try {
2772 return mService.getCrossProfileCallerIdDisabled(who);
2773 } catch (RemoteException e) {
2774 Log.w(TAG, "Failed talking with device policy service", e);
2775 }
2776 }
2777 return false;
2778 }
2779
2780 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07002781 * Determine whether or not caller-Id information has been disabled.
2782 *
2783 * @param userHandle The user for whom to check the caller-id permission
2784 * @hide
2785 */
2786 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
2787 if (mService != null) {
2788 try {
2789 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
2790 } catch (RemoteException e) {
2791 Log.w(TAG, "Failed talking with device policy service", e);
2792 }
2793 }
2794 return false;
2795 }
2796
2797 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002798 * Called by the profile owner of a managed profile so that some intents sent in the managed
2799 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002801 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2802 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01002803 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
2804 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002805 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002806 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002807 if (mService != null) {
2808 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002809 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002810 } catch (RemoteException e) {
2811 Log.w(TAG, "Failed talking with device policy service", e);
2812 }
2813 }
2814 }
2815
2816 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07002817 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
2818 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002819 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2821 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002822 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002823 if (mService != null) {
2824 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002825 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002826 } catch (RemoteException e) {
2827 Log.w(TAG, "Failed talking with device policy service", e);
2828 }
2829 }
2830 }
2831
2832 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002833 * Called by a profile or device owner to set the permitted accessibility services. When
2834 * set by a device owner or profile owner the restriction applies to all profiles of the
2835 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07002836 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002837 * By default the user can use any accessiblity service. When zero or more packages have
2838 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07002839 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01002840 *
2841 * <p> Calling with a null value for the list disables the restriction so that all services
2842 * can be used, calling with an empty list only allows the builtin system's services.
2843 *
2844 * <p> System accesibility services are always available to the user the list can't modify
2845 * this.
2846 *
2847 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2848 * @param packageNames List of accessibility service package names.
2849 *
2850 * @return true if setting the restriction succeeded. It fail if there is
2851 * one or more non-system accessibility services enabled, that are not in the list.
2852 */
2853 public boolean setPermittedAccessibilityServices(ComponentName admin,
2854 List<String> packageNames) {
2855 if (mService != null) {
2856 try {
2857 return mService.setPermittedAccessibilityServices(admin, packageNames);
2858 } catch (RemoteException e) {
2859 Log.w(TAG, "Failed talking with device policy service", e);
2860 }
2861 }
2862 return false;
2863 }
2864
2865 /**
2866 * Returns the list of permitted accessibility services set by this device or profile owner.
2867 *
2868 * <p>An empty list means no accessibility services except system services are allowed.
2869 * Null means all accessibility services are allowed.
2870 *
2871 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2872 * @return List of accessiblity service package names.
2873 */
2874 public List<String> getPermittedAccessibilityServices(ComponentName admin) {
2875 if (mService != null) {
2876 try {
2877 return mService.getPermittedAccessibilityServices(admin);
2878 } catch (RemoteException e) {
2879 Log.w(TAG, "Failed talking with device policy service", e);
2880 }
2881 }
2882 return null;
2883 }
2884
2885 /**
2886 * Returns the list of accessibility services permitted by the device or profiles
2887 * owners of this user.
2888 *
2889 * <p>Null means all accessibility services are allowed, if a non-null list is returned
2890 * it will contain the intersection of the permitted lists for any device or profile
2891 * owners that apply to this user. It will also include any system accessibility services.
2892 *
2893 * @param userId which user to check for.
2894 * @return List of accessiblity service package names.
2895 * @hide
2896 */
2897 @SystemApi
2898 public List<String> getPermittedAccessibilityServices(int userId) {
2899 if (mService != null) {
2900 try {
2901 return mService.getPermittedAccessibilityServicesForUser(userId);
2902 } catch (RemoteException e) {
2903 Log.w(TAG, "Failed talking with device policy service", e);
2904 }
2905 }
2906 return null;
2907 }
2908
2909 /**
2910 * Called by a profile or device owner to set the permitted input methods services. When
2911 * set by a device owner or profile owner the restriction applies to all profiles of the
2912 * user the device owner or profile owner is an admin for.
2913 *
2914 * By default the user can use any input method. When zero or more packages have
2915 * been added, input method that are not in the list and not part of the system
2916 * can not be enabled by the user.
2917 *
2918 * This method will fail if it is called for a admin that is not for the foreground user
2919 * or a profile of the foreground user.
2920 *
2921 * <p> Calling with a null value for the list disables the restriction so that all input methods
2922 * can be used, calling with an empty list disables all but the system's own input methods.
2923 *
2924 * <p> System input methods are always available to the user this method can't modify this.
2925 *
2926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2927 * @param packageNames List of input method package names.
2928 * @return true if setting the restriction succeeded. It will fail if there is
2929 * one or more input method enabled, that are not in the list or user if the foreground
2930 * user.
2931 */
2932 public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
2933 if (mService != null) {
2934 try {
2935 return mService.setPermittedInputMethods(admin, packageNames);
2936 } catch (RemoteException e) {
2937 Log.w(TAG, "Failed talking with device policy service", e);
2938 }
2939 }
2940 return false;
2941 }
2942
2943
2944 /**
2945 * Returns the list of permitted input methods set by this device or profile owner.
2946 *
2947 * <p>An empty list means no input methods except system input methods are allowed.
2948 * Null means all input methods are allowed.
2949 *
2950 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2951 * @return List of input method package names.
2952 */
2953 public List<String> getPermittedInputMethods(ComponentName admin) {
2954 if (mService != null) {
2955 try {
2956 return mService.getPermittedInputMethods(admin);
2957 } catch (RemoteException e) {
2958 Log.w(TAG, "Failed talking with device policy service", e);
2959 }
2960 }
2961 return null;
2962 }
2963
2964 /**
2965 * Returns the list of input methods permitted by the device or profiles
2966 * owners of the current user.
2967 *
2968 * <p>Null means all input methods are allowed, if a non-null list is returned
2969 * it will contain the intersection of the permitted lists for any device or profile
2970 * owners that apply to this user. It will also include any system input methods.
2971 *
2972 * @return List of input method package names.
2973 * @hide
2974 */
2975 @SystemApi
2976 public List<String> getPermittedInputMethodsForCurrentUser() {
2977 if (mService != null) {
2978 try {
2979 return mService.getPermittedInputMethodsForCurrentUser();
2980 } catch (RemoteException e) {
2981 Log.w(TAG, "Failed talking with device policy service", e);
2982 }
2983 }
2984 return null;
2985 }
2986
2987 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002988 * Called by a device owner to create a user with the specified name. The UserHandle returned
2989 * by this method should not be persisted as user handles are recycled as users are removed and
2990 * created. If you need to persist an identifier for this user, use
2991 * {@link UserManager#getSerialNumberForUser}.
2992 *
2993 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2994 * @param name the user's name
2995 * @see UserHandle
2996 * @return the UserHandle object for the created user, or null if the user could not be created.
2997 */
2998 public UserHandle createUser(ComponentName admin, String name) {
2999 try {
3000 return mService.createUser(admin, name);
3001 } catch (RemoteException re) {
3002 Log.w(TAG, "Could not create a user", re);
3003 }
3004 return null;
3005 }
3006
3007 /**
Jason Monk03978a42014-06-10 15:05:30 -04003008 * Called by a device owner to create a user with the specified name. The UserHandle returned
3009 * by this method should not be persisted as user handles are recycled as users are removed and
3010 * created. If you need to persist an identifier for this user, use
3011 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3012 * immediately.
3013 *
3014 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3015 * as registered as an active admin on the new user. The profile owner package will be
3016 * installed on the new user if it already is installed on the device.
3017 *
3018 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3019 * profileOwnerComponent when onEnable is called.
3020 *
3021 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3022 * @param name the user's name
3023 * @param ownerName the human readable name of the organisation associated with this DPM.
3024 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3025 * the user.
3026 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3027 * on the new user.
3028 * @see UserHandle
3029 * @return the UserHandle object for the created user, or null if the user could not be created.
3030 */
3031 public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName,
3032 ComponentName profileOwnerComponent, Bundle adminExtras) {
3033 try {
3034 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3035 adminExtras);
3036 } catch (RemoteException re) {
3037 Log.w(TAG, "Could not create a user", re);
3038 }
3039 return null;
3040 }
3041
3042 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003043 * Called by a device owner to remove a user and all associated data. The primary user can
3044 * not be removed.
3045 *
3046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3047 * @param userHandle the user to remove.
3048 * @return {@code true} if the user was removed, {@code false} otherwise.
3049 */
3050 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
3051 try {
3052 return mService.removeUser(admin, userHandle);
3053 } catch (RemoteException re) {
3054 Log.w(TAG, "Could not remove user ", re);
3055 return false;
3056 }
3057 }
3058
3059 /**
Jason Monk582d9112014-07-09 19:57:08 -04003060 * Called by a device owner to switch the specified user to the foreground.
3061 *
3062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3063 * @param userHandle the user to switch to; null will switch to primary.
3064 * @return {@code true} if the switch was successful, {@code false} otherwise.
3065 *
3066 * @see Intent#ACTION_USER_FOREGROUND
3067 */
3068 public boolean switchUser(ComponentName admin, UserHandle userHandle) {
3069 try {
3070 return mService.switchUser(admin, userHandle);
3071 } catch (RemoteException re) {
3072 Log.w(TAG, "Could not switch user ", re);
3073 return false;
3074 }
3075 }
3076
3077 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003078 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003079 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003080 *
3081 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3082 * exception will be thrown.
3083 *
3084 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3085 * @param packageName The name of the package to fetch restricted settings of.
3086 * @return {@link Bundle} of settings corresponding to what was set last time
3087 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3088 * if no restrictions have been set.
3089 */
3090 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
3091 if (mService != null) {
3092 try {
3093 return mService.getApplicationRestrictions(admin, packageName);
3094 } catch (RemoteException e) {
3095 Log.w(TAG, "Failed talking with device policy service", e);
3096 }
3097 }
3098 return null;
3099 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003100
3101 /**
3102 * Called by a profile or device owner to set a user restriction specified
3103 * by the key.
3104 * <p>
3105 * The calling device admin must be a profile or device owner; if it is not,
3106 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003107 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003108 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3109 * with.
3110 * @param key The key of the restriction. See the constants in
3111 * {@link android.os.UserManager} for the list of keys.
3112 */
3113 public void addUserRestriction(ComponentName admin, String key) {
3114 if (mService != null) {
3115 try {
3116 mService.setUserRestriction(admin, key, true);
3117 } catch (RemoteException e) {
3118 Log.w(TAG, "Failed talking with device policy service", e);
3119 }
3120 }
3121 }
3122
3123 /**
3124 * Called by a profile or device owner to clear a user restriction specified
3125 * by the key.
3126 * <p>
3127 * The calling device admin must be a profile or device owner; if it is not,
3128 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003129 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003130 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3131 * with.
3132 * @param key The key of the restriction. See the constants in
3133 * {@link android.os.UserManager} for the list of keys.
3134 */
3135 public void clearUserRestriction(ComponentName admin, String key) {
3136 if (mService != null) {
3137 try {
3138 mService.setUserRestriction(admin, key, false);
3139 } catch (RemoteException e) {
3140 Log.w(TAG, "Failed talking with device policy service", e);
3141 }
3142 }
3143 }
Adam Connors010cfd42014-04-16 12:48:13 +01003144
3145 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003146 * Called by device or profile owner to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003147 * is unavailable for use, but the data and actual package file remain.
3148 *
3149 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003150 * @param packageName The name of the package to hide or unhide.
3151 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3152 * unhidden.
3153 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003154 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003155 public boolean setApplicationHidden(ComponentName admin, String packageName,
3156 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003157 if (mService != null) {
3158 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003159 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003160 } catch (RemoteException e) {
3161 Log.w(TAG, "Failed talking with device policy service", e);
3162 }
3163 }
3164 return false;
3165 }
3166
3167 /**
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003168 * Called by device or profile owner to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003169 *
3170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003171 * @param packageName The name of the package to retrieve the hidden status of.
3172 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003173 */
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003174 public boolean isApplicationHidden(ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003175 if (mService != null) {
3176 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003177 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003178 } catch (RemoteException e) {
3179 Log.w(TAG, "Failed talking with device policy service", e);
3180 }
3181 }
3182 return false;
3183 }
3184
3185 /**
Adam Connors655be2a2014-07-14 09:01:25 +00003186 * Called by profile or device owner to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003187 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003188 *
3189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3190 * @param packageName The package to be re-enabled in the current profile.
3191 */
3192 public void enableSystemApp(ComponentName admin, String packageName) {
3193 if (mService != null) {
3194 try {
3195 mService.enableSystemApp(admin, packageName);
3196 } catch (RemoteException e) {
3197 Log.w(TAG, "Failed to install package: " + packageName);
3198 }
3199 }
3200 }
3201
3202 /**
3203 * Called by profile or device owner to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003204 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003205 *
3206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3207 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3208 * intent will be re-enabled in the current profile.
3209 * @return int The number of activities that matched the intent and were installed.
3210 */
3211 public int enableSystemApp(ComponentName admin, Intent intent) {
3212 if (mService != null) {
3213 try {
3214 return mService.enableSystemAppWithIntent(admin, intent);
3215 } catch (RemoteException e) {
3216 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3217 }
3218 }
3219 return 0;
3220 }
3221
3222 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003223 * Called by a device owner or profile owner to disable account management for a specific type
3224 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003225 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003226 * <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 +01003227 * security exception will be thrown.
3228 *
3229 * <p>When account management is disabled for an account type, adding or removing an account
3230 * of that type will not be possible.
3231 *
3232 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3233 * @param accountType For which account management is disabled or enabled.
3234 * @param disabled The boolean indicating that account management will be disabled (true) or
3235 * enabled (false).
3236 */
3237 public void setAccountManagementDisabled(ComponentName admin, String accountType,
3238 boolean disabled) {
3239 if (mService != null) {
3240 try {
3241 mService.setAccountManagementDisabled(admin, accountType, disabled);
3242 } catch (RemoteException e) {
3243 Log.w(TAG, "Failed talking with device policy service", e);
3244 }
3245 }
3246 }
3247
3248 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003249 * Gets the array of accounts for which account management is disabled by the profile owner.
3250 *
3251 * <p> Account management can be disabled/enabled by calling
3252 * {@link #setAccountManagementDisabled}.
3253 *
3254 * @return a list of account types for which account management has been disabled.
3255 *
3256 * @see #setAccountManagementDisabled
3257 */
3258 public String[] getAccountTypesWithManagementDisabled() {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003259 return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003260 }
3261
3262 /**
3263 * @see #getAccountTypesWithManagementDisabled()
3264 * @hide
3265 */
3266 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003267 if (mService != null) {
3268 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003269 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003270 } catch (RemoteException e) {
3271 Log.w(TAG, "Failed talking with device policy service", e);
3272 }
3273 }
3274
3275 return null;
3276 }
justinzhang511e0d82014-03-24 16:09:24 -04003277
3278 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003279 * Sets which packages may enter lock task mode.
3280 *
3281 * <p>Any packages that shares uid with an allowed package will also be allowed
3282 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003283 *
Jason Monkc5185f22014-06-24 11:12:42 -04003284 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003285 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003286 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003287 *
3288 * @see Activity#startLockTask()
Jason Monk1c7c3192014-06-26 12:52:18 -04003289 * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String)
3290 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003291 */
Jason Monk48aacba2014-08-13 16:29:08 -04003292 public void setLockTaskPackages(ComponentName admin, String[] packages)
3293 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003294 if (mService != null) {
3295 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003296 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003297 } catch (RemoteException e) {
3298 Log.w(TAG, "Failed talking with device policy service", e);
3299 }
3300 }
3301 }
3302
3303 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003304 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003305 *
3306 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003307 * @hide
3308 */
Jason Monk48aacba2014-08-13 16:29:08 -04003309 public String[] getLockTaskPackages(ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003310 if (mService != null) {
3311 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003312 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003313 } catch (RemoteException e) {
3314 Log.w(TAG, "Failed talking with device policy service", e);
3315 }
3316 }
3317 return null;
3318 }
3319
3320 /**
3321 * This function lets the caller know whether the given component is allowed to start the
3322 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003323 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003324 */
Jason Monkd7b86212014-06-16 13:15:38 -04003325 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003326 if (mService != null) {
3327 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003328 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003329 } catch (RemoteException e) {
3330 Log.w(TAG, "Failed talking with device policy service", e);
3331 }
3332 }
3333 return false;
3334 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003335
3336 /**
3337 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
3338 * 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 -04003339 * <p>The settings that can be updated with this method are:
3340 * <ul>
3341 * <li>{@link Settings.Global#ADB_ENABLED}</li>
3342 * <li>{@link Settings.Global#AUTO_TIME}</li>
3343 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
3344 * <li>{@link Settings.Global#BLUETOOTH_ON}</li>
3345 * <li>{@link Settings.Global#DATA_ROAMING}</li>
3346 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
3347 * <li>{@link Settings.Global#MODE_RINGER}</li>
3348 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
3349 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
3350 * <li>{@link Settings.Global#WIFI_ON}</li>
3351 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
3352 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003353 *
3354 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3355 * @param setting The name of the setting to update.
3356 * @param value The value to update the setting to.
3357 */
3358 public void setGlobalSetting(ComponentName admin, String setting, String value) {
3359 if (mService != null) {
3360 try {
3361 mService.setGlobalSetting(admin, setting, value);
3362 } catch (RemoteException e) {
3363 Log.w(TAG, "Failed talking with device policy service", e);
3364 }
3365 }
3366 }
3367
3368 /**
3369 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
3370 * that the value of the setting is in the correct form for the setting type should be performed
3371 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04003372 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003373 * <ul>
3374 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07003375 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04003376 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
3377 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04003378 * <p>A device owner can additionally update the following settings:
3379 * <ul>
3380 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
3381 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04003382 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3383 * @param setting The name of the setting to update.
3384 * @param value The value to update the setting to.
3385 */
3386 public void setSecureSetting(ComponentName admin, String setting, String value) {
3387 if (mService != null) {
3388 try {
3389 mService.setSecureSetting(admin, setting, value);
3390 } catch (RemoteException e) {
3391 Log.w(TAG, "Failed talking with device policy service", e);
3392 }
3393 }
3394 }
3395
Amith Yamasanif20d6402014-05-24 15:34:37 -07003396 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003397 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07003398 * making permission requests of a local or remote administrator of the user.
3399 * <p/>
3400 * Only a profile owner can designate the restrictions provider.
3401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003402 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07003403 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07003404 * it removes the restrictions provider previously assigned.
3405 */
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003406 public void setRestrictionsProvider(ComponentName admin, ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07003407 if (mService != null) {
3408 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07003409 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07003410 } catch (RemoteException re) {
3411 Log.w(TAG, "Failed to set permission provider on device policy service");
3412 }
3413 }
3414 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04003415
3416 /**
3417 * Called by profile or device owners to set the master volume mute on or off.
3418 *
3419 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3420 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
3421 */
3422 public void setMasterVolumeMuted(ComponentName admin, boolean on) {
3423 if (mService != null) {
3424 try {
3425 mService.setMasterVolumeMuted(admin, on);
3426 } catch (RemoteException re) {
3427 Log.w(TAG, "Failed to setMasterMute on device policy service");
3428 }
3429 }
3430 }
3431
3432 /**
3433 * Called by profile or device owners to check whether the master volume mute is on or off.
3434 *
3435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3436 * @return {@code true} if master volume is muted, {@code false} if it's not.
3437 */
3438 public boolean isMasterVolumeMuted(ComponentName admin) {
3439 if (mService != null) {
3440 try {
3441 return mService.isMasterVolumeMuted(admin);
3442 } catch (RemoteException re) {
3443 Log.w(TAG, "Failed to get isMasterMute on device policy service");
3444 }
3445 }
3446 return false;
3447 }
Kenny Guyc13053b2014-05-29 14:17:17 +01003448
3449 /**
3450 * Called by profile or device owners to change whether a user can uninstall
3451 * a package.
3452 *
3453 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3454 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003455 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01003456 */
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003457 public void setUninstallBlocked(ComponentName admin, String packageName,
3458 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003459 if (mService != null) {
3460 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01003461 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01003462 } catch (RemoteException re) {
3463 Log.w(TAG, "Failed to call block uninstall on device policy service");
3464 }
3465 }
3466 }
3467
3468 /**
Rubin Xua97855b2014-11-07 05:41:00 +00003469 * Check whether the current user has been blocked by device policy from uninstalling a package.
3470 * Requires the caller to be the profile owner if checking a specific admin's policy.
Kenny Guyc13053b2014-05-29 14:17:17 +01003471 *
Rubin Xua97855b2014-11-07 05:41:00 +00003472 * @param admin The name of the admin component whose blocking policy will be checked, or null
3473 * to check if any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01003474 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00003475 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01003476 */
Esteban Talavera729b2a62014-08-27 18:01:58 +01003477 public boolean isUninstallBlocked(ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01003478 if (mService != null) {
3479 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01003480 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01003481 } catch (RemoteException re) {
3482 Log.w(TAG, "Failed to call block uninstall on device policy service");
3483 }
3484 }
3485 return false;
3486 }
Svetoslav976e8bd2014-07-16 15:12:03 -07003487
3488 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003489 * Called by the profile owner of a managed profile to enable widget providers from a
3490 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07003491 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003492 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07003493 * a package may have zero or more provider components, where each component
3494 * provides a different widget type.
3495 * <p>
3496 * <strong>Note:</strong> By default no widget provider package is white-listed.
3497 * </p>
3498 *
3499 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3500 * @param packageName The package from which widget providers are white-listed.
3501 * @return Whether the package was added.
3502 *
3503 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3504 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3505 */
3506 public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3507 if (mService != null) {
3508 try {
3509 return mService.addCrossProfileWidgetProvider(admin, packageName);
3510 } catch (RemoteException re) {
3511 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
3512 }
3513 }
3514 return false;
3515 }
3516
3517 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003518 * Called by the profile owner of a managed profile to disable widget providers from a given
3519 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07003520 * package should have been added via {@link #addCrossProfileWidgetProvider(
3521 * android.content.ComponentName, String)}.
3522 * <p>
3523 * <strong>Note:</strong> By default no widget provider package is white-listed.
3524 * </p>
3525 *
3526 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3527 * @param packageName The package from which widget providers are no longer
3528 * white-listed.
3529 * @return Whether the package was removed.
3530 *
3531 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3532 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
3533 */
3534 public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) {
3535 if (mService != null) {
3536 try {
3537 return mService.removeCrossProfileWidgetProvider(admin, packageName);
3538 } catch (RemoteException re) {
3539 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
3540 }
3541 }
3542 return false;
3543 }
3544
3545 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003546 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07003547 * available in the parent profile.
3548 *
3549 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3550 * @return The white-listed package list.
3551 *
3552 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
3553 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
3554 */
3555 public List<String> getCrossProfileWidgetProviders(ComponentName admin) {
3556 if (mService != null) {
3557 try {
3558 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
3559 if (providers != null) {
3560 return providers;
3561 }
3562 } catch (RemoteException re) {
3563 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
3564 }
3565 }
3566 return Collections.emptyList();
3567 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08003568}