blob: 2b7e4275f06143f1e170c7f547c38ef841cd2917 [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 /**
684 * Retrieve the current password history length for all admins
685 * or a particular one.
686 * @param admin The name of the admin component to check, or null to aggregate
687 * all admins.
688 * @return The length of the password history
689 */
690 public int getPasswordHistoryLength(ComponentName admin) {
691 if (mService != null) {
692 try {
693 return mService.getPasswordHistoryLength(admin);
694 } catch (RemoteException e) {
695 Log.w(TAG, "Failed talking with device policy service", e);
696 }
697 }
698 return 0;
699 }
700
Dianne Hackbornd6847842010-01-12 18:14:19 -0800701 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800702 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800703 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800704 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800705 * @return Returns the maximum length that the user can enter.
706 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800707 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800708 // Kind-of arbitrary.
709 return 16;
710 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700711
Dianne Hackborn254cb442010-01-27 19:23:59 -0800712 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800713 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800714 * to meet the policy requirements (quality, minimum length) that have been
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800715 * requested.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700716 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800717 * <p>The calling device admin must have requested
718 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
719 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700720 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800721 * @return Returns true if the password meets the current requirements,
722 * else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800723 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800724 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800725 if (mService != null) {
726 try {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800727 return mService.isActivePasswordSufficient();
Dianne Hackbornd6847842010-01-12 18:14:19 -0800728 } catch (RemoteException e) {
729 Log.w(TAG, "Failed talking with device policy service", e);
730 }
731 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800732 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800733 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700734
Dianne Hackbornd6847842010-01-12 18:14:19 -0800735 /**
736 * Retrieve the number of times the user has failed at entering a
737 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700738 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800739 * <p>The calling device admin must have requested
740 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
741 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800742 */
743 public int getCurrentFailedPasswordAttempts() {
744 if (mService != null) {
745 try {
746 return mService.getCurrentFailedPasswordAttempts();
747 } catch (RemoteException e) {
748 Log.w(TAG, "Failed talking with device policy service", e);
749 }
750 }
751 return -1;
752 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800753
754 /**
Andrew Stadler88209d12010-02-08 22:59:36 -0800755 * Setting this to a value greater than zero enables a built-in policy
756 * that will perform a device wipe after too many incorrect
757 * device-unlock passwords have been entered. This built-in policy combines
758 * watching for failed passwords and wiping the device, and requires
759 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800760 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700761 *
Andrew Stadler88209d12010-02-08 22:59:36 -0800762 * <p>To implement any other policy (e.g. wiping data for a particular
763 * application only, erasing or revoking credentials, or reporting the
764 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800765 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -0800766 * instead. Do not use this API, because if the maximum count is reached,
767 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700768 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800769 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800770 * @param num The number of failed password attempts at which point the
771 * device will wipe its data.
772 */
773 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
774 if (mService != null) {
775 try {
776 mService.setMaximumFailedPasswordsForWipe(admin, num);
777 } catch (RemoteException e) {
778 Log.w(TAG, "Failed talking with device policy service", e);
779 }
780 }
781 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700782
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800783 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800784 * Retrieve the current maximum number of login attempts that are allowed
785 * before the device wipes itself, for all admins
786 * or a particular one.
787 * @param admin The name of the admin component to check, or null to aggregate
788 * all admins.
789 */
790 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
791 if (mService != null) {
792 try {
793 return mService.getMaximumFailedPasswordsForWipe(admin);
794 } catch (RemoteException e) {
795 Log.w(TAG, "Failed talking with device policy service", e);
796 }
797 }
798 return 0;
799 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700800
Dianne Hackborn254cb442010-01-27 19:23:59 -0800801 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800802 * Flag for {@link #resetPassword}: don't allow other admins to change
803 * the password again until the user has entered it.
804 */
805 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700806
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800807 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800808 * Force a new device unlock password (the password needed to access the
809 * entire device, not for individual accounts) on the user. This takes
810 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800811 * The given password must be sufficient for the
812 * current password quality and length constraints as returned by
813 * {@link #getPasswordQuality(ComponentName)} and
814 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
815 * these constraints, then it will be rejected and false returned. Note
816 * that the password may be a stronger quality (containing alphanumeric
817 * characters when the requested quality is only numeric), in which case
818 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700819 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800820 * <p>The calling device admin must have requested
821 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
822 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700823 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800824 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800825 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800826 * @return Returns true if the password was applied, or false if it is
827 * not acceptable for the current constraints.
828 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800829 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800830 if (mService != null) {
831 try {
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800832 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800833 } catch (RemoteException e) {
834 Log.w(TAG, "Failed talking with device policy service", e);
835 }
836 }
837 return false;
838 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700839
Dianne Hackbornd6847842010-01-12 18:14:19 -0800840 /**
841 * Called by an application that is administering the device to set the
842 * maximum time for user activity until the device will lock. This limits
843 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700844 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800845 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -0800846 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800847 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700848 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800850 * @param timeMs The new desired maximum time to lock in milliseconds.
851 * A value of 0 means there is no restriction.
852 */
853 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
854 if (mService != null) {
855 try {
856 mService.setMaximumTimeToLock(admin, timeMs);
857 } catch (RemoteException e) {
858 Log.w(TAG, "Failed talking with device policy service", e);
859 }
860 }
861 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700862
Dianne Hackbornd6847842010-01-12 18:14:19 -0800863 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800864 * Retrieve the current maximum time to unlock for all admins
865 * or a particular one.
866 * @param admin The name of the admin component to check, or null to aggregate
867 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800868 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800869 public long getMaximumTimeToLock(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800870 if (mService != null) {
871 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800872 return mService.getMaximumTimeToLock(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800873 } catch (RemoteException e) {
874 Log.w(TAG, "Failed talking with device policy service", e);
875 }
876 }
877 return 0;
878 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700879
Dianne Hackbornd6847842010-01-12 18:14:19 -0800880 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800881 * Make the device lock immediately, as if the lock screen timeout has
882 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700883 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800884 * <p>The calling device admin must have requested
885 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
886 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800887 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800888 public void lockNow() {
889 if (mService != null) {
890 try {
891 mService.lockNow();
892 } catch (RemoteException e) {
893 Log.w(TAG, "Failed talking with device policy service", e);
894 }
895 }
896 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700897
Dianne Hackbornd6847842010-01-12 18:14:19 -0800898 /**
899 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800900 * erasing all user data while next booting up. External storage such
901 * as SD cards will not be erased.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700902 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800903 * <p>The calling device admin must have requested
904 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
905 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700906 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800907 * @param flags Bit mask of additional options: currently must be 0.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800908 */
909 public void wipeData(int flags) {
910 if (mService != null) {
911 try {
912 mService.wipeData(flags);
913 } catch (RemoteException e) {
914 Log.w(TAG, "Failed talking with device policy service", e);
915 }
916 }
917 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700918
Dianne Hackbornd6847842010-01-12 18:14:19 -0800919 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -0700920 * Called by an application that is administering the device to set the
921 * global proxy and exclusion list.
922 * <p>
923 * The calling device admin must have requested
924 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
925 * this method; if it has not, a security exception will be thrown.
926 * Only the first device admin can set the proxy. If a second admin attempts
927 * to set the proxy, the {@link ComponentName} of the admin originally setting the
928 * proxy will be returned. If successful in setting the proxy, null will
929 * be returned.
930 * The method can be called repeatedly by the device admin alrady setting the
931 * proxy to update the proxy and exclusion list.
932 *
933 * @param admin Which {@link DeviceAdminReceiver} this request is associated
934 * with.
935 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
936 * Pass Proxy.NO_PROXY to reset the proxy.
937 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -0700938 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
939 * of the device admin that sets thew proxy otherwise.
940 */
941 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
942 List<String> exclusionList ) {
943 if (proxySpec == null) {
944 throw new NullPointerException();
945 }
946 if (mService != null) {
947 try {
948 String hostSpec;
949 String exclSpec;
950 if (proxySpec.equals(Proxy.NO_PROXY)) {
951 hostSpec = null;
952 exclSpec = null;
953 } else {
954 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
955 throw new IllegalArgumentException();
956 }
957 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
958 String hostName = sa.getHostName();
959 int port = sa.getPort();
960 StringBuilder hostBuilder = new StringBuilder();
961 hostSpec = hostBuilder.append(hostName)
962 .append(":").append(Integer.toString(port)).toString();
963 if (exclusionList == null) {
964 exclSpec = "";
965 } else {
966 StringBuilder listBuilder = new StringBuilder();
967 boolean firstDomain = true;
968 for (String exclDomain : exclusionList) {
969 if (!firstDomain) {
970 listBuilder = listBuilder.append(",");
971 } else {
972 firstDomain = false;
973 }
974 listBuilder = listBuilder.append(exclDomain.trim());
975 }
976 exclSpec = listBuilder.toString();
977 }
978 android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec);
979 }
980 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
981 } catch (RemoteException e) {
982 Log.w(TAG, "Failed talking with device policy service", e);
983 }
984 }
985 return null;
986 }
987
988 /**
989 * Returns the component name setting the global proxy.
990 * @return ComponentName object of the device admin that set the global proxy, or
991 * null if no admin has set the proxy.
992 */
993 public ComponentName getGlobalProxyAdmin() {
994 if (mService != null) {
995 try {
996 return mService.getGlobalProxyAdmin();
997 } catch (RemoteException e) {
998 Log.w(TAG, "Failed talking with device policy service", e);
999 }
1000 }
1001 return null;
1002 }
1003
1004 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001005 * @hide
1006 */
1007 public void setActiveAdmin(ComponentName policyReceiver) {
1008 if (mService != null) {
1009 try {
1010 mService.setActiveAdmin(policyReceiver);
1011 } catch (RemoteException e) {
1012 Log.w(TAG, "Failed talking with device policy service", e);
1013 }
1014 }
1015 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001016
Dianne Hackbornd6847842010-01-12 18:14:19 -08001017 /**
1018 * @hide
1019 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001020 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001021 ActivityInfo ai;
1022 try {
1023 ai = mContext.getPackageManager().getReceiverInfo(cn,
1024 PackageManager.GET_META_DATA);
1025 } catch (PackageManager.NameNotFoundException e) {
1026 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1027 return null;
1028 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001029
Dianne Hackbornd6847842010-01-12 18:14:19 -08001030 ResolveInfo ri = new ResolveInfo();
1031 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001032
Dianne Hackbornd6847842010-01-12 18:14:19 -08001033 try {
1034 return new DeviceAdminInfo(mContext, ri);
1035 } catch (XmlPullParserException e) {
1036 Log.w(TAG, "Unable to parse device policy " + cn, e);
1037 return null;
1038 } catch (IOException e) {
1039 Log.w(TAG, "Unable to parse device policy " + cn, e);
1040 return null;
1041 }
1042 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001043
Dianne Hackbornd6847842010-01-12 18:14:19 -08001044 /**
1045 * @hide
1046 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001047 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1048 if (mService != null) {
1049 try {
1050 mService.getRemoveWarning(admin, result);
1051 } catch (RemoteException e) {
1052 Log.w(TAG, "Failed talking with device policy service", e);
1053 }
1054 }
1055 }
1056
1057 /**
1058 * @hide
1059 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001060 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001061 int lowercase, int numbers, int symbols, int nonletter) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001062 if (mService != null) {
1063 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001064 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001065 numbers, symbols, nonletter);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001066 } catch (RemoteException e) {
1067 Log.w(TAG, "Failed talking with device policy service", e);
1068 }
1069 }
1070 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001071
Dianne Hackbornd6847842010-01-12 18:14:19 -08001072 /**
1073 * @hide
1074 */
1075 public void reportFailedPasswordAttempt() {
1076 if (mService != null) {
1077 try {
1078 mService.reportFailedPasswordAttempt();
1079 } 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 /**
1086 * @hide
1087 */
1088 public void reportSuccessfulPasswordAttempt() {
1089 if (mService != null) {
1090 try {
1091 mService.reportSuccessfulPasswordAttempt();
1092 } catch (RemoteException e) {
1093 Log.w(TAG, "Failed talking with device policy service", e);
1094 }
1095 }
1096 }
Oscar Montemayor69238c62010-08-03 10:51:06 -07001097
Dianne Hackbornd6847842010-01-12 18:14:19 -08001098}