blob: cea55452516eca8c7a4d9066cfeb6e322f3ed671 [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;
21import android.content.ComponentName;
22import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010023import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000024import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.pm.ActivityInfo;
26import android.content.pm.PackageManager;
27import android.content.pm.ResolveInfo;
Amith Yamasanif20d6402014-05-24 15:34:37 -070028import android.content.RestrictionsManager;
Robin Lee66e5d962014-04-09 16:44:21 +010029import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080030import android.os.Handler;
Adam Connors776c5552014-01-09 10:42:56 +000031import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080032import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.os.RemoteException;
34import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070035import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040036import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040037import android.provider.Settings;
Jim Miller50e62182014-04-23 17:25:00 -070038import android.service.trust.TrustAgentService;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.util.Log;
40
Maggie Benthallda51e682013-08-08 22:35:44 -040041import com.android.org.conscrypt.TrustedCertificateStore;
42
Jessica Hummel91da58d2014-04-10 17:39:43 +010043import org.xmlpull.v1.XmlPullParserException;
44
Maggie Benthallda51e682013-08-08 22:35:44 -040045import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070047import java.net.InetSocketAddress;
48import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040049import java.security.cert.CertificateException;
50import java.security.cert.CertificateFactory;
51import java.security.cert.X509Certificate;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080052import java.util.List;
Maggie Benthallda51e682013-08-08 22:35:44 -040053import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054
55/**
56 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080057 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080058 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080059 *
60 * <div class="special reference">
61 * <h3>Developer Guides</h3>
62 * <p>For more information about managing policies for device adminstration, read the
63 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
64 * developer guide.</p>
65 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080066 */
67public class DevicePolicyManager {
68 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080069
70 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080071 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070072
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080073 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080074 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080075 mService = IDevicePolicyManager.Stub.asInterface(
76 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
77 }
78
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080079 /** @hide */
80 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080081 DevicePolicyManager me = new DevicePolicyManager(context, handler);
82 return me.mService != null ? me : null;
83 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070084
Dianne Hackbornd6847842010-01-12 18:14:19 -080085 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +010086 * Activity action: Used to indicate that the receiving activity is being started as part of the
87 * managed profile provisioning flow. This intent is typically sent to a mobile device
88 * management application (mdm) after the first part of the provisioning process is complete in
89 * the expectation that this app will (after optionally showing it's own UI) ultimately call
90 * {@link #ACTION_PROVISION_MANAGED_PROFILE} to complete the creation of the managed profile.
91 *
92 * <p> The intent may contain the extras {@link #EXTRA_PROVISIONING_TOKEN} and
93 * {@link #EXTRA_PROVISIONING_EMAIL_ADDRESS}.
94 */
95 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
96 public static final String ACTION_SEND_PROVISIONING_VALUES
97 = "android.app.action.ACTION_SEND_PROVISIONING_VALUES";
98
99 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000100 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000101 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100102 * <p>A managed profile allows data separation for example for the usage of a
103 * device as a personal and corporate device. The user which provisioning is started from and
104 * the managed profile share a launcher.
105 *
106 * <p>This intent will typically be sent by a mobile device management application (mdm).
107 * Provisioning adds a managed profile and sets the mdm as the profile owner who has full
108 * control over the profile
109 *
110 * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}
111 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000112 *
113 * <p> When managed provisioning has completed, an intent of the type
114 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
Jessica Hummel9da60392014-05-21 12:32:57 +0100115 * managed profile. The intent is sent to the {@link DeviceAdminReceiver} specified in the
116 * {@link #EXTRA_DEVICE_ADMIN} exclusively.
117 *
118 * If provisioning fails, the managedProfile is removed so the device returns to its previous
119 * state.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000120 *
121 * <p>Input: Nothing.</p>
122 * <p>Output: Nothing</p>
123 */
124 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
125 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000126 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127
128 /**
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100129 * A broadcast intent with this action can be sent to ManagedProvisionning to specify that the
130 * user has already consented to the creation of the managed profile.
131 * The intent must contain the extras
132 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} and
133 * {@link #EXTRA_PROVISIONING_TOKEN}
134 * @hide
135 */
136 public static final String ACTION_PROVISIONING_USER_HAS_CONSENTED
137 = "android.app.action.USER_HAS_CONSENTED";
138
139 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000140 * A String extra holding the name of the package of the mobile device management application
141 * that starts the managed provisioning flow. This package will be set as the profile owner.
142 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
143 */
144 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100145 = "android.app.extra.deviceAdminPackageName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000146
147 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100148 * An int extra used to identify that during the current setup process the user has already
149 * consented to setting up a managed profile. This is typically received by
150 * a mobile device management application when it is started with
151 * {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
152 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. The
153 * token indicates that steps asking for user consent can be skipped as the user has previously
154 * consented.
Nicolas Prevot3742ec32014-05-27 18:22:35 +0100155 */
156 public static final String EXTRA_PROVISIONING_TOKEN
157 = "android.app.extra.token";
158
159 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000160 * A String extra holding the default name of the profile that is created during managed profile
161 * provisioning.
162 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
163 */
164 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
Jessica Hummel9da60392014-05-21 12:32:57 +0100165 = "android.app.extra.defaultManagedProfileName";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000166
167 /**
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100168 * A String extra holding the email address of the profile that is created during managed
169 * profile provisioning. This is typically received by a mobile management application when it
170 * is started with {@link #ACTION_SEND_PROVISIONING_VALUES} and passed on in an intent
171 * {@link #ACTION_PROVISION_MANAGED_PROFILE} which starts the setup of the managed profile. It
172 * is eventually passed on in an intent
173 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
174 */
175 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
176 = "android.app.extra.ManagedProfileEmailAddress";
177
178 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800179 * Activity action: ask the user to add a new device administrator to the system.
180 * The desired policy is the ComponentName of the policy in the
181 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
182 * bring the user through adding the device administrator to the system (or
183 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700184 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800185 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
186 * field to provide the user with additional explanation (in addition
187 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800188 *
189 * <p>If your administrator is already active, this will ordinarily return immediately (without
190 * user intervention). However, if your administrator has been updated and is requesting
191 * additional uses-policy flags, the user will be presented with the new list. New policies
192 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800193 */
194 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
195 public static final String ACTION_ADD_DEVICE_ADMIN
196 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700197
Dianne Hackbornd6847842010-01-12 18:14:19 -0800198 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700199 * Activity action: send when any policy admin changes a policy.
200 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700201 *
Jim Miller284b62e2010-06-08 14:27:42 -0700202 * @hide
203 */
204 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
205 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
206
207 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800208 * The ComponentName of the administrator component.
209 *
210 * @see #ACTION_ADD_DEVICE_ADMIN
211 */
212 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700213
Dianne Hackbornd6847842010-01-12 18:14:19 -0800214 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800215 * An optional CharSequence providing additional explanation for why the
216 * admin is being added.
217 *
218 * @see #ACTION_ADD_DEVICE_ADMIN
219 */
220 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700221
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800222 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700223 * Activity action: have the user enter a new password. This activity should
224 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
225 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
226 * enter a new password that meets the current requirements. You can use
227 * {@link #isActivePasswordSufficient()} to determine whether you need to
228 * have the user select a new password in order to meet the current
229 * constraints. Upon being resumed from this activity, you can check the new
230 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800231 */
232 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
233 public static final String ACTION_SET_NEW_PASSWORD
234 = "android.app.action.SET_NEW_PASSWORD";
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000235 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100236 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a
237 * managed profile to its parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000238 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100239 public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000240
241 /**
Nicolas Prevot81948992014-05-16 18:25:26 +0100242 * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the
243 * parent to its managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000244 */
Nicolas Prevot81948992014-05-16 18:25:26 +0100245 public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700246
Dianne Hackbornd6847842010-01-12 18:14:19 -0800247 /**
248 * Return true if the given administrator component is currently
249 * active (enabled) in the system.
250 */
251 public boolean isAdminActive(ComponentName who) {
252 if (mService != null) {
253 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700254 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800255 } catch (RemoteException e) {
256 Log.w(TAG, "Failed talking with device policy service", e);
257 }
258 }
259 return false;
260 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700261
Dianne Hackbornd6847842010-01-12 18:14:19 -0800262 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800263 * Return a list of all currently active device administrator's component
264 * names. Note that if there are no administrators than null may be
265 * returned.
266 */
267 public List<ComponentName> getActiveAdmins() {
268 if (mService != null) {
269 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700270 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800271 } catch (RemoteException e) {
272 Log.w(TAG, "Failed talking with device policy service", e);
273 }
274 }
275 return null;
276 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700277
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800278 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700279 * Used by package administration code to determine if a package can be stopped
280 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800281 * @hide
282 */
283 public boolean packageHasActiveAdmins(String packageName) {
284 if (mService != null) {
285 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700286 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800287 } catch (RemoteException e) {
288 Log.w(TAG, "Failed talking with device policy service", e);
289 }
290 }
291 return false;
292 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700293
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800294 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800295 * Remove a current administration component. This can only be called
296 * by the application that owns the administration component; if you
297 * try to remove someone else's component, a security exception will be
298 * thrown.
299 */
300 public void removeActiveAdmin(ComponentName who) {
301 if (mService != null) {
302 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700303 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800304 } catch (RemoteException e) {
305 Log.w(TAG, "Failed talking with device policy service", e);
306 }
307 }
308 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700309
Dianne Hackbornd6847842010-01-12 18:14:19 -0800310 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800311 * Returns true if an administrator has been granted a particular device policy. This can
312 * be used to check if the administrator was activated under an earlier set of policies,
313 * but requires additional policies after an upgrade.
314 *
315 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
316 * an active administrator, or an exception will be thrown.
317 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
318 */
319 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
320 if (mService != null) {
321 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700322 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800323 } catch (RemoteException e) {
324 Log.w(TAG, "Failed talking with device policy service", e);
325 }
326 }
327 return false;
328 }
329
330 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800331 * Constant for {@link #setPasswordQuality}: the policy has no requirements
332 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800333 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800334 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800335 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700336
Dianne Hackbornd6847842010-01-12 18:14:19 -0800337 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700338 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
339 * recognition technology. This implies technologies that can recognize the identity of
340 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
341 * Note that quality constants are ordered so that higher values are more restrictive.
342 */
343 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
344
345 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800346 * Constant for {@link #setPasswordQuality}: the policy requires some kind
347 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800348 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800349 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800350 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700351
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800352 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800353 * Constant for {@link #setPasswordQuality}: the user must have entered a
354 * password containing at least numeric characters. Note that quality
355 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800356 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800357 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700358
Dianne Hackbornd6847842010-01-12 18:14:19 -0800359 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800360 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700361 * password containing at least alphabetic (or other symbol) characters.
362 * Note that quality constants are ordered so that higher values are more
363 * restrictive.
364 */
365 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700366
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700367 /**
368 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800369 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700370 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800371 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800372 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700373 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700374
Dianne Hackbornd6847842010-01-12 18:14:19 -0800375 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700376 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700377 * password containing at least a letter, a numerical digit and a special
378 * symbol, by default. With this password quality, passwords can be
379 * restricted to contain various sets of characters, like at least an
380 * uppercase letter, etc. These are specified using various methods,
381 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
382 * that quality constants are ordered so that higher values are more
383 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700384 */
385 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
386
387 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800388 * Called by an application that is administering the device to set the
389 * password restrictions it is imposing. After setting this, the user
390 * will not be able to enter a new password that is not at least as
391 * restrictive as what has been set. Note that the current password
392 * will remain until the user has set a new one, so the change does not
393 * take place immediately. To prompt the user for a new password, use
394 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700395 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800396 * <p>Quality constants are ordered so that higher values are more restrictive;
397 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800398 * the user's preference, and any other considerations) is the one that
399 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700400 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800401 * <p>The calling device admin must have requested
402 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
403 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700404 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800405 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800406 * @param quality The new desired quality. One of
407 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700408 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700409 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800410 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800411 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800412 if (mService != null) {
413 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700414 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800415 } catch (RemoteException e) {
416 Log.w(TAG, "Failed talking with device policy service", e);
417 }
418 }
419 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700420
Dianne Hackbornd6847842010-01-12 18:14:19 -0800421 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100422 * Retrieve the current minimum password quality for all admins of this user
423 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800424 * @param admin The name of the admin component to check, or null to aggregate
425 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800426 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800427 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700428 return getPasswordQuality(admin, UserHandle.myUserId());
429 }
430
431 /** @hide per-user version */
432 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800433 if (mService != null) {
434 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700435 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800436 } catch (RemoteException e) {
437 Log.w(TAG, "Failed talking with device policy service", e);
438 }
439 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800440 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800441 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700442
Dianne Hackbornd6847842010-01-12 18:14:19 -0800443 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800444 * Called by an application that is administering the device to set the
445 * minimum allowed password length. After setting this, the user
446 * will not be able to enter a new password that is not at least as
447 * restrictive as what has been set. Note that the current password
448 * will remain until the user has set a new one, so the change does not
449 * take place immediately. To prompt the user for a new password, use
450 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
451 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700452 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
453 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800454 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700455 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800456 * <p>The calling device admin must have requested
457 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
458 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700459 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800460 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800461 * @param length The new desired minimum password length. A value of 0
462 * means there is no restriction.
463 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800464 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800465 if (mService != null) {
466 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700467 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800468 } catch (RemoteException e) {
469 Log.w(TAG, "Failed talking with device policy service", e);
470 }
471 }
472 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700473
Dianne Hackbornd6847842010-01-12 18:14:19 -0800474 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100475 * Retrieve the current minimum password length for all admins of this
476 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800477 * @param admin The name of the admin component to check, or null to aggregate
478 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800479 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800480 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700481 return getPasswordMinimumLength(admin, UserHandle.myUserId());
482 }
483
484 /** @hide per-user version */
485 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800486 if (mService != null) {
487 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700488 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800489 } catch (RemoteException e) {
490 Log.w(TAG, "Failed talking with device policy service", e);
491 }
492 }
493 return 0;
494 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700495
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700496 /**
497 * Called by an application that is administering the device to set the
498 * minimum number of upper case letters required in the password. After
499 * setting this, the user will not be able to enter a new password that is
500 * not at least as restrictive as what has been set. Note that the current
501 * password will remain until the user has set a new one, so the change does
502 * not take place immediately. To prompt the user for a new password, use
503 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
504 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700505 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
506 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700507 * <p>
508 * The calling device admin must have requested
509 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
510 * this method; if it has not, a security exception will be thrown.
511 *
512 * @param admin Which {@link DeviceAdminReceiver} this request is associated
513 * with.
514 * @param length The new desired minimum number of upper case letters
515 * required in the password. A value of 0 means there is no
516 * restriction.
517 */
518 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
519 if (mService != null) {
520 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700521 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700522 } catch (RemoteException e) {
523 Log.w(TAG, "Failed talking with device policy service", e);
524 }
525 }
526 }
527
528 /**
529 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100530 * password for all admins of this user and its profiles or a particular one.
531 * This is the same value as set by
532 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700533 * and only applies when the password quality is
534 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700535 *
536 * @param admin The name of the admin component to check, or null to
537 * aggregate all admins.
538 * @return The minimum number of upper case letters required in the
539 * password.
540 */
541 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700542 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
543 }
544
545 /** @hide per-user version */
546 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700547 if (mService != null) {
548 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700549 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700550 } catch (RemoteException e) {
551 Log.w(TAG, "Failed talking with device policy service", e);
552 }
553 }
554 return 0;
555 }
556
557 /**
558 * Called by an application that is administering the device to set the
559 * minimum number of lower case letters required in the password. After
560 * setting this, the user will not be able to enter a new password that is
561 * not at least as restrictive as what has been set. Note that the current
562 * password will remain until the user has set a new one, so the change does
563 * not take place immediately. To prompt the user for a new password, use
564 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
565 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700566 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
567 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700568 * <p>
569 * The calling device admin must have requested
570 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
571 * this method; if it has not, a security exception will be thrown.
572 *
573 * @param admin Which {@link DeviceAdminReceiver} this request is associated
574 * with.
575 * @param length The new desired minimum number of lower case letters
576 * required in the password. A value of 0 means there is no
577 * restriction.
578 */
579 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
580 if (mService != null) {
581 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700582 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700583 } catch (RemoteException e) {
584 Log.w(TAG, "Failed talking with device policy service", e);
585 }
586 }
587 }
588
589 /**
590 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100591 * password for all admins of this user and its profiles or a particular one.
592 * This is the same value as set by
593 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700594 * and only applies when the password quality is
595 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700596 *
597 * @param admin The name of the admin component to check, or null to
598 * aggregate all admins.
599 * @return The minimum number of lower case letters required in the
600 * password.
601 */
602 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700603 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
604 }
605
606 /** @hide per-user version */
607 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700608 if (mService != null) {
609 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700610 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700611 } catch (RemoteException e) {
612 Log.w(TAG, "Failed talking with device policy service", e);
613 }
614 }
615 return 0;
616 }
617
618 /**
619 * Called by an application that is administering the device to set the
620 * minimum number of letters required in the password. After setting this,
621 * the user will not be able to enter a new password that is not at least as
622 * restrictive as what has been set. Note that the current password will
623 * remain until the user has set a new one, so the change does not take
624 * place immediately. To prompt the user for a new password, use
625 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
626 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700627 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
628 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700629 * <p>
630 * The calling device admin must have requested
631 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
632 * this method; if it has not, a security exception will be thrown.
633 *
634 * @param admin Which {@link DeviceAdminReceiver} this request is associated
635 * with.
636 * @param length The new desired minimum number of letters required in the
637 * password. A value of 0 means there is no restriction.
638 */
639 public void setPasswordMinimumLetters(ComponentName admin, int length) {
640 if (mService != null) {
641 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700642 mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700643 } catch (RemoteException e) {
644 Log.w(TAG, "Failed talking with device policy service", e);
645 }
646 }
647 }
648
649 /**
650 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700651 * admins or a particular one. This is the same value as
652 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
653 * and only applies when the password quality is
654 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700655 *
656 * @param admin The name of the admin component to check, or null to
657 * aggregate all admins.
658 * @return The minimum number of letters required in the password.
659 */
660 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700661 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
662 }
663
664 /** @hide per-user version */
665 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700666 if (mService != null) {
667 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700668 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700669 } catch (RemoteException e) {
670 Log.w(TAG, "Failed talking with device policy service", e);
671 }
672 }
673 return 0;
674 }
675
676 /**
677 * Called by an application that is administering the device to set the
678 * minimum number of numerical digits required in the password. After
679 * setting this, the user will not be able to enter a new password that is
680 * not at least as restrictive as what has been set. Note that the current
681 * password will remain until the user has set a new one, so the change does
682 * not take place immediately. To prompt the user for a new password, use
683 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
684 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700685 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
686 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700687 * <p>
688 * The calling device admin must have requested
689 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
690 * this method; if it has not, a security exception will be thrown.
691 *
692 * @param admin Which {@link DeviceAdminReceiver} this request is associated
693 * with.
694 * @param length The new desired minimum number of numerical digits required
695 * in the password. A value of 0 means there is no restriction.
696 */
697 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
698 if (mService != null) {
699 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700700 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700701 } catch (RemoteException e) {
702 Log.w(TAG, "Failed talking with device policy service", e);
703 }
704 }
705 }
706
707 /**
708 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100709 * for all admins of this user and its profiles or a particular one.
710 * This is the same value as set by
711 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700712 * and only applies when the password quality is
713 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700714 *
715 * @param admin The name of the admin component to check, or null to
716 * aggregate all admins.
717 * @return The minimum number of numerical digits required in the password.
718 */
719 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700720 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
721 }
722
723 /** @hide per-user version */
724 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700725 if (mService != null) {
726 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700727 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700728 } catch (RemoteException e) {
729 Log.w(TAG, "Failed talking with device policy service", e);
730 }
731 }
732 return 0;
733 }
734
735 /**
736 * Called by an application that is administering the device to set the
737 * minimum number of symbols required in the password. After setting this,
738 * the user will not be able to enter a new password that is not at least as
739 * restrictive as what has been set. Note that the current password will
740 * remain until the user has set a new one, so the change does not take
741 * place immediately. To prompt the user for a new password, use
742 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
743 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700744 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
745 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700746 * <p>
747 * The calling device admin must have requested
748 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
749 * this method; if it has not, a security exception will be thrown.
750 *
751 * @param admin Which {@link DeviceAdminReceiver} this request is associated
752 * with.
753 * @param length The new desired minimum number of symbols required in the
754 * password. A value of 0 means there is no restriction.
755 */
756 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
757 if (mService != null) {
758 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700759 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700760 } catch (RemoteException e) {
761 Log.w(TAG, "Failed talking with device policy service", e);
762 }
763 }
764 }
765
766 /**
767 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700768 * admins or a particular one. This is the same value as
769 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
770 * and only applies when the password quality is
771 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700772 *
773 * @param admin The name of the admin component to check, or null to
774 * aggregate all admins.
775 * @return The minimum number of symbols required in the password.
776 */
777 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700778 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
779 }
780
781 /** @hide per-user version */
782 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700783 if (mService != null) {
784 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700785 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700786 } catch (RemoteException e) {
787 Log.w(TAG, "Failed talking with device policy service", e);
788 }
789 }
790 return 0;
791 }
792
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700793 /**
794 * Called by an application that is administering the device to set the
795 * minimum number of non-letter characters (numerical digits or symbols)
796 * required in the password. After setting this, the user will not be able
797 * to enter a new password that is not at least as restrictive as what has
798 * been set. Note that the current password will remain until the user has
799 * set a new one, so the change does not take place immediately. To prompt
800 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
801 * setting this value. This constraint is only imposed if the administrator
802 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
803 * {@link #setPasswordQuality}. The default value is 0.
804 * <p>
805 * The calling device admin must have requested
806 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
807 * this method; if it has not, a security exception will be thrown.
808 *
809 * @param admin Which {@link DeviceAdminReceiver} this request is associated
810 * with.
811 * @param length The new desired minimum number of letters required in the
812 * password. A value of 0 means there is no restriction.
813 */
814 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
815 if (mService != null) {
816 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700817 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700818 } catch (RemoteException e) {
819 Log.w(TAG, "Failed talking with device policy service", e);
820 }
821 }
822 }
823
824 /**
825 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100826 * password for all admins of this user and its profiles or a particular one.
827 * This is the same value as set by
828 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700829 * and only applies when the password quality is
830 * {@link #PASSWORD_QUALITY_COMPLEX}.
831 *
832 * @param admin The name of the admin component to check, or null to
833 * aggregate all admins.
834 * @return The minimum number of letters required in the password.
835 */
836 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700837 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
838 }
839
840 /** @hide per-user version */
841 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700842 if (mService != null) {
843 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700844 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700845 } catch (RemoteException e) {
846 Log.w(TAG, "Failed talking with device policy service", e);
847 }
848 }
849 return 0;
850 }
851
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700852 /**
853 * Called by an application that is administering the device to set the length
854 * of the password history. After setting this, the user will not be able to
855 * enter a new password that is the same as any password in the history. Note
856 * that the current password will remain until the user has set a new one, so
857 * the change does not take place immediately. To prompt the user for a new
858 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
859 * This constraint is only imposed if the administrator has also requested
860 * either {@link #PASSWORD_QUALITY_NUMERIC},
861 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
862 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
863 *
864 * <p>
865 * The calling device admin must have requested
866 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
867 * method; if it has not, a security exception will be thrown.
868 *
869 * @param admin Which {@link DeviceAdminReceiver} this request is associated
870 * with.
871 * @param length The new desired length of password history. A value of 0
872 * means there is no restriction.
873 */
874 public void setPasswordHistoryLength(ComponentName admin, int length) {
875 if (mService != null) {
876 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700877 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700878 } catch (RemoteException e) {
879 Log.w(TAG, "Failed talking with device policy service", e);
880 }
881 }
882 }
883
884 /**
Jim Millera4e28d12010-11-08 16:15:47 -0800885 * Called by a device admin to set the password expiration timeout. Calling this method
886 * will restart the countdown for password expiration for the given admin, as will changing
887 * the device password (for all admins).
888 *
889 * <p>The provided timeout is the time delta in ms and will be added to the current time.
890 * For example, to have the password expire 5 days from now, timeout would be
891 * 5 * 86400 * 1000 = 432000000 ms for timeout.
892 *
893 * <p>To disable password expiration, a value of 0 may be used for timeout.
894 *
Jim Millera4e28d12010-11-08 16:15:47 -0800895 * <p>The calling device admin must have requested
896 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
897 * method; if it has not, a security exception will be thrown.
898 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100899 * <p> Note that setting the password will automatically reset the expiration time for all
900 * active admins. Active admins do not need to explicitly call this method in that case.
901 *
Jim Millera4e28d12010-11-08 16:15:47 -0800902 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
903 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
904 * means there is no restriction (unlimited).
905 */
906 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
907 if (mService != null) {
908 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700909 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800910 } catch (RemoteException e) {
911 Log.w(TAG, "Failed talking with device policy service", e);
912 }
913 }
914 }
915
916 /**
Jim Miller6b857682011-02-16 16:27:41 -0800917 * Get the password expiration timeout for the given admin. The expiration timeout is the
918 * recurring expiration timeout provided in the call to
919 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
920 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -0800921 *
922 * @param admin The name of the admin component to check, or null to aggregate all admins.
923 * @return The timeout for the given admin or the minimum of all timeouts
924 */
925 public long getPasswordExpirationTimeout(ComponentName admin) {
926 if (mService != null) {
927 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700928 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800929 } catch (RemoteException e) {
930 Log.w(TAG, "Failed talking with device policy service", e);
931 }
932 }
933 return 0;
934 }
935
936 /**
937 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +0100938 * all admins of this user and its profiles if admin is null. If the password is
939 * expired, this will return the time since the password expired as a negative number.
940 * If admin is null, then a composite of all expiration timeouts is returned
941 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -0800942 *
943 * @param admin The name of the admin component to check, or null to aggregate all admins.
944 * @return The password expiration time, in ms.
945 */
946 public long getPasswordExpiration(ComponentName admin) {
947 if (mService != null) {
948 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700949 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800950 } catch (RemoteException e) {
951 Log.w(TAG, "Failed talking with device policy service", e);
952 }
953 }
954 return 0;
955 }
956
957 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100958 * Retrieve the current password history length for all admins of this
959 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700960 * @param admin The name of the admin component to check, or null to aggregate
961 * all admins.
962 * @return The length of the password history
963 */
964 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700965 return getPasswordHistoryLength(admin, UserHandle.myUserId());
966 }
967
968 /** @hide per-user version */
969 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700970 if (mService != null) {
971 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700972 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700973 } catch (RemoteException e) {
974 Log.w(TAG, "Failed talking with device policy service", e);
975 }
976 }
977 return 0;
978 }
979
Dianne Hackbornd6847842010-01-12 18:14:19 -0800980 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800981 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800982 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800983 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800984 * @return Returns the maximum length that the user can enter.
985 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800986 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800987 // Kind-of arbitrary.
988 return 16;
989 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700990
Dianne Hackborn254cb442010-01-27 19:23:59 -0800991 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800992 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800993 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +0100994 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700995 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800996 * <p>The calling device admin must have requested
997 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
998 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700999 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001000 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001001 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001002 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001003 if (mService != null) {
1004 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001005 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001006 } catch (RemoteException e) {
1007 Log.w(TAG, "Failed talking with device policy service", e);
1008 }
1009 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001010 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001011 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001012
Dianne Hackbornd6847842010-01-12 18:14:19 -08001013 /**
1014 * Retrieve the number of times the user has failed at entering a
1015 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001016 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001017 * <p>The calling device admin must have requested
1018 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1019 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001020 */
1021 public int getCurrentFailedPasswordAttempts() {
1022 if (mService != null) {
1023 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001024 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001025 } catch (RemoteException e) {
1026 Log.w(TAG, "Failed talking with device policy service", e);
1027 }
1028 }
1029 return -1;
1030 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001031
1032 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001033 * Setting this to a value greater than zero enables a built-in policy
1034 * that will perform a device wipe after too many incorrect
1035 * device-unlock passwords have been entered. This built-in policy combines
1036 * watching for failed passwords and wiping the device, and requires
1037 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001038 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001039 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001040 * <p>To implement any other policy (e.g. wiping data for a particular
1041 * application only, erasing or revoking credentials, or reporting the
1042 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001043 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001044 * instead. Do not use this API, because if the maximum count is reached,
1045 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001046 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001047 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001048 * @param num The number of failed password attempts at which point the
1049 * device will wipe its data.
1050 */
1051 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
1052 if (mService != null) {
1053 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001054 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001055 } catch (RemoteException e) {
1056 Log.w(TAG, "Failed talking with device policy service", e);
1057 }
1058 }
1059 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001060
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001061 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001062 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001063 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001064 * or a particular one.
1065 * @param admin The name of the admin component to check, or null to aggregate
1066 * all admins.
1067 */
1068 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001069 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1070 }
1071
1072 /** @hide per-user version */
1073 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001074 if (mService != null) {
1075 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001076 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001077 } catch (RemoteException e) {
1078 Log.w(TAG, "Failed talking with device policy service", e);
1079 }
1080 }
1081 return 0;
1082 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001083
Dianne Hackborn254cb442010-01-27 19:23:59 -08001084 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001085 * Flag for {@link #resetPassword}: don't allow other admins to change
1086 * the password again until the user has entered it.
1087 */
1088 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001089
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001090 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001091 * Force a new device unlock password (the password needed to access the
1092 * entire device, not for individual accounts) on the user. This takes
1093 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001094 * The given password must be sufficient for the
1095 * current password quality and length constraints as returned by
1096 * {@link #getPasswordQuality(ComponentName)} and
1097 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1098 * these constraints, then it will be rejected and false returned. Note
1099 * that the password may be a stronger quality (containing alphanumeric
1100 * characters when the requested quality is only numeric), in which case
1101 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001102 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001103 * <p>The calling device admin must have requested
1104 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1105 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001106 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001107 * Can not be called from a managed profile.
1108 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001109 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001110 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001111 * @return Returns true if the password was applied, or false if it is
1112 * not acceptable for the current constraints.
1113 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001114 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001115 if (mService != null) {
1116 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001117 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001118 } catch (RemoteException e) {
1119 Log.w(TAG, "Failed talking with device policy service", e);
1120 }
1121 }
1122 return false;
1123 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001124
Dianne Hackbornd6847842010-01-12 18:14:19 -08001125 /**
1126 * Called by an application that is administering the device to set the
1127 * maximum time for user activity until the device will lock. This limits
1128 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001129 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001130 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001131 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001132 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001133 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001134 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001135 * @param timeMs The new desired maximum time to lock in milliseconds.
1136 * A value of 0 means there is no restriction.
1137 */
1138 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1139 if (mService != null) {
1140 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001141 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001142 } catch (RemoteException e) {
1143 Log.w(TAG, "Failed talking with device policy service", e);
1144 }
1145 }
1146 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001147
Dianne Hackbornd6847842010-01-12 18:14:19 -08001148 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001149 * Retrieve the current maximum time to unlock for all admins of this user
1150 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001151 * @param admin The name of the admin component to check, or null to aggregate
1152 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001153 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001154 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001155 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1156 }
1157
1158 /** @hide per-user version */
1159 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001160 if (mService != null) {
1161 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001162 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001163 } catch (RemoteException e) {
1164 Log.w(TAG, "Failed talking with device policy service", e);
1165 }
1166 }
1167 return 0;
1168 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001169
Dianne Hackbornd6847842010-01-12 18:14:19 -08001170 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001171 * Make the device lock immediately, as if the lock screen timeout has
1172 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001173 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001174 * <p>The calling device admin must have requested
1175 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1176 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001177 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001178 public void lockNow() {
1179 if (mService != null) {
1180 try {
1181 mService.lockNow();
1182 } catch (RemoteException e) {
1183 Log.w(TAG, "Failed talking with device policy service", e);
1184 }
1185 }
1186 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001187
Dianne Hackbornd6847842010-01-12 18:14:19 -08001188 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001189 * Flag for {@link #wipeData(int)}: also erase the device's external
1190 * storage.
1191 */
1192 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1193
1194 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001195 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001196 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001197 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1198 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001199 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001200 * <p>The calling device admin must have requested
1201 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1202 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001203 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001204 * @param flags Bit mask of additional options: currently 0 and
1205 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001206 */
1207 public void wipeData(int flags) {
1208 if (mService != null) {
1209 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001210 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001211 } catch (RemoteException e) {
1212 Log.w(TAG, "Failed talking with device policy service", e);
1213 }
1214 }
1215 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001216
Dianne Hackbornd6847842010-01-12 18:14:19 -08001217 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001218 * Called by an application that is administering the device to set the
1219 * global proxy and exclusion list.
1220 * <p>
1221 * The calling device admin must have requested
1222 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1223 * this method; if it has not, a security exception will be thrown.
1224 * Only the first device admin can set the proxy. If a second admin attempts
1225 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1226 * proxy will be returned. If successful in setting the proxy, null will
1227 * be returned.
1228 * The method can be called repeatedly by the device admin alrady setting the
1229 * proxy to update the proxy and exclusion list.
1230 *
1231 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1232 * with.
1233 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1234 * Pass Proxy.NO_PROXY to reset the proxy.
1235 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001236 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1237 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001238 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001239 */
1240 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1241 List<String> exclusionList ) {
1242 if (proxySpec == null) {
1243 throw new NullPointerException();
1244 }
1245 if (mService != null) {
1246 try {
1247 String hostSpec;
1248 String exclSpec;
1249 if (proxySpec.equals(Proxy.NO_PROXY)) {
1250 hostSpec = null;
1251 exclSpec = null;
1252 } else {
1253 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1254 throw new IllegalArgumentException();
1255 }
1256 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1257 String hostName = sa.getHostName();
1258 int port = sa.getPort();
1259 StringBuilder hostBuilder = new StringBuilder();
1260 hostSpec = hostBuilder.append(hostName)
1261 .append(":").append(Integer.toString(port)).toString();
1262 if (exclusionList == null) {
1263 exclSpec = "";
1264 } else {
1265 StringBuilder listBuilder = new StringBuilder();
1266 boolean firstDomain = true;
1267 for (String exclDomain : exclusionList) {
1268 if (!firstDomain) {
1269 listBuilder = listBuilder.append(",");
1270 } else {
1271 firstDomain = false;
1272 }
1273 listBuilder = listBuilder.append(exclDomain.trim());
1274 }
1275 exclSpec = listBuilder.toString();
1276 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001277 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1278 != android.net.Proxy.PROXY_VALID)
1279 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001280 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001281 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001282 } catch (RemoteException e) {
1283 Log.w(TAG, "Failed talking with device policy service", e);
1284 }
1285 }
1286 return null;
1287 }
1288
1289 /**
1290 * Returns the component name setting the global proxy.
1291 * @return ComponentName object of the device admin that set the global proxy, or
1292 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001293 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001294 */
1295 public ComponentName getGlobalProxyAdmin() {
1296 if (mService != null) {
1297 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001298 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001299 } catch (RemoteException e) {
1300 Log.w(TAG, "Failed talking with device policy service", e);
1301 }
1302 }
1303 return null;
1304 }
1305
1306 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001307 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001308 * indicating that encryption is not supported.
1309 */
1310 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1311
1312 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001313 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001314 * indicating that encryption is supported, but is not currently active.
1315 */
1316 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1317
1318 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001319 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001320 * indicating that encryption is not currently active, but is currently
1321 * being activated. This is only reported by devices that support
1322 * encryption of data and only when the storage is currently
1323 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1324 * to become encrypted will never return this value.
1325 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001326 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001327
1328 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001329 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001330 * indicating that encryption is active.
1331 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001332 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001333
1334 /**
1335 * Activity action: begin the process of encrypting data on the device. This activity should
1336 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1337 * After resuming from this activity, use {@link #getStorageEncryption}
1338 * to check encryption status. However, on some devices this activity may never return, as
1339 * it may trigger a reboot and in some cases a complete data wipe of the device.
1340 */
1341 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1342 public static final String ACTION_START_ENCRYPTION
1343 = "android.app.action.START_ENCRYPTION";
1344
1345 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001346 * Widgets are enabled in keyguard
1347 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001348 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001349
1350 /**
Jim Miller50e62182014-04-23 17:25:00 -07001351 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001352 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001353 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1354
1355 /**
1356 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1357 */
1358 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1359
1360 /**
Jim Miller50e62182014-04-23 17:25:00 -07001361 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1362 */
1363 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1364
1365 /**
1366 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1367 */
1368 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1369
1370 /**
1371 * Ignore {@link TrustAgentService} state on secure keyguard screens
1372 * (e.g. PIN/Pattern/Password).
1373 */
1374 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1375
1376 /**
Jim Miller35207742012-11-02 15:33:20 -07001377 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001378 */
1379 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001380
1381 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001382 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001383 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001384 *
1385 * <p>When multiple device administrators attempt to control device
1386 * encryption, the most secure, supported setting will always be
1387 * used. If any device administrator requests device encryption,
1388 * it will be enabled; Conversely, if a device administrator
1389 * attempts to disable device encryption while another
1390 * device administrator has enabled it, the call to disable will
1391 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1392 *
1393 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001394 * written to other storage areas may or may not be encrypted, and this policy does not require
1395 * or control the encryption of any other storage areas.
1396 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1397 * {@code true}, then the directory returned by
1398 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1399 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001400 *
1401 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1402 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1403 * the encryption key may not be fully secured. For maximum security, the administrator should
1404 * also require (and check for) a pattern, PIN, or password.
1405 *
1406 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1407 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001408 * @return the new request status (for all active admins) - will be one of
1409 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1410 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1411 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001412 */
1413 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1414 if (mService != null) {
1415 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001416 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001417 } catch (RemoteException e) {
1418 Log.w(TAG, "Failed talking with device policy service", e);
1419 }
1420 }
1421 return ENCRYPTION_STATUS_UNSUPPORTED;
1422 }
1423
1424 /**
1425 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001426 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001427 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1429 * this will return the requested encryption setting as an aggregate of all active
1430 * administrators.
1431 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001432 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001433 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001434 if (mService != null) {
1435 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001436 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001437 } catch (RemoteException e) {
1438 Log.w(TAG, "Failed talking with device policy service", e);
1439 }
1440 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001441 return false;
1442 }
1443
1444 /**
1445 * Called by an application that is administering the device to
1446 * determine the current encryption status of the device.
1447 *
1448 * Depending on the returned status code, the caller may proceed in different
1449 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1450 * storage system does not support encryption. If the
1451 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1452 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1453 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1454 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1455 *
1456 * @return current status of encryption. The value will be one of
1457 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1458 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1459 */
1460 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001461 return getStorageEncryptionStatus(UserHandle.myUserId());
1462 }
1463
1464 /** @hide per-user version */
1465 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001466 if (mService != null) {
1467 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001468 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001469 } catch (RemoteException e) {
1470 Log.w(TAG, "Failed talking with device policy service", e);
1471 }
1472 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001473 return ENCRYPTION_STATUS_UNSUPPORTED;
1474 }
1475
1476 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001477 * Installs the given certificate as a User CA.
1478 *
1479 * @return false if the certBuffer cannot be parsed or installation is
1480 * interrupted, otherwise true
1481 * @hide
1482 */
1483 public boolean installCaCert(byte[] certBuffer) {
1484 if (mService != null) {
1485 try {
1486 return mService.installCaCert(certBuffer);
1487 } catch (RemoteException e) {
1488 Log.w(TAG, "Failed talking with device policy service", e);
1489 }
1490 }
1491 return false;
1492 }
1493
1494 /**
1495 * Uninstalls the given certificate from the list of User CAs, if present.
1496 *
1497 * @hide
1498 */
1499 public void uninstallCaCert(byte[] certBuffer) {
1500 if (mService != null) {
1501 try {
1502 mService.uninstallCaCert(certBuffer);
1503 } catch (RemoteException e) {
1504 Log.w(TAG, "Failed talking with device policy service", e);
1505 }
1506 }
1507 }
1508
1509 /**
1510 * Returns whether there are any user-installed CA certificates.
1511 *
1512 * @hide
1513 */
Maggie Benthall0469f412013-09-05 15:30:26 -04001514 public static boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001515 TrustedCertificateStore certStore = new TrustedCertificateStore();
1516 Set<String> aliases = certStore.userAliases();
1517 return aliases != null && !aliases.isEmpty();
1518 }
1519
1520 /**
1521 * Returns whether this certificate has been installed as a User CA.
1522 *
1523 * @hide
1524 */
1525 public boolean hasCaCertInstalled(byte[] certBuffer) {
1526 TrustedCertificateStore certStore = new TrustedCertificateStore();
1527 String alias;
1528 byte[] pemCert;
1529 try {
1530 CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1531 X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1532 new ByteArrayInputStream(certBuffer));
1533 return certStore.getCertificateAlias(cert) != null;
1534 } catch (CertificateException ce) {
1535 Log.w(TAG, "Could not parse certificate", ce);
1536 }
1537 return false;
1538 }
1539
1540 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001541 * Called by an application that is administering the device to disable all cameras
1542 * on the device. After setting this, no applications will be able to access any cameras
1543 * on the device.
1544 *
1545 * <p>The calling device admin must have requested
1546 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1547 * this method; if it has not, a security exception will be thrown.
1548 *
1549 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1550 * @param disabled Whether or not the camera should be disabled.
1551 */
1552 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1553 if (mService != null) {
1554 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001555 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001556 } catch (RemoteException e) {
1557 Log.w(TAG, "Failed talking with device policy service", e);
1558 }
1559 }
1560 }
1561
1562 /**
1563 * Determine whether or not the device's cameras have been disabled either by the current
1564 * admin, if specified, or all admins.
1565 * @param admin The name of the admin component to check, or null to check if any admins
1566 * have disabled the camera
1567 */
1568 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001569 return getCameraDisabled(admin, UserHandle.myUserId());
1570 }
1571
1572 /** @hide per-user version */
1573 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001574 if (mService != null) {
1575 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001576 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001577 } catch (RemoteException e) {
1578 Log.w(TAG, "Failed talking with device policy service", e);
1579 }
1580 }
1581 return false;
1582 }
1583
1584 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001585 * Called by an application that is administering the device to disable keyguard customizations,
1586 * such as widgets. After setting this, keyguard features will be disabled according to the
1587 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001588 *
1589 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001590 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001591 * this method; if it has not, a security exception will be thrown.
1592 *
1593 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001594 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1595 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001596 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1597 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001598 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001599 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001600 if (mService != null) {
1601 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001602 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001603 } catch (RemoteException e) {
1604 Log.w(TAG, "Failed talking with device policy service", e);
1605 }
1606 }
1607 }
1608
1609 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001610 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001611 * admin, if specified, or all admins.
1612 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001613 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001614 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1615 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001616 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001617 public int getKeyguardDisabledFeatures(ComponentName admin) {
1618 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001619 }
1620
1621 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001622 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001623 if (mService != null) {
1624 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001625 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001626 } catch (RemoteException e) {
1627 Log.w(TAG, "Failed talking with device policy service", e);
1628 }
1629 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001630 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001631 }
1632
1633 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001634 * @hide
1635 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001636 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001637 if (mService != null) {
1638 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001639 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001640 } catch (RemoteException e) {
1641 Log.w(TAG, "Failed talking with device policy service", e);
1642 }
1643 }
1644 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001645
Dianne Hackbornd6847842010-01-12 18:14:19 -08001646 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001647 * @hide
1648 */
1649 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1650 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1651 }
1652
1653 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001654 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001655 * @hide
1656 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001657 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001658 ActivityInfo ai;
1659 try {
1660 ai = mContext.getPackageManager().getReceiverInfo(cn,
1661 PackageManager.GET_META_DATA);
1662 } catch (PackageManager.NameNotFoundException e) {
1663 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1664 return null;
1665 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001666
Dianne Hackbornd6847842010-01-12 18:14:19 -08001667 ResolveInfo ri = new ResolveInfo();
1668 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001669
Dianne Hackbornd6847842010-01-12 18:14:19 -08001670 try {
1671 return new DeviceAdminInfo(mContext, ri);
1672 } catch (XmlPullParserException e) {
1673 Log.w(TAG, "Unable to parse device policy " + cn, e);
1674 return null;
1675 } catch (IOException e) {
1676 Log.w(TAG, "Unable to parse device policy " + cn, e);
1677 return null;
1678 }
1679 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001680
Dianne Hackbornd6847842010-01-12 18:14:19 -08001681 /**
1682 * @hide
1683 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001684 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1685 if (mService != null) {
1686 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001687 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001688 } catch (RemoteException e) {
1689 Log.w(TAG, "Failed talking with device policy service", e);
1690 }
1691 }
1692 }
1693
1694 /**
1695 * @hide
1696 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001697 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001698 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001699 if (mService != null) {
1700 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001701 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001702 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001703 } catch (RemoteException e) {
1704 Log.w(TAG, "Failed talking with device policy service", e);
1705 }
1706 }
1707 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001708
Dianne Hackbornd6847842010-01-12 18:14:19 -08001709 /**
1710 * @hide
1711 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001712 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001713 if (mService != null) {
1714 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001715 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001716 } catch (RemoteException e) {
1717 Log.w(TAG, "Failed talking with device policy service", e);
1718 }
1719 }
1720 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001721
Dianne Hackbornd6847842010-01-12 18:14:19 -08001722 /**
1723 * @hide
1724 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001725 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001726 if (mService != null) {
1727 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001728 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001729 } catch (RemoteException e) {
1730 Log.w(TAG, "Failed talking with device policy service", e);
1731 }
1732 }
1733 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001734
1735 /**
1736 * @hide
1737 * Sets the given package as the device owner. The package must already be installed and there
1738 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1739 * method must be called before the device is provisioned.
1740 * @param packageName the package name of the application to be registered as the device owner.
1741 * @return whether the package was successfully registered as the device owner.
1742 * @throws IllegalArgumentException if the package name is null or invalid
1743 * @throws IllegalStateException if a device owner is already registered or the device has
1744 * already been provisioned.
1745 */
1746 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1747 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001748 return setDeviceOwner(packageName, null);
1749 }
1750
1751 /**
1752 * @hide
1753 * Sets the given package as the device owner. The package must already be installed and there
1754 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1755 * method must be called before the device is provisioned.
1756 * @param packageName the package name of the application to be registered as the device owner.
1757 * @param ownerName the human readable name of the institution that owns this device.
1758 * @return whether the package was successfully registered as the device owner.
1759 * @throws IllegalArgumentException if the package name is null or invalid
1760 * @throws IllegalStateException if a device owner is already registered or the device has
1761 * already been provisioned.
1762 */
1763 public boolean setDeviceOwner(String packageName, String ownerName)
1764 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001765 if (mService != null) {
1766 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001767 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07001768 } catch (RemoteException re) {
1769 Log.w(TAG, "Failed to set device owner");
1770 }
1771 }
1772 return false;
1773 }
1774
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001775
Amith Yamasani71e6c692013-03-24 17:39:28 -07001776 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001777 * Used to determine if a particular package has been registered as a Device Owner app.
1778 * A device owner app is a special device admin that cannot be deactivated by the user, once
1779 * activated as a device admin. It also cannot be uninstalled. To check if a particular
1780 * package is currently registered as the device owner app, pass in the package name from
1781 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
1782 * admin apps that want to check if they are also registered as the device owner app. The
1783 * exact mechanism by which a device admin app is registered as a device owner app is defined by
1784 * the setup process.
1785 * @param packageName the package name of the app, to compare with the registered device owner
1786 * app, if any.
1787 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001788 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001789 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001790 if (mService != null) {
1791 try {
1792 return mService.isDeviceOwner(packageName);
1793 } catch (RemoteException re) {
1794 Log.w(TAG, "Failed to check device owner");
1795 }
1796 }
1797 return false;
1798 }
1799
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001800 /**
1801 * @hide
1802 * Redirect to isDeviceOwnerApp.
1803 */
1804 public boolean isDeviceOwner(String packageName) {
1805 return isDeviceOwnerApp(packageName);
1806 }
1807
Amith Yamasani71e6c692013-03-24 17:39:28 -07001808 /** @hide */
1809 public String getDeviceOwner() {
1810 if (mService != null) {
1811 try {
1812 return mService.getDeviceOwner();
1813 } catch (RemoteException re) {
1814 Log.w(TAG, "Failed to get device owner");
1815 }
1816 }
1817 return null;
1818 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001819
1820 /** @hide */
1821 public String getDeviceOwnerName() {
1822 if (mService != null) {
1823 try {
1824 return mService.getDeviceOwnerName();
1825 } catch (RemoteException re) {
1826 Log.w(TAG, "Failed to get device owner");
1827 }
1828 }
1829 return null;
1830 }
Adam Connors776c5552014-01-09 10:42:56 +00001831
1832 /**
1833 * @hide
1834 * Sets the given package as the profile owner of the given user profile. The package must
1835 * already be installed and there shouldn't be an existing profile owner registered for this
1836 * user. Also, this method must be called before the user has been used for the first time.
1837 * @param packageName the package name of the application to be registered as profile owner.
1838 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00001839 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00001840 * @return whether the package was successfully registered as the profile owner.
1841 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
1842 * the user has already been set up.
1843 */
Adam Connors661ec472014-02-11 13:59:46 +00001844 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00001845 throws IllegalArgumentException {
1846 if (mService != null) {
1847 try {
Adam Connors661ec472014-02-11 13:59:46 +00001848 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00001849 } catch (RemoteException re) {
1850 Log.w(TAG, "Failed to set profile owner", re);
1851 throw new IllegalArgumentException("Couldn't set profile owner.", re);
1852 }
1853 }
1854 return false;
1855 }
1856
1857 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001858 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
1859 * be used. Only the profile owner can call this.
1860 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001861 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001862 *
1863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1864 */
1865 public void setProfileEnabled(ComponentName admin) {
1866 if (mService != null) {
1867 try {
1868 mService.setProfileEnabled(admin);
1869 } catch (RemoteException e) {
1870 Log.w(TAG, "Failed talking with device policy service", e);
1871 }
1872 }
1873 }
1874
1875 /**
Adam Connors776c5552014-01-09 10:42:56 +00001876 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001877 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00001878 * within the managed profile.
1879 *
1880 * @param packageName The package name of the app to compare with the registered profile owner.
1881 * @return Whether or not the package is registered as the profile owner.
1882 */
1883 public boolean isProfileOwnerApp(String packageName) {
1884 if (mService != null) {
1885 try {
1886 String profileOwnerPackage = mService.getProfileOwner(
1887 Process.myUserHandle().getIdentifier());
1888 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
1889 } catch (RemoteException re) {
1890 Log.w(TAG, "Failed to check profile owner");
1891 }
1892 }
1893 return false;
1894 }
1895
1896 /**
1897 * @hide
1898 * @return the packageName of the owner of the given user profile or null if no profile
1899 * owner has been set for that user.
1900 * @throws IllegalArgumentException if the userId is invalid.
1901 */
1902 public String getProfileOwner() throws IllegalArgumentException {
1903 if (mService != null) {
1904 try {
1905 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
1906 } catch (RemoteException re) {
1907 Log.w(TAG, "Failed to get profile owner");
1908 throw new IllegalArgumentException(
1909 "Requested profile owner for invalid userId", re);
1910 }
1911 }
1912 return null;
1913 }
1914
1915 /**
1916 * @hide
1917 * @return the human readable name of the organisation associated with this DPM or null if
1918 * one is not set.
1919 * @throws IllegalArgumentException if the userId is invalid.
1920 */
1921 public String getProfileOwnerName() throws IllegalArgumentException {
1922 if (mService != null) {
1923 try {
1924 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
1925 } catch (RemoteException re) {
1926 Log.w(TAG, "Failed to get profile owner");
1927 throw new IllegalArgumentException(
1928 "Requested profile owner for invalid userId", re);
1929 }
1930 }
1931 return null;
1932 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001933
1934 /**
1935 * Called by a profile owner or device owner to add a default intent handler activity for
1936 * intents that match a certain intent filter. This activity will remain the default intent
1937 * handler even if the set of potential event handlers for the intent filter changes and if
1938 * the intent preferences are reset.
1939 *
1940 * <p>The default disambiguation mechanism takes over if the activity is not installed
1941 * (anymore). When the activity is (re)installed, it is automatically reset as default
1942 * intent handler for the filter.
1943 *
1944 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
1945 * security exception will be thrown.
1946 *
1947 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1948 * @param filter The IntentFilter for which a default handler is added.
1949 * @param activity The Activity that is added as default intent handler.
1950 */
1951 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
1952 ComponentName activity) {
1953 if (mService != null) {
1954 try {
1955 mService.addPersistentPreferredActivity(admin, filter, activity);
1956 } catch (RemoteException e) {
1957 Log.w(TAG, "Failed talking with device policy service", e);
1958 }
1959 }
1960 }
1961
1962 /**
1963 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00001964 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001965 *
1966 * <p>The calling device admin must be a profile owner. If it is not, a security
1967 * exception will be thrown.
1968 *
1969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1970 * @param packageName The name of the package for which preferences are removed.
1971 */
1972 public void clearPackagePersistentPreferredActivities(ComponentName admin,
1973 String packageName) {
1974 if (mService != null) {
1975 try {
1976 mService.clearPackagePersistentPreferredActivities(admin, packageName);
1977 } catch (RemoteException e) {
1978 Log.w(TAG, "Failed talking with device policy service", e);
1979 }
1980 }
1981 }
Robin Lee66e5d962014-04-09 16:44:21 +01001982
1983 /**
1984 * Called by a profile or device owner to set the application restrictions for a given target
1985 * application running in the managed profile.
1986 *
1987 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
1988 * {@link Boolean}, {@link String}, or {@link String}[]. The recommended format for key strings
1989 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
1990 * components such as {@link android.webkit.WebView}.
1991 *
1992 * <p>The application restrictions are only made visible to the target application and the
1993 * profile or device owner.
1994 *
1995 * <p>The calling device admin must be a profile or device owner; if it is not, a security
1996 * exception will be thrown.
1997 *
1998 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1999 * @param packageName The name of the package to update restricted settings for.
2000 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
2001 * set of active restrictions.
2002 */
2003 public void setApplicationRestrictions(ComponentName admin, String packageName,
2004 Bundle settings) {
2005 if (mService != null) {
2006 try {
2007 mService.setApplicationRestrictions(admin, packageName, settings);
2008 } catch (RemoteException e) {
2009 Log.w(TAG, "Failed talking with device policy service", e);
2010 }
2011 }
2012 }
2013
2014 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002015 * Called by the profile owner so that some intents sent in the managed profile can also be
2016 * resolved in the parent, or vice versa.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002017 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01002018 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
2019 * other profile
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002020 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002021 public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002022 if (mService != null) {
2023 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002024 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002025 } catch (RemoteException e) {
2026 Log.w(TAG, "Failed talking with device policy service", e);
2027 }
2028 }
2029 }
2030
2031 /**
Nicolas Prevot81948992014-05-16 18:25:26 +01002032 * Called by a profile owner to remove the cross-profile intent filters from the managed profile
2033 * and from the parent.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002034 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2035 */
Nicolas Prevot81948992014-05-16 18:25:26 +01002036 public void clearCrossProfileIntentFilters(ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002037 if (mService != null) {
2038 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01002039 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00002040 } catch (RemoteException e) {
2041 Log.w(TAG, "Failed talking with device policy service", e);
2042 }
2043 }
2044 }
2045
2046 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04002047 * Called by a device owner to create a user with the specified name. The UserHandle returned
2048 * by this method should not be persisted as user handles are recycled as users are removed and
2049 * created. If you need to persist an identifier for this user, use
2050 * {@link UserManager#getSerialNumberForUser}.
2051 *
2052 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2053 * @param name the user's name
2054 * @see UserHandle
2055 * @return the UserHandle object for the created user, or null if the user could not be created.
2056 */
2057 public UserHandle createUser(ComponentName admin, String name) {
2058 try {
2059 return mService.createUser(admin, name);
2060 } catch (RemoteException re) {
2061 Log.w(TAG, "Could not create a user", re);
2062 }
2063 return null;
2064 }
2065
2066 /**
2067 * Called by a device owner to remove a user and all associated data. The primary user can
2068 * not be removed.
2069 *
2070 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2071 * @param userHandle the user to remove.
2072 * @return {@code true} if the user was removed, {@code false} otherwise.
2073 */
2074 public boolean removeUser(ComponentName admin, UserHandle userHandle) {
2075 try {
2076 return mService.removeUser(admin, userHandle);
2077 } catch (RemoteException re) {
2078 Log.w(TAG, "Could not remove user ", re);
2079 return false;
2080 }
2081 }
2082
2083 /**
Robin Lee66e5d962014-04-09 16:44:21 +01002084 * Called by a profile or device owner to get the application restrictions for a given target
2085 * application running in the managed profile.
2086 *
2087 * <p>The calling device admin must be a profile or device owner; if it is not, a security
2088 * exception will be thrown.
2089 *
2090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2091 * @param packageName The name of the package to fetch restricted settings of.
2092 * @return {@link Bundle} of settings corresponding to what was set last time
2093 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
2094 * if no restrictions have been set.
2095 */
2096 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
2097 if (mService != null) {
2098 try {
2099 return mService.getApplicationRestrictions(admin, packageName);
2100 } catch (RemoteException e) {
2101 Log.w(TAG, "Failed talking with device policy service", e);
2102 }
2103 }
2104 return null;
2105 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002106
2107 /**
2108 * Called by a profile or device owner to set a user restriction specified
2109 * by the key.
2110 * <p>
2111 * The calling device admin must be a profile or device owner; if it is not,
2112 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002113 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002114 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2115 * with.
2116 * @param key The key of the restriction. See the constants in
2117 * {@link android.os.UserManager} for the list of keys.
2118 */
2119 public void addUserRestriction(ComponentName admin, String key) {
2120 if (mService != null) {
2121 try {
2122 mService.setUserRestriction(admin, key, true);
2123 } catch (RemoteException e) {
2124 Log.w(TAG, "Failed talking with device policy service", e);
2125 }
2126 }
2127 }
2128
2129 /**
2130 * Called by a profile or device owner to clear a user restriction specified
2131 * by the key.
2132 * <p>
2133 * The calling device admin must be a profile or device owner; if it is not,
2134 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002135 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002136 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2137 * with.
2138 * @param key The key of the restriction. See the constants in
2139 * {@link android.os.UserManager} for the list of keys.
2140 */
2141 public void clearUserRestriction(ComponentName admin, String key) {
2142 if (mService != null) {
2143 try {
2144 mService.setUserRestriction(admin, key, false);
2145 } catch (RemoteException e) {
2146 Log.w(TAG, "Failed talking with device policy service", e);
2147 }
2148 }
2149 }
Adam Connors010cfd42014-04-16 12:48:13 +01002150
2151 /**
Julia Reynolds966881e2014-05-14 12:23:08 -04002152 * Called by device or profile owner to block or unblock packages. When a package is blocked it
2153 * is unavailable for use, but the data and actual package file remain.
2154 *
2155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2156 * @param packageName The name of the package to block or unblock.
2157 * @param blocked {@code true} if the package should be blocked, {@code false} if it should be
2158 * unblocked.
2159 * @return boolean Whether the blocked setting of the package was successfully updated.
2160 */
2161 public boolean setApplicationBlocked(ComponentName admin, String packageName,
2162 boolean blocked) {
2163 if (mService != null) {
2164 try {
2165 return mService.setApplicationBlocked(admin, packageName, blocked);
2166 } catch (RemoteException e) {
2167 Log.w(TAG, "Failed talking with device policy service", e);
2168 }
2169 }
2170 return false;
2171 }
2172
2173 /**
2174 * Called by profile or device owner to block or unblock currently installed packages. This
2175 * should only be called by a profile or device owner running within a managed profile.
2176 *
2177 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2178 * @param intent An intent matching the app(s) to be updated. All apps that resolve for this
2179 * intent will be updated in the current profile.
2180 * @param blocked {@code true} if the packages should be blocked, {@code false} if they should
2181 * be unblocked.
2182 * @return int The number of activities that matched the intent and were updated.
2183 */
2184 public int setApplicationsBlocked(ComponentName admin, Intent intent, boolean blocked) {
2185 if (mService != null) {
2186 try {
2187 return mService.setApplicationsBlocked(admin, intent, blocked);
2188 } catch (RemoteException e) {
2189 Log.w(TAG, "Failed talking with device policy service", e);
2190 }
2191 }
2192 return 0;
2193 }
2194
2195 /**
2196 * Called by device or profile owner to determine if a package is blocked.
2197 *
2198 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2199 * @param packageName The name of the package to retrieve the blocked status of.
2200 * @return boolean {@code true} if the package is blocked, {@code false} otherwise.
2201 */
2202 public boolean isApplicationBlocked(ComponentName admin, String packageName) {
2203 if (mService != null) {
2204 try {
2205 return mService.isApplicationBlocked(admin, packageName);
2206 } catch (RemoteException e) {
2207 Log.w(TAG, "Failed talking with device policy service", e);
2208 }
2209 }
2210 return false;
2211 }
2212
2213 /**
Sander Alewijnse650c3342014-05-08 18:00:50 +01002214 * Called by a profile owner to disable account management for a specific type of account.
2215 *
2216 * <p>The calling device admin must be a profile owner. If it is not, a
2217 * security exception will be thrown.
2218 *
2219 * <p>When account management is disabled for an account type, adding or removing an account
2220 * of that type will not be possible.
2221 *
2222 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2223 * @param accountType For which account management is disabled or enabled.
2224 * @param disabled The boolean indicating that account management will be disabled (true) or
2225 * enabled (false).
2226 */
2227 public void setAccountManagementDisabled(ComponentName admin, String accountType,
2228 boolean disabled) {
2229 if (mService != null) {
2230 try {
2231 mService.setAccountManagementDisabled(admin, accountType, disabled);
2232 } catch (RemoteException e) {
2233 Log.w(TAG, "Failed talking with device policy service", e);
2234 }
2235 }
2236 }
2237
2238 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002239 * Gets the array of accounts for which account management is disabled by the profile owner.
2240 *
2241 * <p> Account management can be disabled/enabled by calling
2242 * {@link #setAccountManagementDisabled}.
2243 *
2244 * @return a list of account types for which account management has been disabled.
2245 *
2246 * @see #setAccountManagementDisabled
2247 */
2248 public String[] getAccountTypesWithManagementDisabled() {
2249 if (mService != null) {
2250 try {
2251 return mService.getAccountTypesWithManagementDisabled();
2252 } catch (RemoteException e) {
2253 Log.w(TAG, "Failed talking with device policy service", e);
2254 }
2255 }
2256
2257 return null;
2258 }
justinzhang511e0d82014-03-24 16:09:24 -04002259
2260 /**
2261 * Sets which components may enter lock task mode.
2262 *
2263 * This function can only be called by the device owner or the profile owner.
2264 * @param components The list of components allowed to enter lock task mode
2265 */
2266 public void setLockTaskComponents(ComponentName[] components) throws SecurityException {
2267 if (mService != null) {
2268 try {
2269 mService.setLockTaskComponents(components);
2270 } catch (RemoteException e) {
2271 Log.w(TAG, "Failed talking with device policy service", e);
2272 }
2273 }
2274 }
2275
2276 /**
2277 * This function returns the list of components allowed to start the lock task mode.
2278 * @hide
2279 */
2280 public ComponentName[] getLockTaskComponents() {
2281 if (mService != null) {
2282 try {
2283 return mService.getLockTaskComponents();
2284 } catch (RemoteException e) {
2285 Log.w(TAG, "Failed talking with device policy service", e);
2286 }
2287 }
2288 return null;
2289 }
2290
2291 /**
2292 * This function lets the caller know whether the given component is allowed to start the
2293 * lock task mode.
2294 * @param component The component to check
2295 */
2296 public boolean isLockTaskPermitted(ComponentName component) {
2297 if (mService != null) {
2298 try {
2299 return mService.isLockTaskPermitted(component);
2300 } catch (RemoteException e) {
2301 Log.w(TAG, "Failed talking with device policy service", e);
2302 }
2303 }
2304 return false;
2305 }
Julia Reynoldsda551652014-05-14 17:15:16 -04002306
2307 /**
2308 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
2309 * of the setting is in the correct form for the setting type should be performed by the caller.
2310 *
2311 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2312 * @param setting The name of the setting to update.
2313 * @param value The value to update the setting to.
2314 */
2315 public void setGlobalSetting(ComponentName admin, String setting, String value) {
2316 if (mService != null) {
2317 try {
2318 mService.setGlobalSetting(admin, setting, value);
2319 } catch (RemoteException e) {
2320 Log.w(TAG, "Failed talking with device policy service", e);
2321 }
2322 }
2323 }
2324
2325 /**
2326 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
2327 * that the value of the setting is in the correct form for the setting type should be performed
2328 * by the caller.
2329 *
2330 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2331 * @param setting The name of the setting to update.
2332 * @param value The value to update the setting to.
2333 */
2334 public void setSecureSetting(ComponentName admin, String setting, String value) {
2335 if (mService != null) {
2336 try {
2337 mService.setSecureSetting(admin, setting, value);
2338 } catch (RemoteException e) {
2339 Log.w(TAG, "Failed talking with device policy service", e);
2340 }
2341 }
2342 }
2343
Amith Yamasanif20d6402014-05-24 15:34:37 -07002344 /**
2345 * Designates a specific broadcast receiver component as the provider for
2346 * making permission requests of a local or remote administrator of the user.
2347 * <p/>
2348 * Only a profile owner can designate the restrictions provider.
2349 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2350 * @param receiver The component name of a BroadcastReceiver that handles the
2351 * {@link RestrictionsManager#ACTION_REQUEST_PERMISSION} intent. If this param is null,
2352 * it removes the restrictions provider previously assigned.
2353 */
2354 public void setRestrictionsProvider(ComponentName admin, ComponentName receiver) {
2355 if (mService != null) {
2356 try {
2357 mService.setRestrictionsProvider(admin, receiver);
2358 } catch (RemoteException re) {
2359 Log.w(TAG, "Failed to set permission provider on device policy service");
2360 }
2361 }
2362 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08002363}