blob: 08cdd0511d4bfb4eb2de86ec41a5f122aa53a294 [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
17package android.app;
18
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
39 * of this class must have published a {@link DeviceAdmin} that the user
40 * 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;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080049
50 private final Handler mHandler;
Dianne Hackbornd6847842010-01-12 18:14:19 -080051
52 /*package*/ DevicePolicyManager(Context context, Handler handler) {
53 mContext = context;
54 mHandler = handler;
55 mService = IDevicePolicyManager.Stub.asInterface(
56 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
57 }
58
59 /**
60 * Activity action: ask the user to add a new device administrator to the system.
61 * The desired policy is the ComponentName of the policy in the
62 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
63 * bring the user through adding the device administrator to the system (or
64 * allowing them to reject it).
65 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080066 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
67 * field to provide the user with additional explanation (in addition
68 * to your component's description) about what is being added.
Dianne Hackbornd6847842010-01-12 18:14:19 -080069 */
70 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
71 public static final String ACTION_ADD_DEVICE_ADMIN
72 = "android.app.action.ADD_DEVICE_ADMIN";
73
74 /**
75 * The ComponentName of the administrator component.
76 *
77 * @see #ACTION_ADD_DEVICE_ADMIN
78 */
79 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
80
81 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080082 * An optional CharSequence providing additional explanation for why the
83 * admin is being added.
84 *
85 * @see #ACTION_ADD_DEVICE_ADMIN
86 */
87 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
88
89 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 * Activity action: have the user enter a new password. This activity
Dianne Hackborn9327f4f2010-01-29 10:38:29 -080091 * should be launched after using {@link #setPasswordQuality(ComponentName, int)}
Dianne Hackborn254cb442010-01-27 19:23:59 -080092 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the
Dianne Hackborndf83afa2010-01-20 13:37:26 -080093 * user enter a new password that meets the current requirements. You can
94 * use {@link #isActivePasswordSufficient()} to determine whether you need
95 * to have the user select a new password in order to meet the current
96 * constraints. Upon being resumed from this activity,
Dianne Hackbornd6847842010-01-12 18:14:19 -080097 * you can check the new password characteristics to see if they are
98 * sufficient.
99 */
100 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
101 public static final String ACTION_SET_NEW_PASSWORD
102 = "android.app.action.SET_NEW_PASSWORD";
103
104 /**
105 * Return true if the given administrator component is currently
106 * active (enabled) in the system.
107 */
108 public boolean isAdminActive(ComponentName who) {
109 if (mService != null) {
110 try {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800111 return mService.isAdminActive(who);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800112 } catch (RemoteException e) {
113 Log.w(TAG, "Failed talking with device policy service", e);
114 }
115 }
116 return false;
117 }
118
119 /**
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800120 * Return a list of all currently active device administrator's component
121 * names. Note that if there are no administrators than null may be
122 * returned.
123 */
124 public List<ComponentName> getActiveAdmins() {
125 if (mService != null) {
126 try {
127 return mService.getActiveAdmins();
128 } catch (RemoteException e) {
129 Log.w(TAG, "Failed talking with device policy service", e);
130 }
131 }
132 return null;
133 }
134
135 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800136 * Remove a current administration component. This can only be called
137 * by the application that owns the administration component; if you
138 * try to remove someone else's component, a security exception will be
139 * thrown.
140 */
141 public void removeActiveAdmin(ComponentName who) {
142 if (mService != null) {
143 try {
144 mService.removeActiveAdmin(who);
145 } catch (RemoteException e) {
146 Log.w(TAG, "Failed talking with device policy service", e);
147 }
148 }
149 }
150
151 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800152 * Constant for {@link #setPasswordQuality}: the policy has no requirements
153 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800154 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800155 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800156 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800157
158 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800159 * Constant for {@link #setPasswordQuality}: the policy requires some kind
160 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800161 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800162 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800163 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800164
165 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800166 * Constant for {@link #setPasswordQuality}: the user must have entered a
167 * password containing at least numeric characters. Note that quality
168 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800169 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800170 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800171
172 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800173 * Constant for {@link #setPasswordQuality}: the user must have entered a
174 * password containing at least <em>both></em> numeric <em>and</em>
175 * alphabeter (or other symbol) characters. Note that quality constants are
176 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800177 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800178 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x30000;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800179
180 /**
181 * Called by an application that is administering the device to set the
182 * password restrictions it is imposing. After setting this, the user
183 * will not be able to enter a new password that is not at least as
184 * restrictive as what has been set. Note that the current password
185 * will remain until the user has set a new one, so the change does not
186 * take place immediately. To prompt the user for a new password, use
187 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
188 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800189 * <p>Quality constants are ordered so that higher values are more restrictive;
190 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800191 * the user's preference, and any other considerations) is the one that
192 * is in effect.
193 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800194 * <p>The calling device admin must have requested
195 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
196 * this method; if it has not, a security exception will be thrown.
197 *
Dianne Hackbornd6847842010-01-12 18:14:19 -0800198 * @param admin Which {@link DeviceAdmin} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800199 * @param quality The new desired quality. One of
200 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
201 * {@link #PASSWORD_QUALITY_NUMERIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800202 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800203 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800204 if (mService != null) {
205 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800206 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800207 } catch (RemoteException e) {
208 Log.w(TAG, "Failed talking with device policy service", e);
209 }
210 }
211 }
212
213 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800214 * Retrieve the current minimum password quality for all admins
Dianne Hackborn254cb442010-01-27 19:23:59 -0800215 * or a particular one.
216 * @param admin The name of the admin component to check, or null to aggregate
217 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800218 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800219 public int getPasswordQuality(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800220 if (mService != null) {
221 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800222 return mService.getPasswordQuality(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800223 } catch (RemoteException e) {
224 Log.w(TAG, "Failed talking with device policy service", e);
225 }
226 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800227 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800228 }
229
230 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800231 * Called by an application that is administering the device to set the
232 * minimum allowed password length. 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. This
238 * constraint is only imposed if the administrator has also requested either
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800239 * {@link #PASSWORD_QUALITY_NUMERIC} or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
240 * with {@link #setPasswordQuality}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800241 *
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.
245 *
Dianne Hackbornd6847842010-01-12 18:14:19 -0800246 * @param admin Which {@link DeviceAdmin} this request is associated with.
247 * @param length The new desired minimum password length. A value of 0
248 * means there is no restriction.
249 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800250 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800251 if (mService != null) {
252 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800253 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800254 } catch (RemoteException e) {
255 Log.w(TAG, "Failed talking with device policy service", e);
256 }
257 }
258 }
259
260 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800261 * Retrieve the current minimum password length for all admins
262 * or a particular one.
263 * @param admin The name of the admin component to check, or null to aggregate
264 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800265 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800266 public int getPasswordMinimumLength(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800267 if (mService != null) {
268 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800269 return mService.getPasswordMinimumLength(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800270 } catch (RemoteException e) {
271 Log.w(TAG, "Failed talking with device policy service", e);
272 }
273 }
274 return 0;
275 }
276
277 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800278 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800279 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800280 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800281 * @return Returns the maximum length that the user can enter.
282 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800283 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800284 // Kind-of arbitrary.
285 return 16;
286 }
287
288 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800289 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800290 * to meet the policy requirements (quality, minimum length) that have been
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800291 * requested.
292 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800293 * <p>The calling device admin must have requested
294 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
295 * this method; if it has not, a security exception will be thrown.
296 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800297 * @return Returns true if the password meets the current requirements,
298 * else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800299 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800300 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800301 if (mService != null) {
302 try {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800303 return mService.isActivePasswordSufficient();
Dianne Hackbornd6847842010-01-12 18:14:19 -0800304 } catch (RemoteException e) {
305 Log.w(TAG, "Failed talking with device policy service", e);
306 }
307 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800308 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800309 }
310
311 /**
312 * Retrieve the number of times the user has failed at entering a
313 * password since that last successful password entry.
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800314 *
315 * <p>The calling device admin must have requested
316 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
317 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800318 */
319 public int getCurrentFailedPasswordAttempts() {
320 if (mService != null) {
321 try {
322 return mService.getCurrentFailedPasswordAttempts();
323 } catch (RemoteException e) {
324 Log.w(TAG, "Failed talking with device policy service", e);
325 }
326 }
327 return -1;
328 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800329
330 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800331 * Set the maximum number of failed password attempts that are allowed
332 * before the device wipes its data. This is convenience for implementing
333 * the corresponding functionality with a combination of watching failed
334 * password attempts and calling {@link #wipeData} upon reaching a certain
335 * count, and as such requires that you request both
336 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
337 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
338 *
339 * @param admin Which {@link DeviceAdmin} this request is associated with.
340 * @param num The number of failed password attempts at which point the
341 * device will wipe its data.
342 */
343 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
344 if (mService != null) {
345 try {
346 mService.setMaximumFailedPasswordsForWipe(admin, num);
347 } catch (RemoteException e) {
348 Log.w(TAG, "Failed talking with device policy service", e);
349 }
350 }
351 }
352
353 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800354 * Retrieve the current maximum number of login attempts that are allowed
355 * before the device wipes itself, for all admins
356 * or a particular one.
357 * @param admin The name of the admin component to check, or null to aggregate
358 * all admins.
359 */
360 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
361 if (mService != null) {
362 try {
363 return mService.getMaximumFailedPasswordsForWipe(admin);
364 } catch (RemoteException e) {
365 Log.w(TAG, "Failed talking with device policy service", e);
366 }
367 }
368 return 0;
369 }
370
371 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800372 * Force a new password on the user. This takes effect immediately.
373 * The given password must be sufficient for the
374 * current password quality and length constraints as returned by
375 * {@link #getPasswordQuality(ComponentName)} and
376 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
377 * these constraints, then it will be rejected and false returned. Note
378 * that the password may be a stronger quality (containing alphanumeric
379 * characters when the requested quality is only numeric), in which case
380 * the currently active quality will be increased to match.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800381 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800382 * <p>The calling device admin must have requested
383 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
384 * this method; if it has not, a security exception will be thrown.
385 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800386 * @param password The new password for the user.
387 * @return Returns true if the password was applied, or false if it is
388 * not acceptable for the current constraints.
389 */
390 public boolean resetPassword(String password) {
391 if (mService != null) {
392 try {
393 return mService.resetPassword(password);
394 } catch (RemoteException e) {
395 Log.w(TAG, "Failed talking with device policy service", e);
396 }
397 }
398 return false;
399 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800400
401 /**
402 * Called by an application that is administering the device to set the
403 * maximum time for user activity until the device will lock. This limits
404 * the length that the user can set. It takes effect immediately.
405 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800406 * <p>The calling device admin must have requested
407 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_UNLOCK} to be able to call
408 * this method; if it has not, a security exception will be thrown.
409 *
Dianne Hackbornd6847842010-01-12 18:14:19 -0800410 * @param admin Which {@link DeviceAdmin} this request is associated with.
411 * @param timeMs The new desired maximum time to lock in milliseconds.
412 * A value of 0 means there is no restriction.
413 */
414 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
415 if (mService != null) {
416 try {
417 mService.setMaximumTimeToLock(admin, timeMs);
418 } catch (RemoteException e) {
419 Log.w(TAG, "Failed talking with device policy service", e);
420 }
421 }
422 }
423
424 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800425 * Retrieve the current maximum time to unlock for all admins
426 * or a particular one.
427 * @param admin The name of the admin component to check, or null to aggregate
428 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800429 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800430 public long getMaximumTimeToLock(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800431 if (mService != null) {
432 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800433 return mService.getMaximumTimeToLock(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800434 } catch (RemoteException e) {
435 Log.w(TAG, "Failed talking with device policy service", e);
436 }
437 }
438 return 0;
439 }
440
441 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800442 * Make the device lock immediately, as if the lock screen timeout has
443 * expired at the point of this call.
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800444 *
445 * <p>The calling device admin must have requested
446 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
447 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800448 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800449 public void lockNow() {
450 if (mService != null) {
451 try {
452 mService.lockNow();
453 } catch (RemoteException e) {
454 Log.w(TAG, "Failed talking with device policy service", e);
455 }
456 }
457 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800458
459 /**
460 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800461 * erasing all user data while next booting up. External storage such
462 * as SD cards will not be erased.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800463 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800464 * <p>The calling device admin must have requested
465 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
466 * this method; if it has not, a security exception will be thrown.
467 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800468 * @param flags Bit mask of additional options: currently must be 0.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800469 */
470 public void wipeData(int flags) {
471 if (mService != null) {
472 try {
473 mService.wipeData(flags);
474 } catch (RemoteException e) {
475 Log.w(TAG, "Failed talking with device policy service", e);
476 }
477 }
478 }
479
480 /**
481 * @hide
482 */
483 public void setActiveAdmin(ComponentName policyReceiver) {
484 if (mService != null) {
485 try {
486 mService.setActiveAdmin(policyReceiver);
487 } catch (RemoteException e) {
488 Log.w(TAG, "Failed talking with device policy service", e);
489 }
490 }
491 }
492
493 /**
494 * @hide
495 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800496 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800497 ActivityInfo ai;
498 try {
499 ai = mContext.getPackageManager().getReceiverInfo(cn,
500 PackageManager.GET_META_DATA);
501 } catch (PackageManager.NameNotFoundException e) {
502 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
503 return null;
504 }
505
506 ResolveInfo ri = new ResolveInfo();
507 ri.activityInfo = ai;
508
509 try {
510 return new DeviceAdminInfo(mContext, ri);
511 } catch (XmlPullParserException e) {
512 Log.w(TAG, "Unable to parse device policy " + cn, e);
513 return null;
514 } catch (IOException e) {
515 Log.w(TAG, "Unable to parse device policy " + cn, e);
516 return null;
517 }
518 }
519
520 /**
521 * @hide
522 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800523 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
524 if (mService != null) {
525 try {
526 mService.getRemoveWarning(admin, result);
527 } catch (RemoteException e) {
528 Log.w(TAG, "Failed talking with device policy service", e);
529 }
530 }
531 }
532
533 /**
534 * @hide
535 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800536 public void setActivePasswordState(int quality, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800537 if (mService != null) {
538 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800539 mService.setActivePasswordState(quality, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800540 } catch (RemoteException e) {
541 Log.w(TAG, "Failed talking with device policy service", e);
542 }
543 }
544 }
545
546 /**
547 * @hide
548 */
549 public void reportFailedPasswordAttempt() {
550 if (mService != null) {
551 try {
552 mService.reportFailedPasswordAttempt();
553 } catch (RemoteException e) {
554 Log.w(TAG, "Failed talking with device policy service", e);
555 }
556 }
557 }
558
559 /**
560 * @hide
561 */
562 public void reportSuccessfulPasswordAttempt() {
563 if (mService != null) {
564 try {
565 mService.reportSuccessfulPasswordAttempt();
566 } catch (RemoteException e) {
567 Log.w(TAG, "Failed talking with device policy service", e);
568 }
569 }
570 }
571}