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