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 | /** |
| 684 | * Retrieve the current password history length for all admins |
| 685 | * or a particular one. |
| 686 | * @param admin The name of the admin component to check, or null to aggregate |
| 687 | * all admins. |
| 688 | * @return The length of the password history |
| 689 | */ |
| 690 | public int getPasswordHistoryLength(ComponentName admin) { |
| 691 | if (mService != null) { |
| 692 | try { |
| 693 | return mService.getPasswordHistoryLength(admin); |
| 694 | } catch (RemoteException e) { |
| 695 | Log.w(TAG, "Failed talking with device policy service", e); |
| 696 | } |
| 697 | } |
| 698 | return 0; |
| 699 | } |
| 700 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 701 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 702 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 703 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 704 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 705 | * @return Returns the maximum length that the user can enter. |
| 706 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 707 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 708 | // Kind-of arbitrary. |
| 709 | return 16; |
| 710 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 711 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 712 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 713 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 714 | * to meet the policy requirements (quality, minimum length) that have been |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 715 | * requested. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 716 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 717 | * <p>The calling device admin must have requested |
| 718 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 719 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 720 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 721 | * @return Returns true if the password meets the current requirements, |
| 722 | * else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 723 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 724 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 725 | if (mService != null) { |
| 726 | try { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 727 | return mService.isActivePasswordSufficient(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 728 | } catch (RemoteException e) { |
| 729 | Log.w(TAG, "Failed talking with device policy service", e); |
| 730 | } |
| 731 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 732 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 733 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 734 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 735 | /** |
| 736 | * Retrieve the number of times the user has failed at entering a |
| 737 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 738 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 739 | * <p>The calling device admin must have requested |
| 740 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 741 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 742 | */ |
| 743 | public int getCurrentFailedPasswordAttempts() { |
| 744 | if (mService != null) { |
| 745 | try { |
| 746 | return mService.getCurrentFailedPasswordAttempts(); |
| 747 | } catch (RemoteException e) { |
| 748 | Log.w(TAG, "Failed talking with device policy service", e); |
| 749 | } |
| 750 | } |
| 751 | return -1; |
| 752 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 753 | |
| 754 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 755 | * Setting this to a value greater than zero enables a built-in policy |
| 756 | * that will perform a device wipe after too many incorrect |
| 757 | * device-unlock passwords have been entered. This built-in policy combines |
| 758 | * watching for failed passwords and wiping the device, and requires |
| 759 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 760 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 761 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 762 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 763 | * application only, erasing or revoking credentials, or reporting the |
| 764 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 765 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 766 | * instead. Do not use this API, because if the maximum count is reached, |
| 767 | * 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] | 768 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 769 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 770 | * @param num The number of failed password attempts at which point the |
| 771 | * device will wipe its data. |
| 772 | */ |
| 773 | public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) { |
| 774 | if (mService != null) { |
| 775 | try { |
| 776 | mService.setMaximumFailedPasswordsForWipe(admin, num); |
| 777 | } catch (RemoteException e) { |
| 778 | Log.w(TAG, "Failed talking with device policy service", e); |
| 779 | } |
| 780 | } |
| 781 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 782 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 783 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 784 | * Retrieve the current maximum number of login attempts that are allowed |
| 785 | * before the device wipes itself, for all admins |
| 786 | * or a particular one. |
| 787 | * @param admin The name of the admin component to check, or null to aggregate |
| 788 | * all admins. |
| 789 | */ |
| 790 | public int getMaximumFailedPasswordsForWipe(ComponentName admin) { |
| 791 | if (mService != null) { |
| 792 | try { |
| 793 | return mService.getMaximumFailedPasswordsForWipe(admin); |
| 794 | } catch (RemoteException e) { |
| 795 | Log.w(TAG, "Failed talking with device policy service", e); |
| 796 | } |
| 797 | } |
| 798 | return 0; |
| 799 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 800 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 801 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 802 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 803 | * the password again until the user has entered it. |
| 804 | */ |
| 805 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 806 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 807 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 808 | * Force a new device unlock password (the password needed to access the |
| 809 | * entire device, not for individual accounts) on the user. This takes |
| 810 | * effect immediately. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 811 | * The given password must be sufficient for the |
| 812 | * current password quality and length constraints as returned by |
| 813 | * {@link #getPasswordQuality(ComponentName)} and |
| 814 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 815 | * these constraints, then it will be rejected and false returned. Note |
| 816 | * that the password may be a stronger quality (containing alphanumeric |
| 817 | * characters when the requested quality is only numeric), in which case |
| 818 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 819 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 820 | * <p>The calling device admin must have requested |
| 821 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 822 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 823 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 824 | * @param password The new password for the user. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 825 | * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 826 | * @return Returns true if the password was applied, or false if it is |
| 827 | * not acceptable for the current constraints. |
| 828 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 829 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 830 | if (mService != null) { |
| 831 | try { |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 832 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 833 | } catch (RemoteException e) { |
| 834 | Log.w(TAG, "Failed talking with device policy service", e); |
| 835 | } |
| 836 | } |
| 837 | return false; |
| 838 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 839 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 840 | /** |
| 841 | * Called by an application that is administering the device to set the |
| 842 | * maximum time for user activity until the device will lock. This limits |
| 843 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 844 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 845 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 846 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 847 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 848 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 849 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 850 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 851 | * A value of 0 means there is no restriction. |
| 852 | */ |
| 853 | public void setMaximumTimeToLock(ComponentName admin, long timeMs) { |
| 854 | if (mService != null) { |
| 855 | try { |
| 856 | mService.setMaximumTimeToLock(admin, timeMs); |
| 857 | } catch (RemoteException e) { |
| 858 | Log.w(TAG, "Failed talking with device policy service", e); |
| 859 | } |
| 860 | } |
| 861 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 862 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 863 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 864 | * Retrieve the current maximum time to unlock for all admins |
| 865 | * or a particular one. |
| 866 | * @param admin The name of the admin component to check, or null to aggregate |
| 867 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 868 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 869 | public long getMaximumTimeToLock(ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 870 | if (mService != null) { |
| 871 | try { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 872 | return mService.getMaximumTimeToLock(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 873 | } catch (RemoteException e) { |
| 874 | Log.w(TAG, "Failed talking with device policy service", e); |
| 875 | } |
| 876 | } |
| 877 | return 0; |
| 878 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 879 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 880 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 881 | * Make the device lock immediately, as if the lock screen timeout has |
| 882 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 883 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 884 | * <p>The calling device admin must have requested |
| 885 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 886 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 887 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 888 | public void lockNow() { |
| 889 | if (mService != null) { |
| 890 | try { |
| 891 | mService.lockNow(); |
| 892 | } catch (RemoteException e) { |
| 893 | Log.w(TAG, "Failed talking with device policy service", e); |
| 894 | } |
| 895 | } |
| 896 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 897 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 898 | /** |
| 899 | * 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] | 900 | * erasing all user data while next booting up. External storage such |
| 901 | * as SD cards will not be erased. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 902 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 903 | * <p>The calling device admin must have requested |
| 904 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 905 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 906 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 907 | * @param flags Bit mask of additional options: currently must be 0. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 908 | */ |
| 909 | public void wipeData(int flags) { |
| 910 | if (mService != null) { |
| 911 | try { |
| 912 | mService.wipeData(flags); |
| 913 | } catch (RemoteException e) { |
| 914 | Log.w(TAG, "Failed talking with device policy service", e); |
| 915 | } |
| 916 | } |
| 917 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 918 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 919 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 920 | * Called by an application that is administering the device to set the |
| 921 | * global proxy and exclusion list. |
| 922 | * <p> |
| 923 | * The calling device admin must have requested |
| 924 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 925 | * this method; if it has not, a security exception will be thrown. |
| 926 | * Only the first device admin can set the proxy. If a second admin attempts |
| 927 | * to set the proxy, the {@link ComponentName} of the admin originally setting the |
| 928 | * proxy will be returned. If successful in setting the proxy, null will |
| 929 | * be returned. |
| 930 | * The method can be called repeatedly by the device admin alrady setting the |
| 931 | * proxy to update the proxy and exclusion list. |
| 932 | * |
| 933 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 934 | * with. |
| 935 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 936 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 937 | * @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] | 938 | * @return returns null if the proxy was successfully set, or a {@link ComponentName} |
| 939 | * of the device admin that sets thew proxy otherwise. |
| 940 | */ |
| 941 | public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec, |
| 942 | List<String> exclusionList ) { |
| 943 | if (proxySpec == null) { |
| 944 | throw new NullPointerException(); |
| 945 | } |
| 946 | if (mService != null) { |
| 947 | try { |
| 948 | String hostSpec; |
| 949 | String exclSpec; |
| 950 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 951 | hostSpec = null; |
| 952 | exclSpec = null; |
| 953 | } else { |
| 954 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 955 | throw new IllegalArgumentException(); |
| 956 | } |
| 957 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 958 | String hostName = sa.getHostName(); |
| 959 | int port = sa.getPort(); |
| 960 | StringBuilder hostBuilder = new StringBuilder(); |
| 961 | hostSpec = hostBuilder.append(hostName) |
| 962 | .append(":").append(Integer.toString(port)).toString(); |
| 963 | if (exclusionList == null) { |
| 964 | exclSpec = ""; |
| 965 | } else { |
| 966 | StringBuilder listBuilder = new StringBuilder(); |
| 967 | boolean firstDomain = true; |
| 968 | for (String exclDomain : exclusionList) { |
| 969 | if (!firstDomain) { |
| 970 | listBuilder = listBuilder.append(","); |
| 971 | } else { |
| 972 | firstDomain = false; |
| 973 | } |
| 974 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 975 | } |
| 976 | exclSpec = listBuilder.toString(); |
| 977 | } |
| 978 | android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec); |
| 979 | } |
| 980 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
| 981 | } catch (RemoteException e) { |
| 982 | Log.w(TAG, "Failed talking with device policy service", e); |
| 983 | } |
| 984 | } |
| 985 | return null; |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * Returns the component name setting the global proxy. |
| 990 | * @return ComponentName object of the device admin that set the global proxy, or |
| 991 | * null if no admin has set the proxy. |
| 992 | */ |
| 993 | public ComponentName getGlobalProxyAdmin() { |
| 994 | if (mService != null) { |
| 995 | try { |
| 996 | return mService.getGlobalProxyAdmin(); |
| 997 | } catch (RemoteException e) { |
| 998 | Log.w(TAG, "Failed talking with device policy service", e); |
| 999 | } |
| 1000 | } |
| 1001 | return null; |
| 1002 | } |
| 1003 | |
| 1004 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1005 | * @hide |
| 1006 | */ |
| 1007 | public void setActiveAdmin(ComponentName policyReceiver) { |
| 1008 | if (mService != null) { |
| 1009 | try { |
| 1010 | mService.setActiveAdmin(policyReceiver); |
| 1011 | } catch (RemoteException e) { |
| 1012 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1013 | } |
| 1014 | } |
| 1015 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1016 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1017 | /** |
| 1018 | * @hide |
| 1019 | */ |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1020 | public DeviceAdminInfo getAdminInfo(ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1021 | ActivityInfo ai; |
| 1022 | try { |
| 1023 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 1024 | PackageManager.GET_META_DATA); |
| 1025 | } catch (PackageManager.NameNotFoundException e) { |
| 1026 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 1027 | return null; |
| 1028 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1029 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1030 | ResolveInfo ri = new ResolveInfo(); |
| 1031 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1032 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1033 | try { |
| 1034 | return new DeviceAdminInfo(mContext, ri); |
| 1035 | } catch (XmlPullParserException e) { |
| 1036 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 1037 | return null; |
| 1038 | } catch (IOException e) { |
| 1039 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 1040 | return null; |
| 1041 | } |
| 1042 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1043 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1044 | /** |
| 1045 | * @hide |
| 1046 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1047 | public void getRemoveWarning(ComponentName admin, RemoteCallback result) { |
| 1048 | if (mService != null) { |
| 1049 | try { |
| 1050 | mService.getRemoveWarning(admin, result); |
| 1051 | } catch (RemoteException e) { |
| 1052 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | /** |
| 1058 | * @hide |
| 1059 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1060 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1061 | int lowercase, int numbers, int symbols, int nonletter) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1062 | if (mService != null) { |
| 1063 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1064 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1065 | numbers, symbols, nonletter); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1066 | } catch (RemoteException e) { |
| 1067 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1068 | } |
| 1069 | } |
| 1070 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1071 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1072 | /** |
| 1073 | * @hide |
| 1074 | */ |
| 1075 | public void reportFailedPasswordAttempt() { |
| 1076 | if (mService != null) { |
| 1077 | try { |
| 1078 | mService.reportFailedPasswordAttempt(); |
| 1079 | } catch (RemoteException e) { |
| 1080 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1081 | } |
| 1082 | } |
| 1083 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1084 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1085 | /** |
| 1086 | * @hide |
| 1087 | */ |
| 1088 | public void reportSuccessfulPasswordAttempt() { |
| 1089 | if (mService != null) { |
| 1090 | try { |
| 1091 | mService.reportSuccessfulPasswordAttempt(); |
| 1092 | } catch (RemoteException e) { |
| 1093 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1097 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1098 | } |