blob: 58049fd11914a644f3cb3d30d0ac14ec34a4082c [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;
Robin Lee66e5d962014-04-09 16:44:21 +010028import android.os.Bundle;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.os.Handler;
Adam Connors776c5552014-01-09 10:42:56 +000030import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080031import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080032import android.os.RemoteException;
33import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070034import android.os.UserHandle;
Jim Miller50e62182014-04-23 17:25:00 -070035import android.service.trust.TrustAgentService;
Dianne Hackbornd6847842010-01-12 18:14:19 -080036import android.util.Log;
37
Maggie Benthallda51e682013-08-08 22:35:44 -040038import com.android.org.conscrypt.TrustedCertificateStore;
39
Jessica Hummel91da58d2014-04-10 17:39:43 +010040import org.xmlpull.v1.XmlPullParserException;
41
Maggie Benthallda51e682013-08-08 22:35:44 -040042import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080043import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070044import java.net.InetSocketAddress;
45import java.net.Proxy;
Maggie Benthallda51e682013-08-08 22:35:44 -040046import java.security.cert.CertificateException;
47import java.security.cert.CertificateFactory;
48import java.security.cert.X509Certificate;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080049import java.util.List;
Maggie Benthallda51e682013-08-08 22:35:44 -040050import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051
52/**
53 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080054 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080055 * has currently enabled.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080056 *
57 * <div class="special reference">
58 * <h3>Developer Guides</h3>
59 * <p>For more information about managing policies for device adminstration, read the
60 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
61 * developer guide.</p>
62 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080063 */
64public class DevicePolicyManager {
65 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080066
67 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080068 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070069
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080070 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080071 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080072 mService = IDevicePolicyManager.Stub.asInterface(
73 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
74 }
75
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080076 /** @hide */
77 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080078 DevicePolicyManager me = new DevicePolicyManager(context, handler);
79 return me.mService != null ? me : null;
80 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070081
Dianne Hackbornd6847842010-01-12 18:14:19 -080082 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +000083 * Activity action: Starts the provisioning flow which sets up a managed profile.
84 * This intent will typically be sent by a mobile device management application(mdm).
85 * Managed profile provisioning creates a profile, moves the mdm to the profile,
86 * sets the mdm as the profile owner and removes all non required applications from the profile.
87 * As a profile owner the mdm than has full control over the managed profile.
88 *
89 * <p>The intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} and
90 * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME}.
91 *
92 * <p> When managed provisioning has completed, an intent of the type
93 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the
94 * mdm app on the managed profile.
95 *
96 * <p>Input: Nothing.</p>
97 * <p>Output: Nothing</p>
98 */
99 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
100 public static final String ACTION_PROVISION_MANAGED_PROFILE
Jessica Hummel03dd2202014-03-13 16:05:26 +0000101 = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000102
103 /**
104 * A String extra holding the name of the package of the mobile device management application
105 * that starts the managed provisioning flow. This package will be set as the profile owner.
106 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
107 */
108 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
109 = "deviceAdminPackageName";
110
111 /**
112 * A String extra holding the default name of the profile that is created during managed profile
113 * provisioning.
114 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}
115 */
116 public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME
117 = "defaultManagedProfileName";
118
119 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800120 * Activity action: ask the user to add a new device administrator to the system.
121 * The desired policy is the ComponentName of the policy in the
122 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
123 * bring the user through adding the device administrator to the system (or
124 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700125 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800126 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
127 * field to provide the user with additional explanation (in addition
128 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800129 *
130 * <p>If your administrator is already active, this will ordinarily return immediately (without
131 * user intervention). However, if your administrator has been updated and is requesting
132 * additional uses-policy flags, the user will be presented with the new list. New policies
133 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800134 */
135 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
136 public static final String ACTION_ADD_DEVICE_ADMIN
137 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700138
Dianne Hackbornd6847842010-01-12 18:14:19 -0800139 /**
Jim Miller284b62e2010-06-08 14:27:42 -0700140 * Activity action: send when any policy admin changes a policy.
141 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700142 *
Jim Miller284b62e2010-06-08 14:27:42 -0700143 * @hide
144 */
145 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
146 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
147
148 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800149 * The ComponentName of the administrator component.
150 *
151 * @see #ACTION_ADD_DEVICE_ADMIN
152 */
153 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700154
Dianne Hackbornd6847842010-01-12 18:14:19 -0800155 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800156 * An optional CharSequence providing additional explanation for why the
157 * admin is being added.
158 *
159 * @see #ACTION_ADD_DEVICE_ADMIN
160 */
161 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700162
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800163 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700164 * Activity action: have the user enter a new password. This activity should
165 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
166 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
167 * enter a new password that meets the current requirements. You can use
168 * {@link #isActivePasswordSufficient()} to determine whether you need to
169 * have the user select a new password in order to meet the current
170 * constraints. Upon being resumed from this activity, you can check the new
171 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800172 */
173 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
174 public static final String ACTION_SET_NEW_PASSWORD
175 = "android.app.action.SET_NEW_PASSWORD";
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000176 /**
Nicolas Prevotc79586e2014-05-06 12:47:57 +0100177 * Flag for {@link #addForwardingIntentFilter}: the intents will forwarded to the primary user.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000178 */
179 public static int FLAG_TO_PRIMARY_USER = 0x0001;
180
181 /**
Nicolas Prevotc79586e2014-05-06 12:47:57 +0100182 * Flag for {@link #addForwardingIntentFilter}: the intents will be forwarded to the managed
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000183 * profile.
184 */
185 public static int FLAG_TO_MANAGED_PROFILE = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700186
Dianne Hackbornd6847842010-01-12 18:14:19 -0800187 /**
188 * Return true if the given administrator component is currently
189 * active (enabled) in the system.
190 */
191 public boolean isAdminActive(ComponentName who) {
192 if (mService != null) {
193 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700194 return mService.isAdminActive(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800195 } catch (RemoteException e) {
196 Log.w(TAG, "Failed talking with device policy service", e);
197 }
198 }
199 return false;
200 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700201
Dianne Hackbornd6847842010-01-12 18:14:19 -0800202 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800203 * Return a list of all currently active device administrator's component
204 * names. Note that if there are no administrators than null may be
205 * returned.
206 */
207 public List<ComponentName> getActiveAdmins() {
208 if (mService != null) {
209 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700210 return mService.getActiveAdmins(UserHandle.myUserId());
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800211 } catch (RemoteException e) {
212 Log.w(TAG, "Failed talking with device policy service", e);
213 }
214 }
215 return null;
216 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700217
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800218 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700219 * Used by package administration code to determine if a package can be stopped
220 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800221 * @hide
222 */
223 public boolean packageHasActiveAdmins(String packageName) {
224 if (mService != null) {
225 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700226 return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800227 } catch (RemoteException e) {
228 Log.w(TAG, "Failed talking with device policy service", e);
229 }
230 }
231 return false;
232 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700233
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800234 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800235 * Remove a current administration component. This can only be called
236 * by the application that owns the administration component; if you
237 * try to remove someone else's component, a security exception will be
238 * thrown.
239 */
240 public void removeActiveAdmin(ComponentName who) {
241 if (mService != null) {
242 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700243 mService.removeActiveAdmin(who, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800244 } catch (RemoteException e) {
245 Log.w(TAG, "Failed talking with device policy service", e);
246 }
247 }
248 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700249
Dianne Hackbornd6847842010-01-12 18:14:19 -0800250 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800251 * Returns true if an administrator has been granted a particular device policy. This can
252 * be used to check if the administrator was activated under an earlier set of policies,
253 * but requires additional policies after an upgrade.
254 *
255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
256 * an active administrator, or an exception will be thrown.
257 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
258 */
259 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
260 if (mService != null) {
261 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700262 return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800263 } catch (RemoteException e) {
264 Log.w(TAG, "Failed talking with device policy service", e);
265 }
266 }
267 return false;
268 }
269
270 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800271 * Constant for {@link #setPasswordQuality}: the policy has no requirements
272 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800273 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800274 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800275 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700276
Dianne Hackbornd6847842010-01-12 18:14:19 -0800277 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700278 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
279 * recognition technology. This implies technologies that can recognize the identity of
280 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
281 * Note that quality constants are ordered so that higher values are more restrictive.
282 */
283 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
284
285 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800286 * Constant for {@link #setPasswordQuality}: the policy requires some kind
287 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800288 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800289 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800290 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700291
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800292 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800293 * Constant for {@link #setPasswordQuality}: the user must have entered a
294 * password containing at least numeric characters. Note that quality
295 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800296 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800297 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700298
Dianne Hackbornd6847842010-01-12 18:14:19 -0800299 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800300 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700301 * password containing at least alphabetic (or other symbol) characters.
302 * Note that quality constants are ordered so that higher values are more
303 * restrictive.
304 */
305 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700306
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700307 /**
308 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800309 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700310 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800311 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800312 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700313 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700314
Dianne Hackbornd6847842010-01-12 18:14:19 -0800315 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700316 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700317 * password containing at least a letter, a numerical digit and a special
318 * symbol, by default. With this password quality, passwords can be
319 * restricted to contain various sets of characters, like at least an
320 * uppercase letter, etc. These are specified using various methods,
321 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
322 * that quality constants are ordered so that higher values are more
323 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700324 */
325 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
326
327 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800328 * Called by an application that is administering the device to set the
329 * password restrictions it is imposing. After setting this, the user
330 * will not be able to enter a new password that is not at least as
331 * restrictive as what has been set. Note that the current password
332 * will remain until the user has set a new one, so the change does not
333 * take place immediately. To prompt the user for a new password, use
334 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700335 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800336 * <p>Quality constants are ordered so that higher values are more restrictive;
337 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800338 * the user's preference, and any other considerations) is the one that
339 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700340 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800341 * <p>The calling device admin must have requested
342 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
343 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700344 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800345 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800346 * @param quality The new desired quality. One of
347 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700348 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700349 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800350 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800351 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800352 if (mService != null) {
353 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700354 mService.setPasswordQuality(admin, quality, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800355 } catch (RemoteException e) {
356 Log.w(TAG, "Failed talking with device policy service", e);
357 }
358 }
359 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700360
Dianne Hackbornd6847842010-01-12 18:14:19 -0800361 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100362 * Retrieve the current minimum password quality for all admins of this user
363 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800364 * @param admin The name of the admin component to check, or null to aggregate
365 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800366 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800367 public int getPasswordQuality(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700368 return getPasswordQuality(admin, UserHandle.myUserId());
369 }
370
371 /** @hide per-user version */
372 public int getPasswordQuality(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800373 if (mService != null) {
374 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700375 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800376 } catch (RemoteException e) {
377 Log.w(TAG, "Failed talking with device policy service", e);
378 }
379 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800380 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800381 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700382
Dianne Hackbornd6847842010-01-12 18:14:19 -0800383 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800384 * Called by an application that is administering the device to set the
385 * minimum allowed password length. After setting this, the user
386 * will not be able to enter a new password that is not at least as
387 * restrictive as what has been set. Note that the current password
388 * will remain until the user has set a new one, so the change does not
389 * take place immediately. To prompt the user for a new password, use
390 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
391 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700392 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
393 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800394 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700395 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800396 * <p>The calling device admin must have requested
397 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
398 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700399 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800401 * @param length The new desired minimum password length. A value of 0
402 * means there is no restriction.
403 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800404 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800405 if (mService != null) {
406 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700407 mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800408 } catch (RemoteException e) {
409 Log.w(TAG, "Failed talking with device policy service", e);
410 }
411 }
412 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700413
Dianne Hackbornd6847842010-01-12 18:14:19 -0800414 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100415 * Retrieve the current minimum password length for all admins of this
416 * user and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800417 * @param admin The name of the admin component to check, or null to aggregate
418 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800419 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800420 public int getPasswordMinimumLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700421 return getPasswordMinimumLength(admin, UserHandle.myUserId());
422 }
423
424 /** @hide per-user version */
425 public int getPasswordMinimumLength(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800426 if (mService != null) {
427 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700428 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800429 } catch (RemoteException e) {
430 Log.w(TAG, "Failed talking with device policy service", e);
431 }
432 }
433 return 0;
434 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700435
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700436 /**
437 * Called by an application that is administering the device to set the
438 * minimum number of upper case letters required in the password. After
439 * setting this, the user will not be able to enter a new password that is
440 * not at least as restrictive as what has been set. Note that the current
441 * password will remain until the user has set a new one, so the change does
442 * not take place immediately. To prompt the user for a new password, use
443 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
444 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700445 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
446 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700447 * <p>
448 * The calling device admin must have requested
449 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
450 * this method; if it has not, a security exception will be thrown.
451 *
452 * @param admin Which {@link DeviceAdminReceiver} this request is associated
453 * with.
454 * @param length The new desired minimum number of upper case letters
455 * required in the password. A value of 0 means there is no
456 * restriction.
457 */
458 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
459 if (mService != null) {
460 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700461 mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700462 } catch (RemoteException e) {
463 Log.w(TAG, "Failed talking with device policy service", e);
464 }
465 }
466 }
467
468 /**
469 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100470 * password for all admins of this user and its profiles or a particular one.
471 * This is the same value as set by
472 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700473 * and only applies when the password quality is
474 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700475 *
476 * @param admin The name of the admin component to check, or null to
477 * aggregate all admins.
478 * @return The minimum number of upper case letters required in the
479 * password.
480 */
481 public int getPasswordMinimumUpperCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700482 return getPasswordMinimumUpperCase(admin, UserHandle.myUserId());
483 }
484
485 /** @hide per-user version */
486 public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700487 if (mService != null) {
488 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700489 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700490 } catch (RemoteException e) {
491 Log.w(TAG, "Failed talking with device policy service", e);
492 }
493 }
494 return 0;
495 }
496
497 /**
498 * Called by an application that is administering the device to set the
499 * minimum number of lower case letters required in the password. After
500 * setting this, the user will not be able to enter a new password that is
501 * not at least as restrictive as what has been set. Note that the current
502 * password will remain until the user has set a new one, so the change does
503 * not take place immediately. To prompt the user for a new password, use
504 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
505 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700506 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
507 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700508 * <p>
509 * The calling device admin must have requested
510 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
511 * this method; if it has not, a security exception will be thrown.
512 *
513 * @param admin Which {@link DeviceAdminReceiver} this request is associated
514 * with.
515 * @param length The new desired minimum number of lower case letters
516 * required in the password. A value of 0 means there is no
517 * restriction.
518 */
519 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
520 if (mService != null) {
521 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700522 mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700523 } catch (RemoteException e) {
524 Log.w(TAG, "Failed talking with device policy service", e);
525 }
526 }
527 }
528
529 /**
530 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100531 * password for all admins of this user and its profiles or a particular one.
532 * This is the same value as set by
533 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700534 * and only applies when the password quality is
535 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700536 *
537 * @param admin The name of the admin component to check, or null to
538 * aggregate all admins.
539 * @return The minimum number of lower case letters required in the
540 * password.
541 */
542 public int getPasswordMinimumLowerCase(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700543 return getPasswordMinimumLowerCase(admin, UserHandle.myUserId());
544 }
545
546 /** @hide per-user version */
547 public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700548 if (mService != null) {
549 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700550 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700551 } catch (RemoteException e) {
552 Log.w(TAG, "Failed talking with device policy service", e);
553 }
554 }
555 return 0;
556 }
557
558 /**
559 * Called by an application that is administering the device to set the
560 * minimum number of letters required in the password. After setting this,
561 * the user will not be able to enter a new password that is not at least as
562 * restrictive as what has been set. Note that the current password will
563 * remain until the user has set a new one, so the change does not take
564 * place immediately. To prompt the user for a new password, use
565 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
566 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700567 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
568 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700569 * <p>
570 * The calling device admin must have requested
571 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
572 * this method; if it has not, a security exception will be thrown.
573 *
574 * @param admin Which {@link DeviceAdminReceiver} this request is associated
575 * with.
576 * @param length The new desired minimum number of letters required in the
577 * password. A value of 0 means there is no restriction.
578 */
579 public void setPasswordMinimumLetters(ComponentName admin, int length) {
580 if (mService != null) {
581 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700582 mService.setPasswordMinimumLetters(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 letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700591 * admins or a particular one. This is the same value as
592 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
593 * and only applies when the password quality is
594 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700595 *
596 * @param admin The name of the admin component to check, or null to
597 * aggregate all admins.
598 * @return The minimum number of letters required in the password.
599 */
600 public int getPasswordMinimumLetters(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700601 return getPasswordMinimumLetters(admin, UserHandle.myUserId());
602 }
603
604 /** @hide per-user version */
605 public int getPasswordMinimumLetters(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700606 if (mService != null) {
607 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700608 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700609 } catch (RemoteException e) {
610 Log.w(TAG, "Failed talking with device policy service", e);
611 }
612 }
613 return 0;
614 }
615
616 /**
617 * Called by an application that is administering the device to set the
618 * minimum number of numerical digits required in the password. After
619 * setting this, the user will not be able to enter a new password that is
620 * not at least as restrictive as what has been set. Note that the current
621 * password will remain until the user has set a new one, so the change does
622 * not take place immediately. To prompt the user for a new password, use
623 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
624 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700625 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
626 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700627 * <p>
628 * The calling device admin must have requested
629 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
630 * this method; if it has not, a security exception will be thrown.
631 *
632 * @param admin Which {@link DeviceAdminReceiver} this request is associated
633 * with.
634 * @param length The new desired minimum number of numerical digits required
635 * in the password. A value of 0 means there is no restriction.
636 */
637 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
638 if (mService != null) {
639 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700640 mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700641 } catch (RemoteException e) {
642 Log.w(TAG, "Failed talking with device policy service", e);
643 }
644 }
645 }
646
647 /**
648 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +0100649 * for all admins of this user and its profiles or a particular one.
650 * This is the same value as set by
651 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700652 * and only applies when the password quality is
653 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700654 *
655 * @param admin The name of the admin component to check, or null to
656 * aggregate all admins.
657 * @return The minimum number of numerical digits required in the password.
658 */
659 public int getPasswordMinimumNumeric(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700660 return getPasswordMinimumNumeric(admin, UserHandle.myUserId());
661 }
662
663 /** @hide per-user version */
664 public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700665 if (mService != null) {
666 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700667 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700668 } catch (RemoteException e) {
669 Log.w(TAG, "Failed talking with device policy service", e);
670 }
671 }
672 return 0;
673 }
674
675 /**
676 * Called by an application that is administering the device to set the
677 * minimum number of symbols required in the password. After setting this,
678 * the user will not be able to enter a new password that is not at least as
679 * restrictive as what has been set. Note that the current password will
680 * remain until the user has set a new one, so the change does not take
681 * place immediately. To prompt the user for a new password, use
682 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
683 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700684 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
685 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700686 * <p>
687 * The calling device admin must have requested
688 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
689 * this method; if it has not, a security exception will be thrown.
690 *
691 * @param admin Which {@link DeviceAdminReceiver} this request is associated
692 * with.
693 * @param length The new desired minimum number of symbols required in the
694 * password. A value of 0 means there is no restriction.
695 */
696 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
697 if (mService != null) {
698 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700699 mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId());
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700700 } catch (RemoteException e) {
701 Log.w(TAG, "Failed talking with device policy service", e);
702 }
703 }
704 }
705
706 /**
707 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700708 * admins or a particular one. This is the same value as
709 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
710 * and only applies when the password quality is
711 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700712 *
713 * @param admin The name of the admin component to check, or null to
714 * aggregate all admins.
715 * @return The minimum number of symbols required in the password.
716 */
717 public int getPasswordMinimumSymbols(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700718 return getPasswordMinimumSymbols(admin, UserHandle.myUserId());
719 }
720
721 /** @hide per-user version */
722 public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700723 if (mService != null) {
724 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700725 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700726 } catch (RemoteException e) {
727 Log.w(TAG, "Failed talking with device policy service", e);
728 }
729 }
730 return 0;
731 }
732
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700733 /**
734 * Called by an application that is administering the device to set the
735 * minimum number of non-letter characters (numerical digits or symbols)
736 * required in the password. After setting this, the user will not be able
737 * to enter a new password that is not at least as restrictive as what has
738 * been set. Note that the current password will remain until the user has
739 * set a new one, so the change does not take place immediately. To prompt
740 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
741 * setting this value. This constraint is only imposed if the administrator
742 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
743 * {@link #setPasswordQuality}. The default value is 0.
744 * <p>
745 * The calling device admin must have requested
746 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
747 * this method; if it has not, a security exception will be thrown.
748 *
749 * @param admin Which {@link DeviceAdminReceiver} this request is associated
750 * with.
751 * @param length The new desired minimum number of letters required in the
752 * password. A value of 0 means there is no restriction.
753 */
754 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
755 if (mService != null) {
756 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700757 mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId());
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700758 } catch (RemoteException e) {
759 Log.w(TAG, "Failed talking with device policy service", e);
760 }
761 }
762 }
763
764 /**
765 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +0100766 * password for all admins of this user and its profiles or a particular one.
767 * This is the same value as set by
768 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700769 * and only applies when the password quality is
770 * {@link #PASSWORD_QUALITY_COMPLEX}.
771 *
772 * @param admin The name of the admin component to check, or null to
773 * aggregate all admins.
774 * @return The minimum number of letters required in the password.
775 */
776 public int getPasswordMinimumNonLetter(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700777 return getPasswordMinimumNonLetter(admin, UserHandle.myUserId());
778 }
779
780 /** @hide per-user version */
781 public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700782 if (mService != null) {
783 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700784 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700785 } catch (RemoteException e) {
786 Log.w(TAG, "Failed talking with device policy service", e);
787 }
788 }
789 return 0;
790 }
791
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700792 /**
793 * Called by an application that is administering the device to set the length
794 * of the password history. After setting this, the user will not be able to
795 * enter a new password that is the same as any password in the history. Note
796 * that the current password will remain until the user has set a new one, so
797 * the change does not take place immediately. To prompt the user for a new
798 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
799 * This constraint is only imposed if the administrator has also requested
800 * either {@link #PASSWORD_QUALITY_NUMERIC},
801 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
802 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
803 *
804 * <p>
805 * The calling device admin must have requested
806 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
807 * 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 length of password history. A value of 0
812 * means there is no restriction.
813 */
814 public void setPasswordHistoryLength(ComponentName admin, int length) {
815 if (mService != null) {
816 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700817 mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId());
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700818 } catch (RemoteException e) {
819 Log.w(TAG, "Failed talking with device policy service", e);
820 }
821 }
822 }
823
824 /**
Jim Millera4e28d12010-11-08 16:15:47 -0800825 * Called by a device admin to set the password expiration timeout. Calling this method
826 * will restart the countdown for password expiration for the given admin, as will changing
827 * the device password (for all admins).
828 *
829 * <p>The provided timeout is the time delta in ms and will be added to the current time.
830 * For example, to have the password expire 5 days from now, timeout would be
831 * 5 * 86400 * 1000 = 432000000 ms for timeout.
832 *
833 * <p>To disable password expiration, a value of 0 may be used for timeout.
834 *
Jim Millera4e28d12010-11-08 16:15:47 -0800835 * <p>The calling device admin must have requested
836 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
837 * method; if it has not, a security exception will be thrown.
838 *
839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
840 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
841 * means there is no restriction (unlimited).
842 */
843 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
844 if (mService != null) {
845 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700846 mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800847 } catch (RemoteException e) {
848 Log.w(TAG, "Failed talking with device policy service", e);
849 }
850 }
851 }
852
853 /**
Jim Miller6b857682011-02-16 16:27:41 -0800854 * Get the password expiration timeout for the given admin. The expiration timeout is the
855 * recurring expiration timeout provided in the call to
856 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
857 * aggregate of all policy administrators if admin is null.
Jim Millera4e28d12010-11-08 16:15:47 -0800858 *
859 * @param admin The name of the admin component to check, or null to aggregate all admins.
860 * @return The timeout for the given admin or the minimum of all timeouts
861 */
862 public long getPasswordExpirationTimeout(ComponentName admin) {
863 if (mService != null) {
864 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700865 return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800866 } catch (RemoteException e) {
867 Log.w(TAG, "Failed talking with device policy service", e);
868 }
869 }
870 return 0;
871 }
872
873 /**
874 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +0100875 * all admins of this user and its profiles if admin is null. If the password is
876 * expired, this will return the time since the password expired as a negative number.
877 * If admin is null, then a composite of all expiration timeouts is returned
878 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -0800879 *
880 * @param admin The name of the admin component to check, or null to aggregate all admins.
881 * @return The password expiration time, in ms.
882 */
883 public long getPasswordExpiration(ComponentName admin) {
884 if (mService != null) {
885 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700886 return mService.getPasswordExpiration(admin, UserHandle.myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -0800887 } catch (RemoteException e) {
888 Log.w(TAG, "Failed talking with device policy service", e);
889 }
890 }
891 return 0;
892 }
893
894 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +0100895 * Retrieve the current password history length for all admins of this
896 * user and its profiles or a particular one.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700897 * @param admin The name of the admin component to check, or null to aggregate
898 * all admins.
899 * @return The length of the password history
900 */
901 public int getPasswordHistoryLength(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700902 return getPasswordHistoryLength(admin, UserHandle.myUserId());
903 }
904
905 /** @hide per-user version */
906 public int getPasswordHistoryLength(ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700907 if (mService != null) {
908 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700909 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700910 } catch (RemoteException e) {
911 Log.w(TAG, "Failed talking with device policy service", e);
912 }
913 }
914 return 0;
915 }
916
Dianne Hackbornd6847842010-01-12 18:14:19 -0800917 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800918 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800919 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800920 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800921 * @return Returns the maximum length that the user can enter.
922 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800923 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800924 // Kind-of arbitrary.
925 return 16;
926 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700927
Dianne Hackborn254cb442010-01-27 19:23:59 -0800928 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800929 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800930 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +0100931 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700932 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800933 * <p>The calling device admin must have requested
934 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
935 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700936 *
Jessica Hummel91da58d2014-04-10 17:39:43 +0100937 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800938 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800939 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800940 if (mService != null) {
941 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700942 return mService.isActivePasswordSufficient(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800943 } catch (RemoteException e) {
944 Log.w(TAG, "Failed talking with device policy service", e);
945 }
946 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800947 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800948 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700949
Dianne Hackbornd6847842010-01-12 18:14:19 -0800950 /**
951 * Retrieve the number of times the user has failed at entering a
952 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700953 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800954 * <p>The calling device admin must have requested
955 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
956 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800957 */
958 public int getCurrentFailedPasswordAttempts() {
959 if (mService != null) {
960 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700961 return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800962 } catch (RemoteException e) {
963 Log.w(TAG, "Failed talking with device policy service", e);
964 }
965 }
966 return -1;
967 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800968
969 /**
Andrew Stadler88209d12010-02-08 22:59:36 -0800970 * Setting this to a value greater than zero enables a built-in policy
971 * that will perform a device wipe after too many incorrect
972 * device-unlock passwords have been entered. This built-in policy combines
973 * watching for failed passwords and wiping the device, and requires
974 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800975 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700976 *
Andrew Stadler88209d12010-02-08 22:59:36 -0800977 * <p>To implement any other policy (e.g. wiping data for a particular
978 * application only, erasing or revoking credentials, or reporting the
979 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800980 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -0800981 * instead. Do not use this API, because if the maximum count is reached,
982 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700983 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800984 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800985 * @param num The number of failed password attempts at which point the
986 * device will wipe its data.
987 */
988 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
989 if (mService != null) {
990 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700991 mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800992 } catch (RemoteException e) {
993 Log.w(TAG, "Failed talking with device policy service", e);
994 }
995 }
996 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700997
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800998 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800999 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001000 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001001 * or a particular one.
1002 * @param admin The name of the admin component to check, or null to aggregate
1003 * all admins.
1004 */
1005 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001006 return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId());
1007 }
1008
1009 /** @hide per-user version */
1010 public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001011 if (mService != null) {
1012 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001013 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001014 } catch (RemoteException e) {
1015 Log.w(TAG, "Failed talking with device policy service", e);
1016 }
1017 }
1018 return 0;
1019 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001020
Dianne Hackborn254cb442010-01-27 19:23:59 -08001021 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001022 * Flag for {@link #resetPassword}: don't allow other admins to change
1023 * the password again until the user has entered it.
1024 */
1025 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001026
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001027 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001028 * Force a new device unlock password (the password needed to access the
1029 * entire device, not for individual accounts) on the user. This takes
1030 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001031 * The given password must be sufficient for the
1032 * current password quality and length constraints as returned by
1033 * {@link #getPasswordQuality(ComponentName)} and
1034 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1035 * these constraints, then it will be rejected and false returned. Note
1036 * that the password may be a stronger quality (containing alphanumeric
1037 * characters when the requested quality is only numeric), in which case
1038 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001039 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001040 * <p>The calling device admin must have requested
1041 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1042 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001043 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001044 * Can not be called from a managed profile.
1045 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001046 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001047 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001048 * @return Returns true if the password was applied, or false if it is
1049 * not acceptable for the current constraints.
1050 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001051 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001052 if (mService != null) {
1053 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001054 return mService.resetPassword(password, flags, UserHandle.myUserId());
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001055 } catch (RemoteException e) {
1056 Log.w(TAG, "Failed talking with device policy service", e);
1057 }
1058 }
1059 return false;
1060 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001061
Dianne Hackbornd6847842010-01-12 18:14:19 -08001062 /**
1063 * Called by an application that is administering the device to set the
1064 * maximum time for user activity until the device will lock. This limits
1065 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001066 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001067 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001068 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001069 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001070 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001071 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001072 * @param timeMs The new desired maximum time to lock in milliseconds.
1073 * A value of 0 means there is no restriction.
1074 */
1075 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
1076 if (mService != null) {
1077 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001078 mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 } catch (RemoteException e) {
1080 Log.w(TAG, "Failed talking with device policy service", e);
1081 }
1082 }
1083 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001084
Dianne Hackbornd6847842010-01-12 18:14:19 -08001085 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001086 * Retrieve the current maximum time to unlock for all admins of this user
1087 * and its profiles or a particular one.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001088 * @param admin The name of the admin component to check, or null to aggregate
1089 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001090 */
Dianne Hackborn254cb442010-01-27 19:23:59 -08001091 public long getMaximumTimeToLock(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001092 return getMaximumTimeToLock(admin, UserHandle.myUserId());
1093 }
1094
1095 /** @hide per-user version */
1096 public long getMaximumTimeToLock(ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001097 if (mService != null) {
1098 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001099 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001100 } catch (RemoteException e) {
1101 Log.w(TAG, "Failed talking with device policy service", e);
1102 }
1103 }
1104 return 0;
1105 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001106
Dianne Hackbornd6847842010-01-12 18:14:19 -08001107 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001108 * Make the device lock immediately, as if the lock screen timeout has
1109 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001110 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001111 * <p>The calling device admin must have requested
1112 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1113 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001114 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001115 public void lockNow() {
1116 if (mService != null) {
1117 try {
1118 mService.lockNow();
1119 } catch (RemoteException e) {
1120 Log.w(TAG, "Failed talking with device policy service", e);
1121 }
1122 }
1123 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001124
Dianne Hackbornd6847842010-01-12 18:14:19 -08001125 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001126 * Flag for {@link #wipeData(int)}: also erase the device's external
1127 * storage.
1128 */
1129 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1130
1131 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001132 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001133 * erasing all user data while next booting up. External storage such
Masanori Oginof535cb042012-02-15 19:25:50 +09001134 * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE}
1135 * is set.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001136 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001137 * <p>The calling device admin must have requested
1138 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1139 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001140 *
Masanori Oginof535cb042012-02-15 19:25:50 +09001141 * @param flags Bit mask of additional options: currently 0 and
1142 * {@link #WIPE_EXTERNAL_STORAGE} are supported.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001143 */
1144 public void wipeData(int flags) {
1145 if (mService != null) {
1146 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001147 mService.wipeData(flags, UserHandle.myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001148 } catch (RemoteException e) {
1149 Log.w(TAG, "Failed talking with device policy service", e);
1150 }
1151 }
1152 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001153
Dianne Hackbornd6847842010-01-12 18:14:19 -08001154 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001155 * Called by an application that is administering the device to set the
1156 * global proxy and exclusion list.
1157 * <p>
1158 * The calling device admin must have requested
1159 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1160 * this method; if it has not, a security exception will be thrown.
1161 * Only the first device admin can set the proxy. If a second admin attempts
1162 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1163 * proxy will be returned. If successful in setting the proxy, null will
1164 * be returned.
1165 * The method can be called repeatedly by the device admin alrady setting the
1166 * proxy to update the proxy and exclusion list.
1167 *
1168 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1169 * with.
1170 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1171 * Pass Proxy.NO_PROXY to reset the proxy.
1172 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001173 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1174 * of the device admin that sets thew proxy otherwise.
Andy Stadlerd2672722011-02-16 10:53:33 -08001175 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001176 */
1177 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1178 List<String> exclusionList ) {
1179 if (proxySpec == null) {
1180 throw new NullPointerException();
1181 }
1182 if (mService != null) {
1183 try {
1184 String hostSpec;
1185 String exclSpec;
1186 if (proxySpec.equals(Proxy.NO_PROXY)) {
1187 hostSpec = null;
1188 exclSpec = null;
1189 } else {
1190 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1191 throw new IllegalArgumentException();
1192 }
1193 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1194 String hostName = sa.getHostName();
1195 int port = sa.getPort();
1196 StringBuilder hostBuilder = new StringBuilder();
1197 hostSpec = hostBuilder.append(hostName)
1198 .append(":").append(Integer.toString(port)).toString();
1199 if (exclusionList == null) {
1200 exclSpec = "";
1201 } else {
1202 StringBuilder listBuilder = new StringBuilder();
1203 boolean firstDomain = true;
1204 for (String exclDomain : exclusionList) {
1205 if (!firstDomain) {
1206 listBuilder = listBuilder.append(",");
1207 } else {
1208 firstDomain = false;
1209 }
1210 listBuilder = listBuilder.append(exclDomain.trim());
1211 }
1212 exclSpec = listBuilder.toString();
1213 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001214 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1215 != android.net.Proxy.PROXY_VALID)
1216 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001217 }
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001218 return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001219 } catch (RemoteException e) {
1220 Log.w(TAG, "Failed talking with device policy service", e);
1221 }
1222 }
1223 return null;
1224 }
1225
1226 /**
1227 * Returns the component name setting the global proxy.
1228 * @return ComponentName object of the device admin that set the global proxy, or
1229 * null if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001230 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001231 */
1232 public ComponentName getGlobalProxyAdmin() {
1233 if (mService != null) {
1234 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001235 return mService.getGlobalProxyAdmin(UserHandle.myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001236 } catch (RemoteException e) {
1237 Log.w(TAG, "Failed talking with device policy service", e);
1238 }
1239 }
1240 return null;
1241 }
1242
1243 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001244 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001245 * indicating that encryption is not supported.
1246 */
1247 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1248
1249 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001250 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001251 * indicating that encryption is supported, but is not currently active.
1252 */
1253 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1254
1255 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001256 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001257 * indicating that encryption is not currently active, but is currently
1258 * being activated. This is only reported by devices that support
1259 * encryption of data and only when the storage is currently
1260 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1261 * to become encrypted will never return this value.
1262 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001263 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001264
1265 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001266 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001267 * indicating that encryption is active.
1268 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001269 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001270
1271 /**
1272 * Activity action: begin the process of encrypting data on the device. This activity should
1273 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1274 * After resuming from this activity, use {@link #getStorageEncryption}
1275 * to check encryption status. However, on some devices this activity may never return, as
1276 * it may trigger a reboot and in some cases a complete data wipe of the device.
1277 */
1278 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1279 public static final String ACTION_START_ENCRYPTION
1280 = "android.app.action.START_ENCRYPTION";
1281
1282 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07001283 * Widgets are enabled in keyguard
1284 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001285 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07001286
1287 /**
Jim Miller50e62182014-04-23 17:25:00 -07001288 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07001289 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001290 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
1291
1292 /**
1293 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
1294 */
1295 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
1296
1297 /**
Jim Miller50e62182014-04-23 17:25:00 -07001298 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1299 */
1300 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
1301
1302 /**
1303 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
1304 */
1305 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
1306
1307 /**
1308 * Ignore {@link TrustAgentService} state on secure keyguard screens
1309 * (e.g. PIN/Pattern/Password).
1310 */
1311 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
1312
1313 /**
Jim Miller35207742012-11-02 15:33:20 -07001314 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07001315 */
1316 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07001317
1318 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001319 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001320 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001321 *
1322 * <p>When multiple device administrators attempt to control device
1323 * encryption, the most secure, supported setting will always be
1324 * used. If any device administrator requests device encryption,
1325 * it will be enabled; Conversely, if a device administrator
1326 * attempts to disable device encryption while another
1327 * device administrator has enabled it, the call to disable will
1328 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1329 *
1330 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08001331 * written to other storage areas may or may not be encrypted, and this policy does not require
1332 * or control the encryption of any other storage areas.
1333 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
1334 * {@code true}, then the directory returned by
1335 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
1336 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001337 *
1338 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1339 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1340 * the encryption key may not be fully secured. For maximum security, the administrator should
1341 * also require (and check for) a pattern, PIN, or password.
1342 *
1343 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1344 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001345 * @return the new request status (for all active admins) - will be one of
1346 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1347 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1348 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001349 */
1350 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1351 if (mService != null) {
1352 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001353 return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001354 } catch (RemoteException e) {
1355 Log.w(TAG, "Failed talking with device policy service", e);
1356 }
1357 }
1358 return ENCRYPTION_STATUS_UNSUPPORTED;
1359 }
1360
1361 /**
1362 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001363 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001364 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001365 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1366 * this will return the requested encryption setting as an aggregate of all active
1367 * administrators.
1368 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001369 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001370 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001371 if (mService != null) {
1372 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001373 return mService.getStorageEncryption(admin, UserHandle.myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001374 } catch (RemoteException e) {
1375 Log.w(TAG, "Failed talking with device policy service", e);
1376 }
1377 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001378 return false;
1379 }
1380
1381 /**
1382 * Called by an application that is administering the device to
1383 * determine the current encryption status of the device.
1384 *
1385 * Depending on the returned status code, the caller may proceed in different
1386 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1387 * storage system does not support encryption. If the
1388 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1389 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1390 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1391 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1392 *
1393 * @return current status of encryption. The value will be one of
1394 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1395 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1396 */
1397 public int getStorageEncryptionStatus() {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001398 return getStorageEncryptionStatus(UserHandle.myUserId());
1399 }
1400
1401 /** @hide per-user version */
1402 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08001403 if (mService != null) {
1404 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001405 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08001406 } catch (RemoteException e) {
1407 Log.w(TAG, "Failed talking with device policy service", e);
1408 }
1409 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001410 return ENCRYPTION_STATUS_UNSUPPORTED;
1411 }
1412
1413 /**
Maggie Benthallda51e682013-08-08 22:35:44 -04001414 * Installs the given certificate as a User CA.
1415 *
1416 * @return false if the certBuffer cannot be parsed or installation is
1417 * interrupted, otherwise true
1418 * @hide
1419 */
1420 public boolean installCaCert(byte[] certBuffer) {
1421 if (mService != null) {
1422 try {
1423 return mService.installCaCert(certBuffer);
1424 } catch (RemoteException e) {
1425 Log.w(TAG, "Failed talking with device policy service", e);
1426 }
1427 }
1428 return false;
1429 }
1430
1431 /**
1432 * Uninstalls the given certificate from the list of User CAs, if present.
1433 *
1434 * @hide
1435 */
1436 public void uninstallCaCert(byte[] certBuffer) {
1437 if (mService != null) {
1438 try {
1439 mService.uninstallCaCert(certBuffer);
1440 } catch (RemoteException e) {
1441 Log.w(TAG, "Failed talking with device policy service", e);
1442 }
1443 }
1444 }
1445
1446 /**
1447 * Returns whether there are any user-installed CA certificates.
1448 *
1449 * @hide
1450 */
Maggie Benthall0469f412013-09-05 15:30:26 -04001451 public static boolean hasAnyCaCertsInstalled() {
Maggie Benthallda51e682013-08-08 22:35:44 -04001452 TrustedCertificateStore certStore = new TrustedCertificateStore();
1453 Set<String> aliases = certStore.userAliases();
1454 return aliases != null && !aliases.isEmpty();
1455 }
1456
1457 /**
1458 * Returns whether this certificate has been installed as a User CA.
1459 *
1460 * @hide
1461 */
1462 public boolean hasCaCertInstalled(byte[] certBuffer) {
1463 TrustedCertificateStore certStore = new TrustedCertificateStore();
1464 String alias;
1465 byte[] pemCert;
1466 try {
1467 CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
1468 X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
1469 new ByteArrayInputStream(certBuffer));
1470 return certStore.getCertificateAlias(cert) != null;
1471 } catch (CertificateException ce) {
1472 Log.w(TAG, "Could not parse certificate", ce);
1473 }
1474 return false;
1475 }
1476
1477 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07001478 * Called by an application that is administering the device to disable all cameras
1479 * on the device. After setting this, no applications will be able to access any cameras
1480 * on the device.
1481 *
1482 * <p>The calling device admin must have requested
1483 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
1484 * this method; if it has not, a security exception will be thrown.
1485 *
1486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1487 * @param disabled Whether or not the camera should be disabled.
1488 */
1489 public void setCameraDisabled(ComponentName admin, boolean disabled) {
1490 if (mService != null) {
1491 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001492 mService.setCameraDisabled(admin, disabled, UserHandle.myUserId());
Ben Komalo2447edd2011-05-09 16:05:33 -07001493 } catch (RemoteException e) {
1494 Log.w(TAG, "Failed talking with device policy service", e);
1495 }
1496 }
1497 }
1498
1499 /**
1500 * Determine whether or not the device's cameras have been disabled either by the current
1501 * admin, if specified, or all admins.
1502 * @param admin The name of the admin component to check, or null to check if any admins
1503 * have disabled the camera
1504 */
1505 public boolean getCameraDisabled(ComponentName admin) {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001506 return getCameraDisabled(admin, UserHandle.myUserId());
1507 }
1508
1509 /** @hide per-user version */
1510 public boolean getCameraDisabled(ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07001511 if (mService != null) {
1512 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001513 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07001514 } catch (RemoteException e) {
1515 Log.w(TAG, "Failed talking with device policy service", e);
1516 }
1517 }
1518 return false;
1519 }
1520
1521 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001522 * Called by an application that is administering the device to disable keyguard customizations,
1523 * such as widgets. After setting this, keyguard features will be disabled according to the
1524 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001525 *
1526 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07001527 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07001528 * this method; if it has not, a security exception will be thrown.
1529 *
1530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07001531 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
1532 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07001533 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
1534 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07001535 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001536 public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001537 if (mService != null) {
1538 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001539 mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
Jim Millerb8ec4702012-08-31 17:19:10 -07001540 } catch (RemoteException e) {
1541 Log.w(TAG, "Failed talking with device policy service", e);
1542 }
1543 }
1544 }
1545
1546 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07001547 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07001548 * admin, if specified, or all admins.
1549 * @param admin The name of the admin component to check, or null to check if any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07001550 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07001551 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
1552 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07001553 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001554 public int getKeyguardDisabledFeatures(ComponentName admin) {
1555 return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001556 }
1557
1558 /** @hide per-user version */
Jim Miller48b9b0d2012-09-19 23:16:50 -07001559 public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07001560 if (mService != null) {
1561 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07001562 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07001563 } catch (RemoteException e) {
1564 Log.w(TAG, "Failed talking with device policy service", e);
1565 }
1566 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07001567 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07001568 }
1569
1570 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001571 * @hide
1572 */
Jessica Hummel6d36b602014-04-04 12:42:17 +01001573 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001574 if (mService != null) {
1575 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01001576 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001577 } catch (RemoteException e) {
1578 Log.w(TAG, "Failed talking with device policy service", e);
1579 }
1580 }
1581 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001582
Dianne Hackbornd6847842010-01-12 18:14:19 -08001583 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01001584 * @hide
1585 */
1586 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
1587 setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId());
1588 }
1589
1590 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001591 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001592 * @hide
1593 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001594 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001595 ActivityInfo ai;
1596 try {
1597 ai = mContext.getPackageManager().getReceiverInfo(cn,
1598 PackageManager.GET_META_DATA);
1599 } catch (PackageManager.NameNotFoundException e) {
1600 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1601 return null;
1602 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001603
Dianne Hackbornd6847842010-01-12 18:14:19 -08001604 ResolveInfo ri = new ResolveInfo();
1605 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001606
Dianne Hackbornd6847842010-01-12 18:14:19 -08001607 try {
1608 return new DeviceAdminInfo(mContext, ri);
1609 } catch (XmlPullParserException e) {
1610 Log.w(TAG, "Unable to parse device policy " + cn, e);
1611 return null;
1612 } catch (IOException e) {
1613 Log.w(TAG, "Unable to parse device policy " + cn, e);
1614 return null;
1615 }
1616 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001617
Dianne Hackbornd6847842010-01-12 18:14:19 -08001618 /**
1619 * @hide
1620 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001621 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1622 if (mService != null) {
1623 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001624 mService.getRemoveWarning(admin, result, UserHandle.myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001625 } catch (RemoteException e) {
1626 Log.w(TAG, "Failed talking with device policy service", e);
1627 }
1628 }
1629 }
1630
1631 /**
1632 * @hide
1633 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001634 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001635 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001636 if (mService != null) {
1637 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001638 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001639 numbers, symbols, nonletter, 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 /**
1647 * @hide
1648 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001649 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001650 if (mService != null) {
1651 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001652 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001653 } catch (RemoteException e) {
1654 Log.w(TAG, "Failed talking with device policy service", e);
1655 }
1656 }
1657 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001658
Dianne Hackbornd6847842010-01-12 18:14:19 -08001659 /**
1660 * @hide
1661 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001662 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001663 if (mService != null) {
1664 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001665 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001666 } catch (RemoteException e) {
1667 Log.w(TAG, "Failed talking with device policy service", e);
1668 }
1669 }
1670 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07001671
1672 /**
1673 * @hide
1674 * Sets the given package as the device owner. The package must already be installed and there
1675 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1676 * method must be called before the device is provisioned.
1677 * @param packageName the package name of the application to be registered as the device owner.
1678 * @return whether the package was successfully registered as the device owner.
1679 * @throws IllegalArgumentException if the package name is null or invalid
1680 * @throws IllegalStateException if a device owner is already registered or the device has
1681 * already been provisioned.
1682 */
1683 public boolean setDeviceOwner(String packageName) throws IllegalArgumentException,
1684 IllegalStateException {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001685 return setDeviceOwner(packageName, null);
1686 }
1687
1688 /**
1689 * @hide
1690 * Sets the given package as the device owner. The package must already be installed and there
1691 * shouldn't be an existing device owner registered, for this call to succeed. Also, this
1692 * method must be called before the device is provisioned.
1693 * @param packageName the package name of the application to be registered as the device owner.
1694 * @param ownerName the human readable name of the institution that owns this device.
1695 * @return whether the package was successfully registered as the device owner.
1696 * @throws IllegalArgumentException if the package name is null or invalid
1697 * @throws IllegalStateException if a device owner is already registered or the device has
1698 * already been provisioned.
1699 */
1700 public boolean setDeviceOwner(String packageName, String ownerName)
1701 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001702 if (mService != null) {
1703 try {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001704 return mService.setDeviceOwner(packageName, ownerName);
Amith Yamasani71e6c692013-03-24 17:39:28 -07001705 } catch (RemoteException re) {
1706 Log.w(TAG, "Failed to set device owner");
1707 }
1708 }
1709 return false;
1710 }
1711
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001712
Amith Yamasani71e6c692013-03-24 17:39:28 -07001713 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001714 * Used to determine if a particular package has been registered as a Device Owner app.
1715 * A device owner app is a special device admin that cannot be deactivated by the user, once
1716 * activated as a device admin. It also cannot be uninstalled. To check if a particular
1717 * package is currently registered as the device owner app, pass in the package name from
1718 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
1719 * admin apps that want to check if they are also registered as the device owner app. The
1720 * exact mechanism by which a device admin app is registered as a device owner app is defined by
1721 * the setup process.
1722 * @param packageName the package name of the app, to compare with the registered device owner
1723 * app, if any.
1724 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07001725 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001726 public boolean isDeviceOwnerApp(String packageName) {
Amith Yamasani71e6c692013-03-24 17:39:28 -07001727 if (mService != null) {
1728 try {
1729 return mService.isDeviceOwner(packageName);
1730 } catch (RemoteException re) {
1731 Log.w(TAG, "Failed to check device owner");
1732 }
1733 }
1734 return false;
1735 }
1736
Amith Yamasani3b458ad2013-04-18 18:40:07 -07001737 /**
1738 * @hide
1739 * Redirect to isDeviceOwnerApp.
1740 */
1741 public boolean isDeviceOwner(String packageName) {
1742 return isDeviceOwnerApp(packageName);
1743 }
1744
Amith Yamasani71e6c692013-03-24 17:39:28 -07001745 /** @hide */
1746 public String getDeviceOwner() {
1747 if (mService != null) {
1748 try {
1749 return mService.getDeviceOwner();
1750 } catch (RemoteException re) {
1751 Log.w(TAG, "Failed to get device owner");
1752 }
1753 }
1754 return null;
1755 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04001756
1757 /** @hide */
1758 public String getDeviceOwnerName() {
1759 if (mService != null) {
1760 try {
1761 return mService.getDeviceOwnerName();
1762 } catch (RemoteException re) {
1763 Log.w(TAG, "Failed to get device owner");
1764 }
1765 }
1766 return null;
1767 }
Adam Connors776c5552014-01-09 10:42:56 +00001768
1769 /**
1770 * @hide
1771 * Sets the given package as the profile owner of the given user profile. The package must
1772 * already be installed and there shouldn't be an existing profile owner registered for this
1773 * user. Also, this method must be called before the user has been used for the first time.
1774 * @param packageName the package name of the application to be registered as profile owner.
1775 * @param ownerName the human readable name of the organisation associated with this DPM.
Adam Connors661ec472014-02-11 13:59:46 +00001776 * @param userHandle the userId to set the profile owner for.
Adam Connors776c5552014-01-09 10:42:56 +00001777 * @return whether the package was successfully registered as the profile owner.
1778 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
1779 * the user has already been set up.
1780 */
Adam Connors661ec472014-02-11 13:59:46 +00001781 public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
Adam Connors776c5552014-01-09 10:42:56 +00001782 throws IllegalArgumentException {
1783 if (mService != null) {
1784 try {
Adam Connors661ec472014-02-11 13:59:46 +00001785 return mService.setProfileOwner(packageName, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00001786 } catch (RemoteException re) {
1787 Log.w(TAG, "Failed to set profile owner", re);
1788 throw new IllegalArgumentException("Couldn't set profile owner.", re);
1789 }
1790 }
1791 return false;
1792 }
1793
1794 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001795 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
1796 * be used. Only the profile owner can call this.
1797 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01001798 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001799 *
1800 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1801 */
1802 public void setProfileEnabled(ComponentName admin) {
1803 if (mService != null) {
1804 try {
1805 mService.setProfileEnabled(admin);
1806 } catch (RemoteException e) {
1807 Log.w(TAG, "Failed talking with device policy service", e);
1808 }
1809 }
1810 }
1811
1812 /**
Adam Connors776c5552014-01-09 10:42:56 +00001813 * Used to determine if a particular package is registered as the Profile Owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01001814 * current user. A profile owner is a special device admin that has additional privileges
Adam Connors776c5552014-01-09 10:42:56 +00001815 * within the managed profile.
1816 *
1817 * @param packageName The package name of the app to compare with the registered profile owner.
1818 * @return Whether or not the package is registered as the profile owner.
1819 */
1820 public boolean isProfileOwnerApp(String packageName) {
1821 if (mService != null) {
1822 try {
1823 String profileOwnerPackage = mService.getProfileOwner(
1824 Process.myUserHandle().getIdentifier());
1825 return profileOwnerPackage != null && profileOwnerPackage.equals(packageName);
1826 } catch (RemoteException re) {
1827 Log.w(TAG, "Failed to check profile owner");
1828 }
1829 }
1830 return false;
1831 }
1832
1833 /**
1834 * @hide
1835 * @return the packageName of the owner of the given user profile or null if no profile
1836 * owner has been set for that user.
1837 * @throws IllegalArgumentException if the userId is invalid.
1838 */
1839 public String getProfileOwner() throws IllegalArgumentException {
1840 if (mService != null) {
1841 try {
1842 return mService.getProfileOwner(Process.myUserHandle().getIdentifier());
1843 } catch (RemoteException re) {
1844 Log.w(TAG, "Failed to get profile owner");
1845 throw new IllegalArgumentException(
1846 "Requested profile owner for invalid userId", re);
1847 }
1848 }
1849 return null;
1850 }
1851
1852 /**
1853 * @hide
1854 * @return the human readable name of the organisation associated with this DPM or null if
1855 * one is not set.
1856 * @throws IllegalArgumentException if the userId is invalid.
1857 */
1858 public String getProfileOwnerName() throws IllegalArgumentException {
1859 if (mService != null) {
1860 try {
1861 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
1862 } catch (RemoteException re) {
1863 Log.w(TAG, "Failed to get profile owner");
1864 throw new IllegalArgumentException(
1865 "Requested profile owner for invalid userId", re);
1866 }
1867 }
1868 return null;
1869 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001870
1871 /**
1872 * Called by a profile owner or device owner to add a default intent handler activity for
1873 * intents that match a certain intent filter. This activity will remain the default intent
1874 * handler even if the set of potential event handlers for the intent filter changes and if
1875 * the intent preferences are reset.
1876 *
1877 * <p>The default disambiguation mechanism takes over if the activity is not installed
1878 * (anymore). When the activity is (re)installed, it is automatically reset as default
1879 * intent handler for the filter.
1880 *
1881 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
1882 * security exception will be thrown.
1883 *
1884 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1885 * @param filter The IntentFilter for which a default handler is added.
1886 * @param activity The Activity that is added as default intent handler.
1887 */
1888 public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter,
1889 ComponentName activity) {
1890 if (mService != null) {
1891 try {
1892 mService.addPersistentPreferredActivity(admin, filter, activity);
1893 } catch (RemoteException e) {
1894 Log.w(TAG, "Failed talking with device policy service", e);
1895 }
1896 }
1897 }
1898
1899 /**
1900 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00001901 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00001902 *
1903 * <p>The calling device admin must be a profile owner. If it is not, a security
1904 * exception will be thrown.
1905 *
1906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1907 * @param packageName The name of the package for which preferences are removed.
1908 */
1909 public void clearPackagePersistentPreferredActivities(ComponentName admin,
1910 String packageName) {
1911 if (mService != null) {
1912 try {
1913 mService.clearPackagePersistentPreferredActivities(admin, packageName);
1914 } catch (RemoteException e) {
1915 Log.w(TAG, "Failed talking with device policy service", e);
1916 }
1917 }
1918 }
Robin Lee66e5d962014-04-09 16:44:21 +01001919
1920 /**
1921 * Called by a profile or device owner to set the application restrictions for a given target
1922 * application running in the managed profile.
1923 *
1924 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be
1925 * {@link Boolean}, {@link String}, or {@link String}[]. The recommended format for key strings
1926 * is "com.example.packagename/example-setting" to avoid naming conflicts with library
1927 * components such as {@link android.webkit.WebView}.
1928 *
1929 * <p>The application restrictions are only made visible to the target application and the
1930 * profile or device owner.
1931 *
1932 * <p>The calling device admin must be a profile or device owner; if it is not, a security
1933 * exception will be thrown.
1934 *
1935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1936 * @param packageName The name of the package to update restricted settings for.
1937 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
1938 * set of active restrictions.
1939 */
1940 public void setApplicationRestrictions(ComponentName admin, String packageName,
1941 Bundle settings) {
1942 if (mService != null) {
1943 try {
1944 mService.setApplicationRestrictions(admin, packageName, settings);
1945 } catch (RemoteException e) {
1946 Log.w(TAG, "Failed talking with device policy service", e);
1947 }
1948 }
1949 }
1950
1951 /**
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001952 * Called by a profile owner to forward intents sent from the managed profile to the owner, or
1953 * from the owner to the managed profile.
1954 * If an intent matches this intent filter, then activities belonging to the other user can
1955 * respond to this intent.
1956 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1957 * @param filter if an intent matches this IntentFilter, then it can be forwarded.
1958 */
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001959 public void addForwardingIntentFilter(ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001960 if (mService != null) {
1961 try {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001962 mService.addForwardingIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001963 } catch (RemoteException e) {
1964 Log.w(TAG, "Failed talking with device policy service", e);
1965 }
1966 }
1967 }
1968
1969 /**
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001970 * Called by a profile owner to remove the forwarding intent filters from the current user
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001971 * and from the owner.
1972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1973 */
1974 public void clearForwardingIntentFilters(ComponentName admin) {
1975 if (mService != null) {
1976 try {
1977 mService.clearForwardingIntentFilters(admin);
1978 } catch (RemoteException e) {
1979 Log.w(TAG, "Failed talking with device policy service", e);
1980 }
1981 }
1982 }
1983
1984 /**
Robin Lee66e5d962014-04-09 16:44:21 +01001985 * Called by a profile or device owner to get the application restrictions for a given target
1986 * application running in the managed profile.
1987 *
1988 * <p>The calling device admin must be a profile or device owner; if it is not, a security
1989 * exception will be thrown.
1990 *
1991 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1992 * @param packageName The name of the package to fetch restricted settings of.
1993 * @return {@link Bundle} of settings corresponding to what was set last time
1994 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
1995 * if no restrictions have been set.
1996 */
1997 public Bundle getApplicationRestrictions(ComponentName admin, String packageName) {
1998 if (mService != null) {
1999 try {
2000 return mService.getApplicationRestrictions(admin, packageName);
2001 } catch (RemoteException e) {
2002 Log.w(TAG, "Failed talking with device policy service", e);
2003 }
2004 }
2005 return null;
2006 }
Amith Yamasanibe465322014-04-24 13:45:17 -07002007
2008 /**
2009 * Called by a profile or device owner to set a user restriction specified
2010 * by the key.
2011 * <p>
2012 * The calling device admin must be a profile or device owner; if it is not,
2013 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002014 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002015 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2016 * with.
2017 * @param key The key of the restriction. See the constants in
2018 * {@link android.os.UserManager} for the list of keys.
2019 */
2020 public void addUserRestriction(ComponentName admin, String key) {
2021 if (mService != null) {
2022 try {
2023 mService.setUserRestriction(admin, key, true);
2024 } catch (RemoteException e) {
2025 Log.w(TAG, "Failed talking with device policy service", e);
2026 }
2027 }
2028 }
2029
2030 /**
2031 * Called by a profile or device owner to clear a user restriction specified
2032 * by the key.
2033 * <p>
2034 * The calling device admin must be a profile or device owner; if it is not,
2035 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07002036 *
Amith Yamasanibe465322014-04-24 13:45:17 -07002037 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2038 * with.
2039 * @param key The key of the restriction. See the constants in
2040 * {@link android.os.UserManager} for the list of keys.
2041 */
2042 public void clearUserRestriction(ComponentName admin, String key) {
2043 if (mService != null) {
2044 try {
2045 mService.setUserRestriction(admin, key, false);
2046 } catch (RemoteException e) {
2047 Log.w(TAG, "Failed talking with device policy service", e);
2048 }
2049 }
2050 }
Adam Connors010cfd42014-04-16 12:48:13 +01002051
2052 /**
2053 * Called by profile or device owner to re-enable a system app that was disabled by default
2054 * when the managed profile was created. This should only be called from a profile or device
2055 * owner running within a managed profile.
2056 *
2057 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2058 * @param packageName The package to be re-enabled in the current profile.
2059 */
2060 public void enableSystemApp(ComponentName admin, String packageName) {
2061 if (mService != null) {
2062 try {
2063 mService.enableSystemApp(admin, packageName);
2064 } catch (RemoteException e) {
2065 Log.w(TAG, "Failed to install package: " + packageName);
2066 }
2067 }
2068 }
2069
2070 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002071 * Called by a profile owner to disable account management for a specific type of account.
2072 *
2073 * <p>The calling device admin must be a profile owner. If it is not, a
2074 * security exception will be thrown.
2075 *
2076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2077 * @param accountType For which account management is disabled or enabled.
2078 * @param disabled The boolean indicating that account management will be disabled (true) or
2079 * enabled (false).
2080 */
2081 public void setAccountManagementDisabled(ComponentName admin, String accountType,
2082 boolean disabled) {
2083 if (mService != null) {
2084 try {
2085 mService.setAccountManagementDisabled(admin, accountType, disabled);
2086 } catch (RemoteException e) {
2087 Log.w(TAG, "Failed talking with device policy service", e);
2088 }
2089 }
2090 }
2091
2092 /**
Adam Connors010cfd42014-04-16 12:48:13 +01002093 * Called by profile or device owner to re-enable system apps by intent that were disabled
2094 * by default when the managed profile was created. This should only be called from a profile
2095 * or device owner running within a managed profile.
2096 *
2097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2098 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
2099 * intent will be re-enabled in the current profile.
Amith Yamasani007bbc02014-05-07 10:23:44 -07002100 * @return int The number of activities that matched the intent and were installed.
Adam Connors010cfd42014-04-16 12:48:13 +01002101 */
2102 public int enableSystemApp(ComponentName admin, Intent intent) {
2103 if (mService != null) {
2104 try {
2105 return mService.enableSystemAppWithIntent(admin, intent);
2106 } catch (RemoteException e) {
2107 Log.w(TAG, "Failed to install packages matching filter: " + intent);
2108 }
2109 }
2110 return 0;
2111 }
Sander Alewijnse5c02db62014-05-07 10:46:57 +01002112
2113 /**
2114 * Gets the array of accounts for which account management is disabled by the profile owner.
2115 *
2116 * <p> Account management can be disabled/enabled by calling
2117 * {@link #setAccountManagementDisabled}.
2118 *
2119 * @return a list of account types for which account management has been disabled.
2120 *
2121 * @see #setAccountManagementDisabled
2122 */
2123 public String[] getAccountTypesWithManagementDisabled() {
2124 if (mService != null) {
2125 try {
2126 return mService.getAccountTypesWithManagementDisabled();
2127 } catch (RemoteException e) {
2128 Log.w(TAG, "Failed talking with device policy service", e);
2129 }
2130 }
2131
2132 return null;
2133 }
justinzhang511e0d82014-03-24 16:09:24 -04002134
2135 /**
2136 * Sets which components may enter lock task mode.
2137 *
2138 * This function can only be called by the device owner or the profile owner.
2139 * @param components The list of components allowed to enter lock task mode
2140 */
2141 public void setLockTaskComponents(ComponentName[] components) throws SecurityException {
2142 if (mService != null) {
2143 try {
2144 mService.setLockTaskComponents(components);
2145 } catch (RemoteException e) {
2146 Log.w(TAG, "Failed talking with device policy service", e);
2147 }
2148 }
2149 }
2150
2151 /**
2152 * This function returns the list of components allowed to start the lock task mode.
2153 * @hide
2154 */
2155 public ComponentName[] getLockTaskComponents() {
2156 if (mService != null) {
2157 try {
2158 return mService.getLockTaskComponents();
2159 } catch (RemoteException e) {
2160 Log.w(TAG, "Failed talking with device policy service", e);
2161 }
2162 }
2163 return null;
2164 }
2165
2166 /**
2167 * This function lets the caller know whether the given component is allowed to start the
2168 * lock task mode.
2169 * @param component The component to check
2170 */
2171 public boolean isLockTaskPermitted(ComponentName component) {
2172 if (mService != null) {
2173 try {
2174 return mService.isLockTaskPermitted(component);
2175 } catch (RemoteException e) {
2176 Log.w(TAG, "Failed talking with device policy service", e);
2177 }
2178 }
2179 return false;
2180 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08002181}