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"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 46 | |
| 47 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 48 | private final IDevicePolicyManager mService; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 49 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 50 | private DevicePolicyManager(Context context, Handler handler) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 51 | mContext = context; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 52 | mService = IDevicePolicyManager.Stub.asInterface( |
| 53 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 54 | } |
| 55 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 56 | /** @hide */ |
| 57 | public static DevicePolicyManager create(Context context, Handler handler) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 58 | DevicePolicyManager me = new DevicePolicyManager(context, handler); |
| 59 | return me.mService != null ? me : null; |
| 60 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 61 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 62 | /** |
| 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 68 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 69 | * <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 Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 72 | * |
| 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 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 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 182 | * 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 Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 202 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 203 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 204 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 205 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 206 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 207 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 208 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 209 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
| 210 | * 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] | 211 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 212 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 213 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 214 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 215 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 216 | * 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 Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 219 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 220 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 221 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 222 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 223 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 224 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 229 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 230 | /** |
| 231 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 232 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 233 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 234 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 235 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 236 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 237 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 238 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 239 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 240 | * 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 247 | */ |
| 248 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 249 | |
| 250 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 251 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 258 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 259 | * <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 Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 261 | * the user's preference, and any other considerations) is the one that |
| 262 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 263 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 264 | * <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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 267 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 268 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 269 | * @param quality The new desired quality. One of |
| 270 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 271 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 272 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 273 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 274 | public void setPasswordQuality(ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 275 | if (mService != null) { |
| 276 | try { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 277 | mService.setPasswordQuality(admin, quality); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 278 | } catch (RemoteException e) { |
| 279 | Log.w(TAG, "Failed talking with device policy service", e); |
| 280 | } |
| 281 | } |
| 282 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 283 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 284 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 285 | * Retrieve the current minimum password quality for all admins |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 286 | * or a particular one. |
| 287 | * @param admin The name of the admin component to check, or null to aggregate |
| 288 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 289 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 290 | public int getPasswordQuality(ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 291 | if (mService != null) { |
| 292 | try { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 293 | return mService.getPasswordQuality(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 294 | } catch (RemoteException e) { |
| 295 | Log.w(TAG, "Failed talking with device policy service", e); |
| 296 | } |
| 297 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 298 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 299 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 300 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 301 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 302 | * 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 310 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC} |
| 311 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 312 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 313 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 314 | * <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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 317 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 318 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 319 | * @param length The new desired minimum password length. A value of 0 |
| 320 | * means there is no restriction. |
| 321 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 322 | public void setPasswordMinimumLength(ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 323 | if (mService != null) { |
| 324 | try { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 325 | mService.setPasswordMinimumLength(admin, length); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 326 | } catch (RemoteException e) { |
| 327 | Log.w(TAG, "Failed talking with device policy service", e); |
| 328 | } |
| 329 | } |
| 330 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 331 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 332 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 333 | * 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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 337 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 338 | public int getPasswordMinimumLength(ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 339 | if (mService != null) { |
| 340 | try { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 341 | return mService.getPasswordMinimumLength(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 342 | } catch (RemoteException e) { |
| 343 | Log.w(TAG, "Failed talking with device policy service", e); |
| 344 | } |
| 345 | } |
| 346 | return 0; |
| 347 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 348 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 349 | /** |
| 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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 358 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 359 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 360 | * <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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 383 | * 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 387 | * |
| 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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 413 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 414 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 415 | * <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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 438 | * 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 442 | * |
| 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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 468 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 469 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 470 | * <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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 492 | * 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 496 | * |
| 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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 521 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 522 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 523 | * <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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 545 | * 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 549 | * |
| 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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 574 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 575 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 576 | * <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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 598 | * 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 602 | * |
| 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 Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 618 | /** |
| 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 671 | /** |
| 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 Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 704 | * 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 Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 714 | * <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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 769 | * 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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 786 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 787 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 788 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 789 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 790 | * @return Returns the maximum length that the user can enter. |
| 791 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 792 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 793 | // Kind-of arbitrary. |
| 794 | return 16; |
| 795 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 796 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 797 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 798 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 799 | * to meet the policy requirements (quality, minimum length) that have been |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 800 | * requested. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 801 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 802 | * <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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 805 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 806 | * @return Returns true if the password meets the current requirements, |
| 807 | * else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 808 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 809 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 810 | if (mService != null) { |
| 811 | try { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 812 | return mService.isActivePasswordSufficient(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 813 | } catch (RemoteException e) { |
| 814 | Log.w(TAG, "Failed talking with device policy service", e); |
| 815 | } |
| 816 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 817 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 818 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 819 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 820 | /** |
| 821 | * Retrieve the number of times the user has failed at entering a |
| 822 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 823 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 824 | * <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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 827 | */ |
| 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 Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 838 | |
| 839 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 840 | * 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 Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 845 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 846 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 847 | * <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 Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 850 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 851 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 853 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 854 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 855 | * @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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 867 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 868 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 869 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 885 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 886 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 887 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 891 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 892 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 893 | * 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 Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 896 | * 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 904 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 905 | * <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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 908 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 909 | * @param password The new password for the user. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 910 | * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 911 | * @return Returns true if the password was applied, or false if it is |
| 912 | * not acceptable for the current constraints. |
| 913 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 914 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 915 | if (mService != null) { |
| 916 | try { |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 917 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 918 | } catch (RemoteException e) { |
| 919 | Log.w(TAG, "Failed talking with device policy service", e); |
| 920 | } |
| 921 | } |
| 922 | return false; |
| 923 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 924 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 925 | /** |
| 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 929 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 930 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 931 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 932 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 933 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 934 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 935 | * @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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 947 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 948 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 949 | * 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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 953 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 954 | public long getMaximumTimeToLock(ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 955 | if (mService != null) { |
| 956 | try { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 957 | return mService.getMaximumTimeToLock(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 958 | } catch (RemoteException e) { |
| 959 | Log.w(TAG, "Failed talking with device policy service", e); |
| 960 | } |
| 961 | } |
| 962 | return 0; |
| 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 | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 966 | * Make the device lock immediately, as if the lock screen timeout has |
| 967 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 968 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 969 | * <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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 972 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 973 | 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 982 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 983 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 984 | * 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 Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 990 | * 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] | 991 | * erasing all user data while next booting up. External storage such |
| 992 | * as SD cards will not be erased. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 993 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 994 | * <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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 997 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 998 | * @param flags Bit mask of additional options: currently must be 0. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 999 | */ |
| 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1009 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1010 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1011 | * 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 Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1029 | * @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 Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1096 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1097 | * indicating that encryption is not supported. |
| 1098 | */ |
| 1099 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 1100 | |
| 1101 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1102 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1103 | * indicating that encryption is supported, but is not currently active. |
| 1104 | */ |
| 1105 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 1106 | |
| 1107 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1108 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1109 | * 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 Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1115 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1116 | |
| 1117 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1118 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1119 | * indicating that encryption is active. |
| 1120 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1121 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1122 | |
| 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 Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1136 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1137 | * |
| 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 Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1157 | * @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 Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1161 | */ |
| 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 Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1175 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1176 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1177 | * @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 Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1181 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1182 | public boolean getStorageEncryption(ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1183 | 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 Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame^] | 1190 | 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 Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1217 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1218 | } |
| 1219 | |
| 1220 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1221 | * @hide |
| 1222 | */ |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1223 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1224 | if (mService != null) { |
| 1225 | try { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1226 | mService.setActiveAdmin(policyReceiver, refreshing); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1227 | } catch (RemoteException e) { |
| 1228 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1229 | } |
| 1230 | } |
| 1231 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1232 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1233 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1234 | * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1235 | * @hide |
| 1236 | */ |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1237 | public DeviceAdminInfo getAdminInfo(ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1238 | 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1246 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1247 | ResolveInfo ri = new ResolveInfo(); |
| 1248 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1249 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1250 | 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1260 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1261 | /** |
| 1262 | * @hide |
| 1263 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1264 | 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 Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1277 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1278 | int lowercase, int numbers, int symbols, int nonletter) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1279 | if (mService != null) { |
| 1280 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1281 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1282 | numbers, symbols, nonletter); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1283 | } catch (RemoteException e) { |
| 1284 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1285 | } |
| 1286 | } |
| 1287 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1288 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1289 | /** |
| 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 Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1301 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1302 | /** |
| 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 Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1314 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1315 | } |