blob: a18fdacca618114aee8d060ac0f17b7530e2d0ce [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
19import org.xmlpull.v1.XmlPullParserException;
20
21import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
23import android.content.ComponentName;
24import android.content.Context;
25import android.content.pm.ActivityInfo;
26import android.content.pm.PackageManager;
27import android.content.pm.ResolveInfo;
28import android.os.Handler;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080029import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080030import android.os.RemoteException;
31import android.os.ServiceManager;
32import android.util.Log;
33
34import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070035import java.net.InetSocketAddress;
36import java.net.Proxy;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080037import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080038
39/**
40 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080041 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080042 * has currently enabled.
43 */
44public class DevicePolicyManager {
45 private static String TAG = "DevicePolicyManager";
46 private static boolean DEBUG = false;
47 private static boolean localLOGV = DEBUG || android.util.Config.LOGV;
48
49 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080050 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070051
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080052 private final Handler mHandler;
Dianne Hackbornd6847842010-01-12 18:14:19 -080053
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080054 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080055 mContext = context;
56 mHandler = handler;
57 mService = IDevicePolicyManager.Stub.asInterface(
58 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
59 }
60
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080061 /** @hide */
62 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080063 DevicePolicyManager me = new DevicePolicyManager(context, handler);
64 return me.mService != null ? me : null;
65 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070066
Dianne Hackbornd6847842010-01-12 18:14:19 -080067 /**
68 * Activity action: ask the user to add a new device administrator to the system.
69 * The desired policy is the ComponentName of the policy in the
70 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
71 * bring the user through adding the device administrator to the system (or
72 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -070073 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080074 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
75 * field to provide the user with additional explanation (in addition
76 * to your component's description) about what is being added.
Dianne Hackbornd6847842010-01-12 18:14:19 -080077 */
78 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
79 public static final String ACTION_ADD_DEVICE_ADMIN
80 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -070081
Dianne Hackbornd6847842010-01-12 18:14:19 -080082 /**
Jim Miller284b62e2010-06-08 14:27:42 -070083 * Activity action: send when any policy admin changes a policy.
84 * This is generally used to find out when a new policy is in effect.
85 *
86 * @hide
87 */
88 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
89 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
90
91 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -080092 * The ComponentName of the administrator component.
93 *
94 * @see #ACTION_ADD_DEVICE_ADMIN
95 */
96 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -070097
Dianne Hackbornd6847842010-01-12 18:14:19 -080098 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080099 * An optional CharSequence providing additional explanation for why the
100 * admin is being added.
101 *
102 * @see #ACTION_ADD_DEVICE_ADMIN
103 */
104 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700105
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800106 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700107 * Activity action: have the user enter a new password. This activity should
108 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
109 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
110 * enter a new password that meets the current requirements. You can use
111 * {@link #isActivePasswordSufficient()} to determine whether you need to
112 * have the user select a new password in order to meet the current
113 * constraints. Upon being resumed from this activity, you can check the new
114 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800115 */
116 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
117 public static final String ACTION_SET_NEW_PASSWORD
118 = "android.app.action.SET_NEW_PASSWORD";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700119
Dianne Hackbornd6847842010-01-12 18:14:19 -0800120 /**
121 * Return true if the given administrator component is currently
122 * active (enabled) in the system.
123 */
124 public boolean isAdminActive(ComponentName who) {
125 if (mService != null) {
126 try {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800127 return mService.isAdminActive(who);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800128 } catch (RemoteException e) {
129 Log.w(TAG, "Failed talking with device policy service", e);
130 }
131 }
132 return false;
133 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700134
Dianne Hackbornd6847842010-01-12 18:14:19 -0800135 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800136 * Return a list of all currently active device administrator's component
137 * names. Note that if there are no administrators than null may be
138 * returned.
139 */
140 public List<ComponentName> getActiveAdmins() {
141 if (mService != null) {
142 try {
143 return mService.getActiveAdmins();
144 } catch (RemoteException e) {
145 Log.w(TAG, "Failed talking with device policy service", e);
146 }
147 }
148 return null;
149 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700150
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800151 /**
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800152 * @hide
153 */
154 public boolean packageHasActiveAdmins(String packageName) {
155 if (mService != null) {
156 try {
157 return mService.packageHasActiveAdmins(packageName);
158 } catch (RemoteException e) {
159 Log.w(TAG, "Failed talking with device policy service", e);
160 }
161 }
162 return false;
163 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700164
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800165 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800166 * Remove a current administration component. This can only be called
167 * by the application that owns the administration component; if you
168 * try to remove someone else's component, a security exception will be
169 * thrown.
170 */
171 public void removeActiveAdmin(ComponentName who) {
172 if (mService != null) {
173 try {
174 mService.removeActiveAdmin(who);
175 } catch (RemoteException e) {
176 Log.w(TAG, "Failed talking with device policy service", e);
177 }
178 }
179 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700180
Dianne Hackbornd6847842010-01-12 18:14:19 -0800181 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800182 * Constant for {@link #setPasswordQuality}: the policy has no requirements
183 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800184 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800185 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800186 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700187
Dianne Hackbornd6847842010-01-12 18:14:19 -0800188 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800189 * Constant for {@link #setPasswordQuality}: the policy requires some kind
190 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800191 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800192 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800193 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700194
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800195 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800196 * Constant for {@link #setPasswordQuality}: the user must have entered a
197 * password containing at least numeric characters. Note that quality
198 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800199 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800200 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700201
Dianne Hackbornd6847842010-01-12 18:14:19 -0800202 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800203 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700204 * password containing at least alphabetic (or other symbol) characters.
205 * Note that quality constants are ordered so that higher values are more
206 * restrictive.
207 */
208 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700209
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700210 /**
211 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800212 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700213 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800214 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800215 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700216 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700217
Dianne Hackbornd6847842010-01-12 18:14:19 -0800218 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700219 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700220 * password containing at least a letter, a numerical digit and a special
221 * symbol, by default. With this password quality, passwords can be
222 * restricted to contain various sets of characters, like at least an
223 * uppercase letter, etc. These are specified using various methods,
224 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
225 * that quality constants are ordered so that higher values are more
226 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700227 */
228 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
229
230 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800231 * Called by an application that is administering the device to set the
232 * password restrictions it is imposing. After setting this, the user
233 * will not be able to enter a new password that is not at least as
234 * restrictive as what has been set. Note that the current password
235 * will remain until the user has set a new one, so the change does not
236 * take place immediately. To prompt the user for a new password, use
237 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700238 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800239 * <p>Quality constants are ordered so that higher values are more restrictive;
240 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800241 * the user's preference, and any other considerations) is the one that
242 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700243 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800244 * <p>The calling device admin must have requested
245 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
246 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700247 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800248 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800249 * @param quality The new desired quality. One of
250 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700251 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700252 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800253 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800254 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800255 if (mService != null) {
256 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800257 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800258 } catch (RemoteException e) {
259 Log.w(TAG, "Failed talking with device policy service", e);
260 }
261 }
262 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700263
Dianne Hackbornd6847842010-01-12 18:14:19 -0800264 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800265 * Retrieve the current minimum password quality for all admins
Dianne Hackborn254cb442010-01-27 19:23:59 -0800266 * or a particular one.
267 * @param admin The name of the admin component to check, or null to aggregate
268 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800269 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800270 public int getPasswordQuality(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800271 if (mService != null) {
272 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800273 return mService.getPasswordQuality(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800274 } catch (RemoteException e) {
275 Log.w(TAG, "Failed talking with device policy service", e);
276 }
277 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800278 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800279 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700280
Dianne Hackbornd6847842010-01-12 18:14:19 -0800281 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800282 * Called by an application that is administering the device to set the
283 * minimum allowed password length. After setting this, the user
284 * will not be able to enter a new password that is not at least as
285 * restrictive as what has been set. Note that the current password
286 * will remain until the user has set a new one, so the change does not
287 * take place immediately. To prompt the user for a new password, use
288 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
289 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700290 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
291 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800292 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700293 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800294 * <p>The calling device admin must have requested
295 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
296 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700297 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800298 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800299 * @param length The new desired minimum password length. A value of 0
300 * means there is no restriction.
301 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800302 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800303 if (mService != null) {
304 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800305 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800306 } catch (RemoteException e) {
307 Log.w(TAG, "Failed talking with device policy service", e);
308 }
309 }
310 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700311
Dianne Hackbornd6847842010-01-12 18:14:19 -0800312 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800313 * Retrieve the current minimum password length for all admins
314 * or a particular one.
315 * @param admin The name of the admin component to check, or null to aggregate
316 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800317 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800318 public int getPasswordMinimumLength(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800319 if (mService != null) {
320 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800321 return mService.getPasswordMinimumLength(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800322 } catch (RemoteException e) {
323 Log.w(TAG, "Failed talking with device policy service", e);
324 }
325 }
326 return 0;
327 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700328
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700329 /**
330 * Called by an application that is administering the device to set the
331 * minimum number of upper case letters required in the password. After
332 * setting this, the user will not be able to enter a new password that is
333 * not at least as restrictive as what has been set. Note that the current
334 * password will remain until the user has set a new one, so the change does
335 * not take place immediately. To prompt the user for a new password, use
336 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
337 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700338 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
339 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700340 * <p>
341 * 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.
344 *
345 * @param admin Which {@link DeviceAdminReceiver} this request is associated
346 * with.
347 * @param length The new desired minimum number of upper case letters
348 * required in the password. A value of 0 means there is no
349 * restriction.
350 */
351 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
352 if (mService != null) {
353 try {
354 mService.setPasswordMinimumUpperCase(admin, length);
355 } catch (RemoteException e) {
356 Log.w(TAG, "Failed talking with device policy service", e);
357 }
358 }
359 }
360
361 /**
362 * Retrieve the current number of upper case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700363 * password for all admins or a particular one. This is the same value as
364 * set by {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
365 * and only applies when the password quality is
366 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700367 *
368 * @param admin The name of the admin component to check, or null to
369 * aggregate all admins.
370 * @return The minimum number of upper case letters required in the
371 * password.
372 */
373 public int getPasswordMinimumUpperCase(ComponentName admin) {
374 if (mService != null) {
375 try {
376 return mService.getPasswordMinimumUpperCase(admin);
377 } catch (RemoteException e) {
378 Log.w(TAG, "Failed talking with device policy service", e);
379 }
380 }
381 return 0;
382 }
383
384 /**
385 * Called by an application that is administering the device to set the
386 * minimum number of lower case letters required in the password. After
387 * setting this, the user will not be able to enter a new password that is
388 * not at least as restrictive as what has been set. Note that the current
389 * password will remain until the user has set a new one, so the change does
390 * not take place immediately. To prompt the user for a new password, use
391 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
392 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700393 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
394 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700395 * <p>
396 * 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.
399 *
400 * @param admin Which {@link DeviceAdminReceiver} this request is associated
401 * with.
402 * @param length The new desired minimum number of lower case letters
403 * required in the password. A value of 0 means there is no
404 * restriction.
405 */
406 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
407 if (mService != null) {
408 try {
409 mService.setPasswordMinimumLowerCase(admin, length);
410 } catch (RemoteException e) {
411 Log.w(TAG, "Failed talking with device policy service", e);
412 }
413 }
414 }
415
416 /**
417 * Retrieve the current number of lower case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700418 * password for all admins or a particular one. This is the same value as
419 * set by {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
420 * and only applies when the password quality is
421 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700422 *
423 * @param admin The name of the admin component to check, or null to
424 * aggregate all admins.
425 * @return The minimum number of lower case letters required in the
426 * password.
427 */
428 public int getPasswordMinimumLowerCase(ComponentName admin) {
429 if (mService != null) {
430 try {
431 return mService.getPasswordMinimumLowerCase(admin);
432 } catch (RemoteException e) {
433 Log.w(TAG, "Failed talking with device policy service", e);
434 }
435 }
436 return 0;
437 }
438
439 /**
440 * Called by an application that is administering the device to set the
441 * minimum number of letters required in the password. After setting this,
442 * the user will not be able to enter a new password that is not at least as
443 * restrictive as what has been set. Note that the current password will
444 * remain until the user has set a new one, so the change does not take
445 * place immediately. To prompt the user for a new password, use
446 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
447 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700448 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
449 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700450 * <p>
451 * The calling device admin must have requested
452 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
453 * this method; if it has not, a security exception will be thrown.
454 *
455 * @param admin Which {@link DeviceAdminReceiver} this request is associated
456 * with.
457 * @param length The new desired minimum number of letters required in the
458 * password. A value of 0 means there is no restriction.
459 */
460 public void setPasswordMinimumLetters(ComponentName admin, int length) {
461 if (mService != null) {
462 try {
463 mService.setPasswordMinimumLetters(admin, length);
464 } catch (RemoteException e) {
465 Log.w(TAG, "Failed talking with device policy service", e);
466 }
467 }
468 }
469
470 /**
471 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700472 * admins or a particular one. This is the same value as
473 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
474 * and only applies when the password quality is
475 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700476 *
477 * @param admin The name of the admin component to check, or null to
478 * aggregate all admins.
479 * @return The minimum number of letters required in the password.
480 */
481 public int getPasswordMinimumLetters(ComponentName admin) {
482 if (mService != null) {
483 try {
484 return mService.getPasswordMinimumLetters(admin);
485 } catch (RemoteException e) {
486 Log.w(TAG, "Failed talking with device policy service", e);
487 }
488 }
489 return 0;
490 }
491
492 /**
493 * Called by an application that is administering the device to set the
494 * minimum number of numerical digits required in the password. After
495 * setting this, the user will not be able to enter a new password that is
496 * not at least as restrictive as what has been set. Note that the current
497 * password will remain until the user has set a new one, so the change does
498 * not take place immediately. To prompt the user for a new password, use
499 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
500 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700501 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
502 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700503 * <p>
504 * The calling device admin must have requested
505 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
506 * this method; if it has not, a security exception will be thrown.
507 *
508 * @param admin Which {@link DeviceAdminReceiver} this request is associated
509 * with.
510 * @param length The new desired minimum number of numerical digits required
511 * in the password. A value of 0 means there is no restriction.
512 */
513 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
514 if (mService != null) {
515 try {
516 mService.setPasswordMinimumNumeric(admin, length);
517 } catch (RemoteException e) {
518 Log.w(TAG, "Failed talking with device policy service", e);
519 }
520 }
521 }
522
523 /**
524 * Retrieve the current number of numerical digits required in the password
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700525 * for all admins or a particular one. This is the same value as
526 * set by {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
527 * and only applies when the password quality is
528 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700529 *
530 * @param admin The name of the admin component to check, or null to
531 * aggregate all admins.
532 * @return The minimum number of numerical digits required in the password.
533 */
534 public int getPasswordMinimumNumeric(ComponentName admin) {
535 if (mService != null) {
536 try {
537 return mService.getPasswordMinimumNumeric(admin);
538 } catch (RemoteException e) {
539 Log.w(TAG, "Failed talking with device policy service", e);
540 }
541 }
542 return 0;
543 }
544
545 /**
546 * Called by an application that is administering the device to set the
547 * minimum number of symbols required in the password. After setting this,
548 * the user will not be able to enter a new password that is not at least as
549 * restrictive as what has been set. Note that the current password will
550 * remain until the user has set a new one, so the change does not take
551 * place immediately. To prompt the user for a new password, use
552 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
553 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700554 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
555 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700556 * <p>
557 * The calling device admin must have requested
558 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
559 * this method; if it has not, a security exception will be thrown.
560 *
561 * @param admin Which {@link DeviceAdminReceiver} this request is associated
562 * with.
563 * @param length The new desired minimum number of symbols required in the
564 * password. A value of 0 means there is no restriction.
565 */
566 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
567 if (mService != null) {
568 try {
569 mService.setPasswordMinimumSymbols(admin, length);
570 } catch (RemoteException e) {
571 Log.w(TAG, "Failed talking with device policy service", e);
572 }
573 }
574 }
575
576 /**
577 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700578 * admins or a particular one. This is the same value as
579 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
580 * and only applies when the password quality is
581 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700582 *
583 * @param admin The name of the admin component to check, or null to
584 * aggregate all admins.
585 * @return The minimum number of symbols required in the password.
586 */
587 public int getPasswordMinimumSymbols(ComponentName admin) {
588 if (mService != null) {
589 try {
590 return mService.getPasswordMinimumSymbols(admin);
591 } catch (RemoteException e) {
592 Log.w(TAG, "Failed talking with device policy service", e);
593 }
594 }
595 return 0;
596 }
597
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700598 /**
599 * Called by an application that is administering the device to set the
600 * minimum number of non-letter characters (numerical digits or symbols)
601 * required in the password. After setting this, the user will not be able
602 * to enter a new password that is not at least as restrictive as what has
603 * been set. Note that the current password will remain until the user has
604 * set a new one, so the change does not take place immediately. To prompt
605 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
606 * setting this value. This constraint is only imposed if the administrator
607 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
608 * {@link #setPasswordQuality}. The default value is 0.
609 * <p>
610 * The calling device admin must have requested
611 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
612 * this method; if it has not, a security exception will be thrown.
613 *
614 * @param admin Which {@link DeviceAdminReceiver} this request is associated
615 * with.
616 * @param length The new desired minimum number of letters required in the
617 * password. A value of 0 means there is no restriction.
618 */
619 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
620 if (mService != null) {
621 try {
622 mService.setPasswordMinimumNonLetter(admin, length);
623 } catch (RemoteException e) {
624 Log.w(TAG, "Failed talking with device policy service", e);
625 }
626 }
627 }
628
629 /**
630 * Retrieve the current number of non-letter characters required in the
631 * password for all admins or a particular one. This is the same value as
632 * set by {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
633 * and only applies when the password quality is
634 * {@link #PASSWORD_QUALITY_COMPLEX}.
635 *
636 * @param admin The name of the admin component to check, or null to
637 * aggregate all admins.
638 * @return The minimum number of letters required in the password.
639 */
640 public int getPasswordMinimumNonLetter(ComponentName admin) {
641 if (mService != null) {
642 try {
643 return mService.getPasswordMinimumNonLetter(admin);
644 } catch (RemoteException e) {
645 Log.w(TAG, "Failed talking with device policy service", e);
646 }
647 }
648 return 0;
649 }
650
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700651 /**
652 * Called by an application that is administering the device to set the length
653 * of the password history. After setting this, the user will not be able to
654 * enter a new password that is the same as any password in the history. Note
655 * that the current password will remain until the user has set a new one, so
656 * the change does not take place immediately. To prompt the user for a new
657 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
658 * This constraint is only imposed if the administrator has also requested
659 * either {@link #PASSWORD_QUALITY_NUMERIC},
660 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
661 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
662 *
663 * <p>
664 * The calling device admin must have requested
665 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
666 * method; if it has not, a security exception will be thrown.
667 *
668 * @param admin Which {@link DeviceAdminReceiver} this request is associated
669 * with.
670 * @param length The new desired length of password history. A value of 0
671 * means there is no restriction.
672 */
673 public void setPasswordHistoryLength(ComponentName admin, int length) {
674 if (mService != null) {
675 try {
676 mService.setPasswordHistoryLength(admin, length);
677 } catch (RemoteException e) {
678 Log.w(TAG, "Failed talking with device policy service", e);
679 }
680 }
681 }
682
683 /**
Jim Millera4e28d12010-11-08 16:15:47 -0800684 * Called by a device admin to set the password expiration timeout. Calling this method
685 * will restart the countdown for password expiration for the given admin, as will changing
686 * the device password (for all admins).
687 *
688 * <p>The provided timeout is the time delta in ms and will be added to the current time.
689 * For example, to have the password expire 5 days from now, timeout would be
690 * 5 * 86400 * 1000 = 432000000 ms for timeout.
691 *
692 * <p>To disable password expiration, a value of 0 may be used for timeout.
693 *
694 * <p>Timeout must be at least 1 day or IllegalArgumentException will be thrown.
695 *
696 * <p>The calling device admin must have requested
697 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
698 * method; if it has not, a security exception will be thrown.
699 *
700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
701 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
702 * means there is no restriction (unlimited).
703 */
704 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
705 if (mService != null) {
706 try {
707 mService.setPasswordExpirationTimeout(admin, timeout);
708 } catch (RemoteException e) {
709 Log.w(TAG, "Failed talking with device policy service", e);
710 }
711 }
712 }
713
714 /**
715 * Get the current password expiration timeout for the given admin or the aggregate
716 * of all admins if admin is null.
717 *
718 * @param admin The name of the admin component to check, or null to aggregate all admins.
719 * @return The timeout for the given admin or the minimum of all timeouts
720 */
721 public long getPasswordExpirationTimeout(ComponentName admin) {
722 if (mService != null) {
723 try {
724 return mService.getPasswordExpirationTimeout(admin);
725 } catch (RemoteException e) {
726 Log.w(TAG, "Failed talking with device policy service", e);
727 }
728 }
729 return 0;
730 }
731
732 /**
733 * Get the current password expiration time for the given admin or an aggregate of
734 * all admins if admin is null.
735 *
736 * @param admin The name of the admin component to check, or null to aggregate all admins.
737 * @return The password expiration time, in ms.
738 */
739 public long getPasswordExpiration(ComponentName admin) {
740 if (mService != null) {
741 try {
742 return mService.getPasswordExpiration(admin);
743 } catch (RemoteException e) {
744 Log.w(TAG, "Failed talking with device policy service", e);
745 }
746 }
747 return 0;
748 }
749
750 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700751 * Retrieve the current password history length for all admins
752 * or a particular one.
753 * @param admin The name of the admin component to check, or null to aggregate
754 * all admins.
755 * @return The length of the password history
756 */
757 public int getPasswordHistoryLength(ComponentName admin) {
758 if (mService != null) {
759 try {
760 return mService.getPasswordHistoryLength(admin);
761 } catch (RemoteException e) {
762 Log.w(TAG, "Failed talking with device policy service", e);
763 }
764 }
765 return 0;
766 }
767
Dianne Hackbornd6847842010-01-12 18:14:19 -0800768 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800769 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800770 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800771 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800772 * @return Returns the maximum length that the user can enter.
773 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800774 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800775 // Kind-of arbitrary.
776 return 16;
777 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700778
Dianne Hackborn254cb442010-01-27 19:23:59 -0800779 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800780 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800781 * to meet the policy requirements (quality, minimum length) that have been
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800782 * requested.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700783 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800784 * <p>The calling device admin must have requested
785 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
786 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700787 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800788 * @return Returns true if the password meets the current requirements,
789 * else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800790 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800791 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800792 if (mService != null) {
793 try {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800794 return mService.isActivePasswordSufficient();
Dianne Hackbornd6847842010-01-12 18:14:19 -0800795 } catch (RemoteException e) {
796 Log.w(TAG, "Failed talking with device policy service", e);
797 }
798 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800799 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800800 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700801
Dianne Hackbornd6847842010-01-12 18:14:19 -0800802 /**
803 * Retrieve the number of times the user has failed at entering a
804 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700805 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800806 * <p>The calling device admin must have requested
807 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
808 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800809 */
810 public int getCurrentFailedPasswordAttempts() {
811 if (mService != null) {
812 try {
813 return mService.getCurrentFailedPasswordAttempts();
814 } catch (RemoteException e) {
815 Log.w(TAG, "Failed talking with device policy service", e);
816 }
817 }
818 return -1;
819 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800820
821 /**
Andrew Stadler88209d12010-02-08 22:59:36 -0800822 * Setting this to a value greater than zero enables a built-in policy
823 * that will perform a device wipe after too many incorrect
824 * device-unlock passwords have been entered. This built-in policy combines
825 * watching for failed passwords and wiping the device, and requires
826 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800827 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700828 *
Andrew Stadler88209d12010-02-08 22:59:36 -0800829 * <p>To implement any other policy (e.g. wiping data for a particular
830 * application only, erasing or revoking credentials, or reporting the
831 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800832 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -0800833 * instead. Do not use this API, because if the maximum count is reached,
834 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700835 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800836 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800837 * @param num The number of failed password attempts at which point the
838 * device will wipe its data.
839 */
840 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
841 if (mService != null) {
842 try {
843 mService.setMaximumFailedPasswordsForWipe(admin, num);
844 } catch (RemoteException e) {
845 Log.w(TAG, "Failed talking with device policy service", e);
846 }
847 }
848 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700849
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800850 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800851 * Retrieve the current maximum number of login attempts that are allowed
852 * before the device wipes itself, for all admins
853 * or a particular one.
854 * @param admin The name of the admin component to check, or null to aggregate
855 * all admins.
856 */
857 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
858 if (mService != null) {
859 try {
860 return mService.getMaximumFailedPasswordsForWipe(admin);
861 } catch (RemoteException e) {
862 Log.w(TAG, "Failed talking with device policy service", e);
863 }
864 }
865 return 0;
866 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700867
Dianne Hackborn254cb442010-01-27 19:23:59 -0800868 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800869 * Flag for {@link #resetPassword}: don't allow other admins to change
870 * the password again until the user has entered it.
871 */
872 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700873
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800874 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800875 * Force a new device unlock password (the password needed to access the
876 * entire device, not for individual accounts) on the user. This takes
877 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800878 * The given password must be sufficient for the
879 * current password quality and length constraints as returned by
880 * {@link #getPasswordQuality(ComponentName)} and
881 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
882 * these constraints, then it will be rejected and false returned. Note
883 * that the password may be a stronger quality (containing alphanumeric
884 * characters when the requested quality is only numeric), in which case
885 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700886 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800887 * <p>The calling device admin must have requested
888 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
889 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700890 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800891 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800892 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800893 * @return Returns true if the password was applied, or false if it is
894 * not acceptable for the current constraints.
895 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800896 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800897 if (mService != null) {
898 try {
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800899 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800900 } catch (RemoteException e) {
901 Log.w(TAG, "Failed talking with device policy service", e);
902 }
903 }
904 return false;
905 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700906
Dianne Hackbornd6847842010-01-12 18:14:19 -0800907 /**
908 * Called by an application that is administering the device to set the
909 * maximum time for user activity until the device will lock. This limits
910 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700911 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800912 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -0800913 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800914 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700915 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800916 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800917 * @param timeMs The new desired maximum time to lock in milliseconds.
918 * A value of 0 means there is no restriction.
919 */
920 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
921 if (mService != null) {
922 try {
923 mService.setMaximumTimeToLock(admin, timeMs);
924 } catch (RemoteException e) {
925 Log.w(TAG, "Failed talking with device policy service", e);
926 }
927 }
928 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700929
Dianne Hackbornd6847842010-01-12 18:14:19 -0800930 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800931 * Retrieve the current maximum time to unlock for all admins
932 * or a particular one.
933 * @param admin The name of the admin component to check, or null to aggregate
934 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800935 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800936 public long getMaximumTimeToLock(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800937 if (mService != null) {
938 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800939 return mService.getMaximumTimeToLock(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800940 } catch (RemoteException e) {
941 Log.w(TAG, "Failed talking with device policy service", e);
942 }
943 }
944 return 0;
945 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700946
Dianne Hackbornd6847842010-01-12 18:14:19 -0800947 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800948 * Make the device lock immediately, as if the lock screen timeout has
949 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700950 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800951 * <p>The calling device admin must have requested
952 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
953 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800954 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800955 public void lockNow() {
956 if (mService != null) {
957 try {
958 mService.lockNow();
959 } catch (RemoteException e) {
960 Log.w(TAG, "Failed talking with device policy service", e);
961 }
962 }
963 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700964
Dianne Hackbornd6847842010-01-12 18:14:19 -0800965 /**
Dianne Hackborn42499172010-10-15 18:45:07 -0700966 * Flag for {@link #wipeData(int)}: also erase the device's external
967 * storage.
968 */
969 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
970
971 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800972 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800973 * erasing all user data while next booting up. External storage such
974 * as SD cards will not be erased.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700975 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800976 * <p>The calling device admin must have requested
977 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
978 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700979 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800980 * @param flags Bit mask of additional options: currently must be 0.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800981 */
982 public void wipeData(int flags) {
983 if (mService != null) {
984 try {
985 mService.wipeData(flags);
986 } catch (RemoteException e) {
987 Log.w(TAG, "Failed talking with device policy service", e);
988 }
989 }
990 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700991
Dianne Hackbornd6847842010-01-12 18:14:19 -0800992 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -0700993 * Called by an application that is administering the device to set the
994 * global proxy and exclusion list.
995 * <p>
996 * The calling device admin must have requested
997 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
998 * this method; if it has not, a security exception will be thrown.
999 * Only the first device admin can set the proxy. If a second admin attempts
1000 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1001 * proxy will be returned. If successful in setting the proxy, null will
1002 * be returned.
1003 * The method can be called repeatedly by the device admin alrady setting the
1004 * proxy to update the proxy and exclusion list.
1005 *
1006 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1007 * with.
1008 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1009 * Pass Proxy.NO_PROXY to reset the proxy.
1010 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001011 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1012 * of the device admin that sets thew proxy otherwise.
1013 */
1014 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1015 List<String> exclusionList ) {
1016 if (proxySpec == null) {
1017 throw new NullPointerException();
1018 }
1019 if (mService != null) {
1020 try {
1021 String hostSpec;
1022 String exclSpec;
1023 if (proxySpec.equals(Proxy.NO_PROXY)) {
1024 hostSpec = null;
1025 exclSpec = null;
1026 } else {
1027 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1028 throw new IllegalArgumentException();
1029 }
1030 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1031 String hostName = sa.getHostName();
1032 int port = sa.getPort();
1033 StringBuilder hostBuilder = new StringBuilder();
1034 hostSpec = hostBuilder.append(hostName)
1035 .append(":").append(Integer.toString(port)).toString();
1036 if (exclusionList == null) {
1037 exclSpec = "";
1038 } else {
1039 StringBuilder listBuilder = new StringBuilder();
1040 boolean firstDomain = true;
1041 for (String exclDomain : exclusionList) {
1042 if (!firstDomain) {
1043 listBuilder = listBuilder.append(",");
1044 } else {
1045 firstDomain = false;
1046 }
1047 listBuilder = listBuilder.append(exclDomain.trim());
1048 }
1049 exclSpec = listBuilder.toString();
1050 }
1051 android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec);
1052 }
1053 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
1054 } catch (RemoteException e) {
1055 Log.w(TAG, "Failed talking with device policy service", e);
1056 }
1057 }
1058 return null;
1059 }
1060
1061 /**
1062 * Returns the component name setting the global proxy.
1063 * @return ComponentName object of the device admin that set the global proxy, or
1064 * null if no admin has set the proxy.
1065 */
1066 public ComponentName getGlobalProxyAdmin() {
1067 if (mService != null) {
1068 try {
1069 return mService.getGlobalProxyAdmin();
1070 } catch (RemoteException e) {
1071 Log.w(TAG, "Failed talking with device policy service", e);
1072 }
1073 }
1074 return null;
1075 }
1076
1077 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001078 * @hide
1079 */
1080 public void setActiveAdmin(ComponentName policyReceiver) {
1081 if (mService != null) {
1082 try {
1083 mService.setActiveAdmin(policyReceiver);
1084 } catch (RemoteException e) {
1085 Log.w(TAG, "Failed talking with device policy service", e);
1086 }
1087 }
1088 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001089
Dianne Hackbornd6847842010-01-12 18:14:19 -08001090 /**
1091 * @hide
1092 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001093 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001094 ActivityInfo ai;
1095 try {
1096 ai = mContext.getPackageManager().getReceiverInfo(cn,
1097 PackageManager.GET_META_DATA);
1098 } catch (PackageManager.NameNotFoundException e) {
1099 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1100 return null;
1101 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001102
Dianne Hackbornd6847842010-01-12 18:14:19 -08001103 ResolveInfo ri = new ResolveInfo();
1104 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001105
Dianne Hackbornd6847842010-01-12 18:14:19 -08001106 try {
1107 return new DeviceAdminInfo(mContext, ri);
1108 } catch (XmlPullParserException e) {
1109 Log.w(TAG, "Unable to parse device policy " + cn, e);
1110 return null;
1111 } catch (IOException e) {
1112 Log.w(TAG, "Unable to parse device policy " + cn, e);
1113 return null;
1114 }
1115 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001116
Dianne Hackbornd6847842010-01-12 18:14:19 -08001117 /**
1118 * @hide
1119 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001120 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1121 if (mService != null) {
1122 try {
1123 mService.getRemoveWarning(admin, result);
1124 } catch (RemoteException e) {
1125 Log.w(TAG, "Failed talking with device policy service", e);
1126 }
1127 }
1128 }
1129
1130 /**
1131 * @hide
1132 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001133 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001134 int lowercase, int numbers, int symbols, int nonletter) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001135 if (mService != null) {
1136 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001137 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001138 numbers, symbols, nonletter);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001139 } catch (RemoteException e) {
1140 Log.w(TAG, "Failed talking with device policy service", e);
1141 }
1142 }
1143 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001144
Dianne Hackbornd6847842010-01-12 18:14:19 -08001145 /**
1146 * @hide
1147 */
1148 public void reportFailedPasswordAttempt() {
1149 if (mService != null) {
1150 try {
1151 mService.reportFailedPasswordAttempt();
1152 } catch (RemoteException e) {
1153 Log.w(TAG, "Failed talking with device policy service", e);
1154 }
1155 }
1156 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001157
Dianne Hackbornd6847842010-01-12 18:14:19 -08001158 /**
1159 * @hide
1160 */
1161 public void reportSuccessfulPasswordAttempt() {
1162 if (mService != null) {
1163 try {
1164 mService.reportSuccessfulPasswordAttempt();
1165 } catch (RemoteException e) {
1166 Log.w(TAG, "Failed talking with device policy service", e);
1167 }
1168 }
1169 }
Oscar Montemayor69238c62010-08-03 10:51:06 -07001170
Dianne Hackbornd6847842010-01-12 18:14:19 -08001171}