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; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 25 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 26 | import android.content.pm.ActivityInfo; |
| 27 | import android.content.pm.PackageManager; |
| 28 | import android.content.pm.ResolveInfo; |
| 29 | import android.os.Handler; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 30 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 31 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 32 | import android.os.RemoteException; |
| 33 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 34 | import android.os.UserHandle; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 35 | import android.util.Log; |
| 36 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 37 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 38 | |
| 39 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 40 | import java.io.IOException; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 41 | import java.net.InetSocketAddress; |
| 42 | import java.net.Proxy; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 43 | import java.security.cert.CertificateException; |
| 44 | import java.security.cert.CertificateFactory; |
| 45 | import java.security.cert.X509Certificate; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 46 | import java.util.List; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 47 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Public interface for managing policies enforced on a device. Most clients |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 51 | * of this class must have published a {@link DeviceAdminReceiver} that the user |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 52 | * has currently enabled. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 53 | * |
| 54 | * <div class="special reference"> |
| 55 | * <h3>Developer Guides</h3> |
| 56 | * <p>For more information about managing policies for device adminstration, read the |
| 57 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
| 58 | * developer guide.</p> |
| 59 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 60 | */ |
| 61 | public class DevicePolicyManager { |
| 62 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 63 | |
| 64 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 65 | private final IDevicePolicyManager mService; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 66 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 67 | private DevicePolicyManager(Context context, Handler handler) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 68 | mContext = context; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 69 | mService = IDevicePolicyManager.Stub.asInterface( |
| 70 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 71 | } |
| 72 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 73 | /** @hide */ |
| 74 | public static DevicePolicyManager create(Context context, Handler handler) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 75 | DevicePolicyManager me = new DevicePolicyManager(context, handler); |
| 76 | return me.mService != null ? me : null; |
| 77 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 78 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Activity action: ask the user to add a new device administrator to the system. |
| 81 | * The desired policy is the ComponentName of the policy in the |
| 82 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 83 | * bring the user through adding the device administrator to the system (or |
| 84 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 85 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 86 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 87 | * field to provide the user with additional explanation (in addition |
| 88 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 89 | * |
| 90 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 91 | * user intervention). However, if your administrator has been updated and is requesting |
| 92 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 93 | * 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] | 94 | */ |
| 95 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 96 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 97 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 99 | /** |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 100 | * Activity action: send when any policy admin changes a policy. |
| 101 | * This is generally used to find out when a new policy is in effect. |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 102 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 103 | * @hide |
| 104 | */ |
| 105 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 106 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 107 | |
| 108 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 109 | * The ComponentName of the administrator component. |
| 110 | * |
| 111 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 112 | */ |
| 113 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 114 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 115 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 116 | * An optional CharSequence providing additional explanation for why the |
| 117 | * admin is being added. |
| 118 | * |
| 119 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 120 | */ |
| 121 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 122 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 123 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 124 | * Activity action: have the user enter a new password. This activity should |
| 125 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 126 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 127 | * enter a new password that meets the current requirements. You can use |
| 128 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 129 | * have the user select a new password in order to meet the current |
| 130 | * constraints. Upon being resumed from this activity, you can check the new |
| 131 | * password characteristics to see if they are sufficient. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 132 | */ |
| 133 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 134 | public static final String ACTION_SET_NEW_PASSWORD |
| 135 | = "android.app.action.SET_NEW_PASSWORD"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 136 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 137 | /** |
| 138 | * Return true if the given administrator component is currently |
| 139 | * active (enabled) in the system. |
| 140 | */ |
| 141 | public boolean isAdminActive(ComponentName who) { |
| 142 | if (mService != null) { |
| 143 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 144 | return mService.isAdminActive(who, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 145 | } catch (RemoteException e) { |
| 146 | Log.w(TAG, "Failed talking with device policy service", e); |
| 147 | } |
| 148 | } |
| 149 | return false; |
| 150 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 151 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 152 | /** |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 153 | * Return a list of all currently active device administrator's component |
| 154 | * names. Note that if there are no administrators than null may be |
| 155 | * returned. |
| 156 | */ |
| 157 | public List<ComponentName> getActiveAdmins() { |
| 158 | if (mService != null) { |
| 159 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 160 | return mService.getActiveAdmins(UserHandle.myUserId()); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 161 | } catch (RemoteException e) { |
| 162 | Log.w(TAG, "Failed talking with device policy service", e); |
| 163 | } |
| 164 | } |
| 165 | return null; |
| 166 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 167 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 168 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 169 | * Used by package administration code to determine if a package can be stopped |
| 170 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 171 | * @hide |
| 172 | */ |
| 173 | public boolean packageHasActiveAdmins(String packageName) { |
| 174 | if (mService != null) { |
| 175 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 176 | return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 177 | } catch (RemoteException e) { |
| 178 | Log.w(TAG, "Failed talking with device policy service", e); |
| 179 | } |
| 180 | } |
| 181 | return false; |
| 182 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 183 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 184 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 185 | * Remove a current administration component. This can only be called |
| 186 | * by the application that owns the administration component; if you |
| 187 | * try to remove someone else's component, a security exception will be |
| 188 | * thrown. |
| 189 | */ |
| 190 | public void removeActiveAdmin(ComponentName who) { |
| 191 | if (mService != null) { |
| 192 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 193 | mService.removeActiveAdmin(who, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 194 | } catch (RemoteException e) { |
| 195 | Log.w(TAG, "Failed talking with device policy service", e); |
| 196 | } |
| 197 | } |
| 198 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 199 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 200 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 201 | * Returns true if an administrator has been granted a particular device policy. This can |
| 202 | * be used to check if the administrator was activated under an earlier set of policies, |
| 203 | * but requires additional policies after an upgrade. |
| 204 | * |
| 205 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 206 | * an active administrator, or an exception will be thrown. |
| 207 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 208 | */ |
| 209 | public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) { |
| 210 | if (mService != null) { |
| 211 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 212 | return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 213 | } catch (RemoteException e) { |
| 214 | Log.w(TAG, "Failed talking with device policy service", e); |
| 215 | } |
| 216 | } |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 221 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 222 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 223 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 224 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 225 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 226 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 227 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 228 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 229 | * recognition technology. This implies technologies that can recognize the identity of |
| 230 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 231 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 232 | */ |
| 233 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 234 | |
| 235 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 236 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
| 237 | * 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] | 238 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 239 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 240 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 241 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 242 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 243 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 244 | * password containing at least numeric characters. Note that quality |
| 245 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 246 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 247 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 248 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 249 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 250 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 251 | * password containing at least alphabetic (or other symbol) characters. |
| 252 | * Note that quality constants are ordered so that higher values are more |
| 253 | * restrictive. |
| 254 | */ |
| 255 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 256 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 257 | /** |
| 258 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 259 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 260 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 261 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 262 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 263 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 264 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 265 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 266 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 267 | * password containing at least a letter, a numerical digit and a special |
| 268 | * symbol, by default. With this password quality, passwords can be |
| 269 | * restricted to contain various sets of characters, like at least an |
| 270 | * uppercase letter, etc. These are specified using various methods, |
| 271 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 272 | * that quality constants are ordered so that higher values are more |
| 273 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 274 | */ |
| 275 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 276 | |
| 277 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 278 | * Called by an application that is administering the device to set the |
| 279 | * password restrictions it is imposing. After setting this, the user |
| 280 | * will not be able to enter a new password that is not at least as |
| 281 | * restrictive as what has been set. Note that the current password |
| 282 | * will remain until the user has set a new one, so the change does not |
| 283 | * take place immediately. To prompt the user for a new password, use |
| 284 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 285 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 286 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 287 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 288 | * the user's preference, and any other considerations) is the one that |
| 289 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 290 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 291 | * <p>The calling device admin must have requested |
| 292 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 293 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 294 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 295 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 296 | * @param quality The new desired quality. One of |
| 297 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 298 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 299 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 300 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 301 | public void setPasswordQuality(ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 302 | if (mService != null) { |
| 303 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 304 | mService.setPasswordQuality(admin, quality, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 305 | } catch (RemoteException e) { |
| 306 | Log.w(TAG, "Failed talking with device policy service", e); |
| 307 | } |
| 308 | } |
| 309 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 310 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 311 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 312 | * Retrieve the current minimum password quality for all admins |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 313 | * or a particular one. |
| 314 | * @param admin The name of the admin component to check, or null to aggregate |
| 315 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 316 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 317 | public int getPasswordQuality(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 318 | return getPasswordQuality(admin, UserHandle.myUserId()); |
| 319 | } |
| 320 | |
| 321 | /** @hide per-user version */ |
| 322 | public int getPasswordQuality(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 323 | if (mService != null) { |
| 324 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 325 | return mService.getPasswordQuality(admin, userHandle); |
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 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 330 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 331 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 332 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 333 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 334 | * Called by an application that is administering the device to set the |
| 335 | * minimum allowed password length. After setting this, the user |
| 336 | * will not be able to enter a new password that is not at least as |
| 337 | * restrictive as what has been set. Note that the current password |
| 338 | * will remain until the user has set a new one, so the change does not |
| 339 | * take place immediately. To prompt the user for a new password, use |
| 340 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 341 | * constraint is only imposed if the administrator has also requested either |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 342 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_ALPHABETIC} |
| 343 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 344 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 345 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 346 | * <p>The calling device admin must have requested |
| 347 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 348 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 349 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 350 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 351 | * @param length The new desired minimum password length. A value of 0 |
| 352 | * means there is no restriction. |
| 353 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 354 | public void setPasswordMinimumLength(ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 355 | if (mService != null) { |
| 356 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 357 | mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 358 | } catch (RemoteException e) { |
| 359 | Log.w(TAG, "Failed talking with device policy service", e); |
| 360 | } |
| 361 | } |
| 362 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 363 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 364 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 365 | * Retrieve the current minimum password length for all admins |
| 366 | * or a particular one. |
| 367 | * @param admin The name of the admin component to check, or null to aggregate |
| 368 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 369 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 370 | public int getPasswordMinimumLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 371 | return getPasswordMinimumLength(admin, UserHandle.myUserId()); |
| 372 | } |
| 373 | |
| 374 | /** @hide per-user version */ |
| 375 | public int getPasswordMinimumLength(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 376 | if (mService != null) { |
| 377 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 378 | return mService.getPasswordMinimumLength(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 379 | } catch (RemoteException e) { |
| 380 | Log.w(TAG, "Failed talking with device policy service", e); |
| 381 | } |
| 382 | } |
| 383 | return 0; |
| 384 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 385 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 386 | /** |
| 387 | * Called by an application that is administering the device to set the |
| 388 | * minimum number of upper case letters required in the password. After |
| 389 | * setting this, the user will not be able to enter a new password that is |
| 390 | * not at least as restrictive as what has been set. Note that the current |
| 391 | * password will remain until the user has set a new one, so the change does |
| 392 | * not take place immediately. To prompt the user for a new password, use |
| 393 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 394 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 395 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 396 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 397 | * <p> |
| 398 | * The calling device admin must have requested |
| 399 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 400 | * this method; if it has not, a security exception will be thrown. |
| 401 | * |
| 402 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 403 | * with. |
| 404 | * @param length The new desired minimum number of upper case letters |
| 405 | * required in the password. A value of 0 means there is no |
| 406 | * restriction. |
| 407 | */ |
| 408 | public void setPasswordMinimumUpperCase(ComponentName admin, int length) { |
| 409 | if (mService != null) { |
| 410 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 411 | mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 412 | } catch (RemoteException e) { |
| 413 | Log.w(TAG, "Failed talking with device policy service", e); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Retrieve the current number of upper case letters required in the |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 420 | * password for all admins or a particular one. This is the same value as |
| 421 | * set by {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
| 422 | * and only applies when the password quality is |
| 423 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 424 | * |
| 425 | * @param admin The name of the admin component to check, or null to |
| 426 | * aggregate all admins. |
| 427 | * @return The minimum number of upper case letters required in the |
| 428 | * password. |
| 429 | */ |
| 430 | public int getPasswordMinimumUpperCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 431 | return getPasswordMinimumUpperCase(admin, UserHandle.myUserId()); |
| 432 | } |
| 433 | |
| 434 | /** @hide per-user version */ |
| 435 | public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 436 | if (mService != null) { |
| 437 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 438 | return mService.getPasswordMinimumUpperCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 439 | } catch (RemoteException e) { |
| 440 | Log.w(TAG, "Failed talking with device policy service", e); |
| 441 | } |
| 442 | } |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Called by an application that is administering the device to set the |
| 448 | * minimum number of lower case letters required in the password. After |
| 449 | * setting this, the user will not be able to enter a new password that is |
| 450 | * not at least as restrictive as what has been set. Note that the current |
| 451 | * password will remain until the user has set a new one, so the change does |
| 452 | * not take place immediately. To prompt the user for a new password, use |
| 453 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 454 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 455 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 456 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 457 | * <p> |
| 458 | * The calling device admin must have requested |
| 459 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 460 | * this method; if it has not, a security exception will be thrown. |
| 461 | * |
| 462 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 463 | * with. |
| 464 | * @param length The new desired minimum number of lower case letters |
| 465 | * required in the password. A value of 0 means there is no |
| 466 | * restriction. |
| 467 | */ |
| 468 | public void setPasswordMinimumLowerCase(ComponentName admin, int length) { |
| 469 | if (mService != null) { |
| 470 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 471 | mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 472 | } catch (RemoteException e) { |
| 473 | Log.w(TAG, "Failed talking with device policy service", e); |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Retrieve the current number of lower case letters required in the |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 480 | * password for all admins or a particular one. This is the same value as |
| 481 | * set by {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
| 482 | * and only applies when the password quality is |
| 483 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 484 | * |
| 485 | * @param admin The name of the admin component to check, or null to |
| 486 | * aggregate all admins. |
| 487 | * @return The minimum number of lower case letters required in the |
| 488 | * password. |
| 489 | */ |
| 490 | public int getPasswordMinimumLowerCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 491 | return getPasswordMinimumLowerCase(admin, UserHandle.myUserId()); |
| 492 | } |
| 493 | |
| 494 | /** @hide per-user version */ |
| 495 | public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 496 | if (mService != null) { |
| 497 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 498 | return mService.getPasswordMinimumLowerCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 499 | } catch (RemoteException e) { |
| 500 | Log.w(TAG, "Failed talking with device policy service", e); |
| 501 | } |
| 502 | } |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Called by an application that is administering the device to set the |
| 508 | * minimum number of letters required in the password. After setting this, |
| 509 | * the user will not be able to enter a new password that is not at least as |
| 510 | * restrictive as what has been set. Note that the current password will |
| 511 | * remain until the user has set a new one, so the change does not take |
| 512 | * place immediately. To prompt the user for a new password, use |
| 513 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 514 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 515 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 516 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 517 | * <p> |
| 518 | * The calling device admin must have requested |
| 519 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 520 | * this method; if it has not, a security exception will be thrown. |
| 521 | * |
| 522 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 523 | * with. |
| 524 | * @param length The new desired minimum number of letters required in the |
| 525 | * password. A value of 0 means there is no restriction. |
| 526 | */ |
| 527 | public void setPasswordMinimumLetters(ComponentName admin, int length) { |
| 528 | if (mService != null) { |
| 529 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 530 | mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 531 | } catch (RemoteException e) { |
| 532 | Log.w(TAG, "Failed talking with device policy service", e); |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 539 | * admins or a particular one. This is the same value as |
| 540 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 541 | * and only applies when the password quality is |
| 542 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 543 | * |
| 544 | * @param admin The name of the admin component to check, or null to |
| 545 | * aggregate all admins. |
| 546 | * @return The minimum number of letters required in the password. |
| 547 | */ |
| 548 | public int getPasswordMinimumLetters(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 549 | return getPasswordMinimumLetters(admin, UserHandle.myUserId()); |
| 550 | } |
| 551 | |
| 552 | /** @hide per-user version */ |
| 553 | public int getPasswordMinimumLetters(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 554 | if (mService != null) { |
| 555 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 556 | return mService.getPasswordMinimumLetters(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 557 | } catch (RemoteException e) { |
| 558 | Log.w(TAG, "Failed talking with device policy service", e); |
| 559 | } |
| 560 | } |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * Called by an application that is administering the device to set the |
| 566 | * minimum number of numerical digits required in the password. After |
| 567 | * setting this, the user will not be able to enter a new password that is |
| 568 | * not at least as restrictive as what has been set. Note that the current |
| 569 | * password will remain until the user has set a new one, so the change does |
| 570 | * not take place immediately. To prompt the user for a new password, use |
| 571 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 572 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 573 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 574 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 575 | * <p> |
| 576 | * The calling device admin must have requested |
| 577 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 578 | * this method; if it has not, a security exception will be thrown. |
| 579 | * |
| 580 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 581 | * with. |
| 582 | * @param length The new desired minimum number of numerical digits required |
| 583 | * in the password. A value of 0 means there is no restriction. |
| 584 | */ |
| 585 | public void setPasswordMinimumNumeric(ComponentName admin, int length) { |
| 586 | if (mService != null) { |
| 587 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 588 | mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 589 | } catch (RemoteException e) { |
| 590 | Log.w(TAG, "Failed talking with device policy service", e); |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Retrieve the current number of numerical digits required in the password |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 597 | * for all admins or a particular one. This is the same value as |
| 598 | * set by {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
| 599 | * and only applies when the password quality is |
| 600 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 601 | * |
| 602 | * @param admin The name of the admin component to check, or null to |
| 603 | * aggregate all admins. |
| 604 | * @return The minimum number of numerical digits required in the password. |
| 605 | */ |
| 606 | public int getPasswordMinimumNumeric(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 607 | return getPasswordMinimumNumeric(admin, UserHandle.myUserId()); |
| 608 | } |
| 609 | |
| 610 | /** @hide per-user version */ |
| 611 | public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 612 | if (mService != null) { |
| 613 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 614 | return mService.getPasswordMinimumNumeric(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 615 | } catch (RemoteException e) { |
| 616 | Log.w(TAG, "Failed talking with device policy service", e); |
| 617 | } |
| 618 | } |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * Called by an application that is administering the device to set the |
| 624 | * minimum number of symbols required in the password. After setting this, |
| 625 | * the user will not be able to enter a new password that is not at least as |
| 626 | * restrictive as what has been set. Note that the current password will |
| 627 | * remain until the user has set a new one, so the change does not take |
| 628 | * place immediately. To prompt the user for a new password, use |
| 629 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 630 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 631 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 632 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 633 | * <p> |
| 634 | * The calling device admin must have requested |
| 635 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 636 | * this method; if it has not, a security exception will be thrown. |
| 637 | * |
| 638 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 639 | * with. |
| 640 | * @param length The new desired minimum number of symbols required in the |
| 641 | * password. A value of 0 means there is no restriction. |
| 642 | */ |
| 643 | public void setPasswordMinimumSymbols(ComponentName admin, int length) { |
| 644 | if (mService != null) { |
| 645 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 646 | mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 647 | } catch (RemoteException e) { |
| 648 | Log.w(TAG, "Failed talking with device policy service", e); |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 655 | * admins or a particular one. This is the same value as |
| 656 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 657 | * and only applies when the password quality is |
| 658 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 659 | * |
| 660 | * @param admin The name of the admin component to check, or null to |
| 661 | * aggregate all admins. |
| 662 | * @return The minimum number of symbols required in the password. |
| 663 | */ |
| 664 | public int getPasswordMinimumSymbols(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 665 | return getPasswordMinimumSymbols(admin, UserHandle.myUserId()); |
| 666 | } |
| 667 | |
| 668 | /** @hide per-user version */ |
| 669 | public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 670 | if (mService != null) { |
| 671 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 672 | return mService.getPasswordMinimumSymbols(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 673 | } catch (RemoteException e) { |
| 674 | Log.w(TAG, "Failed talking with device policy service", e); |
| 675 | } |
| 676 | } |
| 677 | return 0; |
| 678 | } |
| 679 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 680 | /** |
| 681 | * Called by an application that is administering the device to set the |
| 682 | * minimum number of non-letter characters (numerical digits or symbols) |
| 683 | * required in the password. After setting this, the user will not be able |
| 684 | * to enter a new password that is not at least as restrictive as what has |
| 685 | * been set. Note that the current password will remain until the user has |
| 686 | * set a new one, so the change does not take place immediately. To prompt |
| 687 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 688 | * setting this value. This constraint is only imposed if the administrator |
| 689 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 690 | * {@link #setPasswordQuality}. The default value is 0. |
| 691 | * <p> |
| 692 | * The calling device admin must have requested |
| 693 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 694 | * this method; if it has not, a security exception will be thrown. |
| 695 | * |
| 696 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 697 | * with. |
| 698 | * @param length The new desired minimum number of letters required in the |
| 699 | * password. A value of 0 means there is no restriction. |
| 700 | */ |
| 701 | public void setPasswordMinimumNonLetter(ComponentName admin, int length) { |
| 702 | if (mService != null) { |
| 703 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 704 | mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 705 | } catch (RemoteException e) { |
| 706 | Log.w(TAG, "Failed talking with device policy service", e); |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Retrieve the current number of non-letter characters required in the |
| 713 | * password for all admins or a particular one. This is the same value as |
| 714 | * set by {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
| 715 | * and only applies when the password quality is |
| 716 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 717 | * |
| 718 | * @param admin The name of the admin component to check, or null to |
| 719 | * aggregate all admins. |
| 720 | * @return The minimum number of letters required in the password. |
| 721 | */ |
| 722 | public int getPasswordMinimumNonLetter(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 723 | return getPasswordMinimumNonLetter(admin, UserHandle.myUserId()); |
| 724 | } |
| 725 | |
| 726 | /** @hide per-user version */ |
| 727 | public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 728 | if (mService != null) { |
| 729 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 730 | return mService.getPasswordMinimumNonLetter(admin, userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 731 | } catch (RemoteException e) { |
| 732 | Log.w(TAG, "Failed talking with device policy service", e); |
| 733 | } |
| 734 | } |
| 735 | return 0; |
| 736 | } |
| 737 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 738 | /** |
| 739 | * Called by an application that is administering the device to set the length |
| 740 | * of the password history. After setting this, the user will not be able to |
| 741 | * enter a new password that is the same as any password in the history. Note |
| 742 | * that the current password will remain until the user has set a new one, so |
| 743 | * the change does not take place immediately. To prompt the user for a new |
| 744 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 745 | * This constraint is only imposed if the administrator has also requested |
| 746 | * either {@link #PASSWORD_QUALITY_NUMERIC}, |
| 747 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 748 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 749 | * |
| 750 | * <p> |
| 751 | * The calling device admin must have requested |
| 752 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 753 | * method; if it has not, a security exception will be thrown. |
| 754 | * |
| 755 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 756 | * with. |
| 757 | * @param length The new desired length of password history. A value of 0 |
| 758 | * means there is no restriction. |
| 759 | */ |
| 760 | public void setPasswordHistoryLength(ComponentName admin, int length) { |
| 761 | if (mService != null) { |
| 762 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 763 | mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 764 | } catch (RemoteException e) { |
| 765 | Log.w(TAG, "Failed talking with device policy service", e); |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 771 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 772 | * will restart the countdown for password expiration for the given admin, as will changing |
| 773 | * the device password (for all admins). |
| 774 | * |
| 775 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 776 | * For example, to have the password expire 5 days from now, timeout would be |
| 777 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 778 | * |
| 779 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 780 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 781 | * <p>The calling device admin must have requested |
| 782 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 783 | * method; if it has not, a security exception will be thrown. |
| 784 | * |
| 785 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 786 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 787 | * means there is no restriction (unlimited). |
| 788 | */ |
| 789 | public void setPasswordExpirationTimeout(ComponentName admin, long timeout) { |
| 790 | if (mService != null) { |
| 791 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 792 | mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 793 | } catch (RemoteException e) { |
| 794 | Log.w(TAG, "Failed talking with device policy service", e); |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 800 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 801 | * recurring expiration timeout provided in the call to |
| 802 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
| 803 | * aggregate of all policy administrators if admin is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 804 | * |
| 805 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 806 | * @return The timeout for the given admin or the minimum of all timeouts |
| 807 | */ |
| 808 | public long getPasswordExpirationTimeout(ComponentName admin) { |
| 809 | if (mService != null) { |
| 810 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 811 | return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 812 | } catch (RemoteException e) { |
| 813 | Log.w(TAG, "Failed talking with device policy service", e); |
| 814 | } |
| 815 | } |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * Get the current password expiration time for the given admin or an aggregate of |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 821 | * all admins if admin is null. If the password is expired, this will return the time since |
| 822 | * the password expired as a negative number. If admin is null, then a composite of all |
| 823 | * expiration timeouts is returned - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 824 | * |
| 825 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 826 | * @return The password expiration time, in ms. |
| 827 | */ |
| 828 | public long getPasswordExpiration(ComponentName admin) { |
| 829 | if (mService != null) { |
| 830 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 831 | return mService.getPasswordExpiration(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 832 | } catch (RemoteException e) { |
| 833 | Log.w(TAG, "Failed talking with device policy service", e); |
| 834 | } |
| 835 | } |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 840 | * Retrieve the current password history length for all admins |
| 841 | * or a particular one. |
| 842 | * @param admin The name of the admin component to check, or null to aggregate |
| 843 | * all admins. |
| 844 | * @return The length of the password history |
| 845 | */ |
| 846 | public int getPasswordHistoryLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 847 | return getPasswordHistoryLength(admin, UserHandle.myUserId()); |
| 848 | } |
| 849 | |
| 850 | /** @hide per-user version */ |
| 851 | public int getPasswordHistoryLength(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 852 | if (mService != null) { |
| 853 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 854 | return mService.getPasswordHistoryLength(admin, userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 855 | } catch (RemoteException e) { |
| 856 | Log.w(TAG, "Failed talking with device policy service", e); |
| 857 | } |
| 858 | } |
| 859 | return 0; |
| 860 | } |
| 861 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 862 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 863 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 864 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 865 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 866 | * @return Returns the maximum length that the user can enter. |
| 867 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 868 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 869 | // Kind-of arbitrary. |
| 870 | return 16; |
| 871 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 872 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 873 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 874 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 875 | * to meet the policy requirements (quality, minimum length) that have been |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 876 | * requested. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 877 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 878 | * <p>The calling device admin must have requested |
| 879 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 880 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 881 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 882 | * @return Returns true if the password meets the current requirements, |
| 883 | * else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 884 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 885 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 886 | if (mService != null) { |
| 887 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 888 | return mService.isActivePasswordSufficient(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 889 | } catch (RemoteException e) { |
| 890 | Log.w(TAG, "Failed talking with device policy service", e); |
| 891 | } |
| 892 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 893 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 894 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 895 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 896 | /** |
| 897 | * Retrieve the number of times the user has failed at entering a |
| 898 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 899 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 900 | * <p>The calling device admin must have requested |
| 901 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 902 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 903 | */ |
| 904 | public int getCurrentFailedPasswordAttempts() { |
| 905 | if (mService != null) { |
| 906 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 907 | return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 908 | } catch (RemoteException e) { |
| 909 | Log.w(TAG, "Failed talking with device policy service", e); |
| 910 | } |
| 911 | } |
| 912 | return -1; |
| 913 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 914 | |
| 915 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 916 | * Setting this to a value greater than zero enables a built-in policy |
| 917 | * that will perform a device wipe after too many incorrect |
| 918 | * device-unlock passwords have been entered. This built-in policy combines |
| 919 | * watching for failed passwords and wiping the device, and requires |
| 920 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 921 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 922 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 923 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 924 | * application only, erasing or revoking credentials, or reporting the |
| 925 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 926 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 927 | * instead. Do not use this API, because if the maximum count is reached, |
| 928 | * 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] | 929 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 930 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 931 | * @param num The number of failed password attempts at which point the |
| 932 | * device will wipe its data. |
| 933 | */ |
| 934 | public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) { |
| 935 | if (mService != null) { |
| 936 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 937 | mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 938 | } catch (RemoteException e) { |
| 939 | Log.w(TAG, "Failed talking with device policy service", e); |
| 940 | } |
| 941 | } |
| 942 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 943 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 944 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 945 | * Retrieve the current maximum number of login attempts that are allowed |
| 946 | * before the device wipes itself, for all admins |
| 947 | * or a particular one. |
| 948 | * @param admin The name of the admin component to check, or null to aggregate |
| 949 | * all admins. |
| 950 | */ |
| 951 | public int getMaximumFailedPasswordsForWipe(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 952 | return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId()); |
| 953 | } |
| 954 | |
| 955 | /** @hide per-user version */ |
| 956 | public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 957 | if (mService != null) { |
| 958 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 959 | return mService.getMaximumFailedPasswordsForWipe(admin, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 960 | } catch (RemoteException e) { |
| 961 | Log.w(TAG, "Failed talking with device policy service", e); |
| 962 | } |
| 963 | } |
| 964 | return 0; |
| 965 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 966 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 967 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 968 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 969 | * the password again until the user has entered it. |
| 970 | */ |
| 971 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 972 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 973 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 974 | * Force a new device unlock password (the password needed to access the |
| 975 | * entire device, not for individual accounts) on the user. This takes |
| 976 | * effect immediately. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 977 | * The given password must be sufficient for the |
| 978 | * current password quality and length constraints as returned by |
| 979 | * {@link #getPasswordQuality(ComponentName)} and |
| 980 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 981 | * these constraints, then it will be rejected and false returned. Note |
| 982 | * that the password may be a stronger quality (containing alphanumeric |
| 983 | * characters when the requested quality is only numeric), in which case |
| 984 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 985 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 986 | * <p>The calling device admin must have requested |
| 987 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 988 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 989 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 990 | * @param password The new password for the user. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 991 | * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 992 | * @return Returns true if the password was applied, or false if it is |
| 993 | * not acceptable for the current constraints. |
| 994 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 995 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 996 | if (mService != null) { |
| 997 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 998 | return mService.resetPassword(password, flags, UserHandle.myUserId()); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 999 | } catch (RemoteException e) { |
| 1000 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1001 | } |
| 1002 | } |
| 1003 | return false; |
| 1004 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1005 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1006 | /** |
| 1007 | * Called by an application that is administering the device to set the |
| 1008 | * maximum time for user activity until the device will lock. This limits |
| 1009 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1010 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1011 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1012 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1013 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1014 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1015 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1016 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1017 | * A value of 0 means there is no restriction. |
| 1018 | */ |
| 1019 | public void setMaximumTimeToLock(ComponentName admin, long timeMs) { |
| 1020 | if (mService != null) { |
| 1021 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1022 | mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1023 | } catch (RemoteException e) { |
| 1024 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1025 | } |
| 1026 | } |
| 1027 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1028 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1029 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1030 | * Retrieve the current maximum time to unlock for all admins |
| 1031 | * or a particular one. |
| 1032 | * @param admin The name of the admin component to check, or null to aggregate |
| 1033 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1034 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1035 | public long getMaximumTimeToLock(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1036 | return getMaximumTimeToLock(admin, UserHandle.myUserId()); |
| 1037 | } |
| 1038 | |
| 1039 | /** @hide per-user version */ |
| 1040 | public long getMaximumTimeToLock(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1041 | if (mService != null) { |
| 1042 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1043 | return mService.getMaximumTimeToLock(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1044 | } catch (RemoteException e) { |
| 1045 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1046 | } |
| 1047 | } |
| 1048 | return 0; |
| 1049 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1050 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1051 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1052 | * Make the device lock immediately, as if the lock screen timeout has |
| 1053 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1054 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1055 | * <p>The calling device admin must have requested |
| 1056 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 1057 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1058 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1059 | public void lockNow() { |
| 1060 | if (mService != null) { |
| 1061 | try { |
| 1062 | mService.lockNow(); |
| 1063 | } catch (RemoteException e) { |
| 1064 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1065 | } |
| 1066 | } |
| 1067 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1068 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1069 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1070 | * Flag for {@link #wipeData(int)}: also erase the device's external |
| 1071 | * storage. |
| 1072 | */ |
| 1073 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 1074 | |
| 1075 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1076 | * 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] | 1077 | * erasing all user data while next booting up. External storage such |
Masanori Ogino | f535cb04 | 2012-02-15 19:25:50 +0900 | [diff] [blame] | 1078 | * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE} |
| 1079 | * is set. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1080 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1081 | * <p>The calling device admin must have requested |
| 1082 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 1083 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1084 | * |
Masanori Ogino | f535cb04 | 2012-02-15 19:25:50 +0900 | [diff] [blame] | 1085 | * @param flags Bit mask of additional options: currently 0 and |
| 1086 | * {@link #WIPE_EXTERNAL_STORAGE} are supported. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1087 | */ |
| 1088 | public void wipeData(int flags) { |
| 1089 | if (mService != null) { |
| 1090 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1091 | mService.wipeData(flags, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1092 | } catch (RemoteException e) { |
| 1093 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1097 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1098 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1099 | * Called by an application that is administering the device to set the |
| 1100 | * global proxy and exclusion list. |
| 1101 | * <p> |
| 1102 | * The calling device admin must have requested |
| 1103 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 1104 | * this method; if it has not, a security exception will be thrown. |
| 1105 | * Only the first device admin can set the proxy. If a second admin attempts |
| 1106 | * to set the proxy, the {@link ComponentName} of the admin originally setting the |
| 1107 | * proxy will be returned. If successful in setting the proxy, null will |
| 1108 | * be returned. |
| 1109 | * The method can be called repeatedly by the device admin alrady setting the |
| 1110 | * proxy to update the proxy and exclusion list. |
| 1111 | * |
| 1112 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1113 | * with. |
| 1114 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 1115 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 1116 | * @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] | 1117 | * @return returns null if the proxy was successfully set, or a {@link ComponentName} |
| 1118 | * of the device admin that sets thew proxy otherwise. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1119 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1120 | */ |
| 1121 | public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec, |
| 1122 | List<String> exclusionList ) { |
| 1123 | if (proxySpec == null) { |
| 1124 | throw new NullPointerException(); |
| 1125 | } |
| 1126 | if (mService != null) { |
| 1127 | try { |
| 1128 | String hostSpec; |
| 1129 | String exclSpec; |
| 1130 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 1131 | hostSpec = null; |
| 1132 | exclSpec = null; |
| 1133 | } else { |
| 1134 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 1135 | throw new IllegalArgumentException(); |
| 1136 | } |
| 1137 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 1138 | String hostName = sa.getHostName(); |
| 1139 | int port = sa.getPort(); |
| 1140 | StringBuilder hostBuilder = new StringBuilder(); |
| 1141 | hostSpec = hostBuilder.append(hostName) |
| 1142 | .append(":").append(Integer.toString(port)).toString(); |
| 1143 | if (exclusionList == null) { |
| 1144 | exclSpec = ""; |
| 1145 | } else { |
| 1146 | StringBuilder listBuilder = new StringBuilder(); |
| 1147 | boolean firstDomain = true; |
| 1148 | for (String exclDomain : exclusionList) { |
| 1149 | if (!firstDomain) { |
| 1150 | listBuilder = listBuilder.append(","); |
| 1151 | } else { |
| 1152 | firstDomain = false; |
| 1153 | } |
| 1154 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 1155 | } |
| 1156 | exclSpec = listBuilder.toString(); |
| 1157 | } |
| 1158 | android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec); |
| 1159 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1160 | return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1161 | } catch (RemoteException e) { |
| 1162 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1163 | } |
| 1164 | } |
| 1165 | return null; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Returns the component name setting the global proxy. |
| 1170 | * @return ComponentName object of the device admin that set the global proxy, or |
| 1171 | * null if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1172 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1173 | */ |
| 1174 | public ComponentName getGlobalProxyAdmin() { |
| 1175 | if (mService != null) { |
| 1176 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1177 | return mService.getGlobalProxyAdmin(UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1178 | } catch (RemoteException e) { |
| 1179 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1180 | } |
| 1181 | } |
| 1182 | return null; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1186 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1187 | * indicating that encryption is not supported. |
| 1188 | */ |
| 1189 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 1190 | |
| 1191 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1192 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1193 | * indicating that encryption is supported, but is not currently active. |
| 1194 | */ |
| 1195 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 1196 | |
| 1197 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1198 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1199 | * indicating that encryption is not currently active, but is currently |
| 1200 | * being activated. This is only reported by devices that support |
| 1201 | * encryption of data and only when the storage is currently |
| 1202 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 1203 | * to become encrypted will never return this value. |
| 1204 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1205 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1206 | |
| 1207 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1208 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1209 | * indicating that encryption is active. |
| 1210 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1211 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1212 | |
| 1213 | /** |
| 1214 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 1215 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 1216 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 1217 | * to check encryption status. However, on some devices this activity may never return, as |
| 1218 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 1219 | */ |
| 1220 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1221 | public static final String ACTION_START_ENCRYPTION |
| 1222 | = "android.app.action.START_ENCRYPTION"; |
| 1223 | |
| 1224 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1225 | * Widgets are enabled in keyguard |
| 1226 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1227 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1228 | |
| 1229 | /** |
| 1230 | * Disable all keyguard widgets |
| 1231 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1232 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 1233 | |
| 1234 | /** |
| 1235 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1236 | */ |
| 1237 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 1238 | |
| 1239 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1240 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1241 | */ |
| 1242 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1243 | |
| 1244 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1245 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1246 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1247 | * |
| 1248 | * <p>When multiple device administrators attempt to control device |
| 1249 | * encryption, the most secure, supported setting will always be |
| 1250 | * used. If any device administrator requests device encryption, |
| 1251 | * it will be enabled; Conversely, if a device administrator |
| 1252 | * attempts to disable device encryption while another |
| 1253 | * device administrator has enabled it, the call to disable will |
| 1254 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 1255 | * |
| 1256 | * <p>This policy controls encryption of the secure (application data) storage area. Data |
Andy Stadler | 50c294f | 2011-03-07 19:13:42 -0800 | [diff] [blame] | 1257 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 1258 | * or control the encryption of any other storage areas. |
| 1259 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 1260 | * {@code true}, then the directory returned by |
| 1261 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 1262 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1263 | * |
| 1264 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 1265 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 1266 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 1267 | * also require (and check for) a pattern, PIN, or password. |
| 1268 | * |
| 1269 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1270 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1271 | * @return the new request status (for all active admins) - will be one of |
| 1272 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 1273 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 1274 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1275 | */ |
| 1276 | public int setStorageEncryption(ComponentName admin, boolean encrypt) { |
| 1277 | if (mService != null) { |
| 1278 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1279 | return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1280 | } catch (RemoteException e) { |
| 1281 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1282 | } |
| 1283 | } |
| 1284 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1289 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1290 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1291 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 1292 | * this will return the requested encryption setting as an aggregate of all active |
| 1293 | * administrators. |
| 1294 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1295 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1296 | public boolean getStorageEncryption(ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1297 | if (mService != null) { |
| 1298 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1299 | return mService.getStorageEncryption(admin, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1300 | } catch (RemoteException e) { |
| 1301 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1302 | } |
| 1303 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1304 | return false; |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * Called by an application that is administering the device to |
| 1309 | * determine the current encryption status of the device. |
| 1310 | * |
| 1311 | * Depending on the returned status code, the caller may proceed in different |
| 1312 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 1313 | * storage system does not support encryption. If the |
| 1314 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 1315 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
| 1316 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
| 1317 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 1318 | * |
| 1319 | * @return current status of encryption. The value will be one of |
| 1320 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
| 1321 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}. |
| 1322 | */ |
| 1323 | public int getStorageEncryptionStatus() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1324 | return getStorageEncryptionStatus(UserHandle.myUserId()); |
| 1325 | } |
| 1326 | |
| 1327 | /** @hide per-user version */ |
| 1328 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1329 | if (mService != null) { |
| 1330 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1331 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1332 | } catch (RemoteException e) { |
| 1333 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1334 | } |
| 1335 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1336 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1337 | } |
| 1338 | |
| 1339 | /** |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1340 | * Installs the given certificate as a User CA. |
| 1341 | * |
| 1342 | * @return false if the certBuffer cannot be parsed or installation is |
| 1343 | * interrupted, otherwise true |
| 1344 | * @hide |
| 1345 | */ |
| 1346 | public boolean installCaCert(byte[] certBuffer) { |
| 1347 | if (mService != null) { |
| 1348 | try { |
| 1349 | return mService.installCaCert(certBuffer); |
| 1350 | } catch (RemoteException e) { |
| 1351 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1352 | } |
| 1353 | } |
| 1354 | return false; |
| 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * Uninstalls the given certificate from the list of User CAs, if present. |
| 1359 | * |
| 1360 | * @hide |
| 1361 | */ |
| 1362 | public void uninstallCaCert(byte[] certBuffer) { |
| 1363 | if (mService != null) { |
| 1364 | try { |
| 1365 | mService.uninstallCaCert(certBuffer); |
| 1366 | } catch (RemoteException e) { |
| 1367 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1368 | } |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * Returns whether there are any user-installed CA certificates. |
| 1374 | * |
| 1375 | * @hide |
| 1376 | */ |
Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 1377 | public static boolean hasAnyCaCertsInstalled() { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1378 | TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 1379 | Set<String> aliases = certStore.userAliases(); |
| 1380 | return aliases != null && !aliases.isEmpty(); |
| 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * Returns whether this certificate has been installed as a User CA. |
| 1385 | * |
| 1386 | * @hide |
| 1387 | */ |
| 1388 | public boolean hasCaCertInstalled(byte[] certBuffer) { |
| 1389 | TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 1390 | String alias; |
| 1391 | byte[] pemCert; |
| 1392 | try { |
| 1393 | CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 1394 | X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 1395 | new ByteArrayInputStream(certBuffer)); |
| 1396 | return certStore.getCertificateAlias(cert) != null; |
| 1397 | } catch (CertificateException ce) { |
| 1398 | Log.w(TAG, "Could not parse certificate", ce); |
| 1399 | } |
| 1400 | return false; |
| 1401 | } |
| 1402 | |
| 1403 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1404 | * Called by an application that is administering the device to disable all cameras |
| 1405 | * on the device. After setting this, no applications will be able to access any cameras |
| 1406 | * on the device. |
| 1407 | * |
| 1408 | * <p>The calling device admin must have requested |
| 1409 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 1410 | * this method; if it has not, a security exception will be thrown. |
| 1411 | * |
| 1412 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1413 | * @param disabled Whether or not the camera should be disabled. |
| 1414 | */ |
| 1415 | public void setCameraDisabled(ComponentName admin, boolean disabled) { |
| 1416 | if (mService != null) { |
| 1417 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1418 | mService.setCameraDisabled(admin, disabled, UserHandle.myUserId()); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1419 | } catch (RemoteException e) { |
| 1420 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | /** |
| 1426 | * Determine whether or not the device's cameras have been disabled either by the current |
| 1427 | * admin, if specified, or all admins. |
| 1428 | * @param admin The name of the admin component to check, or null to check if any admins |
| 1429 | * have disabled the camera |
| 1430 | */ |
| 1431 | public boolean getCameraDisabled(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1432 | return getCameraDisabled(admin, UserHandle.myUserId()); |
| 1433 | } |
| 1434 | |
| 1435 | /** @hide per-user version */ |
| 1436 | public boolean getCameraDisabled(ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1437 | if (mService != null) { |
| 1438 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1439 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1440 | } catch (RemoteException e) { |
| 1441 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1442 | } |
| 1443 | } |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1448 | * Called by an application that is administering the device to disable keyguard customizations, |
| 1449 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 1450 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1451 | * |
| 1452 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1453 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1454 | * this method; if it has not, a security exception will be thrown. |
| 1455 | * |
| 1456 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1457 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 1458 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 1459 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1460 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1461 | public void setKeyguardDisabledFeatures(ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1462 | if (mService != null) { |
| 1463 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1464 | mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId()); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1465 | } catch (RemoteException e) { |
| 1466 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1472 | * Determine whether or not features have been disabled in keyguard either by the current |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1473 | * admin, if specified, or all admins. |
| 1474 | * @param admin The name of the admin component to check, or null to check if any admins |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1475 | * have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1476 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 1477 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1478 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1479 | public int getKeyguardDisabledFeatures(ComponentName admin) { |
| 1480 | return getKeyguardDisabledFeatures(admin, UserHandle.myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /** @hide per-user version */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1484 | public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1485 | if (mService != null) { |
| 1486 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1487 | return mService.getKeyguardDisabledFeatures(admin, userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1488 | } catch (RemoteException e) { |
| 1489 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1490 | } |
| 1491 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1492 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1496 | * @hide |
| 1497 | */ |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1498 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1499 | if (mService != null) { |
| 1500 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1501 | mService.setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1502 | } catch (RemoteException e) { |
| 1503 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1504 | } |
| 1505 | } |
| 1506 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1507 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1508 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1509 | * 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] | 1510 | * @hide |
| 1511 | */ |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1512 | public DeviceAdminInfo getAdminInfo(ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1513 | ActivityInfo ai; |
| 1514 | try { |
| 1515 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 1516 | PackageManager.GET_META_DATA); |
| 1517 | } catch (PackageManager.NameNotFoundException e) { |
| 1518 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 1519 | return null; |
| 1520 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1521 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1522 | ResolveInfo ri = new ResolveInfo(); |
| 1523 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1524 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1525 | try { |
| 1526 | return new DeviceAdminInfo(mContext, ri); |
| 1527 | } catch (XmlPullParserException e) { |
| 1528 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 1529 | return null; |
| 1530 | } catch (IOException e) { |
| 1531 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 1532 | return null; |
| 1533 | } |
| 1534 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1535 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1536 | /** |
| 1537 | * @hide |
| 1538 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1539 | public void getRemoveWarning(ComponentName admin, RemoteCallback result) { |
| 1540 | if (mService != null) { |
| 1541 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1542 | mService.getRemoveWarning(admin, result, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1543 | } catch (RemoteException e) { |
| 1544 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * @hide |
| 1551 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1552 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1553 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1554 | if (mService != null) { |
| 1555 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1556 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1557 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1558 | } catch (RemoteException e) { |
| 1559 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1560 | } |
| 1561 | } |
| 1562 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1563 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1564 | /** |
| 1565 | * @hide |
| 1566 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1567 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1568 | if (mService != null) { |
| 1569 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1570 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1571 | } catch (RemoteException e) { |
| 1572 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1573 | } |
| 1574 | } |
| 1575 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1576 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1577 | /** |
| 1578 | * @hide |
| 1579 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1580 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1581 | if (mService != null) { |
| 1582 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1583 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1584 | } catch (RemoteException e) { |
| 1585 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1586 | } |
| 1587 | } |
| 1588 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1589 | |
| 1590 | /** |
| 1591 | * @hide |
| 1592 | * Sets the given package as the device owner. The package must already be installed and there |
| 1593 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 1594 | * method must be called before the device is provisioned. |
| 1595 | * @param packageName the package name of the application to be registered as the device owner. |
| 1596 | * @return whether the package was successfully registered as the device owner. |
| 1597 | * @throws IllegalArgumentException if the package name is null or invalid |
| 1598 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 1599 | * already been provisioned. |
| 1600 | */ |
| 1601 | public boolean setDeviceOwner(String packageName) throws IllegalArgumentException, |
| 1602 | IllegalStateException { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 1603 | return setDeviceOwner(packageName, null); |
| 1604 | } |
| 1605 | |
| 1606 | /** |
| 1607 | * @hide |
| 1608 | * Sets the given package as the device owner. The package must already be installed and there |
| 1609 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 1610 | * method must be called before the device is provisioned. |
| 1611 | * @param packageName the package name of the application to be registered as the device owner. |
| 1612 | * @param ownerName the human readable name of the institution that owns this device. |
| 1613 | * @return whether the package was successfully registered as the device owner. |
| 1614 | * @throws IllegalArgumentException if the package name is null or invalid |
| 1615 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 1616 | * already been provisioned. |
| 1617 | */ |
| 1618 | public boolean setDeviceOwner(String packageName, String ownerName) |
| 1619 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1620 | if (mService != null) { |
| 1621 | try { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 1622 | return mService.setDeviceOwner(packageName, ownerName); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1623 | } catch (RemoteException re) { |
| 1624 | Log.w(TAG, "Failed to set device owner"); |
| 1625 | } |
| 1626 | } |
| 1627 | return false; |
| 1628 | } |
| 1629 | |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 1630 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1631 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 1632 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 1633 | * A device owner app is a special device admin that cannot be deactivated by the user, once |
| 1634 | * activated as a device admin. It also cannot be uninstalled. To check if a particular |
| 1635 | * package is currently registered as the device owner app, pass in the package name from |
| 1636 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
| 1637 | * admin apps that want to check if they are also registered as the device owner app. The |
| 1638 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 1639 | * the setup process. |
| 1640 | * @param packageName the package name of the app, to compare with the registered device owner |
| 1641 | * app, if any. |
| 1642 | * @return whether or not the package is registered as the device owner app. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1643 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 1644 | public boolean isDeviceOwnerApp(String packageName) { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1645 | if (mService != null) { |
| 1646 | try { |
| 1647 | return mService.isDeviceOwner(packageName); |
| 1648 | } catch (RemoteException re) { |
| 1649 | Log.w(TAG, "Failed to check device owner"); |
| 1650 | } |
| 1651 | } |
| 1652 | return false; |
| 1653 | } |
| 1654 | |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 1655 | /** |
| 1656 | * @hide |
| 1657 | * Redirect to isDeviceOwnerApp. |
| 1658 | */ |
| 1659 | public boolean isDeviceOwner(String packageName) { |
| 1660 | return isDeviceOwnerApp(packageName); |
| 1661 | } |
| 1662 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1663 | /** @hide */ |
| 1664 | public String getDeviceOwner() { |
| 1665 | if (mService != null) { |
| 1666 | try { |
| 1667 | return mService.getDeviceOwner(); |
| 1668 | } catch (RemoteException re) { |
| 1669 | Log.w(TAG, "Failed to get device owner"); |
| 1670 | } |
| 1671 | } |
| 1672 | return null; |
| 1673 | } |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 1674 | |
| 1675 | /** @hide */ |
| 1676 | public String getDeviceOwnerName() { |
| 1677 | if (mService != null) { |
| 1678 | try { |
| 1679 | return mService.getDeviceOwnerName(); |
| 1680 | } catch (RemoteException re) { |
| 1681 | Log.w(TAG, "Failed to get device owner"); |
| 1682 | } |
| 1683 | } |
| 1684 | return null; |
| 1685 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 1686 | |
| 1687 | /** |
| 1688 | * @hide |
| 1689 | * Sets the given package as the profile owner of the given user profile. The package must |
| 1690 | * already be installed and there shouldn't be an existing profile owner registered for this |
| 1691 | * user. Also, this method must be called before the user has been used for the first time. |
| 1692 | * @param packageName the package name of the application to be registered as profile owner. |
| 1693 | * @param ownerName the human readable name of the organisation associated with this DPM. |
Adam Connors | 661ec47 | 2014-02-11 13:59:46 +0000 | [diff] [blame] | 1694 | * @param userHandle the userId to set the profile owner for. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 1695 | * @return whether the package was successfully registered as the profile owner. |
| 1696 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 1697 | * the user has already been set up. |
| 1698 | */ |
Adam Connors | 661ec47 | 2014-02-11 13:59:46 +0000 | [diff] [blame] | 1699 | public boolean setProfileOwner(String packageName, String ownerName, int userHandle) |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 1700 | throws IllegalArgumentException { |
| 1701 | if (mService != null) { |
| 1702 | try { |
Adam Connors | 661ec47 | 2014-02-11 13:59:46 +0000 | [diff] [blame] | 1703 | return mService.setProfileOwner(packageName, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 1704 | } catch (RemoteException re) { |
| 1705 | Log.w(TAG, "Failed to set profile owner", re); |
| 1706 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 1707 | } |
| 1708 | } |
| 1709 | return false; |
| 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * Used to determine if a particular package is registered as the Profile Owner for the |
| 1714 | * current user. A profile owner is a special device admin that has additional priviledges |
| 1715 | * within the managed profile. |
| 1716 | * |
| 1717 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 1718 | * @return Whether or not the package is registered as the profile owner. |
| 1719 | */ |
| 1720 | public boolean isProfileOwnerApp(String packageName) { |
| 1721 | if (mService != null) { |
| 1722 | try { |
| 1723 | String profileOwnerPackage = mService.getProfileOwner( |
| 1724 | Process.myUserHandle().getIdentifier()); |
| 1725 | return profileOwnerPackage != null && profileOwnerPackage.equals(packageName); |
| 1726 | } catch (RemoteException re) { |
| 1727 | Log.w(TAG, "Failed to check profile owner"); |
| 1728 | } |
| 1729 | } |
| 1730 | return false; |
| 1731 | } |
| 1732 | |
| 1733 | /** |
| 1734 | * @hide |
| 1735 | * @return the packageName of the owner of the given user profile or null if no profile |
| 1736 | * owner has been set for that user. |
| 1737 | * @throws IllegalArgumentException if the userId is invalid. |
| 1738 | */ |
| 1739 | public String getProfileOwner() throws IllegalArgumentException { |
| 1740 | if (mService != null) { |
| 1741 | try { |
| 1742 | return mService.getProfileOwner(Process.myUserHandle().getIdentifier()); |
| 1743 | } catch (RemoteException re) { |
| 1744 | Log.w(TAG, "Failed to get profile owner"); |
| 1745 | throw new IllegalArgumentException( |
| 1746 | "Requested profile owner for invalid userId", re); |
| 1747 | } |
| 1748 | } |
| 1749 | return null; |
| 1750 | } |
| 1751 | |
| 1752 | /** |
| 1753 | * @hide |
| 1754 | * @return the human readable name of the organisation associated with this DPM or null if |
| 1755 | * one is not set. |
| 1756 | * @throws IllegalArgumentException if the userId is invalid. |
| 1757 | */ |
| 1758 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 1759 | if (mService != null) { |
| 1760 | try { |
| 1761 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 1762 | } catch (RemoteException re) { |
| 1763 | Log.w(TAG, "Failed to get profile owner"); |
| 1764 | throw new IllegalArgumentException( |
| 1765 | "Requested profile owner for invalid userId", re); |
| 1766 | } |
| 1767 | } |
| 1768 | return null; |
| 1769 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1770 | |
| 1771 | /** |
| 1772 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 1773 | * intents that match a certain intent filter. This activity will remain the default intent |
| 1774 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 1775 | * the intent preferences are reset. |
| 1776 | * |
| 1777 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 1778 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 1779 | * intent handler for the filter. |
| 1780 | * |
| 1781 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 1782 | * security exception will be thrown. |
| 1783 | * |
| 1784 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1785 | * @param filter The IntentFilter for which a default handler is added. |
| 1786 | * @param activity The Activity that is added as default intent handler. |
| 1787 | */ |
| 1788 | public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, |
| 1789 | ComponentName activity) { |
| 1790 | if (mService != null) { |
| 1791 | try { |
| 1792 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 1793 | } catch (RemoteException e) { |
| 1794 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | /** |
| 1800 | * Called by a profile owner or device owner to remove all persistent intent handler preferences |
Torne (Richard Coles) | 875e210 | 2014-02-24 14:11:56 +0000 | [diff] [blame^] | 1801 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1802 | * |
| 1803 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 1804 | * exception will be thrown. |
| 1805 | * |
| 1806 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1807 | * @param packageName The name of the package for which preferences are removed. |
| 1808 | */ |
| 1809 | public void clearPackagePersistentPreferredActivities(ComponentName admin, |
| 1810 | String packageName) { |
| 1811 | if (mService != null) { |
| 1812 | try { |
| 1813 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 1814 | } catch (RemoteException e) { |
| 1815 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1816 | } |
| 1817 | } |
| 1818 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1819 | } |