blob: 3f3aa749f9c04ee4f14eed15a55f07537e94c0a6 [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";
Dianne Hackbornd6847842010-01-12 18:14:19 -080046
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 Hackborn21f1bd12010-02-19 17:02:21 -080050 private DevicePolicyManager(Context context, Handler handler) {
Dianne Hackbornd6847842010-01-12 18:14:19 -080051 mContext = context;
Dianne Hackbornd6847842010-01-12 18:14:19 -080052 mService = IDevicePolicyManager.Stub.asInterface(
53 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
54 }
55
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080056 /** @hide */
57 public static DevicePolicyManager create(Context context, Handler handler) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080058 DevicePolicyManager me = new DevicePolicyManager(context, handler);
59 return me.mService != null ? me : null;
60 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -070061
Dianne Hackbornd6847842010-01-12 18:14:19 -080062 /**
63 * Activity action: ask the user to add a new device administrator to the system.
64 * The desired policy is the ComponentName of the policy in the
65 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
66 * bring the user through adding the device administrator to the system (or
67 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -070068 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080069 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
70 * field to provide the user with additional explanation (in addition
71 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -080072 *
73 * <p>If your administrator is already active, this will ordinarily return immediately (without
74 * user intervention). However, if your administrator has been updated and is requesting
75 * additional uses-policy flags, the user will be presented with the new list. New policies
76 * will not be available to the updated administrator until the user has accepted the new list.
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 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800182 * Returns true if an administrator has been granted a particular device policy. This can
183 * be used to check if the administrator was activated under an earlier set of policies,
184 * but requires additional policies after an upgrade.
185 *
186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
187 * an active administrator, or an exception will be thrown.
188 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
189 */
190 public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) {
191 if (mService != null) {
192 try {
193 return mService.hasGrantedPolicy(admin, usesPolicy);
194 } catch (RemoteException e) {
195 Log.w(TAG, "Failed talking with device policy service", e);
196 }
197 }
198 return false;
199 }
200
201 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800202 * Constant for {@link #setPasswordQuality}: the policy has no requirements
203 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800204 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800205 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800206 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700207
Dianne Hackbornd6847842010-01-12 18:14:19 -0800208 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800209 * Constant for {@link #setPasswordQuality}: the policy requires some kind
210 * of password, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800211 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800212 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800213 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700214
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800215 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800216 * Constant for {@link #setPasswordQuality}: the user must have entered a
217 * password containing at least numeric characters. Note that quality
218 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800219 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800220 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700221
Dianne Hackbornd6847842010-01-12 18:14:19 -0800222 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800223 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700224 * password containing at least alphabetic (or other symbol) characters.
225 * Note that quality constants are ordered so that higher values are more
226 * restrictive.
227 */
228 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700229
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700230 /**
231 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800232 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700233 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800234 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800235 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700236 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700237
Dianne Hackbornd6847842010-01-12 18:14:19 -0800238 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700239 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700240 * password containing at least a letter, a numerical digit and a special
241 * symbol, by default. With this password quality, passwords can be
242 * restricted to contain various sets of characters, like at least an
243 * uppercase letter, etc. These are specified using various methods,
244 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
245 * that quality constants are ordered so that higher values are more
246 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700247 */
248 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
249
250 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800251 * Called by an application that is administering the device to set the
252 * password restrictions it is imposing. After setting this, the user
253 * will not be able to enter a new password that is not at least as
254 * restrictive as what has been set. Note that the current password
255 * will remain until the user has set a new one, so the change does not
256 * take place immediately. To prompt the user for a new password, use
257 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700258 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800259 * <p>Quality constants are ordered so that higher values are more restrictive;
260 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800261 * the user's preference, and any other considerations) is the one that
262 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700263 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800264 * <p>The calling device admin must have requested
265 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
266 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700267 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800268 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800269 * @param quality The new desired quality. One of
270 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700271 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC},
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700272 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800273 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800274 public void setPasswordQuality(ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800275 if (mService != null) {
276 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800277 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800278 } catch (RemoteException e) {
279 Log.w(TAG, "Failed talking with device policy service", e);
280 }
281 }
282 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700283
Dianne Hackbornd6847842010-01-12 18:14:19 -0800284 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800285 * Retrieve the current minimum password quality for all admins
Dianne Hackborn254cb442010-01-27 19:23:59 -0800286 * or a particular one.
287 * @param admin The name of the admin component to check, or null to aggregate
288 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800289 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800290 public int getPasswordQuality(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800291 if (mService != null) {
292 try {
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800293 return mService.getPasswordQuality(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800294 } catch (RemoteException e) {
295 Log.w(TAG, "Failed talking with device policy service", e);
296 }
297 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800298 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800299 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700300
Dianne Hackbornd6847842010-01-12 18:14:19 -0800301 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800302 * Called by an application that is administering the device to set the
303 * minimum allowed password length. After setting this, the user
304 * will not be able to enter a new password that is not at least as
305 * restrictive as what has been set. Note that the current password
306 * will remain until the user has set a new one, so the change does not
307 * take place immediately. To prompt the user for a new password, use
308 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
309 * constraint is only imposed if the administrator has also requested either
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700310 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}
311 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX}
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800312 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700313 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800314 * <p>The calling device admin must have requested
315 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
316 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700317 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800318 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800319 * @param length The new desired minimum password length. A value of 0
320 * means there is no restriction.
321 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800322 public void setPasswordMinimumLength(ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800323 if (mService != null) {
324 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800325 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800326 } catch (RemoteException e) {
327 Log.w(TAG, "Failed talking with device policy service", e);
328 }
329 }
330 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700331
Dianne Hackbornd6847842010-01-12 18:14:19 -0800332 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800333 * Retrieve the current minimum password length for all admins
334 * or a particular one.
335 * @param admin The name of the admin component to check, or null to aggregate
336 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800337 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800338 public int getPasswordMinimumLength(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800339 if (mService != null) {
340 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800341 return mService.getPasswordMinimumLength(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800342 } catch (RemoteException e) {
343 Log.w(TAG, "Failed talking with device policy service", e);
344 }
345 }
346 return 0;
347 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700348
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700349 /**
350 * Called by an application that is administering the device to set the
351 * minimum number of upper case letters required in the password. After
352 * setting this, the user will not be able to enter a new password that is
353 * not at least as restrictive as what has been set. Note that the current
354 * password will remain until the user has set a new one, so the change does
355 * not take place immediately. To prompt the user for a new password, use
356 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
357 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700358 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
359 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700360 * <p>
361 * The calling device admin must have requested
362 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
363 * this method; if it has not, a security exception will be thrown.
364 *
365 * @param admin Which {@link DeviceAdminReceiver} this request is associated
366 * with.
367 * @param length The new desired minimum number of upper case letters
368 * required in the password. A value of 0 means there is no
369 * restriction.
370 */
371 public void setPasswordMinimumUpperCase(ComponentName admin, int length) {
372 if (mService != null) {
373 try {
374 mService.setPasswordMinimumUpperCase(admin, length);
375 } catch (RemoteException e) {
376 Log.w(TAG, "Failed talking with device policy service", e);
377 }
378 }
379 }
380
381 /**
382 * Retrieve the current number of upper case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700383 * password for all admins or a particular one. This is the same value as
384 * set by {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
385 * and only applies when the password quality is
386 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700387 *
388 * @param admin The name of the admin component to check, or null to
389 * aggregate all admins.
390 * @return The minimum number of upper case letters required in the
391 * password.
392 */
393 public int getPasswordMinimumUpperCase(ComponentName admin) {
394 if (mService != null) {
395 try {
396 return mService.getPasswordMinimumUpperCase(admin);
397 } catch (RemoteException e) {
398 Log.w(TAG, "Failed talking with device policy service", e);
399 }
400 }
401 return 0;
402 }
403
404 /**
405 * Called by an application that is administering the device to set the
406 * minimum number of lower case letters required in the password. After
407 * setting this, the user will not be able to enter a new password that is
408 * not at least as restrictive as what has been set. Note that the current
409 * password will remain until the user has set a new one, so the change does
410 * not take place immediately. To prompt the user for a new password, use
411 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
412 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700413 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
414 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700415 * <p>
416 * The calling device admin must have requested
417 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
418 * this method; if it has not, a security exception will be thrown.
419 *
420 * @param admin Which {@link DeviceAdminReceiver} this request is associated
421 * with.
422 * @param length The new desired minimum number of lower case letters
423 * required in the password. A value of 0 means there is no
424 * restriction.
425 */
426 public void setPasswordMinimumLowerCase(ComponentName admin, int length) {
427 if (mService != null) {
428 try {
429 mService.setPasswordMinimumLowerCase(admin, length);
430 } catch (RemoteException e) {
431 Log.w(TAG, "Failed talking with device policy service", e);
432 }
433 }
434 }
435
436 /**
437 * Retrieve the current number of lower case letters required in the
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700438 * password for all admins or a particular one. This is the same value as
439 * set by {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
440 * and only applies when the password quality is
441 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700442 *
443 * @param admin The name of the admin component to check, or null to
444 * aggregate all admins.
445 * @return The minimum number of lower case letters required in the
446 * password.
447 */
448 public int getPasswordMinimumLowerCase(ComponentName admin) {
449 if (mService != null) {
450 try {
451 return mService.getPasswordMinimumLowerCase(admin);
452 } catch (RemoteException e) {
453 Log.w(TAG, "Failed talking with device policy service", e);
454 }
455 }
456 return 0;
457 }
458
459 /**
460 * Called by an application that is administering the device to set the
461 * minimum number of letters required in the password. After setting this,
462 * the user will not be able to enter a new password that is not at least as
463 * restrictive as what has been set. Note that the current password will
464 * remain until the user has set a new one, so the change does not take
465 * place immediately. To prompt the user for a new password, use
466 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
467 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700468 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
469 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700470 * <p>
471 * The calling device admin must have requested
472 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
473 * this method; if it has not, a security exception will be thrown.
474 *
475 * @param admin Which {@link DeviceAdminReceiver} this request is associated
476 * with.
477 * @param length The new desired minimum number of letters required in the
478 * password. A value of 0 means there is no restriction.
479 */
480 public void setPasswordMinimumLetters(ComponentName admin, int length) {
481 if (mService != null) {
482 try {
483 mService.setPasswordMinimumLetters(admin, length);
484 } catch (RemoteException e) {
485 Log.w(TAG, "Failed talking with device policy service", e);
486 }
487 }
488 }
489
490 /**
491 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700492 * admins or a particular one. This is the same value as
493 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
494 * and only applies when the password quality is
495 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700496 *
497 * @param admin The name of the admin component to check, or null to
498 * aggregate all admins.
499 * @return The minimum number of letters required in the password.
500 */
501 public int getPasswordMinimumLetters(ComponentName admin) {
502 if (mService != null) {
503 try {
504 return mService.getPasswordMinimumLetters(admin);
505 } catch (RemoteException e) {
506 Log.w(TAG, "Failed talking with device policy service", e);
507 }
508 }
509 return 0;
510 }
511
512 /**
513 * Called by an application that is administering the device to set the
514 * minimum number of numerical digits required in the password. After
515 * setting this, the user will not be able to enter a new password that is
516 * not at least as restrictive as what has been set. Note that the current
517 * password will remain until the user has set a new one, so the change does
518 * not take place immediately. To prompt the user for a new password, use
519 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
520 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700521 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
522 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700523 * <p>
524 * The calling device admin must have requested
525 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
526 * this method; if it has not, a security exception will be thrown.
527 *
528 * @param admin Which {@link DeviceAdminReceiver} this request is associated
529 * with.
530 * @param length The new desired minimum number of numerical digits required
531 * in the password. A value of 0 means there is no restriction.
532 */
533 public void setPasswordMinimumNumeric(ComponentName admin, int length) {
534 if (mService != null) {
535 try {
536 mService.setPasswordMinimumNumeric(admin, length);
537 } catch (RemoteException e) {
538 Log.w(TAG, "Failed talking with device policy service", e);
539 }
540 }
541 }
542
543 /**
544 * Retrieve the current number of numerical digits required in the password
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700545 * for all admins or a particular one. This is the same value as
546 * set by {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
547 * and only applies when the password quality is
548 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700549 *
550 * @param admin The name of the admin component to check, or null to
551 * aggregate all admins.
552 * @return The minimum number of numerical digits required in the password.
553 */
554 public int getPasswordMinimumNumeric(ComponentName admin) {
555 if (mService != null) {
556 try {
557 return mService.getPasswordMinimumNumeric(admin);
558 } catch (RemoteException e) {
559 Log.w(TAG, "Failed talking with device policy service", e);
560 }
561 }
562 return 0;
563 }
564
565 /**
566 * Called by an application that is administering the device to set the
567 * minimum number of symbols required in the password. After setting this,
568 * the user will not be able to enter a new password that is not at least as
569 * restrictive as what has been set. Note that the current password will
570 * remain until the user has set a new one, so the change does not take
571 * place immediately. To prompt the user for a new password, use
572 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
573 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700574 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
575 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700576 * <p>
577 * The calling device admin must have requested
578 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
579 * this method; if it has not, a security exception will be thrown.
580 *
581 * @param admin Which {@link DeviceAdminReceiver} this request is associated
582 * with.
583 * @param length The new desired minimum number of symbols required in the
584 * password. A value of 0 means there is no restriction.
585 */
586 public void setPasswordMinimumSymbols(ComponentName admin, int length) {
587 if (mService != null) {
588 try {
589 mService.setPasswordMinimumSymbols(admin, length);
590 } catch (RemoteException e) {
591 Log.w(TAG, "Failed talking with device policy service", e);
592 }
593 }
594 }
595
596 /**
597 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700598 * admins or a particular one. This is the same value as
599 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
600 * and only applies when the password quality is
601 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700602 *
603 * @param admin The name of the admin component to check, or null to
604 * aggregate all admins.
605 * @return The minimum number of symbols required in the password.
606 */
607 public int getPasswordMinimumSymbols(ComponentName admin) {
608 if (mService != null) {
609 try {
610 return mService.getPasswordMinimumSymbols(admin);
611 } catch (RemoteException e) {
612 Log.w(TAG, "Failed talking with device policy service", e);
613 }
614 }
615 return 0;
616 }
617
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700618 /**
619 * Called by an application that is administering the device to set the
620 * minimum number of non-letter characters (numerical digits or symbols)
621 * required in the password. After setting this, the user will not be able
622 * to enter a new password that is not at least as restrictive as what has
623 * been set. Note that the current password will remain until the user has
624 * set a new one, so the change does not take place immediately. To prompt
625 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
626 * setting this value. This constraint is only imposed if the administrator
627 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
628 * {@link #setPasswordQuality}. The default value is 0.
629 * <p>
630 * The calling device admin must have requested
631 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
632 * this method; if it has not, a security exception will be thrown.
633 *
634 * @param admin Which {@link DeviceAdminReceiver} this request is associated
635 * with.
636 * @param length The new desired minimum number of letters required in the
637 * password. A value of 0 means there is no restriction.
638 */
639 public void setPasswordMinimumNonLetter(ComponentName admin, int length) {
640 if (mService != null) {
641 try {
642 mService.setPasswordMinimumNonLetter(admin, length);
643 } catch (RemoteException e) {
644 Log.w(TAG, "Failed talking with device policy service", e);
645 }
646 }
647 }
648
649 /**
650 * Retrieve the current number of non-letter characters required in the
651 * password for all admins or a particular one. This is the same value as
652 * set by {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
653 * and only applies when the password quality is
654 * {@link #PASSWORD_QUALITY_COMPLEX}.
655 *
656 * @param admin The name of the admin component to check, or null to
657 * aggregate all admins.
658 * @return The minimum number of letters required in the password.
659 */
660 public int getPasswordMinimumNonLetter(ComponentName admin) {
661 if (mService != null) {
662 try {
663 return mService.getPasswordMinimumNonLetter(admin);
664 } catch (RemoteException e) {
665 Log.w(TAG, "Failed talking with device policy service", e);
666 }
667 }
668 return 0;
669 }
670
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700671 /**
672 * Called by an application that is administering the device to set the length
673 * of the password history. After setting this, the user will not be able to
674 * enter a new password that is the same as any password in the history. Note
675 * that the current password will remain until the user has set a new one, so
676 * the change does not take place immediately. To prompt the user for a new
677 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
678 * This constraint is only imposed if the administrator has also requested
679 * either {@link #PASSWORD_QUALITY_NUMERIC},
680 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or
681 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
682 *
683 * <p>
684 * The calling device admin must have requested
685 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
686 * method; if it has not, a security exception will be thrown.
687 *
688 * @param admin Which {@link DeviceAdminReceiver} this request is associated
689 * with.
690 * @param length The new desired length of password history. A value of 0
691 * means there is no restriction.
692 */
693 public void setPasswordHistoryLength(ComponentName admin, int length) {
694 if (mService != null) {
695 try {
696 mService.setPasswordHistoryLength(admin, length);
697 } catch (RemoteException e) {
698 Log.w(TAG, "Failed talking with device policy service", e);
699 }
700 }
701 }
702
703 /**
Jim Millera4e28d12010-11-08 16:15:47 -0800704 * Called by a device admin to set the password expiration timeout. Calling this method
705 * will restart the countdown for password expiration for the given admin, as will changing
706 * the device password (for all admins).
707 *
708 * <p>The provided timeout is the time delta in ms and will be added to the current time.
709 * For example, to have the password expire 5 days from now, timeout would be
710 * 5 * 86400 * 1000 = 432000000 ms for timeout.
711 *
712 * <p>To disable password expiration, a value of 0 may be used for timeout.
713 *
Jim Millera4e28d12010-11-08 16:15:47 -0800714 * <p>The calling device admin must have requested
715 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
716 * method; if it has not, a security exception will be thrown.
717 *
718 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
719 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
720 * means there is no restriction (unlimited).
721 */
722 public void setPasswordExpirationTimeout(ComponentName admin, long timeout) {
723 if (mService != null) {
724 try {
725 mService.setPasswordExpirationTimeout(admin, timeout);
726 } catch (RemoteException e) {
727 Log.w(TAG, "Failed talking with device policy service", e);
728 }
729 }
730 }
731
732 /**
733 * Get the current password expiration timeout for the given admin or the aggregate
734 * of all admins if admin is null.
735 *
736 * @param admin The name of the admin component to check, or null to aggregate all admins.
737 * @return The timeout for the given admin or the minimum of all timeouts
738 */
739 public long getPasswordExpirationTimeout(ComponentName admin) {
740 if (mService != null) {
741 try {
742 return mService.getPasswordExpirationTimeout(admin);
743 } catch (RemoteException e) {
744 Log.w(TAG, "Failed talking with device policy service", e);
745 }
746 }
747 return 0;
748 }
749
750 /**
751 * Get the current password expiration time for the given admin or an aggregate of
752 * all admins if admin is null.
753 *
754 * @param admin The name of the admin component to check, or null to aggregate all admins.
755 * @return The password expiration time, in ms.
756 */
757 public long getPasswordExpiration(ComponentName admin) {
758 if (mService != null) {
759 try {
760 return mService.getPasswordExpiration(admin);
761 } catch (RemoteException e) {
762 Log.w(TAG, "Failed talking with device policy service", e);
763 }
764 }
765 return 0;
766 }
767
768 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700769 * Retrieve the current password history length for all admins
770 * or a particular one.
771 * @param admin The name of the admin component to check, or null to aggregate
772 * all admins.
773 * @return The length of the password history
774 */
775 public int getPasswordHistoryLength(ComponentName admin) {
776 if (mService != null) {
777 try {
778 return mService.getPasswordHistoryLength(admin);
779 } catch (RemoteException e) {
780 Log.w(TAG, "Failed talking with device policy service", e);
781 }
782 }
783 return 0;
784 }
785
Dianne Hackbornd6847842010-01-12 18:14:19 -0800786 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800787 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800788 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -0800789 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -0800790 * @return Returns the maximum length that the user can enter.
791 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800792 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800793 // Kind-of arbitrary.
794 return 16;
795 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700796
Dianne Hackborn254cb442010-01-27 19:23:59 -0800797 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800798 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800799 * to meet the policy requirements (quality, minimum length) that have been
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800800 * requested.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700801 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800802 * <p>The calling device admin must have requested
803 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
804 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700805 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800806 * @return Returns true if the password meets the current requirements,
807 * else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800808 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800809 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800810 if (mService != null) {
811 try {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800812 return mService.isActivePasswordSufficient();
Dianne Hackbornd6847842010-01-12 18:14:19 -0800813 } catch (RemoteException e) {
814 Log.w(TAG, "Failed talking with device policy service", e);
815 }
816 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800817 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800818 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700819
Dianne Hackbornd6847842010-01-12 18:14:19 -0800820 /**
821 * Retrieve the number of times the user has failed at entering a
822 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700823 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800824 * <p>The calling device admin must have requested
825 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
826 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 */
828 public int getCurrentFailedPasswordAttempts() {
829 if (mService != null) {
830 try {
831 return mService.getCurrentFailedPasswordAttempts();
832 } catch (RemoteException e) {
833 Log.w(TAG, "Failed talking with device policy service", e);
834 }
835 }
836 return -1;
837 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800838
839 /**
Andrew Stadler88209d12010-02-08 22:59:36 -0800840 * Setting this to a value greater than zero enables a built-in policy
841 * that will perform a device wipe after too many incorrect
842 * device-unlock passwords have been entered. This built-in policy combines
843 * watching for failed passwords and wiping the device, and requires
844 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800845 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700846 *
Andrew Stadler88209d12010-02-08 22:59:36 -0800847 * <p>To implement any other policy (e.g. wiping data for a particular
848 * application only, erasing or revoking credentials, or reporting the
849 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800850 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -0800851 * instead. Do not use this API, because if the maximum count is reached,
852 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700853 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800854 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800855 * @param num The number of failed password attempts at which point the
856 * device will wipe its data.
857 */
858 public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) {
859 if (mService != null) {
860 try {
861 mService.setMaximumFailedPasswordsForWipe(admin, num);
862 } catch (RemoteException e) {
863 Log.w(TAG, "Failed talking with device policy service", e);
864 }
865 }
866 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700867
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800868 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800869 * Retrieve the current maximum number of login attempts that are allowed
870 * before the device wipes itself, for all admins
871 * or a particular one.
872 * @param admin The name of the admin component to check, or null to aggregate
873 * all admins.
874 */
875 public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
876 if (mService != null) {
877 try {
878 return mService.getMaximumFailedPasswordsForWipe(admin);
879 } catch (RemoteException e) {
880 Log.w(TAG, "Failed talking with device policy service", e);
881 }
882 }
883 return 0;
884 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700885
Dianne Hackborn254cb442010-01-27 19:23:59 -0800886 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800887 * Flag for {@link #resetPassword}: don't allow other admins to change
888 * the password again until the user has entered it.
889 */
890 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700891
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800892 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800893 * Force a new device unlock password (the password needed to access the
894 * entire device, not for individual accounts) on the user. This takes
895 * effect immediately.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800896 * The given password must be sufficient for the
897 * current password quality and length constraints as returned by
898 * {@link #getPasswordQuality(ComponentName)} and
899 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
900 * these constraints, then it will be rejected and false returned. Note
901 * that the password may be a stronger quality (containing alphanumeric
902 * characters when the requested quality is only numeric), in which case
903 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700904 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800905 * <p>The calling device admin must have requested
906 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
907 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700908 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800909 * @param password The new password for the user.
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800910 * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800911 * @return Returns true if the password was applied, or false if it is
912 * not acceptable for the current constraints.
913 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800914 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800915 if (mService != null) {
916 try {
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800917 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800918 } catch (RemoteException e) {
919 Log.w(TAG, "Failed talking with device policy service", e);
920 }
921 }
922 return false;
923 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700924
Dianne Hackbornd6847842010-01-12 18:14:19 -0800925 /**
926 * Called by an application that is administering the device to set the
927 * maximum time for user activity until the device will lock. This limits
928 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700929 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800930 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -0800931 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800932 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700933 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -0800934 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800935 * @param timeMs The new desired maximum time to lock in milliseconds.
936 * A value of 0 means there is no restriction.
937 */
938 public void setMaximumTimeToLock(ComponentName admin, long timeMs) {
939 if (mService != null) {
940 try {
941 mService.setMaximumTimeToLock(admin, timeMs);
942 } catch (RemoteException e) {
943 Log.w(TAG, "Failed talking with device policy service", e);
944 }
945 }
946 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700947
Dianne Hackbornd6847842010-01-12 18:14:19 -0800948 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -0800949 * Retrieve the current maximum time to unlock for all admins
950 * or a particular one.
951 * @param admin The name of the admin component to check, or null to aggregate
952 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800953 */
Dianne Hackborn254cb442010-01-27 19:23:59 -0800954 public long getMaximumTimeToLock(ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800955 if (mService != null) {
956 try {
Dianne Hackborn254cb442010-01-27 19:23:59 -0800957 return mService.getMaximumTimeToLock(admin);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800958 } catch (RemoteException e) {
959 Log.w(TAG, "Failed talking with device policy service", e);
960 }
961 }
962 return 0;
963 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700964
Dianne Hackbornd6847842010-01-12 18:14:19 -0800965 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800966 * Make the device lock immediately, as if the lock screen timeout has
967 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700968 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800969 * <p>The calling device admin must have requested
970 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
971 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800972 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800973 public void lockNow() {
974 if (mService != null) {
975 try {
976 mService.lockNow();
977 } catch (RemoteException e) {
978 Log.w(TAG, "Failed talking with device policy service", e);
979 }
980 }
981 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700982
Dianne Hackbornd6847842010-01-12 18:14:19 -0800983 /**
Dianne Hackborn42499172010-10-15 18:45:07 -0700984 * Flag for {@link #wipeData(int)}: also erase the device's external
985 * storage.
986 */
987 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
988
989 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800990 * Ask the user date be wiped. This will cause the device to reboot,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800991 * erasing all user data while next booting up. External storage such
992 * as SD cards will not be erased.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700993 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800994 * <p>The calling device admin must have requested
995 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
996 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700997 *
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800998 * @param flags Bit mask of additional options: currently must be 0.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800999 */
1000 public void wipeData(int flags) {
1001 if (mService != null) {
1002 try {
1003 mService.wipeData(flags);
1004 } catch (RemoteException e) {
1005 Log.w(TAG, "Failed talking with device policy service", e);
1006 }
1007 }
1008 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001009
Dianne Hackbornd6847842010-01-12 18:14:19 -08001010 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001011 * Called by an application that is administering the device to set the
1012 * global proxy and exclusion list.
1013 * <p>
1014 * The calling device admin must have requested
1015 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1016 * this method; if it has not, a security exception will be thrown.
1017 * Only the first device admin can set the proxy. If a second admin attempts
1018 * to set the proxy, the {@link ComponentName} of the admin originally setting the
1019 * proxy will be returned. If successful in setting the proxy, null will
1020 * be returned.
1021 * The method can be called repeatedly by the device admin alrady setting the
1022 * proxy to update the proxy and exclusion list.
1023 *
1024 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1025 * with.
1026 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1027 * Pass Proxy.NO_PROXY to reset the proxy.
1028 * @param exclusionList a list of domains to be excluded from the global proxy.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001029 * @return returns null if the proxy was successfully set, or a {@link ComponentName}
1030 * of the device admin that sets thew proxy otherwise.
1031 */
1032 public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
1033 List<String> exclusionList ) {
1034 if (proxySpec == null) {
1035 throw new NullPointerException();
1036 }
1037 if (mService != null) {
1038 try {
1039 String hostSpec;
1040 String exclSpec;
1041 if (proxySpec.equals(Proxy.NO_PROXY)) {
1042 hostSpec = null;
1043 exclSpec = null;
1044 } else {
1045 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1046 throw new IllegalArgumentException();
1047 }
1048 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1049 String hostName = sa.getHostName();
1050 int port = sa.getPort();
1051 StringBuilder hostBuilder = new StringBuilder();
1052 hostSpec = hostBuilder.append(hostName)
1053 .append(":").append(Integer.toString(port)).toString();
1054 if (exclusionList == null) {
1055 exclSpec = "";
1056 } else {
1057 StringBuilder listBuilder = new StringBuilder();
1058 boolean firstDomain = true;
1059 for (String exclDomain : exclusionList) {
1060 if (!firstDomain) {
1061 listBuilder = listBuilder.append(",");
1062 } else {
1063 firstDomain = false;
1064 }
1065 listBuilder = listBuilder.append(exclDomain.trim());
1066 }
1067 exclSpec = listBuilder.toString();
1068 }
1069 android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec);
1070 }
1071 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
1072 } catch (RemoteException e) {
1073 Log.w(TAG, "Failed talking with device policy service", e);
1074 }
1075 }
1076 return null;
1077 }
1078
1079 /**
1080 * Returns the component name setting the global proxy.
1081 * @return ComponentName object of the device admin that set the global proxy, or
1082 * null if no admin has set the proxy.
1083 */
1084 public ComponentName getGlobalProxyAdmin() {
1085 if (mService != null) {
1086 try {
1087 return mService.getGlobalProxyAdmin();
1088 } catch (RemoteException e) {
1089 Log.w(TAG, "Failed talking with device policy service", e);
1090 }
1091 }
1092 return null;
1093 }
1094
1095 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001096 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001097 * indicating that encryption is not supported.
1098 */
1099 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1100
1101 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001102 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001103 * indicating that encryption is supported, but is not currently active.
1104 */
1105 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1106
1107 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001108 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001109 * indicating that encryption is not currently active, but is currently
1110 * being activated. This is only reported by devices that support
1111 * encryption of data and only when the storage is currently
1112 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
1113 * to become encrypted will never return this value.
1114 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001115 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001116
1117 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08001118 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001119 * indicating that encryption is active.
1120 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001121 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001122
1123 /**
1124 * Activity action: begin the process of encrypting data on the device. This activity should
1125 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
1126 * After resuming from this activity, use {@link #getStorageEncryption}
1127 * to check encryption status. However, on some devices this activity may never return, as
1128 * it may trigger a reboot and in some cases a complete data wipe of the device.
1129 */
1130 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1131 public static final String ACTION_START_ENCRYPTION
1132 = "android.app.action.START_ENCRYPTION";
1133
1134 /**
1135 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001136 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001137 *
1138 * <p>When multiple device administrators attempt to control device
1139 * encryption, the most secure, supported setting will always be
1140 * used. If any device administrator requests device encryption,
1141 * it will be enabled; Conversely, if a device administrator
1142 * attempts to disable device encryption while another
1143 * device administrator has enabled it, the call to disable will
1144 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
1145 *
1146 * <p>This policy controls encryption of the secure (application data) storage area. Data
1147 * written to other areas (e.g. the directory returned by
1148 * {@link android.os.Environment#getExternalStorageDirectory()} may or may not be encrypted.
1149 *
1150 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
1151 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
1152 * the encryption key may not be fully secured. For maximum security, the administrator should
1153 * also require (and check for) a pattern, PIN, or password.
1154 *
1155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1156 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08001157 * @return the new request status (for all active admins) - will be one of
1158 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
1159 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
1160 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001161 */
1162 public int setStorageEncryption(ComponentName admin, boolean encrypt) {
1163 if (mService != null) {
1164 try {
1165 return mService.setStorageEncryption(admin, encrypt);
1166 } catch (RemoteException e) {
1167 Log.w(TAG, "Failed talking with device policy service", e);
1168 }
1169 }
1170 return ENCRYPTION_STATUS_UNSUPPORTED;
1171 }
1172
1173 /**
1174 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08001175 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001176 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08001177 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
1178 * this will return the requested encryption setting as an aggregate of all active
1179 * administrators.
1180 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001181 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08001182 public boolean getStorageEncryption(ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001183 if (mService != null) {
1184 try {
1185 return mService.getStorageEncryption(admin);
1186 } catch (RemoteException e) {
1187 Log.w(TAG, "Failed talking with device policy service", e);
1188 }
1189 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08001190 return false;
1191 }
1192
1193 /**
1194 * Called by an application that is administering the device to
1195 * determine the current encryption status of the device.
1196 *
1197 * Depending on the returned status code, the caller may proceed in different
1198 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
1199 * storage system does not support encryption. If the
1200 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
1201 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
1202 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
1203 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
1204 *
1205 * @return current status of encryption. The value will be one of
1206 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
1207 * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}.
1208 */
1209 public int getStorageEncryptionStatus() {
1210 if (mService != null) {
1211 try {
1212 return mService.getStorageEncryptionStatus();
1213 } catch (RemoteException e) {
1214 Log.w(TAG, "Failed talking with device policy service", e);
1215 }
1216 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08001217 return ENCRYPTION_STATUS_UNSUPPORTED;
1218 }
1219
1220 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001221 * @hide
1222 */
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001223 public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001224 if (mService != null) {
1225 try {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001226 mService.setActiveAdmin(policyReceiver, refreshing);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001227 } catch (RemoteException e) {
1228 Log.w(TAG, "Failed talking with device policy service", e);
1229 }
1230 }
1231 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001232
Dianne Hackbornd6847842010-01-12 18:14:19 -08001233 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001234 * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08001235 * @hide
1236 */
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001237 public DeviceAdminInfo getAdminInfo(ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001238 ActivityInfo ai;
1239 try {
1240 ai = mContext.getPackageManager().getReceiverInfo(cn,
1241 PackageManager.GET_META_DATA);
1242 } catch (PackageManager.NameNotFoundException e) {
1243 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
1244 return null;
1245 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001246
Dianne Hackbornd6847842010-01-12 18:14:19 -08001247 ResolveInfo ri = new ResolveInfo();
1248 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001249
Dianne Hackbornd6847842010-01-12 18:14:19 -08001250 try {
1251 return new DeviceAdminInfo(mContext, ri);
1252 } catch (XmlPullParserException e) {
1253 Log.w(TAG, "Unable to parse device policy " + cn, e);
1254 return null;
1255 } catch (IOException e) {
1256 Log.w(TAG, "Unable to parse device policy " + cn, e);
1257 return null;
1258 }
1259 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001260
Dianne Hackbornd6847842010-01-12 18:14:19 -08001261 /**
1262 * @hide
1263 */
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001264 public void getRemoveWarning(ComponentName admin, RemoteCallback result) {
1265 if (mService != null) {
1266 try {
1267 mService.getRemoveWarning(admin, result);
1268 } catch (RemoteException e) {
1269 Log.w(TAG, "Failed talking with device policy service", e);
1270 }
1271 }
1272 }
1273
1274 /**
1275 * @hide
1276 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001277 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001278 int lowercase, int numbers, int symbols, int nonletter) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001279 if (mService != null) {
1280 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001281 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001282 numbers, symbols, nonletter);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001283 } catch (RemoteException e) {
1284 Log.w(TAG, "Failed talking with device policy service", e);
1285 }
1286 }
1287 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001288
Dianne Hackbornd6847842010-01-12 18:14:19 -08001289 /**
1290 * @hide
1291 */
1292 public void reportFailedPasswordAttempt() {
1293 if (mService != null) {
1294 try {
1295 mService.reportFailedPasswordAttempt();
1296 } catch (RemoteException e) {
1297 Log.w(TAG, "Failed talking with device policy service", e);
1298 }
1299 }
1300 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001301
Dianne Hackbornd6847842010-01-12 18:14:19 -08001302 /**
1303 * @hide
1304 */
1305 public void reportSuccessfulPasswordAttempt() {
1306 if (mService != null) {
1307 try {
1308 mService.reportSuccessfulPasswordAttempt();
1309 } catch (RemoteException e) {
1310 Log.w(TAG, "Failed talking with device policy service", e);
1311 }
1312 }
1313 }
Oscar Montemayor69238c62010-08-03 10:51:06 -07001314
Dianne Hackbornd6847842010-01-12 18:14:19 -08001315}