blob: 3066f5ca47c9c9764adeec7953f3c0fa617638f1 [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;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080035import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080036
37/**
38 * Public interface for managing policies enforced on a device. Most clients
Dianne Hackbornef6b22f2010-02-16 20:38:49 -080039 * of this class must have published a {@link DeviceAdminReceiver} that the user
Dianne Hackbornd6847842010-01-12 18:14:19 -080040 * has currently enabled.
41 */
42public class DevicePolicyManager {
43 private static String TAG = "DevicePolicyManager";
44 private static boolean DEBUG = false;
45 private static boolean localLOGV = DEBUG || android.util.Config.LOGV;
46
47 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080048 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070049
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080050 private final Handler mHandler;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080052 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080053 mContext = context;
54 mHandler = handler;
55 mService = IDevicePolicyManager.Stub.asInterface(
56 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
57 }
58
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080059 /** @hide */
60 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080061 DevicePolicyManager me = new DevicePolicyManager(context, handler);
62 return me.mService != null ? me : null;
63 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070064
Dianne Hackbornd6847842010-01-12 18:14:19 -080065 /**
66 * Activity action: ask the user to add a new device administrator to the system.
67 * The desired policy is the ComponentName of the policy in the
68 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
69 * bring the user through adding the device administrator to the system (or
70 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -070071 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080072 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
73 * field to provide the user with additional explanation (in addition
74 * to your component's description) about what is being added.
Dianne Hackbornd6847842010-01-12 18:14:19 -080075 */
76 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
77 public static final String ACTION_ADD_DEVICE_ADMIN
78 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -070079
Dianne Hackbornd6847842010-01-12 18:14:19 -080080 /**
Jim Miller284b62e2010-06-08 14:27:42 -070081 * Activity action: send when any policy admin changes a policy.
82 * This is generally used to find out when a new policy is in effect.
83 *
84 * @hide
85 */
86 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
87 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
88
89 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 * The ComponentName of the administrator component.
91 *
92 * @see #ACTION_ADD_DEVICE_ADMIN
93 */
94 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -070095
Dianne Hackbornd6847842010-01-12 18:14:19 -080096 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080097 * An optional CharSequence providing additional explanation for why the
98 * admin is being added.
99 *
100 * @see #ACTION_ADD_DEVICE_ADMIN
101 */
102 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700103
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800104 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700105 * Activity action: have the user enter a new password. This activity should
106 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
107 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
108 * enter a new password that meets the current requirements. You can use
109 * {@link #isActivePasswordSufficient()} to determine whether you need to
110 * have the user select a new password in order to meet the current
111 * constraints. Upon being resumed from this activity, you can check the new
112 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800113 */
114 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
115 public static final String ACTION_SET_NEW_PASSWORD
116 = "android.app.action.SET_NEW_PASSWORD";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700117
Dianne Hackbornd6847842010-01-12 18:14:19 -0800118 /**
119 * Return true if the given administrator component is currently
120 * active (enabled) in the system.
121 */
122 public boolean isAdminActive(ComponentName who) {
123 if (mService != null) {
124 try {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800125 return mService.isAdminActive(who);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800126 } catch (RemoteException e) {
127 Log.w(TAG, "Failed talking with device policy service", e);
128 }
129 }
130 return false;
131 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700132
Dianne Hackbornd6847842010-01-12 18:14:19 -0800133 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800134 * Return a list of all currently active device administrator's component
135 * names. Note that if there are no administrators than null may be
136 * returned.
137 */
138 public List<ComponentName> getActiveAdmins() {
139 if (mService != null) {
140 try {
141 return mService.getActiveAdmins();
142 } catch (RemoteException e) {
143 Log.w(TAG, "Failed talking with device policy service", e);
144 }
145 }
146 return null;
147 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700148
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800149 /**
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800150 * @hide
151 */
152 public boolean packageHasActiveAdmins(String packageName) {
153 if (mService != null) {
154 try {
155 return mService.packageHasActiveAdmins(packageName);
156 } catch (RemoteException e) {
157 Log.w(TAG, "Failed talking with device policy service", e);
158 }
159 }
160 return false;
161 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700162
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800163 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800164 * Remove a current administration component. This can only be called
165 * by the application that owns the administration component; if you
166 * try to remove someone else's component, a security exception will be
167 * thrown.
168 */
169 public void removeActiveAdmin(ComponentName who) {
170 if (mService != null) {
171 try {
172 mService.removeActiveAdmin(who);
173 } catch (RemoteException e) {
174 Log.w(TAG, "Failed talking with device policy service", e);
175 }
176 }
177 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700178
Dianne Hackbornd6847842010-01-12 18:14:19 -0800179 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800180 * Constant for {@link #setPasswordQuality}: the policy has no requirements
181 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800182 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800183 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800184 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700185
Dianne Hackbornd6847842010-01-12 18:14:19 -0800186 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800187 * Constant for {@link #setPasswordQuality}: the policy requires some kind
188 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800189 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800190 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800191 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700192
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800193 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800194 * Constant for {@link #setPasswordQuality}: the user must have entered a
195 * password containing at least numeric characters. Note that quality
196 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800197 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800198 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700199
Dianne Hackbornd6847842010-01-12 18:14:19 -0800200 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800201 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700202 * password containing at least alphabetic (or other symbol) characters.
203 * Note that quality constants are ordered so that higher values are more
204 * restrictive.
205 */
206 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700207
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700208 /**
209 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800210 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700211 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800212 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800213 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700214 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700215
Dianne Hackbornd6847842010-01-12 18:14:19 -0800216 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700217 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700218 * password containing at least a letter, a numerical digit and a special
219 * symbol, by default. With this password quality, passwords can be
220 * restricted to contain various sets of characters, like at least an
221 * uppercase letter, etc. These are specified using various methods,
222 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
223 * that quality constants are ordered so that higher values are more
224 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700225 */
226 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
227
228 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800229 * Called by an application that is administering the device to set the
230 * password restrictions it is imposing. After setting this, the user
231 * will not be able to enter a new password that is not at least as
232 * restrictive as what has been set. Note that the current password
233 * will remain until the user has set a new one, so the change does not
234 * take place immediately. To prompt the user for a new password, use
235 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700236 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800237 * <p>Quality constants are ordered so that higher values are more restrictive;
238 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800239 * the user's preference, and any other considerations) is the one that
240 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700241 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800242 * <p>The calling device admin must have requested
243 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
244 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700245 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800246 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800247 * @param quality The new desired quality. One of
248 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700249 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700250 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800251 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800252 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800253 if (mService != null) {
254 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800255 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800256 } catch (RemoteException e) {
257 Log.w(TAG, "Failed talking with device policy service", e);
258 }
259 }
260 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700261
Dianne Hackbornd6847842010-01-12 18:14:19 -0800262 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800263 * Retrieve the current minimum password quality for all admins
Dianne Hackborn254cb442010-01-27 19:23:59 -0800264 * or a particular one.
265 * @param admin The name of the admin component to check, or null to aggregate
266 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800267 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800268 public int getPasswordQuality(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800269 if (mService != null) {
270 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800271 return mService.getPasswordQuality(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800272 } catch (RemoteException e) {
273 Log.w(TAG, "Failed talking with device policy service", e);
274 }
275 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800276 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800277 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700278
Dianne Hackbornd6847842010-01-12 18:14:19 -0800279 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800280 * Called by an application that is administering the device to set the
281 * minimum allowed password length. After setting this, the user
282 * will not be able to enter a new password that is not at least as
283 * restrictive as what has been set. Note that the current password
284 * will remain until the user has set a new one, so the change does not
285 * take place immediately. To prompt the user for a new password, use
286 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
287 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700288 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
289 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800290 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700291 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800292 * <p>The calling device admin must have requested
293 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
294 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700295 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800296 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800297 * @param length The new desired minimum password length. A value of 0
298 * means there is no restriction.
299 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800300 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800301 if (mService != null) {
302 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800303 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800304 } catch (RemoteException e) {
305 Log.w(TAG, "Failed talking with device policy service", e);
306 }
307 }
308 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700309
Dianne Hackbornd6847842010-01-12 18:14:19 -0800310 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800311 * Retrieve the current minimum password length for all admins
312 * or a particular one.
313 * @param admin The name of the admin component to check, or null to aggregate
314 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800315 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800316 public int getPasswordMinimumLength(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800317 if (mService != null) {
318 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800319 return mService.getPasswordMinimumLength(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800320 } catch (RemoteException e) {
321 Log.w(TAG, "Failed talking with device policy service", e);
322 }
323 }
324 return 0;
325 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700326
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700327 /**
328 * Called by an application that is administering the device to set the
329 * minimum number of upper case letters required in the password. After
330 * setting this, the user will not be able to enter a new password that is
331 * not at least as restrictive as what has been set. Note that the current
332 * password will remain until the user has set a new one, so the change does
333 * not take place immediately. To prompt the user for a new password, use
334 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
335 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700336 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
337 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700338 * <p>
339 * The calling device admin must have requested
340 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
341 * this method; if it has not, a security exception will be thrown.
342 *
343 * @param admin Which {@link DeviceAdminReceiver} this request is associated
344 * with.
345 * @param length The new desired minimum number of upper case letters
346 * required in the password. A value of 0 means there is no
347 * restriction.
348 */
349 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
350 if (mService != null) {
351 try {
352 mService.setPasswordMinimumUpperCase(admin, length);
353 } catch (RemoteException e) {
354 Log.w(TAG, "Failed talking with device policy service", e);
355 }
356 }
357 }
358
359 /**
360 * Retrieve the current number of upper case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700361 * password for all admins or a particular one. This is the same value as
362 * set by {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
363 * and only applies when the password quality is
364 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700365 *
366 * @param admin The name of the admin component to check, or null to
367 * aggregate all admins.
368 * @return The minimum number of upper case letters required in the
369 * password.
370 */
371 public int getPasswordMinimumUpperCase(ComponentName admin) {
372 if (mService != null) {
373 try {
374 return mService.getPasswordMinimumUpperCase(admin);
375 } catch (RemoteException e) {
376 Log.w(TAG, "Failed talking with device policy service", e);
377 }
378 }
379 return 0;
380 }
381
382 /**
383 * Called by an application that is administering the device to set the
384 * minimum number of lower case letters required in the password. After
385 * setting this, the user will not be able to enter a new password that is
386 * not at least as restrictive as what has been set. Note that the current
387 * password will remain until the user has set a new one, so the change does
388 * not take place immediately. To prompt the user for a new password, use
389 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
390 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700391 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
392 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700393 * <p>
394 * The calling device admin must have requested
395 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
396 * this method; if it has not, a security exception will be thrown.
397 *
398 * @param admin Which {@link DeviceAdminReceiver} this request is associated
399 * with.
400 * @param length The new desired minimum number of lower case letters
401 * required in the password. A value of 0 means there is no
402 * restriction.
403 */
404 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
405 if (mService != null) {
406 try {
407 mService.setPasswordMinimumLowerCase(admin, length);
408 } catch (RemoteException e) {
409 Log.w(TAG, "Failed talking with device policy service", e);
410 }
411 }
412 }
413
414 /**
415 * Retrieve the current number of lower case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700416 * password for all admins or a particular one. This is the same value as
417 * set by {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
418 * and only applies when the password quality is
419 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700420 *
421 * @param admin The name of the admin component to check, or null to
422 * aggregate all admins.
423 * @return The minimum number of lower case letters required in the
424 * password.
425 */
426 public int getPasswordMinimumLowerCase(ComponentName admin) {
427 if (mService != null) {
428 try {
429 return mService.getPasswordMinimumLowerCase(admin);
430 } catch (RemoteException e) {
431 Log.w(TAG, "Failed talking with device policy service", e);
432 }
433 }
434 return 0;
435 }
436
437 /**
438 * Called by an application that is administering the device to set the
439 * minimum number of letters required in the password. After setting this,
440 * the user will not be able to enter a new password that is not at least as
441 * restrictive as what has been set. Note that the current password will
442 * remain until the user has set a new one, so the change does not take
443 * place immediately. To prompt the user for a new password, use
444 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
445 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700446 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
447 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700448 * <p>
449 * The calling device admin must have requested
450 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
451 * this method; if it has not, a security exception will be thrown.
452 *
453 * @param admin Which {@link DeviceAdminReceiver} this request is associated
454 * with.
455 * @param length The new desired minimum number of letters required in the
456 * password. A value of 0 means there is no restriction.
457 */
458 public void setPasswordMinimumLetters(ComponentName admin, int length) {
459 if (mService != null) {
460 try {
461 mService.setPasswordMinimumLetters(admin, length);
462 } catch (RemoteException e) {
463 Log.w(TAG, "Failed talking with device policy service", e);
464 }
465 }
466 }
467
468 /**
469 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700470 * admins or a particular one. This is the same value as
471 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
472 * and only applies when the password quality is
473 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700474 *
475 * @param admin The name of the admin component to check, or null to
476 * aggregate all admins.
477 * @return The minimum number of letters required in the password.
478 */
479 public int getPasswordMinimumLetters(ComponentName admin) {
480 if (mService != null) {
481 try {
482 return mService.getPasswordMinimumLetters(admin);
483 } catch (RemoteException e) {
484 Log.w(TAG, "Failed talking with device policy service", e);
485 }
486 }
487 return 0;
488 }
489
490 /**
491 * Called by an application that is administering the device to set the
492 * minimum number of numerical digits required in the password. After
493 * setting this, the user will not be able to enter a new password that is
494 * not at least as restrictive as what has been set. Note that the current
495 * password will remain until the user has set a new one, so the change does
496 * not take place immediately. To prompt the user for a new password, use
497 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
498 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700499 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
500 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700501 * <p>
502 * The calling device admin must have requested
503 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
504 * this method; if it has not, a security exception will be thrown.
505 *
506 * @param admin Which {@link DeviceAdminReceiver} this request is associated
507 * with.
508 * @param length The new desired minimum number of numerical digits required
509 * in the password. A value of 0 means there is no restriction.
510 */
511 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
512 if (mService != null) {
513 try {
514 mService.setPasswordMinimumNumeric(admin, length);
515 } catch (RemoteException e) {
516 Log.w(TAG, "Failed talking with device policy service", e);
517 }
518 }
519 }
520
521 /**
522 * Retrieve the current number of numerical digits required in the password
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700523 * for all admins or a particular one. This is the same value as
524 * set by {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
525 * and only applies when the password quality is
526 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700527 *
528 * @param admin The name of the admin component to check, or null to
529 * aggregate all admins.
530 * @return The minimum number of numerical digits required in the password.
531 */
532 public int getPasswordMinimumNumeric(ComponentName admin) {
533 if (mService != null) {
534 try {
535 return mService.getPasswordMinimumNumeric(admin);
536 } catch (RemoteException e) {
537 Log.w(TAG, "Failed talking with device policy service", e);
538 }
539 }
540 return 0;
541 }
542
543 /**
544 * Called by an application that is administering the device to set the
545 * minimum number of symbols required in the password. After setting this,
546 * the user will not be able to enter a new password that is not at least as
547 * restrictive as what has been set. Note that the current password will
548 * remain until the user has set a new one, so the change does not take
549 * place immediately. To prompt the user for a new password, use
550 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
551 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700552 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
553 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700554 * <p>
555 * The calling device admin must have requested
556 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
557 * this method; if it has not, a security exception will be thrown.
558 *
559 * @param admin Which {@link DeviceAdminReceiver} this request is associated
560 * with.
561 * @param length The new desired minimum number of symbols required in the
562 * password. A value of 0 means there is no restriction.
563 */
564 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
565 if (mService != null) {
566 try {
567 mService.setPasswordMinimumSymbols(admin, length);
568 } catch (RemoteException e) {
569 Log.w(TAG, "Failed talking with device policy service", e);
570 }
571 }
572 }
573
574 /**
575 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700576 * admins or a particular one. This is the same value as
577 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
578 * and only applies when the password quality is
579 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700580 *
581 * @param admin The name of the admin component to check, or null to
582 * aggregate all admins.
583 * @return The minimum number of symbols required in the password.
584 */
585 public int getPasswordMinimumSymbols(ComponentName admin) {
586 if (mService != null) {
587 try {
588 return mService.getPasswordMinimumSymbols(admin);
589 } catch (RemoteException e) {
590 Log.w(TAG, "Failed talking with device policy service", e);
591 }
592 }
593 return 0;
594 }
595
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700596 /**
597 * Called by an application that is administering the device to set the
598 * minimum number of non-letter characters (numerical digits or symbols)
599 * required in the password. After setting this, the user will not be able
600 * to enter a new password that is not at least as restrictive as what has
601 * been set. Note that the current password will remain until the user has
602 * set a new one, so the change does not take place immediately. To prompt
603 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
604 * setting this value. This constraint is only imposed if the administrator
605 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
606 * {@link #setPasswordQuality}. The default value is 0.
607 * <p>
608 * The calling device admin must have requested
609 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
610 * this method; if it has not, a security exception will be thrown.
611 *
612 * @param admin Which {@link DeviceAdminReceiver} this request is associated
613 * with.
614 * @param length The new desired minimum number of letters required in the
615 * password. A value of 0 means there is no restriction.
616 */
617 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
618 if (mService != null) {
619 try {
620 mService.setPasswordMinimumNonLetter(admin, length);
621 } catch (RemoteException e) {
622 Log.w(TAG, "Failed talking with device policy service", e);
623 }
624 }
625 }
626
627 /**
628 * Retrieve the current number of non-letter characters required in the
629 * password for all admins or a particular one. This is the same value as
630 * set by {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
631 * and only applies when the password quality is
632 * {@link #PASSWORD_QUALITY_COMPLEX}.
633 *
634 * @param admin The name of the admin component to check, or null to
635 * aggregate all admins.
636 * @return The minimum number of letters required in the password.
637 */
638 public int getPasswordMinimumNonLetter(ComponentName admin) {
639 if (mService != null) {
640 try {
641 return mService.getPasswordMinimumNonLetter(admin);
642 } catch (RemoteException e) {
643 Log.w(TAG, "Failed talking with device policy service", e);
644 }
645 }
646 return 0;
647 }
648
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700649 /**
650 * Called by an application that is administering the device to set the length
651 * of the password history. After setting this, the user will not be able to
652 * enter a new password that is the same as any password in the history. Note
653 * that the current password will remain until the user has set a new one, so
654 * the change does not take place immediately. To prompt the user for a new
655 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
656 * This constraint is only imposed if the administrator has also requested
657 * either {@link #PASSWORD_QUALITY_NUMERIC},
658 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
659 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
660 *
661 * <p>
662 * The calling device admin must have requested
663 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
664 * method; if it has not, a security exception will be thrown.
665 *
666 * @param admin Which {@link DeviceAdminReceiver} this request is associated
667 * with.
668 * @param length The new desired length of password history. A value of 0
669 * means there is no restriction.
670 */
671 public void setPasswordHistoryLength(ComponentName admin, int length) {
672 if (mService != null) {
673 try {
674 mService.setPasswordHistoryLength(admin, length);
675 } catch (RemoteException e) {
676 Log.w(TAG, "Failed talking with device policy service", e);
677 }
678 }
679 }
680
681 /**
682 * Retrieve the current password history length for all admins
683 * or a particular one.
684 * @param admin The name of the admin component to check, or null to aggregate
685 * all admins.
686 * @return The length of the password history
687 */
688 public int getPasswordHistoryLength(ComponentName admin) {
689 if (mService != null) {
690 try {
691 return mService.getPasswordHistoryLength(admin);
692 } catch (RemoteException e) {
693 Log.w(TAG, "Failed talking with device policy service", e);
694 }
695 }
696 return 0;
697 }
698
Dianne Hackbornd6847842010-01-12 18:14:19 -0800699 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800700 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800701 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800702 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800703 * @return Returns the maximum length that the user can enter.
704 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800705 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800706 // Kind-of arbitrary.
707 return 16;
708 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700709
Dianne Hackborn254cb442010-01-27 19:23:59 -0800710 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800711 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800712 * to meet the policy requirements (quality, minimum length) that have been
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800713 * requested.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700714 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800715 * <p>The calling device admin must have requested
716 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
717 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700718 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800719 * @return Returns true if the password meets the current requirements,
720 * else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800721 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800722 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800723 if (mService != null) {
724 try {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800725 return mService.isActivePasswordSufficient();
Dianne Hackbornd6847842010-01-12 18:14:19 -0800726 } catch (RemoteException e) {
727 Log.w(TAG, "Failed talking with device policy service", e);
728 }
729 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800730 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800731 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700732
Dianne Hackbornd6847842010-01-12 18:14:19 -0800733 /**
734 * Retrieve the number of times the user has failed at entering a
735 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700736 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800737 * <p>The calling device admin must have requested
738 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
739 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800740 */
741 public int getCurrentFailedPasswordAttempts() {
742 if (mService != null) {
743 try {
744 return mService.getCurrentFailedPasswordAttempts();
745 } catch (RemoteException e) {
746 Log.w(TAG, "Failed talking with device policy service", e);
747 }
748 }
749 return -1;
750 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800751
752 /**
Andrew Stadler88209d12010-02-08 22:59:36 -0800753 * Setting this to a value greater than zero enables a built-in policy
754 * that will perform a device wipe after too many incorrect
755 * device-unlock passwords have been entered. This built-in policy combines
756 * watching for failed passwords and wiping the device, and requires
757 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800758 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700759 *
Andrew Stadler88209d12010-02-08 22:59:36 -0800760 * <p>To implement any other policy (e.g. wiping data for a particular
761 * application only, erasing or revoking credentials, or reporting the
762 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800763 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -0800764 * instead. Do not use this API, because if the maximum count is reached,
765 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700766 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800768 * @param num The number of failed password attempts at which point the
769 * device will wipe its data.
770 */
771 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
772 if (mService != null) {
773 try {
774 mService.setMaximumFailedPasswordsForWipe(admin, num);
775 } catch (RemoteException e) {
776 Log.w(TAG, "Failed talking with device policy service", e);
777 }
778 }
779 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700780
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800781 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800782 * Retrieve the current maximum number of login attempts that are allowed
783 * before the device wipes itself, for all admins
784 * or a particular one.
785 * @param admin The name of the admin component to check, or null to aggregate
786 * all admins.
787 */
788 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
789 if (mService != null) {
790 try {
791 return mService.getMaximumFailedPasswordsForWipe(admin);
792 } catch (RemoteException e) {
793 Log.w(TAG, "Failed talking with device policy service", e);
794 }
795 }
796 return 0;
797 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700798
Dianne Hackborn254cb442010-01-27 19:23:59 -0800799 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800800 * Flag for {@link #resetPassword}: don't allow other admins to change
801 * the password again until the user has entered it.
802 */
803 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700804
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800805 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800806 * Force a new device unlock password (the password needed to access the
807 * entire device, not for individual accounts) on the user. This takes
808 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800809 * The given password must be sufficient for the
810 * current password quality and length constraints as returned by
811 * {@link #getPasswordQuality(ComponentName)} and
812 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
813 * these constraints, then it will be rejected and false returned. Note
814 * that the password may be a stronger quality (containing alphanumeric
815 * characters when the requested quality is only numeric), in which case
816 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700817 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800818 * <p>The calling device admin must have requested
819 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
820 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700821 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800822 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800823 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800824 * @return Returns true if the password was applied, or false if it is
825 * not acceptable for the current constraints.
826 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800827 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800828 if (mService != null) {
829 try {
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800830 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800831 } catch (RemoteException e) {
832 Log.w(TAG, "Failed talking with device policy service", e);
833 }
834 }
835 return false;
836 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700837
Dianne Hackbornd6847842010-01-12 18:14:19 -0800838 /**
839 * Called by an application that is administering the device to set the
840 * maximum time for user activity until the device will lock. This limits
841 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700842 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800843 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -0800844 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800845 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700846 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800847 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800848 * @param timeMs The new desired maximum time to lock in milliseconds.
849 * A value of 0 means there is no restriction.
850 */
851 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
852 if (mService != null) {
853 try {
854 mService.setMaximumTimeToLock(admin, timeMs);
855 } catch (RemoteException e) {
856 Log.w(TAG, "Failed talking with device policy service", e);
857 }
858 }
859 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700860
Dianne Hackbornd6847842010-01-12 18:14:19 -0800861 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800862 * Retrieve the current maximum time to unlock for all admins
863 * or a particular one.
864 * @param admin The name of the admin component to check, or null to aggregate
865 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800866 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800867 public long getMaximumTimeToLock(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800868 if (mService != null) {
869 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800870 return mService.getMaximumTimeToLock(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800871 } catch (RemoteException e) {
872 Log.w(TAG, "Failed talking with device policy service", e);
873 }
874 }
875 return 0;
876 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700877
Dianne Hackbornd6847842010-01-12 18:14:19 -0800878 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800879 * Make the device lock immediately, as if the lock screen timeout has
880 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700881 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800882 * <p>The calling device admin must have requested
883 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
884 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800885 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800886 public void lockNow() {
887 if (mService != null) {
888 try {
889 mService.lockNow();
890 } catch (RemoteException e) {
891 Log.w(TAG, "Failed talking with device policy service", e);
892 }
893 }
894 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700895
Dianne Hackbornd6847842010-01-12 18:14:19 -0800896 /**
897 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800898 * erasing all user data while next booting up. External storage such
899 * as SD cards will not be erased.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700900 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800901 * <p>The calling device admin must have requested
902 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
903 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700904 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800905 * @param flags Bit mask of additional options: currently must be 0.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800906 */
907 public void wipeData(int flags) {
908 if (mService != null) {
909 try {
910 mService.wipeData(flags);
911 } catch (RemoteException e) {
912 Log.w(TAG, "Failed talking with device policy service", e);
913 }
914 }
915 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700916
Dianne Hackbornd6847842010-01-12 18:14:19 -0800917 /**
918 * @hide
919 */
920 public void setActiveAdmin(ComponentName policyReceiver) {
921 if (mService != null) {
922 try {
923 mService.setActiveAdmin(policyReceiver);
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 /**
931 * @hide
932 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800933 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800934 ActivityInfo ai;
935 try {
936 ai = mContext.getPackageManager().getReceiverInfo(cn,
937 PackageManager.GET_META_DATA);
938 } catch (PackageManager.NameNotFoundException e) {
939 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
940 return null;
941 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700942
Dianne Hackbornd6847842010-01-12 18:14:19 -0800943 ResolveInfo ri = new ResolveInfo();
944 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700945
Dianne Hackbornd6847842010-01-12 18:14:19 -0800946 try {
947 return new DeviceAdminInfo(mContext, ri);
948 } catch (XmlPullParserException e) {
949 Log.w(TAG, "Unable to parse device policy " + cn, e);
950 return null;
951 } catch (IOException e) {
952 Log.w(TAG, "Unable to parse device policy " + cn, e);
953 return null;
954 }
955 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700956
Dianne Hackbornd6847842010-01-12 18:14:19 -0800957 /**
958 * @hide
959 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800960 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
961 if (mService != null) {
962 try {
963 mService.getRemoveWarning(admin, result);
964 } catch (RemoteException e) {
965 Log.w(TAG, "Failed talking with device policy service", e);
966 }
967 }
968 }
969
970 /**
971 * @hide
972 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700973 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700974 int lowercase, int numbers, int symbols, int nonletter) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800975 if (mService != null) {
976 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700977 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700978 numbers, symbols, nonletter);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800979 } catch (RemoteException e) {
980 Log.w(TAG, "Failed talking with device policy service", e);
981 }
982 }
983 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700984
Dianne Hackbornd6847842010-01-12 18:14:19 -0800985 /**
986 * @hide
987 */
988 public void reportFailedPasswordAttempt() {
989 if (mService != null) {
990 try {
991 mService.reportFailedPasswordAttempt();
992 } catch (RemoteException e) {
993 Log.w(TAG, "Failed talking with device policy service", e);
994 }
995 }
996 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700997
Dianne Hackbornd6847842010-01-12 18:14:19 -0800998 /**
999 * @hide
1000 */
1001 public void reportSuccessfulPasswordAttempt() {
1002 if (mService != null) {
1003 try {
1004 mService.reportSuccessfulPasswordAttempt();
1005 } catch (RemoteException e) {
1006 Log.w(TAG, "Failed talking with device policy service", e);
1007 }
1008 }
1009 }
1010}