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