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