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