Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 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 Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
| 19 | import org.xmlpull.v1.XmlPullParserException; |
| 20 | |
| 21 | import android.annotation.SdkConstant; |
| 22 | import android.annotation.SdkConstant.SdkConstantType; |
| 23 | import android.content.ComponentName; |
| 24 | import android.content.Context; |
| 25 | import android.content.pm.ActivityInfo; |
| 26 | import android.content.pm.PackageManager; |
| 27 | import android.content.pm.ResolveInfo; |
| 28 | import android.os.Handler; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 29 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 30 | import android.os.RemoteException; |
| 31 | import android.os.ServiceManager; |
| 32 | import android.util.Log; |
| 33 | |
| 34 | import java.io.IOException; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 35 | import java.net.InetSocketAddress; |
| 36 | import java.net.Proxy; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 37 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Public interface for managing policies enforced on a device. Most clients |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 41 | * of this class must have published a {@link DeviceAdminReceiver} that the user |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 42 | * has currently enabled. |
| 43 | */ |
| 44 | public class DevicePolicyManager { |
| 45 | private static String TAG = "DevicePolicyManager"; |
| 46 | private static boolean DEBUG = false; |
| 47 | private static boolean localLOGV = DEBUG || android.util.Config.LOGV; |
| 48 | |
| 49 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 50 | private final IDevicePolicyManager mService; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 51 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 52 | private final Handler mHandler; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 53 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 54 | private DevicePolicyManager(Context context, Handler handler) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 55 | mContext = context; |
| 56 | mHandler = handler; |
| 57 | mService = IDevicePolicyManager.Stub.asInterface( |
| 58 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 59 | } |
| 60 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 61 | /** @hide */ |
| 62 | public static DevicePolicyManager create(Context context, Handler handler) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 63 | DevicePolicyManager me = new DevicePolicyManager(context, handler); |
| 64 | return me.mService != null ? me : null; |
| 65 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 66 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 67 | /** |
| 68 | * Activity action: ask the user to add a new device administrator to the system. |
| 69 | * The desired policy is the ComponentName of the policy in the |
| 70 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 71 | * bring the user through adding the device administrator to the system (or |
| 72 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 73 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 74 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 75 | * field to provide the user with additional explanation (in addition |
| 76 | * to your component's description) about what is being added. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 77 | */ |
| 78 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 79 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 80 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 81 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 82 | /** |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 83 | * 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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 92 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 97 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 99 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 105 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 106 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 107 | * 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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 115 | */ |
| 116 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 117 | public static final String ACTION_SET_NEW_PASSWORD |
| 118 | = "android.app.action.SET_NEW_PASSWORD"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 119 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 120 | /** |
| 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 Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 127 | return mService.isAdminActive(who); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 128 | } catch (RemoteException e) { |
| 129 | Log.w(TAG, "Failed talking with device policy service", e); |
| 130 | } |
| 131 | } |
| 132 | return false; |
| 133 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 134 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 135 | /** |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 136 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 150 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 151 | /** |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 152 | * @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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 164 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 165 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 166 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 180 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 181 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 182 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 183 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 184 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 185 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 186 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 187 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 188 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 189 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
| 190 | * of password, but doesn't care what it is. Note that quality constants |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 191 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 192 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 193 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 194 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 195 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 196 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 197 | * password containing at least numeric characters. Note that quality |
| 198 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 199 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 200 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 201 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 202 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 203 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 204 | * password containing at least alphabetic (or other symbol) characters. |
| 205 | * Note that quality constants are ordered so that higher values are more |
| 206 | * restrictive. |
| 207 | */ |
| 208 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 209 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 210 | /** |
| 211 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 212 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 213 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 214 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 215 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 216 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 217 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 218 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 219 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 220 | * password containing at least a letter, a numerical digit and a special |
| 221 | * symbol, by default. With this password quality, passwords can be |
| 222 | * restricted to contain various sets of characters, like at least an |
| 223 | * uppercase letter, etc. These are specified using various methods, |
| 224 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 225 | * that quality constants are ordered so that higher values are more |
| 226 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 227 | */ |
| 228 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 229 | |
| 230 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 231 | * Called by an application that is administering the device to set the |
| 232 | * password restrictions it is imposing. After setting this, the user |
| 233 | * will not be able to enter a new password that is not at least as |
| 234 | * restrictive as what has been set. Note that the current password |
| 235 | * will remain until the user has set a new one, so the change does not |
| 236 | * take place immediately. To prompt the user for a new password, use |
| 237 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 238 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 239 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 240 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 241 | * the user's preference, and any other considerations) is the one that |
| 242 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 243 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 244 | * <p>The calling device admin must have requested |
| 245 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 246 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 247 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 248 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 249 | * @param quality The new desired quality. One of |
| 250 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 251 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 252 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 253 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 254 | public void setPasswordQuality(ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 255 | if (mService != null) { |
| 256 | try { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 257 | mService.setPasswordQuality(admin, quality); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 258 | } catch (RemoteException e) { |
| 259 | Log.w(TAG, "Failed talking with device policy service", e); |
| 260 | } |
| 261 | } |
| 262 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 263 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 264 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 265 | * Retrieve the current minimum password quality for all admins |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 266 | * or a particular one. |
| 267 | * @param admin The name of the admin component to check, or null to aggregate |
| 268 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 269 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 270 | public int getPasswordQuality(ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 271 | if (mService != null) { |
| 272 | try { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 273 | return mService.getPasswordQuality(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 274 | } catch (RemoteException e) { |
| 275 | Log.w(TAG, "Failed talking with device policy service", e); |
| 276 | } |
| 277 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 278 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 279 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 280 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 281 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 282 | * Called by an application that is administering the device to set the |
| 283 | * minimum allowed password length. After setting this, the user |
| 284 | * will not be able to enter a new password that is not at least as |
| 285 | * restrictive as what has been set. Note that the current password |
| 286 | * will remain until the user has set a new one, so the change does not |
| 287 | * take place immediately. To prompt the user for a new password, use |
| 288 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 289 | * constraint is only imposed if the administrator has also requested either |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 290 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC} |
| 291 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 292 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 293 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 294 | * <p>The calling device admin must have requested |
| 295 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 296 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 297 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 298 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 299 | * @param length The new desired minimum password length. A value of 0 |
| 300 | * means there is no restriction. |
| 301 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 302 | public void setPasswordMinimumLength(ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 303 | if (mService != null) { |
| 304 | try { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 305 | mService.setPasswordMinimumLength(admin, length); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 306 | } catch (RemoteException e) { |
| 307 | Log.w(TAG, "Failed talking with device policy service", e); |
| 308 | } |
| 309 | } |
| 310 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 311 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 312 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 313 | * Retrieve the current minimum password length for all admins |
| 314 | * or a particular one. |
| 315 | * @param admin The name of the admin component to check, or null to aggregate |
| 316 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 317 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 318 | public int getPasswordMinimumLength(ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 319 | if (mService != null) { |
| 320 | try { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 321 | return mService.getPasswordMinimumLength(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 322 | } catch (RemoteException e) { |
| 323 | Log.w(TAG, "Failed talking with device policy service", e); |
| 324 | } |
| 325 | } |
| 326 | return 0; |
| 327 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 328 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 329 | /** |
| 330 | * Called by an application that is administering the device to set the |
| 331 | * minimum number of upper case letters required in the password. After |
| 332 | * setting this, the user will not be able to enter a new password that is |
| 333 | * not at least as restrictive as what has been set. Note that the current |
| 334 | * password will remain until the user has set a new one, so the change does |
| 335 | * not take place immediately. To prompt the user for a new password, use |
| 336 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 337 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 338 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 339 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 340 | * <p> |
| 341 | * The calling device admin must have requested |
| 342 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 343 | * this method; if it has not, a security exception will be thrown. |
| 344 | * |
| 345 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 346 | * with. |
| 347 | * @param length The new desired minimum number of upper case letters |
| 348 | * required in the password. A value of 0 means there is no |
| 349 | * restriction. |
| 350 | */ |
| 351 | public void setPasswordMinimumUpperCase(ComponentName admin, int length) { |
| 352 | if (mService != null) { |
| 353 | try { |
| 354 | mService.setPasswordMinimumUpperCase(admin, length); |
| 355 | } catch (RemoteException e) { |
| 356 | Log.w(TAG, "Failed talking with device policy service", e); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Retrieve the current number of upper case letters required in the |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 363 | * password for all admins or a particular one. This is the same value as |
| 364 | * set by {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
| 365 | * and only applies when the password quality is |
| 366 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 367 | * |
| 368 | * @param admin The name of the admin component to check, or null to |
| 369 | * aggregate all admins. |
| 370 | * @return The minimum number of upper case letters required in the |
| 371 | * password. |
| 372 | */ |
| 373 | public int getPasswordMinimumUpperCase(ComponentName admin) { |
| 374 | if (mService != null) { |
| 375 | try { |
| 376 | return mService.getPasswordMinimumUpperCase(admin); |
| 377 | } catch (RemoteException e) { |
| 378 | Log.w(TAG, "Failed talking with device policy service", e); |
| 379 | } |
| 380 | } |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Called by an application that is administering the device to set the |
| 386 | * minimum number of lower case letters required in the password. After |
| 387 | * setting this, the user will not be able to enter a new password that is |
| 388 | * not at least as restrictive as what has been set. Note that the current |
| 389 | * password will remain until the user has set a new one, so the change does |
| 390 | * not take place immediately. To prompt the user for a new password, use |
| 391 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 392 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 393 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 394 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 395 | * <p> |
| 396 | * The calling device admin must have requested |
| 397 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 398 | * this method; if it has not, a security exception will be thrown. |
| 399 | * |
| 400 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 401 | * with. |
| 402 | * @param length The new desired minimum number of lower case letters |
| 403 | * required in the password. A value of 0 means there is no |
| 404 | * restriction. |
| 405 | */ |
| 406 | public void setPasswordMinimumLowerCase(ComponentName admin, int length) { |
| 407 | if (mService != null) { |
| 408 | try { |
| 409 | mService.setPasswordMinimumLowerCase(admin, length); |
| 410 | } catch (RemoteException e) { |
| 411 | Log.w(TAG, "Failed talking with device policy service", e); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Retrieve the current number of lower case letters required in the |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 418 | * password for all admins or a particular one. This is the same value as |
| 419 | * set by {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
| 420 | * and only applies when the password quality is |
| 421 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 422 | * |
| 423 | * @param admin The name of the admin component to check, or null to |
| 424 | * aggregate all admins. |
| 425 | * @return The minimum number of lower case letters required in the |
| 426 | * password. |
| 427 | */ |
| 428 | public int getPasswordMinimumLowerCase(ComponentName admin) { |
| 429 | if (mService != null) { |
| 430 | try { |
| 431 | return mService.getPasswordMinimumLowerCase(admin); |
| 432 | } catch (RemoteException e) { |
| 433 | Log.w(TAG, "Failed talking with device policy service", e); |
| 434 | } |
| 435 | } |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Called by an application that is administering the device to set the |
| 441 | * minimum number of letters required in the password. After setting this, |
| 442 | * the user will not be able to enter a new password that is not at least as |
| 443 | * restrictive as what has been set. Note that the current password will |
| 444 | * remain until the user has set a new one, so the change does not take |
| 445 | * place immediately. To prompt the user for a new password, use |
| 446 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 447 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 448 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 449 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 450 | * <p> |
| 451 | * The calling device admin must have requested |
| 452 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 453 | * this method; if it has not, a security exception will be thrown. |
| 454 | * |
| 455 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 456 | * with. |
| 457 | * @param length The new desired minimum number of letters required in the |
| 458 | * password. A value of 0 means there is no restriction. |
| 459 | */ |
| 460 | public void setPasswordMinimumLetters(ComponentName admin, int length) { |
| 461 | if (mService != null) { |
| 462 | try { |
| 463 | mService.setPasswordMinimumLetters(admin, length); |
| 464 | } catch (RemoteException e) { |
| 465 | Log.w(TAG, "Failed talking with device policy service", e); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 472 | * admins or a particular one. This is the same value as |
| 473 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 474 | * and only applies when the password quality is |
| 475 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 476 | * |
| 477 | * @param admin The name of the admin component to check, or null to |
| 478 | * aggregate all admins. |
| 479 | * @return The minimum number of letters required in the password. |
| 480 | */ |
| 481 | public int getPasswordMinimumLetters(ComponentName admin) { |
| 482 | if (mService != null) { |
| 483 | try { |
| 484 | return mService.getPasswordMinimumLetters(admin); |
| 485 | } catch (RemoteException e) { |
| 486 | Log.w(TAG, "Failed talking with device policy service", e); |
| 487 | } |
| 488 | } |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Called by an application that is administering the device to set the |
| 494 | * minimum number of numerical digits required in the password. After |
| 495 | * setting this, the user will not be able to enter a new password that is |
| 496 | * not at least as restrictive as what has been set. Note that the current |
| 497 | * password will remain until the user has set a new one, so the change does |
| 498 | * not take place immediately. To prompt the user for a new password, use |
| 499 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 500 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 501 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 502 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 503 | * <p> |
| 504 | * The calling device admin must have requested |
| 505 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 506 | * this method; if it has not, a security exception will be thrown. |
| 507 | * |
| 508 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 509 | * with. |
| 510 | * @param length The new desired minimum number of numerical digits required |
| 511 | * in the password. A value of 0 means there is no restriction. |
| 512 | */ |
| 513 | public void setPasswordMinimumNumeric(ComponentName admin, int length) { |
| 514 | if (mService != null) { |
| 515 | try { |
| 516 | mService.setPasswordMinimumNumeric(admin, length); |
| 517 | } catch (RemoteException e) { |
| 518 | Log.w(TAG, "Failed talking with device policy service", e); |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Retrieve the current number of numerical digits required in the password |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 525 | * for all admins or a particular one. This is the same value as |
| 526 | * set by {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
| 527 | * and only applies when the password quality is |
| 528 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 529 | * |
| 530 | * @param admin The name of the admin component to check, or null to |
| 531 | * aggregate all admins. |
| 532 | * @return The minimum number of numerical digits required in the password. |
| 533 | */ |
| 534 | public int getPasswordMinimumNumeric(ComponentName admin) { |
| 535 | if (mService != null) { |
| 536 | try { |
| 537 | return mService.getPasswordMinimumNumeric(admin); |
| 538 | } catch (RemoteException e) { |
| 539 | Log.w(TAG, "Failed talking with device policy service", e); |
| 540 | } |
| 541 | } |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Called by an application that is administering the device to set the |
| 547 | * minimum number of symbols required in the password. After setting this, |
| 548 | * the user will not be able to enter a new password that is not at least as |
| 549 | * restrictive as what has been set. Note that the current password will |
| 550 | * remain until the user has set a new one, so the change does not take |
| 551 | * place immediately. To prompt the user for a new password, use |
| 552 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 553 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 554 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 555 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 556 | * <p> |
| 557 | * The calling device admin must have requested |
| 558 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 559 | * this method; if it has not, a security exception will be thrown. |
| 560 | * |
| 561 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 562 | * with. |
| 563 | * @param length The new desired minimum number of symbols required in the |
| 564 | * password. A value of 0 means there is no restriction. |
| 565 | */ |
| 566 | public void setPasswordMinimumSymbols(ComponentName admin, int length) { |
| 567 | if (mService != null) { |
| 568 | try { |
| 569 | mService.setPasswordMinimumSymbols(admin, length); |
| 570 | } catch (RemoteException e) { |
| 571 | Log.w(TAG, "Failed talking with device policy service", e); |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 578 | * admins or a particular one. This is the same value as |
| 579 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 580 | * and only applies when the password quality is |
| 581 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 582 | * |
| 583 | * @param admin The name of the admin component to check, or null to |
| 584 | * aggregate all admins. |
| 585 | * @return The minimum number of symbols required in the password. |
| 586 | */ |
| 587 | public int getPasswordMinimumSymbols(ComponentName admin) { |
| 588 | if (mService != null) { |
| 589 | try { |
| 590 | return mService.getPasswordMinimumSymbols(admin); |
| 591 | } catch (RemoteException e) { |
| 592 | Log.w(TAG, "Failed talking with device policy service", e); |
| 593 | } |
| 594 | } |
| 595 | return 0; |
| 596 | } |
| 597 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 598 | /** |
| 599 | * Called by an application that is administering the device to set the |
| 600 | * minimum number of non-letter characters (numerical digits or symbols) |
| 601 | * required in the password. After setting this, the user will not be able |
| 602 | * to enter a new password that is not at least as restrictive as what has |
| 603 | * been set. Note that the current password will remain until the user has |
| 604 | * set a new one, so the change does not take place immediately. To prompt |
| 605 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 606 | * setting this value. This constraint is only imposed if the administrator |
| 607 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 608 | * {@link #setPasswordQuality}. The default value is 0. |
| 609 | * <p> |
| 610 | * The calling device admin must have requested |
| 611 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 612 | * this method; if it has not, a security exception will be thrown. |
| 613 | * |
| 614 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 615 | * with. |
| 616 | * @param length The new desired minimum number of letters required in the |
| 617 | * password. A value of 0 means there is no restriction. |
| 618 | */ |
| 619 | public void setPasswordMinimumNonLetter(ComponentName admin, int length) { |
| 620 | if (mService != null) { |
| 621 | try { |
| 622 | mService.setPasswordMinimumNonLetter(admin, length); |
| 623 | } catch (RemoteException e) { |
| 624 | Log.w(TAG, "Failed talking with device policy service", e); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Retrieve the current number of non-letter characters required in the |
| 631 | * password for all admins or a particular one. This is the same value as |
| 632 | * set by {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
| 633 | * and only applies when the password quality is |
| 634 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 635 | * |
| 636 | * @param admin The name of the admin component to check, or null to |
| 637 | * aggregate all admins. |
| 638 | * @return The minimum number of letters required in the password. |
| 639 | */ |
| 640 | public int getPasswordMinimumNonLetter(ComponentName admin) { |
| 641 | if (mService != null) { |
| 642 | try { |
| 643 | return mService.getPasswordMinimumNonLetter(admin); |
| 644 | } catch (RemoteException e) { |
| 645 | Log.w(TAG, "Failed talking with device policy service", e); |
| 646 | } |
| 647 | } |
| 648 | return 0; |
| 649 | } |
| 650 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 651 | /** |
| 652 | * Called by an application that is administering the device to set the length |
| 653 | * of the password history. After setting this, the user will not be able to |
| 654 | * enter a new password that is the same as any password in the history. Note |
| 655 | * that the current password will remain until the user has set a new one, so |
| 656 | * the change does not take place immediately. To prompt the user for a new |
| 657 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 658 | * This constraint is only imposed if the administrator has also requested |
| 659 | * either {@link #PASSWORD_QUALITY_NUMERIC}, |
| 660 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 661 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 662 | * |
| 663 | * <p> |
| 664 | * The calling device admin must have requested |
| 665 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 666 | * method; if it has not, a security exception will be thrown. |
| 667 | * |
| 668 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 669 | * with. |
| 670 | * @param length The new desired length of password history. A value of 0 |
| 671 | * means there is no restriction. |
| 672 | */ |
| 673 | public void setPasswordHistoryLength(ComponentName admin, int length) { |
| 674 | if (mService != null) { |
| 675 | try { |
| 676 | mService.setPasswordHistoryLength(admin, length); |
| 677 | } catch (RemoteException e) { |
| 678 | Log.w(TAG, "Failed talking with device policy service", e); |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame^] | 684 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 685 | * will restart the countdown for password expiration for the given admin, as will changing |
| 686 | * the device password (for all admins). |
| 687 | * |
| 688 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 689 | * For example, to have the password expire 5 days from now, timeout would be |
| 690 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 691 | * |
| 692 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 693 | * |
| 694 | * <p>Timeout must be at least 1 day or IllegalArgumentException will be thrown. |
| 695 | * |
| 696 | * <p>The calling device admin must have requested |
| 697 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 698 | * method; if it has not, a security exception will be thrown. |
| 699 | * |
| 700 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 701 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 702 | * means there is no restriction (unlimited). |
| 703 | */ |
| 704 | public void setPasswordExpirationTimeout(ComponentName admin, long timeout) { |
| 705 | if (mService != null) { |
| 706 | try { |
| 707 | mService.setPasswordExpirationTimeout(admin, timeout); |
| 708 | } catch (RemoteException e) { |
| 709 | Log.w(TAG, "Failed talking with device policy service", e); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Get the current password expiration timeout for the given admin or the aggregate |
| 716 | * of all admins if admin is null. |
| 717 | * |
| 718 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 719 | * @return The timeout for the given admin or the minimum of all timeouts |
| 720 | */ |
| 721 | public long getPasswordExpirationTimeout(ComponentName admin) { |
| 722 | if (mService != null) { |
| 723 | try { |
| 724 | return mService.getPasswordExpirationTimeout(admin); |
| 725 | } catch (RemoteException e) { |
| 726 | Log.w(TAG, "Failed talking with device policy service", e); |
| 727 | } |
| 728 | } |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Get the current password expiration time for the given admin or an aggregate of |
| 734 | * all admins if admin is null. |
| 735 | * |
| 736 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 737 | * @return The password expiration time, in ms. |
| 738 | */ |
| 739 | public long getPasswordExpiration(ComponentName admin) { |
| 740 | if (mService != null) { |
| 741 | try { |
| 742 | return mService.getPasswordExpiration(admin); |
| 743 | } catch (RemoteException e) { |
| 744 | Log.w(TAG, "Failed talking with device policy service", e); |
| 745 | } |
| 746 | } |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 751 | * Retrieve the current password history length for all admins |
| 752 | * or a particular one. |
| 753 | * @param admin The name of the admin component to check, or null to aggregate |
| 754 | * all admins. |
| 755 | * @return The length of the password history |
| 756 | */ |
| 757 | public int getPasswordHistoryLength(ComponentName admin) { |
| 758 | if (mService != null) { |
| 759 | try { |
| 760 | return mService.getPasswordHistoryLength(admin); |
| 761 | } catch (RemoteException e) { |
| 762 | Log.w(TAG, "Failed talking with device policy service", e); |
| 763 | } |
| 764 | } |
| 765 | return 0; |
| 766 | } |
| 767 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 768 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 769 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 770 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 771 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 772 | * @return Returns the maximum length that the user can enter. |
| 773 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 774 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 775 | // Kind-of arbitrary. |
| 776 | return 16; |
| 777 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 778 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 779 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 780 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 781 | * to meet the policy requirements (quality, minimum length) that have been |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 782 | * requested. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 783 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 784 | * <p>The calling device admin must have requested |
| 785 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 786 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 787 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 788 | * @return Returns true if the password meets the current requirements, |
| 789 | * else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 790 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 791 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 792 | if (mService != null) { |
| 793 | try { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 794 | return mService.isActivePasswordSufficient(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 795 | } catch (RemoteException e) { |
| 796 | Log.w(TAG, "Failed talking with device policy service", e); |
| 797 | } |
| 798 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 799 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 800 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 801 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 802 | /** |
| 803 | * Retrieve the number of times the user has failed at entering a |
| 804 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 805 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 806 | * <p>The calling device admin must have requested |
| 807 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 808 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 809 | */ |
| 810 | public int getCurrentFailedPasswordAttempts() { |
| 811 | if (mService != null) { |
| 812 | try { |
| 813 | return mService.getCurrentFailedPasswordAttempts(); |
| 814 | } catch (RemoteException e) { |
| 815 | Log.w(TAG, "Failed talking with device policy service", e); |
| 816 | } |
| 817 | } |
| 818 | return -1; |
| 819 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 820 | |
| 821 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 822 | * Setting this to a value greater than zero enables a built-in policy |
| 823 | * that will perform a device wipe after too many incorrect |
| 824 | * device-unlock passwords have been entered. This built-in policy combines |
| 825 | * watching for failed passwords and wiping the device, and requires |
| 826 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 827 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 828 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 829 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 830 | * application only, erasing or revoking credentials, or reporting the |
| 831 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 832 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 833 | * instead. Do not use this API, because if the maximum count is reached, |
| 834 | * the device will be wiped immediately, and your callback will not be invoked. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 835 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 836 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 837 | * @param num The number of failed password attempts at which point the |
| 838 | * device will wipe its data. |
| 839 | */ |
| 840 | public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) { |
| 841 | if (mService != null) { |
| 842 | try { |
| 843 | mService.setMaximumFailedPasswordsForWipe(admin, num); |
| 844 | } catch (RemoteException e) { |
| 845 | Log.w(TAG, "Failed talking with device policy service", e); |
| 846 | } |
| 847 | } |
| 848 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 849 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 850 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 851 | * Retrieve the current maximum number of login attempts that are allowed |
| 852 | * before the device wipes itself, for all admins |
| 853 | * or a particular one. |
| 854 | * @param admin The name of the admin component to check, or null to aggregate |
| 855 | * all admins. |
| 856 | */ |
| 857 | public int getMaximumFailedPasswordsForWipe(ComponentName admin) { |
| 858 | if (mService != null) { |
| 859 | try { |
| 860 | return mService.getMaximumFailedPasswordsForWipe(admin); |
| 861 | } catch (RemoteException e) { |
| 862 | Log.w(TAG, "Failed talking with device policy service", e); |
| 863 | } |
| 864 | } |
| 865 | return 0; |
| 866 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 867 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 868 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 869 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 870 | * the password again until the user has entered it. |
| 871 | */ |
| 872 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 873 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 874 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 875 | * Force a new device unlock password (the password needed to access the |
| 876 | * entire device, not for individual accounts) on the user. This takes |
| 877 | * effect immediately. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 878 | * The given password must be sufficient for the |
| 879 | * current password quality and length constraints as returned by |
| 880 | * {@link #getPasswordQuality(ComponentName)} and |
| 881 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 882 | * these constraints, then it will be rejected and false returned. Note |
| 883 | * that the password may be a stronger quality (containing alphanumeric |
| 884 | * characters when the requested quality is only numeric), in which case |
| 885 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 886 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 887 | * <p>The calling device admin must have requested |
| 888 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 889 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 890 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 891 | * @param password The new password for the user. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 892 | * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 893 | * @return Returns true if the password was applied, or false if it is |
| 894 | * not acceptable for the current constraints. |
| 895 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 896 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 897 | if (mService != null) { |
| 898 | try { |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 899 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 900 | } catch (RemoteException e) { |
| 901 | Log.w(TAG, "Failed talking with device policy service", e); |
| 902 | } |
| 903 | } |
| 904 | return false; |
| 905 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 906 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 907 | /** |
| 908 | * Called by an application that is administering the device to set the |
| 909 | * maximum time for user activity until the device will lock. This limits |
| 910 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 911 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 912 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 913 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 914 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 915 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 916 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 917 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 918 | * A value of 0 means there is no restriction. |
| 919 | */ |
| 920 | public void setMaximumTimeToLock(ComponentName admin, long timeMs) { |
| 921 | if (mService != null) { |
| 922 | try { |
| 923 | mService.setMaximumTimeToLock(admin, timeMs); |
| 924 | } catch (RemoteException e) { |
| 925 | Log.w(TAG, "Failed talking with device policy service", e); |
| 926 | } |
| 927 | } |
| 928 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 929 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 930 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 931 | * Retrieve the current maximum time to unlock for all admins |
| 932 | * or a particular one. |
| 933 | * @param admin The name of the admin component to check, or null to aggregate |
| 934 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 935 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 936 | public long getMaximumTimeToLock(ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 937 | if (mService != null) { |
| 938 | try { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 939 | return mService.getMaximumTimeToLock(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 940 | } catch (RemoteException e) { |
| 941 | Log.w(TAG, "Failed talking with device policy service", e); |
| 942 | } |
| 943 | } |
| 944 | return 0; |
| 945 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 946 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 947 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 948 | * Make the device lock immediately, as if the lock screen timeout has |
| 949 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 950 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 951 | * <p>The calling device admin must have requested |
| 952 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 953 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 954 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 955 | public void lockNow() { |
| 956 | if (mService != null) { |
| 957 | try { |
| 958 | mService.lockNow(); |
| 959 | } catch (RemoteException e) { |
| 960 | Log.w(TAG, "Failed talking with device policy service", e); |
| 961 | } |
| 962 | } |
| 963 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 964 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 965 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 966 | * Flag for {@link #wipeData(int)}: also erase the device's external |
| 967 | * storage. |
| 968 | */ |
| 969 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 970 | |
| 971 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 972 | * Ask the user date be wiped. This will cause the device to reboot, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 973 | * erasing all user data while next booting up. External storage such |
| 974 | * as SD cards will not be erased. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 975 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 976 | * <p>The calling device admin must have requested |
| 977 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 978 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 979 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 980 | * @param flags Bit mask of additional options: currently must be 0. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 981 | */ |
| 982 | public void wipeData(int flags) { |
| 983 | if (mService != null) { |
| 984 | try { |
| 985 | mService.wipeData(flags); |
| 986 | } catch (RemoteException e) { |
| 987 | Log.w(TAG, "Failed talking with device policy service", e); |
| 988 | } |
| 989 | } |
| 990 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 991 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 992 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 993 | * Called by an application that is administering the device to set the |
| 994 | * global proxy and exclusion list. |
| 995 | * <p> |
| 996 | * The calling device admin must have requested |
| 997 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 998 | * this method; if it has not, a security exception will be thrown. |
| 999 | * Only the first device admin can set the proxy. If a second admin attempts |
| 1000 | * to set the proxy, the {@link ComponentName} of the admin originally setting the |
| 1001 | * proxy will be returned. If successful in setting the proxy, null will |
| 1002 | * be returned. |
| 1003 | * The method can be called repeatedly by the device admin alrady setting the |
| 1004 | * proxy to update the proxy and exclusion list. |
| 1005 | * |
| 1006 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1007 | * with. |
| 1008 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 1009 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 1010 | * @param exclusionList a list of domains to be excluded from the global proxy. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1011 | * @return returns null if the proxy was successfully set, or a {@link ComponentName} |
| 1012 | * of the device admin that sets thew proxy otherwise. |
| 1013 | */ |
| 1014 | public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec, |
| 1015 | List<String> exclusionList ) { |
| 1016 | if (proxySpec == null) { |
| 1017 | throw new NullPointerException(); |
| 1018 | } |
| 1019 | if (mService != null) { |
| 1020 | try { |
| 1021 | String hostSpec; |
| 1022 | String exclSpec; |
| 1023 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 1024 | hostSpec = null; |
| 1025 | exclSpec = null; |
| 1026 | } else { |
| 1027 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 1028 | throw new IllegalArgumentException(); |
| 1029 | } |
| 1030 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 1031 | String hostName = sa.getHostName(); |
| 1032 | int port = sa.getPort(); |
| 1033 | StringBuilder hostBuilder = new StringBuilder(); |
| 1034 | hostSpec = hostBuilder.append(hostName) |
| 1035 | .append(":").append(Integer.toString(port)).toString(); |
| 1036 | if (exclusionList == null) { |
| 1037 | exclSpec = ""; |
| 1038 | } else { |
| 1039 | StringBuilder listBuilder = new StringBuilder(); |
| 1040 | boolean firstDomain = true; |
| 1041 | for (String exclDomain : exclusionList) { |
| 1042 | if (!firstDomain) { |
| 1043 | listBuilder = listBuilder.append(","); |
| 1044 | } else { |
| 1045 | firstDomain = false; |
| 1046 | } |
| 1047 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 1048 | } |
| 1049 | exclSpec = listBuilder.toString(); |
| 1050 | } |
| 1051 | android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec); |
| 1052 | } |
| 1053 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
| 1054 | } catch (RemoteException e) { |
| 1055 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1056 | } |
| 1057 | } |
| 1058 | return null; |
| 1059 | } |
| 1060 | |
| 1061 | /** |
| 1062 | * Returns the component name setting the global proxy. |
| 1063 | * @return ComponentName object of the device admin that set the global proxy, or |
| 1064 | * null if no admin has set the proxy. |
| 1065 | */ |
| 1066 | public ComponentName getGlobalProxyAdmin() { |
| 1067 | if (mService != null) { |
| 1068 | try { |
| 1069 | return mService.getGlobalProxyAdmin(); |
| 1070 | } catch (RemoteException e) { |
| 1071 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1072 | } |
| 1073 | } |
| 1074 | return null; |
| 1075 | } |
| 1076 | |
| 1077 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1078 | * @hide |
| 1079 | */ |
| 1080 | public void setActiveAdmin(ComponentName policyReceiver) { |
| 1081 | if (mService != null) { |
| 1082 | try { |
| 1083 | mService.setActiveAdmin(policyReceiver); |
| 1084 | } catch (RemoteException e) { |
| 1085 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1089 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1090 | /** |
| 1091 | * @hide |
| 1092 | */ |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1093 | public DeviceAdminInfo getAdminInfo(ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1094 | ActivityInfo ai; |
| 1095 | try { |
| 1096 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 1097 | PackageManager.GET_META_DATA); |
| 1098 | } catch (PackageManager.NameNotFoundException e) { |
| 1099 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 1100 | return null; |
| 1101 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1102 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1103 | ResolveInfo ri = new ResolveInfo(); |
| 1104 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1105 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1106 | try { |
| 1107 | return new DeviceAdminInfo(mContext, ri); |
| 1108 | } catch (XmlPullParserException e) { |
| 1109 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 1110 | return null; |
| 1111 | } catch (IOException e) { |
| 1112 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 1113 | return null; |
| 1114 | } |
| 1115 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1116 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1117 | /** |
| 1118 | * @hide |
| 1119 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1120 | public void getRemoveWarning(ComponentName admin, RemoteCallback result) { |
| 1121 | if (mService != null) { |
| 1122 | try { |
| 1123 | mService.getRemoveWarning(admin, result); |
| 1124 | } catch (RemoteException e) { |
| 1125 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | /** |
| 1131 | * @hide |
| 1132 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1133 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1134 | int lowercase, int numbers, int symbols, int nonletter) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1135 | if (mService != null) { |
| 1136 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1137 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1138 | numbers, symbols, nonletter); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1139 | } catch (RemoteException e) { |
| 1140 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1141 | } |
| 1142 | } |
| 1143 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1144 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1145 | /** |
| 1146 | * @hide |
| 1147 | */ |
| 1148 | public void reportFailedPasswordAttempt() { |
| 1149 | if (mService != null) { |
| 1150 | try { |
| 1151 | mService.reportFailedPasswordAttempt(); |
| 1152 | } catch (RemoteException e) { |
| 1153 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1154 | } |
| 1155 | } |
| 1156 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1157 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1158 | /** |
| 1159 | * @hide |
| 1160 | */ |
| 1161 | public void reportSuccessfulPasswordAttempt() { |
| 1162 | if (mService != null) { |
| 1163 | try { |
| 1164 | mService.reportSuccessfulPasswordAttempt(); |
| 1165 | } catch (RemoteException e) { |
| 1166 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1167 | } |
| 1168 | } |
| 1169 | } |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1170 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1171 | } |