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