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; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 22 | import android.app.Activity; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 23 | import android.app.admin.IDevicePolicyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 26 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 28 | import android.content.pm.ActivityInfo; |
| 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.pm.ResolveInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 31 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 32 | import android.net.ProxyInfo; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 33 | import android.os.Bundle; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 34 | import android.os.Handler; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 35 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 36 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 37 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 38 | import android.os.RemoteException; |
| 39 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 40 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 41 | import android.os.UserManager; |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 42 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 43 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 44 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 45 | import android.util.Log; |
| 46 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 47 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 48 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 49 | import org.xmlpull.v1.XmlPullParserException; |
| 50 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 51 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 52 | import java.io.IOException; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 53 | import java.net.InetSocketAddress; |
| 54 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 55 | import java.security.KeyFactory; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 56 | import java.security.PrivateKey; |
| 57 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 58 | import java.security.cert.CertificateException; |
| 59 | import java.security.cert.CertificateFactory; |
| 60 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 61 | import java.security.spec.PKCS8EncodedKeySpec; |
| 62 | import java.security.spec.InvalidKeySpecException; |
| 63 | import java.security.NoSuchAlgorithmException; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 64 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 65 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 66 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 69 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 70 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 71 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally, |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 72 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 73 | * accessible to all device administrators unless the documentation for that method specifies that |
| 74 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 75 | * |
| 76 | * <div class="special reference"> |
| 77 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 78 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 79 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
| 80 | * developer guide.</p> |
| 81 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 82 | */ |
| 83 | public class DevicePolicyManager { |
| 84 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 85 | |
| 86 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 87 | private final IDevicePolicyManager mService; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 88 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 89 | private DevicePolicyManager(Context context, Handler handler) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 90 | mContext = context; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 91 | mService = IDevicePolicyManager.Stub.asInterface( |
| 92 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 93 | } |
| 94 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 95 | /** @hide */ |
| 96 | public static DevicePolicyManager create(Context context, Handler handler) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 97 | DevicePolicyManager me = new DevicePolicyManager(context, handler); |
| 98 | return me.mService != null ? me : null; |
| 99 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 100 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 101 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 102 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 103 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 104 | * <p>A managed profile allows data separation for example for the usage of a |
| 105 | * device as a personal and corporate device. The user which provisioning is started from and |
| 106 | * the managed profile share a launcher. |
| 107 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 108 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 109 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 110 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 111 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 112 | * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the |
| 113 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
| 114 | * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain the extra |
| 115 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 116 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 117 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 118 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 119 | * in the provisioning intent. The |
| 120 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 121 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 122 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 123 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 124 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 125 | * previous state. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 126 | * |
| 127 | * <p>Input: Nothing.</p> |
| 128 | * <p>Output: Nothing</p> |
| 129 | */ |
| 130 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 131 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 132 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 133 | |
| 134 | /** |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 135 | * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows |
| 136 | * a mobile device management application that starts managed profile provisioning to pass data |
| 137 | * to itself on the managed profile when provisioning completes. The mobile device management |
| 138 | * application sends this extra in an intent with the action |
| 139 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in |
| 140 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 141 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
| 142 | * during the managed profile provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 143 | */ |
| 144 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 145 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 146 | |
| 147 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 148 | * A String extra holding the package name of the mobile device management application that |
| 149 | * will be set as the profile owner or device owner. |
| 150 | * |
| 151 | * <p>If an application starts provisioning directly via an intent with action |
| 152 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 153 | * application that started provisioning. The package will be set as profile owner in that case. |
| 154 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 155 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 156 | * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 157 | * |
| 158 | * <p> When this extra is set, the application must have exactly one device admin receiver. |
| 159 | * This receiver will be set as the profile or device owner and active admin.</p> |
| 160 | |
| 161 | * @see DeviceAdminReceiver |
| 162 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
| 163 | * supported. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 164 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 165 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 166 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 167 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 168 | |
| 169 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 170 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 171 | * application that will be set as the profile owner or device owner and active admin. |
| 172 | * |
| 173 | * <p>If an application starts provisioning directly via an intent with action |
| 174 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} the package name of this component has to match the |
| 175 | * package name of the application that started provisioning. |
| 176 | * |
| 177 | * <p>This component is set as device owner and active admin when device owner provisioning is |
| 178 | * started by an NFC message containing an NFC record with MIME type |
| 179 | * {@link #MIME_TYPE_PROVISIONING_NFC}. |
| 180 | * |
| 181 | * @see DeviceAdminReceiver |
| 182 | */ |
| 183 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 184 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 185 | |
| 186 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 187 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 188 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 189 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 190 | * |
| 191 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 192 | */ |
| 193 | |
| 194 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 195 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 196 | |
| 197 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 198 | * A String extra that, holds the email address of the account which a managed profile is |
| 199 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 200 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 201 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 202 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 203 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 204 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 205 | * contains this extra, it is forwarded in the |
| 206 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 207 | * device management application that was set as the profile owner during provisioning. |
| 208 | * It is usually used to avoid that the user has to enter their email address twice. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 209 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 210 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 211 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 212 | |
| 213 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 214 | * A Boolean extra that can be used by the mobile device management application to skip the |
| 215 | * disabling of system apps during provisioning when set to <code>true</code>. |
| 216 | * |
| 217 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 218 | * provisioning via an NFC bump. |
| 219 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 220 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 221 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 222 | |
| 223 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 224 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 225 | * will be set to. |
| 226 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 227 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 228 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 229 | */ |
| 230 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 231 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 232 | |
| 233 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 234 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 235 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 236 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 237 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 238 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 239 | */ |
| 240 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 241 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 245 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 246 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 247 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 248 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 249 | */ |
| 250 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 251 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 252 | |
| 253 | /** |
| 254 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 255 | * owner provisioning for downloading the mobile device management application. |
| 256 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 257 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 258 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 259 | */ |
| 260 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 261 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 265 | * is hidden or not. |
| 266 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 267 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 268 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 269 | */ |
| 270 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 271 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * A String extra indicating the security type of the wifi network in |
| 275 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 276 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 277 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 278 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 279 | */ |
| 280 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 281 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * A String extra holding the password of the wifi network in |
| 285 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 286 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 287 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 288 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 289 | */ |
| 290 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 291 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 292 | |
| 293 | /** |
| 294 | * A String extra holding the proxy host for the wifi network in |
| 295 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 296 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 297 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 298 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 299 | */ |
| 300 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 301 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * An int extra holding the proxy port for the wifi network in |
| 305 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 306 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 307 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 308 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 309 | */ |
| 310 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 311 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 312 | |
| 313 | /** |
| 314 | * A String extra holding the proxy bypass for the wifi network in |
| 315 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 316 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 317 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 318 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 319 | */ |
| 320 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 321 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 325 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 326 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 327 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 328 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 329 | */ |
| 330 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 331 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * A String extra holding a url that specifies the download location of the device admin |
| 335 | * package. When not provided it is assumed that the device admin package is already installed. |
| 336 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 337 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 338 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 339 | */ |
| 340 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 341 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 342 | |
| 343 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 344 | * An int extra holding a minimum required version code for the device admin package. If the |
| 345 | * device admin is already installed on the device, it will only be re-downloaded from |
| 346 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 347 | * installed package is less than this version code. |
| 348 | * |
| 349 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 350 | * provisioning via an NFC bump. |
| 351 | */ |
| 352 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 353 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 354 | |
| 355 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 356 | * A String extra holding a http cookie header which should be used in the http request to the |
| 357 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 358 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 359 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 360 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 361 | */ |
| 362 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 363 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 364 | |
| 365 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 366 | * A String extra holding the SHA-1 checksum of the file at download location specified in |
| 367 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match |
| 368 | * the file at the download location an error will be shown to the user and the user will be |
| 369 | * asked to factory reset the device. |
| 370 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 371 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 372 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 373 | */ |
| 374 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 375 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 376 | |
| 377 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 378 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 379 | * has completed successfully. |
| 380 | * |
| 381 | * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning |
| 382 | * intent (@see #ACTION_PROVISION_MANAGED_PROFILE). |
| 383 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 384 | * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 385 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 386 | */ |
| 387 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 388 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 389 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 390 | |
| 391 | /** |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 392 | * A boolean extra indicating whether device encryption is required as part of Device Owner |
| 393 | * provisioning. |
| 394 | * |
| 395 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 396 | * provisioning via an NFC bump. |
| 397 | */ |
| 398 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 399 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 400 | |
| 401 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 402 | * On devices managed by a device owner app, a String representation of a Component name extra |
| 403 | * indicating the component of the application that is temporarily granted device owner |
| 404 | * privileges during device initialization and profile owner privileges during secondary user |
| 405 | * initialization. |
| 406 | * |
| 407 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 408 | * provisioning via an NFC bump. |
| 409 | * @see ComponentName#unflattenFromString() |
| 410 | */ |
| 411 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME |
| 412 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME"; |
| 413 | |
| 414 | /** |
| 415 | * A String extra holding an http url that specifies the download location of the device |
| 416 | * initializer package. When not provided it is assumed that the device initializer package is |
| 417 | * already installed. |
| 418 | * |
| 419 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 420 | * provisioning via an NFC bump. |
| 421 | */ |
| 422 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION |
| 423 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION"; |
| 424 | |
| 425 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 426 | * An int extra holding a minimum required version code for the device initializer package. |
| 427 | * If the initializer is already installed on the device, it will only be re-downloaded from |
| 428 | * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of |
| 429 | * the installed package is less than this version code. |
| 430 | * |
| 431 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 432 | * provisioning via an NFC bump. |
| 433 | */ |
| 434 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE |
| 435 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE"; |
| 436 | |
| 437 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 438 | * A String extra holding a http cookie header which should be used in the http request to the |
| 439 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. |
| 440 | * |
| 441 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 442 | * provisioning via an NFC bump. |
| 443 | */ |
| 444 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER |
| 445 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
| 446 | |
| 447 | /** |
| 448 | * A String extra holding the SHA-1 checksum of the file at download location specified in |
| 449 | * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't |
| 450 | * match the file at the download location an error will be shown to the user and the user will |
| 451 | * be asked to factory reset the device. |
| 452 | * |
| 453 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 454 | * provisioning via an NFC bump. |
| 455 | */ |
| 456 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM |
| 457 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM"; |
| 458 | |
| 459 | /** |
Craig Lafayette | 97e473e | 2015-03-19 10:19:38 -0400 | [diff] [blame] | 460 | * A String extra holding the MAC address of the Bluetooth device to connect to with status |
| 461 | * updates during provisioning. |
| 462 | * |
| 463 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 464 | * provisioning via an NFC bump. |
| 465 | */ |
| 466 | public static final String EXTRA_PROVISIONING_BT_MAC_ADDRESS |
| 467 | = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS"; |
| 468 | |
| 469 | /** |
| 470 | * A String extra holding the Bluetooth service UUID on the device to connect to with status |
| 471 | * updates during provisioning. |
| 472 | * |
| 473 | * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present. |
| 474 | * |
| 475 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 476 | * provisioning via an NFC bump. |
| 477 | */ |
| 478 | public static final String EXTRA_PROVISIONING_BT_UUID |
| 479 | = "android.app.extra.PROVISIONING_BT_UUID"; |
| 480 | |
| 481 | /** |
| 482 | * A String extra holding a unique identifier used to identify the device connecting over |
| 483 | * Bluetooth. This identifier will be part of every status message sent to the remote device. |
| 484 | * |
| 485 | * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present. |
| 486 | * |
| 487 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 488 | * provisioning via an NFC bump. |
| 489 | */ |
| 490 | public static final String EXTRA_PROVISIONING_BT_DEVICE_ID |
| 491 | = "android.app.extra.PROVISIONING_BT_DEVICE_ID"; |
| 492 | |
| 493 | /** |
| 494 | * A Boolean extra that that will cause a provisioned device to temporarily proxy network |
| 495 | * traffic over Bluetooth. When a Wi-Fi network is available, the network proxy will stop. |
| 496 | * |
| 497 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 498 | * provisioning via an NFC bump. |
| 499 | */ |
| 500 | public static final String EXTRA_PROVISIONING_BT_USE_PROXY |
| 501 | = "android.app.extra.PROVISIONING_BT_USE_PROXY"; |
| 502 | |
| 503 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 504 | * This MIME type is used for starting the Device Owner provisioning. |
| 505 | * |
| 506 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 507 | * A device owner has full control over the device. The device owner can not be modified by the |
| 508 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 509 | * reset. |
| 510 | * |
| 511 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 512 | * employee or client. |
| 513 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 514 | * <p> The NFC message should be send to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 515 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 516 | * <p>The NFC record must contain a serialized {@link java.util.Properties} object which |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 517 | * contains the following properties: |
| 518 | * <ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 519 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 520 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 521 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li> |
| 522 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 523 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 524 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 525 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 526 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 527 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 528 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 529 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 530 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 531 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 532 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 533 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 534 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 535 | * <p> |
| 536 | * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, it should also contain |
| 537 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
| 538 | * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain |
| 539 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, (although |
| 540 | * specifying only {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
| 541 | * This componentName must have been converted to a String via |
| 542 | * {@link android.content.ComponentName#flattenToString()} |
| 543 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 544 | * <p> When device owner provisioning has completed, an intent of the type |
| 545 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the |
| 546 | * device owner. |
| 547 | * |
| 548 | * <p> |
| 549 | * If provisioning fails, the device is factory reset. |
| 550 | * |
| 551 | * <p>Input: Nothing.</p> |
| 552 | * <p>Output: Nothing</p> |
| 553 | */ |
Esteban Talavera | f057f06 | 2014-08-20 14:27:45 +0100 | [diff] [blame] | 554 | public static final String MIME_TYPE_PROVISIONING_NFC |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 555 | = "application/com.android.managedprovisioning"; |
| 556 | |
| 557 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 558 | * Activity action: ask the user to add a new device administrator to the system. |
| 559 | * The desired policy is the ComponentName of the policy in the |
| 560 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 561 | * bring the user through adding the device administrator to the system (or |
| 562 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 563 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 564 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 565 | * field to provide the user with additional explanation (in addition |
| 566 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 567 | * |
| 568 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 569 | * user intervention). However, if your administrator has been updated and is requesting |
| 570 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 571 | * 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] | 572 | */ |
| 573 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 574 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 575 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 576 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 577 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 578 | * @hide |
| 579 | * Activity action: ask the user to add a new device administrator as the profile owner |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame^] | 580 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 581 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame^] | 582 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 583 | * extra field. This will invoke a UI to bring the user through adding the profile owner admin |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 584 | * to remotely control restrictions on the user. |
| 585 | * |
| 586 | * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the |
| 587 | * result of whether or not the user approved the action. If approved, the result will |
| 588 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 589 | * as a profile owner. |
| 590 | * |
| 591 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 592 | * field to provide the user with additional explanation (in addition |
| 593 | * to your component's description) about what is being added. |
| 594 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame^] | 595 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 596 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 597 | */ |
| 598 | @SystemApi |
| 599 | public static final String ACTION_SET_PROFILE_OWNER |
| 600 | = "android.app.action.SET_PROFILE_OWNER"; |
| 601 | |
| 602 | /** |
| 603 | * @hide |
| 604 | * Name of the profile owner admin that controls the user. |
| 605 | */ |
| 606 | @SystemApi |
| 607 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 608 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 609 | |
| 610 | /** |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 611 | * Activity action: send when any policy admin changes a policy. |
| 612 | * 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] | 613 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 614 | * @hide |
| 615 | */ |
| 616 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 617 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 618 | |
| 619 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 620 | * The ComponentName of the administrator component. |
| 621 | * |
| 622 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 623 | */ |
| 624 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 625 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 626 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 627 | * An optional CharSequence providing additional explanation for why the |
| 628 | * admin is being added. |
| 629 | * |
| 630 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 631 | */ |
| 632 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 633 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 634 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 635 | * Activity action: have the user enter a new password. This activity should |
| 636 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 637 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 638 | * enter a new password that meets the current requirements. You can use |
| 639 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 640 | * have the user select a new password in order to meet the current |
| 641 | * constraints. Upon being resumed from this activity, you can check the new |
| 642 | * password characteristics to see if they are sufficient. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 643 | */ |
| 644 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 645 | public static final String ACTION_SET_NEW_PASSWORD |
| 646 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 647 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 648 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 649 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 650 | * the parent profile to access intents sent from the managed profile. |
| 651 | * That is, when an app in the managed profile calls |
| 652 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 653 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 654 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 655 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 656 | |
| 657 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 658 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 659 | * the managed profile to access intents sent from the parent profile. |
| 660 | * That is, when an app in the parent profile calls |
| 661 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 662 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 663 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 664 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 665 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 666 | /** |
| 667 | * Return true if the given administrator component is currently |
| 668 | * active (enabled) in the system. |
| 669 | */ |
| 670 | public boolean isAdminActive(ComponentName who) { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 671 | return isAdminActiveAsUser(who, UserHandle.myUserId()); |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * @see #isAdminActive(ComponentName) |
| 676 | * @hide |
| 677 | */ |
| 678 | public boolean isAdminActiveAsUser(ComponentName who, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 679 | if (mService != null) { |
| 680 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 681 | return mService.isAdminActive(who, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 682 | } catch (RemoteException e) { |
| 683 | Log.w(TAG, "Failed talking with device policy service", e); |
| 684 | } |
| 685 | } |
| 686 | return false; |
| 687 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 688 | /** |
| 689 | * Return true if the given administrator component is currently being removed |
| 690 | * for the user. |
| 691 | * @hide |
| 692 | */ |
| 693 | public boolean isRemovingAdmin(ComponentName who, int userId) { |
| 694 | if (mService != null) { |
| 695 | try { |
| 696 | return mService.isRemovingAdmin(who, userId); |
| 697 | } catch (RemoteException e) { |
| 698 | Log.w(TAG, "Failed talking with device policy service", e); |
| 699 | } |
| 700 | } |
| 701 | return false; |
| 702 | } |
| 703 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 704 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 705 | /** |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 706 | * Return a list of all currently active device administrator's component |
| 707 | * names. Note that if there are no administrators than null may be |
| 708 | * returned. |
| 709 | */ |
| 710 | public List<ComponentName> getActiveAdmins() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 711 | return getActiveAdminsAsUser(UserHandle.myUserId()); |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * @see #getActiveAdmins() |
| 716 | * @hide |
| 717 | */ |
| 718 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 719 | if (mService != null) { |
| 720 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 721 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 722 | } catch (RemoteException e) { |
| 723 | Log.w(TAG, "Failed talking with device policy service", e); |
| 724 | } |
| 725 | } |
| 726 | return null; |
| 727 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 728 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 729 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 730 | * Used by package administration code to determine if a package can be stopped |
| 731 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 732 | * @hide |
| 733 | */ |
| 734 | public boolean packageHasActiveAdmins(String packageName) { |
| 735 | if (mService != null) { |
| 736 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 737 | return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 738 | } catch (RemoteException e) { |
| 739 | Log.w(TAG, "Failed talking with device policy service", e); |
| 740 | } |
| 741 | } |
| 742 | return false; |
| 743 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 744 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 745 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 746 | * Remove a current administration component. This can only be called |
| 747 | * by the application that owns the administration component; if you |
| 748 | * try to remove someone else's component, a security exception will be |
| 749 | * thrown. |
| 750 | */ |
| 751 | public void removeActiveAdmin(ComponentName who) { |
| 752 | if (mService != null) { |
| 753 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 754 | mService.removeActiveAdmin(who, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 755 | } catch (RemoteException e) { |
| 756 | Log.w(TAG, "Failed talking with device policy service", e); |
| 757 | } |
| 758 | } |
| 759 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 760 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 761 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 762 | * Returns true if an administrator has been granted a particular device policy. This can |
| 763 | * be used to check if the administrator was activated under an earlier set of policies, |
| 764 | * but requires additional policies after an upgrade. |
| 765 | * |
| 766 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 767 | * an active administrator, or an exception will be thrown. |
| 768 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 769 | */ |
| 770 | public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) { |
| 771 | if (mService != null) { |
| 772 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 773 | return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 774 | } catch (RemoteException e) { |
| 775 | Log.w(TAG, "Failed talking with device policy service", e); |
| 776 | } |
| 777 | } |
| 778 | return false; |
| 779 | } |
| 780 | |
| 781 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 782 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 783 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 784 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 785 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 786 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 787 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 788 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 789 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 790 | * recognition technology. This implies technologies that can recognize the identity of |
| 791 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 792 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 793 | */ |
| 794 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 795 | |
| 796 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 797 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
| 798 | * 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] | 799 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 800 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 801 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 802 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 803 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 804 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 805 | * password containing at least numeric characters. Note that quality |
| 806 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 807 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 808 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 809 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 810 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 811 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 812 | * password containing at least numeric characters with no repeating (4444) |
| 813 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 814 | * constants are ordered so that higher values are more restrictive. |
| 815 | */ |
| 816 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 817 | |
| 818 | /** |
| 819 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 820 | * password containing at least alphabetic (or other symbol) characters. |
| 821 | * Note that quality constants are ordered so that higher values are more |
| 822 | * restrictive. |
| 823 | */ |
| 824 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 825 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 826 | /** |
| 827 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 828 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 829 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 830 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 831 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 832 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 833 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 834 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 835 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 836 | * password containing at least a letter, a numerical digit and a special |
| 837 | * symbol, by default. With this password quality, passwords can be |
| 838 | * restricted to contain various sets of characters, like at least an |
| 839 | * uppercase letter, etc. These are specified using various methods, |
| 840 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 841 | * that quality constants are ordered so that higher values are more |
| 842 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 843 | */ |
| 844 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 845 | |
| 846 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 847 | * Called by an application that is administering the device to set the |
| 848 | * password restrictions it is imposing. After setting this, the user |
| 849 | * will not be able to enter a new password that is not at least as |
| 850 | * restrictive as what has been set. Note that the current password |
| 851 | * will remain until the user has set a new one, so the change does not |
| 852 | * take place immediately. To prompt the user for a new password, use |
| 853 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 854 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 855 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 856 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 857 | * the user's preference, and any other considerations) is the one that |
| 858 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 859 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 860 | * <p>The calling device admin must have requested |
| 861 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 862 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 863 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 864 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 865 | * @param quality The new desired quality. One of |
| 866 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 867 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 868 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 869 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 870 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 871 | public void setPasswordQuality(ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 872 | if (mService != null) { |
| 873 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 874 | mService.setPasswordQuality(admin, quality); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 875 | } catch (RemoteException e) { |
| 876 | Log.w(TAG, "Failed talking with device policy service", e); |
| 877 | } |
| 878 | } |
| 879 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 880 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 881 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 882 | * Retrieve the current minimum password quality for all admins of this user |
| 883 | * and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 884 | * @param admin The name of the admin component to check, or null to aggregate |
| 885 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 886 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 887 | public int getPasswordQuality(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 888 | return getPasswordQuality(admin, UserHandle.myUserId()); |
| 889 | } |
| 890 | |
| 891 | /** @hide per-user version */ |
| 892 | public int getPasswordQuality(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 893 | if (mService != null) { |
| 894 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 895 | return mService.getPasswordQuality(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 896 | } catch (RemoteException e) { |
| 897 | Log.w(TAG, "Failed talking with device policy service", e); |
| 898 | } |
| 899 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 900 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 901 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 902 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 903 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 904 | * Called by an application that is administering the device to set the |
| 905 | * minimum allowed password length. After setting this, the user |
| 906 | * will not be able to enter a new password that is not at least as |
| 907 | * restrictive as what has been set. Note that the current password |
| 908 | * will remain until the user has set a new one, so the change does not |
| 909 | * take place immediately. To prompt the user for a new password, use |
| 910 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 911 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 912 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 913 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 914 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 915 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 916 | * <p>The calling device admin must have requested |
| 917 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 918 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 919 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 920 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 921 | * @param length The new desired minimum password length. A value of 0 |
| 922 | * means there is no restriction. |
| 923 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 924 | public void setPasswordMinimumLength(ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 925 | if (mService != null) { |
| 926 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 927 | mService.setPasswordMinimumLength(admin, length); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 928 | } catch (RemoteException e) { |
| 929 | Log.w(TAG, "Failed talking with device policy service", e); |
| 930 | } |
| 931 | } |
| 932 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 933 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 934 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 935 | * Retrieve the current minimum password length for all admins of this |
| 936 | * user and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 937 | * @param admin The name of the admin component to check, or null to aggregate |
| 938 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 939 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 940 | public int getPasswordMinimumLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 941 | return getPasswordMinimumLength(admin, UserHandle.myUserId()); |
| 942 | } |
| 943 | |
| 944 | /** @hide per-user version */ |
| 945 | public int getPasswordMinimumLength(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 946 | if (mService != null) { |
| 947 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 948 | return mService.getPasswordMinimumLength(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 949 | } catch (RemoteException e) { |
| 950 | Log.w(TAG, "Failed talking with device policy service", e); |
| 951 | } |
| 952 | } |
| 953 | return 0; |
| 954 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 955 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 956 | /** |
| 957 | * Called by an application that is administering the device to set the |
| 958 | * minimum number of upper case letters required in the password. After |
| 959 | * setting this, the user will not be able to enter a new password that is |
| 960 | * not at least as restrictive as what has been set. Note that the current |
| 961 | * password will remain until the user has set a new one, so the change does |
| 962 | * not take place immediately. To prompt the user for a new password, use |
| 963 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 964 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 965 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 966 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 967 | * <p> |
| 968 | * The calling device admin must have requested |
| 969 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 970 | * this method; if it has not, a security exception will be thrown. |
| 971 | * |
| 972 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 973 | * with. |
| 974 | * @param length The new desired minimum number of upper case letters |
| 975 | * required in the password. A value of 0 means there is no |
| 976 | * restriction. |
| 977 | */ |
| 978 | public void setPasswordMinimumUpperCase(ComponentName admin, int length) { |
| 979 | if (mService != null) { |
| 980 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 981 | mService.setPasswordMinimumUpperCase(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 982 | } catch (RemoteException e) { |
| 983 | Log.w(TAG, "Failed talking with device policy service", e); |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 990 | * password for all admins of this user and its profiles or a particular one. |
| 991 | * This is the same value as set by |
| 992 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 993 | * and only applies when the password quality is |
| 994 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 995 | * |
| 996 | * @param admin The name of the admin component to check, or null to |
| 997 | * aggregate all admins. |
| 998 | * @return The minimum number of upper case letters required in the |
| 999 | * password. |
| 1000 | */ |
| 1001 | public int getPasswordMinimumUpperCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1002 | return getPasswordMinimumUpperCase(admin, UserHandle.myUserId()); |
| 1003 | } |
| 1004 | |
| 1005 | /** @hide per-user version */ |
| 1006 | public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1007 | if (mService != null) { |
| 1008 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1009 | return mService.getPasswordMinimumUpperCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1010 | } catch (RemoteException e) { |
| 1011 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1012 | } |
| 1013 | } |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Called by an application that is administering the device to set the |
| 1019 | * minimum number of lower case letters required in the password. After |
| 1020 | * setting this, the user will not be able to enter a new password that is |
| 1021 | * not at least as restrictive as what has been set. Note that the current |
| 1022 | * password will remain until the user has set a new one, so the change does |
| 1023 | * not take place immediately. To prompt the user for a new password, use |
| 1024 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1025 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1026 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1027 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1028 | * <p> |
| 1029 | * The calling device admin must have requested |
| 1030 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1031 | * this method; if it has not, a security exception will be thrown. |
| 1032 | * |
| 1033 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1034 | * with. |
| 1035 | * @param length The new desired minimum number of lower case letters |
| 1036 | * required in the password. A value of 0 means there is no |
| 1037 | * restriction. |
| 1038 | */ |
| 1039 | public void setPasswordMinimumLowerCase(ComponentName admin, int length) { |
| 1040 | if (mService != null) { |
| 1041 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1042 | mService.setPasswordMinimumLowerCase(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1043 | } catch (RemoteException e) { |
| 1044 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | /** |
| 1050 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1051 | * password for all admins of this user and its profiles or a particular one. |
| 1052 | * This is the same value as set by |
| 1053 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1054 | * and only applies when the password quality is |
| 1055 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1056 | * |
| 1057 | * @param admin The name of the admin component to check, or null to |
| 1058 | * aggregate all admins. |
| 1059 | * @return The minimum number of lower case letters required in the |
| 1060 | * password. |
| 1061 | */ |
| 1062 | public int getPasswordMinimumLowerCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1063 | return getPasswordMinimumLowerCase(admin, UserHandle.myUserId()); |
| 1064 | } |
| 1065 | |
| 1066 | /** @hide per-user version */ |
| 1067 | public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1068 | if (mService != null) { |
| 1069 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1070 | return mService.getPasswordMinimumLowerCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1071 | } catch (RemoteException e) { |
| 1072 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1073 | } |
| 1074 | } |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * Called by an application that is administering the device to set the |
| 1080 | * minimum number of letters required in the password. After setting this, |
| 1081 | * the user will not be able to enter a new password that is not at least as |
| 1082 | * restrictive as what has been set. Note that the current password will |
| 1083 | * remain until the user has set a new one, so the change does not take |
| 1084 | * place immediately. To prompt the user for a new password, use |
| 1085 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1086 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1087 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1088 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1089 | * <p> |
| 1090 | * The calling device admin must have requested |
| 1091 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1092 | * this method; if it has not, a security exception will be thrown. |
| 1093 | * |
| 1094 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1095 | * with. |
| 1096 | * @param length The new desired minimum number of letters required in the |
| 1097 | * password. A value of 0 means there is no restriction. |
| 1098 | */ |
| 1099 | public void setPasswordMinimumLetters(ComponentName admin, int length) { |
| 1100 | if (mService != null) { |
| 1101 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1102 | mService.setPasswordMinimumLetters(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1103 | } catch (RemoteException e) { |
| 1104 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1111 | * admins or a particular one. This is the same value as |
| 1112 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 1113 | * and only applies when the password quality is |
| 1114 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1115 | * |
| 1116 | * @param admin The name of the admin component to check, or null to |
| 1117 | * aggregate all admins. |
| 1118 | * @return The minimum number of letters required in the password. |
| 1119 | */ |
| 1120 | public int getPasswordMinimumLetters(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1121 | return getPasswordMinimumLetters(admin, UserHandle.myUserId()); |
| 1122 | } |
| 1123 | |
| 1124 | /** @hide per-user version */ |
| 1125 | public int getPasswordMinimumLetters(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1126 | if (mService != null) { |
| 1127 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1128 | return mService.getPasswordMinimumLetters(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1129 | } catch (RemoteException e) { |
| 1130 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1131 | } |
| 1132 | } |
| 1133 | return 0; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * Called by an application that is administering the device to set the |
| 1138 | * minimum number of numerical digits required in the password. After |
| 1139 | * setting this, the user will not be able to enter a new password that is |
| 1140 | * not at least as restrictive as what has been set. Note that the current |
| 1141 | * password will remain until the user has set a new one, so the change does |
| 1142 | * not take place immediately. To prompt the user for a new password, use |
| 1143 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1144 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1145 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1146 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1147 | * <p> |
| 1148 | * The calling device admin must have requested |
| 1149 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1150 | * this method; if it has not, a security exception will be thrown. |
| 1151 | * |
| 1152 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1153 | * with. |
| 1154 | * @param length The new desired minimum number of numerical digits required |
| 1155 | * in the password. A value of 0 means there is no restriction. |
| 1156 | */ |
| 1157 | public void setPasswordMinimumNumeric(ComponentName admin, int length) { |
| 1158 | if (mService != null) { |
| 1159 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1160 | mService.setPasswordMinimumNumeric(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1161 | } catch (RemoteException e) { |
| 1162 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1169 | * for all admins of this user and its profiles or a particular one. |
| 1170 | * This is the same value as set by |
| 1171 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1172 | * and only applies when the password quality is |
| 1173 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1174 | * |
| 1175 | * @param admin The name of the admin component to check, or null to |
| 1176 | * aggregate all admins. |
| 1177 | * @return The minimum number of numerical digits required in the password. |
| 1178 | */ |
| 1179 | public int getPasswordMinimumNumeric(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1180 | return getPasswordMinimumNumeric(admin, UserHandle.myUserId()); |
| 1181 | } |
| 1182 | |
| 1183 | /** @hide per-user version */ |
| 1184 | public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1185 | if (mService != null) { |
| 1186 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1187 | return mService.getPasswordMinimumNumeric(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1188 | } catch (RemoteException e) { |
| 1189 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1190 | } |
| 1191 | } |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * Called by an application that is administering the device to set the |
| 1197 | * minimum number of symbols required in the password. After setting this, |
| 1198 | * the user will not be able to enter a new password that is not at least as |
| 1199 | * restrictive as what has been set. Note that the current password will |
| 1200 | * remain until the user has set a new one, so the change does not take |
| 1201 | * place immediately. To prompt the user for a new password, use |
| 1202 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1203 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1204 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1205 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1206 | * <p> |
| 1207 | * The calling device admin must have requested |
| 1208 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1209 | * this method; if it has not, a security exception will be thrown. |
| 1210 | * |
| 1211 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1212 | * with. |
| 1213 | * @param length The new desired minimum number of symbols required in the |
| 1214 | * password. A value of 0 means there is no restriction. |
| 1215 | */ |
| 1216 | public void setPasswordMinimumSymbols(ComponentName admin, int length) { |
| 1217 | if (mService != null) { |
| 1218 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1219 | mService.setPasswordMinimumSymbols(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1220 | } catch (RemoteException e) { |
| 1221 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1228 | * admins or a particular one. This is the same value as |
| 1229 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1230 | * and only applies when the password quality is |
| 1231 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1232 | * |
| 1233 | * @param admin The name of the admin component to check, or null to |
| 1234 | * aggregate all admins. |
| 1235 | * @return The minimum number of symbols required in the password. |
| 1236 | */ |
| 1237 | public int getPasswordMinimumSymbols(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1238 | return getPasswordMinimumSymbols(admin, UserHandle.myUserId()); |
| 1239 | } |
| 1240 | |
| 1241 | /** @hide per-user version */ |
| 1242 | public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1243 | if (mService != null) { |
| 1244 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1245 | return mService.getPasswordMinimumSymbols(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1246 | } catch (RemoteException e) { |
| 1247 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1248 | } |
| 1249 | } |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1253 | /** |
| 1254 | * Called by an application that is administering the device to set the |
| 1255 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1256 | * required in the password. After setting this, the user will not be able |
| 1257 | * to enter a new password that is not at least as restrictive as what has |
| 1258 | * been set. Note that the current password will remain until the user has |
| 1259 | * set a new one, so the change does not take place immediately. To prompt |
| 1260 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1261 | * setting this value. This constraint is only imposed if the administrator |
| 1262 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1263 | * {@link #setPasswordQuality}. The default value is 0. |
| 1264 | * <p> |
| 1265 | * The calling device admin must have requested |
| 1266 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1267 | * this method; if it has not, a security exception will be thrown. |
| 1268 | * |
| 1269 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1270 | * with. |
| 1271 | * @param length The new desired minimum number of letters required in the |
| 1272 | * password. A value of 0 means there is no restriction. |
| 1273 | */ |
| 1274 | public void setPasswordMinimumNonLetter(ComponentName admin, int length) { |
| 1275 | if (mService != null) { |
| 1276 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1277 | mService.setPasswordMinimumNonLetter(admin, length); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1278 | } catch (RemoteException e) { |
| 1279 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1286 | * password for all admins of this user and its profiles or a particular one. |
| 1287 | * This is the same value as set by |
| 1288 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1289 | * and only applies when the password quality is |
| 1290 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1291 | * |
| 1292 | * @param admin The name of the admin component to check, or null to |
| 1293 | * aggregate all admins. |
| 1294 | * @return The minimum number of letters required in the password. |
| 1295 | */ |
| 1296 | public int getPasswordMinimumNonLetter(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1297 | return getPasswordMinimumNonLetter(admin, UserHandle.myUserId()); |
| 1298 | } |
| 1299 | |
| 1300 | /** @hide per-user version */ |
| 1301 | public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1302 | if (mService != null) { |
| 1303 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1304 | return mService.getPasswordMinimumNonLetter(admin, userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1305 | } catch (RemoteException e) { |
| 1306 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1307 | } |
| 1308 | } |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1312 | /** |
| 1313 | * Called by an application that is administering the device to set the length |
| 1314 | * of the password history. After setting this, the user will not be able to |
| 1315 | * enter a new password that is the same as any password in the history. Note |
| 1316 | * that the current password will remain until the user has set a new one, so |
| 1317 | * the change does not take place immediately. To prompt the user for a new |
| 1318 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1319 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1320 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1321 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1322 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1323 | * |
| 1324 | * <p> |
| 1325 | * The calling device admin must have requested |
| 1326 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1327 | * method; if it has not, a security exception will be thrown. |
| 1328 | * |
| 1329 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1330 | * with. |
| 1331 | * @param length The new desired length of password history. A value of 0 |
| 1332 | * means there is no restriction. |
| 1333 | */ |
| 1334 | public void setPasswordHistoryLength(ComponentName admin, int length) { |
| 1335 | if (mService != null) { |
| 1336 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1337 | mService.setPasswordHistoryLength(admin, length); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1338 | } catch (RemoteException e) { |
| 1339 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1345 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1346 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1347 | * the device password (for all admins). |
| 1348 | * |
| 1349 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1350 | * For example, to have the password expire 5 days from now, timeout would be |
| 1351 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1352 | * |
| 1353 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1354 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1355 | * <p>The calling device admin must have requested |
| 1356 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1357 | * method; if it has not, a security exception will be thrown. |
| 1358 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1359 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1360 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1361 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1362 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1363 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1364 | * means there is no restriction (unlimited). |
| 1365 | */ |
| 1366 | public void setPasswordExpirationTimeout(ComponentName admin, long timeout) { |
| 1367 | if (mService != null) { |
| 1368 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1369 | mService.setPasswordExpirationTimeout(admin, timeout); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1370 | } catch (RemoteException e) { |
| 1371 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1377 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1378 | * recurring expiration timeout provided in the call to |
| 1379 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
| 1380 | * aggregate of all policy administrators if admin is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1381 | * |
| 1382 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 1383 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1384 | */ |
| 1385 | public long getPasswordExpirationTimeout(ComponentName admin) { |
| 1386 | if (mService != null) { |
| 1387 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1388 | return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1389 | } catch (RemoteException e) { |
| 1390 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1391 | } |
| 1392 | } |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
| 1396 | /** |
| 1397 | * 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] | 1398 | * all admins of this user and its profiles if admin is null. If the password is |
| 1399 | * expired, this will return the time since the password expired as a negative number. |
| 1400 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1401 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1402 | * |
| 1403 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 1404 | * @return The password expiration time, in ms. |
| 1405 | */ |
| 1406 | public long getPasswordExpiration(ComponentName admin) { |
| 1407 | if (mService != null) { |
| 1408 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1409 | return mService.getPasswordExpiration(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1410 | } catch (RemoteException e) { |
| 1411 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1412 | } |
| 1413 | } |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
| 1417 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1418 | * Retrieve the current password history length for all admins of this |
| 1419 | * user and its profiles or a particular one. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1420 | * @param admin The name of the admin component to check, or null to aggregate |
| 1421 | * all admins. |
| 1422 | * @return The length of the password history |
| 1423 | */ |
| 1424 | public int getPasswordHistoryLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1425 | return getPasswordHistoryLength(admin, UserHandle.myUserId()); |
| 1426 | } |
| 1427 | |
| 1428 | /** @hide per-user version */ |
| 1429 | public int getPasswordHistoryLength(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1430 | if (mService != null) { |
| 1431 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1432 | return mService.getPasswordHistoryLength(admin, userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1433 | } catch (RemoteException e) { |
| 1434 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1435 | } |
| 1436 | } |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1440 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1441 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1442 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1443 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1444 | * @return Returns the maximum length that the user can enter. |
| 1445 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1446 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1447 | // Kind-of arbitrary. |
| 1448 | return 16; |
| 1449 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1450 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1451 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1452 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1453 | * to meet the policy requirements (quality, minimum length) that have been |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1454 | * requested by the admins of this user and its profiles. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1455 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1456 | * <p>The calling device admin must have requested |
| 1457 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1458 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1459 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1460 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1461 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1462 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1463 | if (mService != null) { |
| 1464 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1465 | return mService.isActivePasswordSufficient(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1466 | } catch (RemoteException e) { |
| 1467 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1468 | } |
| 1469 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1470 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1471 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1472 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1473 | /** |
| 1474 | * Retrieve the number of times the user has failed at entering a |
| 1475 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1476 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1477 | * <p>The calling device admin must have requested |
| 1478 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1479 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1480 | */ |
| 1481 | public int getCurrentFailedPasswordAttempts() { |
| 1482 | if (mService != null) { |
| 1483 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1484 | return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1485 | } catch (RemoteException e) { |
| 1486 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1487 | } |
| 1488 | } |
| 1489 | return -1; |
| 1490 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1491 | |
| 1492 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1493 | * Setting this to a value greater than zero enables a built-in policy |
| 1494 | * that will perform a device wipe after too many incorrect |
| 1495 | * device-unlock passwords have been entered. This built-in policy combines |
| 1496 | * watching for failed passwords and wiping the device, and requires |
| 1497 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1498 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1499 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1500 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1501 | * application only, erasing or revoking credentials, or reporting the |
| 1502 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1503 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1504 | * instead. Do not use this API, because if the maximum count is reached, |
| 1505 | * 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] | 1506 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1507 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1508 | * @param num The number of failed password attempts at which point the |
| 1509 | * device will wipe its data. |
| 1510 | */ |
| 1511 | public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) { |
| 1512 | if (mService != null) { |
| 1513 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1514 | mService.setMaximumFailedPasswordsForWipe(admin, num); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1515 | } catch (RemoteException e) { |
| 1516 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1517 | } |
| 1518 | } |
| 1519 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1520 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1521 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1522 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1523 | * 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] | 1524 | * or a particular one. |
| 1525 | * @param admin The name of the admin component to check, or null to aggregate |
| 1526 | * all admins. |
| 1527 | */ |
| 1528 | public int getMaximumFailedPasswordsForWipe(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1529 | return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId()); |
| 1530 | } |
| 1531 | |
| 1532 | /** @hide per-user version */ |
| 1533 | public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1534 | if (mService != null) { |
| 1535 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1536 | return mService.getMaximumFailedPasswordsForWipe(admin, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1537 | } catch (RemoteException e) { |
| 1538 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1539 | } |
| 1540 | } |
| 1541 | return 0; |
| 1542 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1543 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1544 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1545 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1546 | * for the given user. So for primary user, it might return the primary or |
| 1547 | * a managed profile. For a secondary user, it would be the same as the |
| 1548 | * user passed in. |
| 1549 | * @hide Used only by Keyguard |
| 1550 | */ |
| 1551 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1552 | if (mService != null) { |
| 1553 | try { |
| 1554 | return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle); |
| 1555 | } catch (RemoteException e) { |
| 1556 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1557 | } |
| 1558 | } |
| 1559 | return UserHandle.USER_NULL; |
| 1560 | } |
| 1561 | |
| 1562 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1563 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1564 | * the password again until the user has entered it. |
| 1565 | */ |
| 1566 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1567 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1568 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1569 | * Force a new device unlock password (the password needed to access the |
| 1570 | * entire device, not for individual accounts) on the user. This takes |
| 1571 | * effect immediately. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1572 | * The given password must be sufficient for the |
| 1573 | * current password quality and length constraints as returned by |
| 1574 | * {@link #getPasswordQuality(ComponentName)} and |
| 1575 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1576 | * these constraints, then it will be rejected and false returned. Note |
| 1577 | * that the password may be a stronger quality (containing alphanumeric |
| 1578 | * characters when the requested quality is only numeric), in which case |
| 1579 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1580 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1581 | * <p>Calling with a null or empty password will clear any existing PIN, |
| 1582 | * pattern or password if the current password constraints allow it. |
| 1583 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1584 | * <p>The calling device admin must have requested |
| 1585 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1586 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1587 | * |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 1588 | * <p>Calling this from a managed profile will throw a security exception. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1589 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1590 | * @param password The new password for the user. Null or empty clears the password. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1591 | * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1592 | * @return Returns true if the password was applied, or false if it is |
| 1593 | * not acceptable for the current constraints. |
| 1594 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1595 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1596 | if (mService != null) { |
| 1597 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1598 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1599 | } catch (RemoteException e) { |
| 1600 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1601 | } |
| 1602 | } |
| 1603 | return false; |
| 1604 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1605 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1606 | /** |
| 1607 | * Called by an application that is administering the device to set the |
| 1608 | * maximum time for user activity until the device will lock. This limits |
| 1609 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1610 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1611 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1612 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1613 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1614 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1615 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1616 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1617 | * A value of 0 means there is no restriction. |
| 1618 | */ |
| 1619 | public void setMaximumTimeToLock(ComponentName admin, long timeMs) { |
| 1620 | if (mService != null) { |
| 1621 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1622 | mService.setMaximumTimeToLock(admin, timeMs); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1623 | } catch (RemoteException e) { |
| 1624 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1625 | } |
| 1626 | } |
| 1627 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1628 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1629 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1630 | * Retrieve the current maximum time to unlock for all admins of this user |
| 1631 | * and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1632 | * @param admin The name of the admin component to check, or null to aggregate |
| 1633 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 1634 | * @return time in milliseconds for the given admin or the minimum value (strictest) of |
Jim Miller | 76b9b8b | 2014-08-22 17:04:57 -0700 | [diff] [blame] | 1635 | * all admins if admin is null. Returns 0 if there are no restrictions. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1636 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1637 | public long getMaximumTimeToLock(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1638 | return getMaximumTimeToLock(admin, UserHandle.myUserId()); |
| 1639 | } |
| 1640 | |
| 1641 | /** @hide per-user version */ |
| 1642 | public long getMaximumTimeToLock(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1643 | if (mService != null) { |
| 1644 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1645 | return mService.getMaximumTimeToLock(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1646 | } catch (RemoteException e) { |
| 1647 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1648 | } |
| 1649 | } |
| 1650 | return 0; |
| 1651 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1652 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1653 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1654 | * Make the device lock immediately, as if the lock screen timeout has |
| 1655 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1656 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1657 | * <p>The calling device admin must have requested |
| 1658 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 1659 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1660 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1661 | public void lockNow() { |
| 1662 | if (mService != null) { |
| 1663 | try { |
| 1664 | mService.lockNow(); |
| 1665 | } catch (RemoteException e) { |
| 1666 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1667 | } |
| 1668 | } |
| 1669 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1670 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1671 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1672 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1673 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1674 | */ |
| 1675 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 1676 | |
| 1677 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1678 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 1679 | * data. |
| 1680 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 1681 | * <p>This flag may only be set by device owner admins; if it is set by |
| 1682 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1683 | */ |
| 1684 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 1685 | |
| 1686 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 1687 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 1688 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1689 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1690 | * <p>The calling device admin must have requested |
| 1691 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 1692 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1693 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1694 | * @param flags Bit mask of additional options: currently supported flags |
| 1695 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 1696 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1697 | */ |
| 1698 | public void wipeData(int flags) { |
| 1699 | if (mService != null) { |
| 1700 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1701 | mService.wipeData(flags, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1702 | } catch (RemoteException e) { |
| 1703 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1704 | } |
| 1705 | } |
| 1706 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1707 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1708 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1709 | * Called by an application that is administering the device to set the |
| 1710 | * global proxy and exclusion list. |
| 1711 | * <p> |
| 1712 | * The calling device admin must have requested |
| 1713 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 1714 | * this method; if it has not, a security exception will be thrown. |
| 1715 | * Only the first device admin can set the proxy. If a second admin attempts |
| 1716 | * to set the proxy, the {@link ComponentName} of the admin originally setting the |
| 1717 | * proxy will be returned. If successful in setting the proxy, null will |
| 1718 | * be returned. |
| 1719 | * The method can be called repeatedly by the device admin alrady setting the |
| 1720 | * proxy to update the proxy and exclusion list. |
| 1721 | * |
| 1722 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1723 | * with. |
| 1724 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 1725 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 1726 | * @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] | 1727 | * @return returns null if the proxy was successfully set, or a {@link ComponentName} |
| 1728 | * of the device admin that sets thew proxy otherwise. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1729 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1730 | */ |
| 1731 | public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec, |
| 1732 | List<String> exclusionList ) { |
| 1733 | if (proxySpec == null) { |
| 1734 | throw new NullPointerException(); |
| 1735 | } |
| 1736 | if (mService != null) { |
| 1737 | try { |
| 1738 | String hostSpec; |
| 1739 | String exclSpec; |
| 1740 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 1741 | hostSpec = null; |
| 1742 | exclSpec = null; |
| 1743 | } else { |
| 1744 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 1745 | throw new IllegalArgumentException(); |
| 1746 | } |
| 1747 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 1748 | String hostName = sa.getHostName(); |
| 1749 | int port = sa.getPort(); |
| 1750 | StringBuilder hostBuilder = new StringBuilder(); |
| 1751 | hostSpec = hostBuilder.append(hostName) |
| 1752 | .append(":").append(Integer.toString(port)).toString(); |
| 1753 | if (exclusionList == null) { |
| 1754 | exclSpec = ""; |
| 1755 | } else { |
| 1756 | StringBuilder listBuilder = new StringBuilder(); |
| 1757 | boolean firstDomain = true; |
| 1758 | for (String exclDomain : exclusionList) { |
| 1759 | if (!firstDomain) { |
| 1760 | listBuilder = listBuilder.append(","); |
| 1761 | } else { |
| 1762 | firstDomain = false; |
| 1763 | } |
| 1764 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 1765 | } |
| 1766 | exclSpec = listBuilder.toString(); |
| 1767 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 1768 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 1769 | != android.net.Proxy.PROXY_VALID) |
| 1770 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1771 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1772 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1773 | } catch (RemoteException e) { |
| 1774 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1775 | } |
| 1776 | } |
| 1777 | return null; |
| 1778 | } |
| 1779 | |
| 1780 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 1781 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 1782 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 1783 | * doing something unusual like general internal filtering this may be useful. On |
| 1784 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 1785 | * |
| 1786 | * <p>This method requires the caller to be the device owner. |
| 1787 | * |
| 1788 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 1789 | * @see ProxyInfo |
| 1790 | * |
| 1791 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1792 | * with. |
| 1793 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 1794 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 1795 | */ |
| 1796 | public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) { |
| 1797 | if (mService != null) { |
| 1798 | try { |
| 1799 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 1800 | } catch (RemoteException e) { |
| 1801 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1807 | * Returns the component name setting the global proxy. |
| 1808 | * @return ComponentName object of the device admin that set the global proxy, or |
| 1809 | * null if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1810 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1811 | */ |
| 1812 | public ComponentName getGlobalProxyAdmin() { |
| 1813 | if (mService != null) { |
| 1814 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1815 | return mService.getGlobalProxyAdmin(UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1816 | } catch (RemoteException e) { |
| 1817 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1818 | } |
| 1819 | } |
| 1820 | return null; |
| 1821 | } |
| 1822 | |
| 1823 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1824 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1825 | * indicating that encryption is not supported. |
| 1826 | */ |
| 1827 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 1828 | |
| 1829 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1830 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1831 | * indicating that encryption is supported, but is not currently active. |
| 1832 | */ |
| 1833 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 1834 | |
| 1835 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 1836 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1837 | * indicating that encryption is not currently active, but is currently |
| 1838 | * being activated. This is only reported by devices that support |
| 1839 | * encryption of data and only when the storage is currently |
| 1840 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 1841 | * to become encrypted will never return this value. |
| 1842 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1843 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1844 | |
| 1845 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1846 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1847 | * indicating that encryption is active. |
| 1848 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1849 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1850 | |
| 1851 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 1852 | * Result code for {@link #getStorageEncryptionStatus}: |
| 1853 | * indicating that encryption is active, but an encryption key has not |
| 1854 | * been set by the user. |
| 1855 | */ |
| 1856 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 1857 | |
| 1858 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1859 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 1860 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 1861 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 1862 | * to check encryption status. However, on some devices this activity may never return, as |
| 1863 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 1864 | */ |
| 1865 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1866 | public static final String ACTION_START_ENCRYPTION |
| 1867 | = "android.app.action.START_ENCRYPTION"; |
| 1868 | |
| 1869 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1870 | * Widgets are enabled in keyguard |
| 1871 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1872 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1873 | |
| 1874 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1875 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1876 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1877 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 1878 | |
| 1879 | /** |
| 1880 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1881 | */ |
| 1882 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 1883 | |
| 1884 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1885 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1886 | */ |
| 1887 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 1888 | |
| 1889 | /** |
| 1890 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1891 | */ |
| 1892 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 1893 | |
| 1894 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 1895 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1896 | * (e.g. PIN/Pattern/Password). |
| 1897 | */ |
| 1898 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 1899 | |
| 1900 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 1901 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 1902 | */ |
| 1903 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 1904 | |
| 1905 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1906 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1907 | */ |
| 1908 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1909 | |
| 1910 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1911 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1912 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1913 | * |
| 1914 | * <p>When multiple device administrators attempt to control device |
| 1915 | * encryption, the most secure, supported setting will always be |
| 1916 | * used. If any device administrator requests device encryption, |
| 1917 | * it will be enabled; Conversely, if a device administrator |
| 1918 | * attempts to disable device encryption while another |
| 1919 | * device administrator has enabled it, the call to disable will |
| 1920 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 1921 | * |
| 1922 | * <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] | 1923 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 1924 | * or control the encryption of any other storage areas. |
| 1925 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 1926 | * {@code true}, then the directory returned by |
| 1927 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 1928 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1929 | * |
| 1930 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 1931 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 1932 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 1933 | * also require (and check for) a pattern, PIN, or password. |
| 1934 | * |
| 1935 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1936 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1937 | * @return the new request status (for all active admins) - will be one of |
| 1938 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 1939 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 1940 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1941 | */ |
| 1942 | public int setStorageEncryption(ComponentName admin, boolean encrypt) { |
| 1943 | if (mService != null) { |
| 1944 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1945 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1946 | } catch (RemoteException e) { |
| 1947 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1948 | } |
| 1949 | } |
| 1950 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1951 | } |
| 1952 | |
| 1953 | /** |
| 1954 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1955 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1956 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1957 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 1958 | * this will return the requested encryption setting as an aggregate of all active |
| 1959 | * administrators. |
| 1960 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1961 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1962 | public boolean getStorageEncryption(ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1963 | if (mService != null) { |
| 1964 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1965 | return mService.getStorageEncryption(admin, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1966 | } catch (RemoteException e) { |
| 1967 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1968 | } |
| 1969 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1970 | return false; |
| 1971 | } |
| 1972 | |
| 1973 | /** |
| 1974 | * Called by an application that is administering the device to |
| 1975 | * determine the current encryption status of the device. |
| 1976 | * |
| 1977 | * Depending on the returned status code, the caller may proceed in different |
| 1978 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 1979 | * storage system does not support encryption. If the |
| 1980 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 1981 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 1982 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 1983 | * storage system has enabled encryption but no password is set so further action |
| 1984 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1985 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 1986 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1987 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1988 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 1989 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 1990 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1991 | */ |
| 1992 | public int getStorageEncryptionStatus() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1993 | return getStorageEncryptionStatus(UserHandle.myUserId()); |
| 1994 | } |
| 1995 | |
| 1996 | /** @hide per-user version */ |
| 1997 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1998 | if (mService != null) { |
| 1999 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2000 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2001 | } catch (RemoteException e) { |
| 2002 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2003 | } |
| 2004 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2005 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2006 | } |
| 2007 | |
| 2008 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2009 | * Installs the given certificate as a user CA. |
| 2010 | * |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2011 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use |
| 2012 | * <code>null</code> if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2013 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2014 | * |
| 2015 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2016 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2017 | */ |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2018 | public boolean installCaCert(ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2019 | if (mService != null) { |
| 2020 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2021 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2022 | } catch (RemoteException e) { |
| 2023 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2024 | } |
| 2025 | } |
| 2026 | return false; |
| 2027 | } |
| 2028 | |
| 2029 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2030 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2031 | * |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2032 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use |
| 2033 | * <code>null</code> if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2034 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2035 | */ |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2036 | public void uninstallCaCert(ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2037 | if (mService != null) { |
| 2038 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2039 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2040 | mService.uninstallCaCert(admin, alias); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2041 | } catch (CertificateException e) { |
| 2042 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2043 | } catch (RemoteException e) { |
| 2044 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2050 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2051 | * If a user has installed any certificates by other means than device policy these will be |
| 2052 | * included too. |
| 2053 | * |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2054 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use |
| 2055 | * <code>null</code> if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2056 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2057 | */ |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2058 | public List<byte[]> getInstalledCaCerts(ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2059 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2060 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2061 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2062 | mService.enforceCanManageCaCerts(admin); |
| 2063 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2064 | for (String alias : certStore.userAliases()) { |
| 2065 | try { |
| 2066 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2067 | } catch (CertificateException ce) { |
| 2068 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2069 | } |
| 2070 | } |
| 2071 | } catch (RemoteException re) { |
| 2072 | Log.w(TAG, "Failed talking with device policy service", re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2079 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2080 | * means other than device policy will also be removed, except for system CA certificates. |
| 2081 | * |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2082 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use |
| 2083 | * <code>null</code> if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2084 | */ |
| 2085 | public void uninstallAllUserCaCerts(ComponentName admin) { |
| 2086 | if (mService != null) { |
| 2087 | for (String alias : new TrustedCertificateStore().userAliases()) { |
| 2088 | try { |
| 2089 | mService.uninstallCaCert(admin, alias); |
| 2090 | } catch (RemoteException re) { |
| 2091 | Log.w(TAG, "Failed talking with device policy service", re); |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | /** |
| 2098 | * Returns whether this certificate is installed as a trusted CA. |
| 2099 | * |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2100 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Use |
| 2101 | * <code>null</code> if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2102 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2103 | */ |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2104 | public boolean hasCaCertInstalled(ComponentName admin, byte[] certBuffer) { |
| 2105 | if (mService != null) { |
| 2106 | try { |
| 2107 | mService.enforceCanManageCaCerts(admin); |
| 2108 | return getCaCertAlias(certBuffer) != null; |
| 2109 | } catch (RemoteException re) { |
| 2110 | Log.w(TAG, "Failed talking with device policy service", re); |
| 2111 | } catch (CertificateException ce) { |
| 2112 | Log.w(TAG, "Could not parse certificate", ce); |
| 2113 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2114 | } |
| 2115 | return false; |
| 2116 | } |
| 2117 | |
| 2118 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2119 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 2120 | * keypair will be visible to all apps within the profile. |
| 2121 | * |
| 2122 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 2123 | * @param privKey The private key to install. |
| 2124 | * @param cert The certificate to install. |
| 2125 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2126 | * with that alias already exists, it will be overwritten. |
| 2127 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2128 | */ |
| 2129 | public boolean installKeyPair(ComponentName who, PrivateKey privKey, Certificate cert, |
| 2130 | String alias) { |
| 2131 | try { |
| 2132 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2133 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2134 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
| 2135 | return mService.installKeyPair(who, pkcs8Key, pemCert, alias); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2136 | } catch (RemoteException e) { |
| 2137 | Log.w(TAG, "Failed talking with device policy service", e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2138 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2139 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2140 | } catch (CertificateException | IOException e) { |
| 2141 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2142 | } |
| 2143 | return false; |
| 2144 | } |
| 2145 | |
| 2146 | /** |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2147 | * Returns the alias of a given CA certificate in the certificate store, or null if it |
| 2148 | * doesn't exist. |
| 2149 | */ |
| 2150 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2151 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2152 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2153 | new ByteArrayInputStream(certBuffer)); |
| 2154 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2155 | } |
| 2156 | |
| 2157 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2158 | * Called by a profile owner or device owner to grant access to privileged certificate |
| 2159 | * manipulation APIs to a third-party CA certificate installer app. Granted APIs include |
| 2160 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 2161 | * {@link #uninstallCaCert} and {@link #uninstallAllUserCaCerts}. |
| 2162 | * <p> |
| 2163 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2164 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2165 | * installer. |
| 2166 | * |
| 2167 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 2168 | * @param installerPackage The package name of the certificate installer which will be given |
| 2169 | * access. If <code>null</code> is given the current package will be cleared. |
| 2170 | */ |
| 2171 | public void setCertInstallerPackage(ComponentName who, String installerPackage) |
| 2172 | throws SecurityException { |
| 2173 | if (mService != null) { |
| 2174 | try { |
| 2175 | mService.setCertInstallerPackage(who, installerPackage); |
| 2176 | } catch (RemoteException e) { |
| 2177 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | |
| 2182 | /** |
| 2183 | * Called by a profile owner or device owner to retrieve the certificate installer for the |
| 2184 | * current user. null if none is set. |
| 2185 | * |
| 2186 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 2187 | * @return The package name of the current delegated certificate installer. <code>null</code> |
| 2188 | * if none is set. |
| 2189 | */ |
| 2190 | public String getCertInstallerPackage(ComponentName who) throws SecurityException { |
| 2191 | if (mService != null) { |
| 2192 | try { |
| 2193 | return mService.getCertInstallerPackage(who); |
| 2194 | } catch (RemoteException e) { |
| 2195 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2196 | } |
| 2197 | } |
| 2198 | return null; |
| 2199 | } |
| 2200 | |
| 2201 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2202 | * Called by an application that is administering the device to disable all cameras |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2203 | * on the device, for this user. After setting this, no applications running as this user |
| 2204 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2205 | * |
| 2206 | * <p>The calling device admin must have requested |
| 2207 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2208 | * this method; if it has not, a security exception will be thrown. |
| 2209 | * |
| 2210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2211 | * @param disabled Whether or not the camera should be disabled. |
| 2212 | */ |
| 2213 | public void setCameraDisabled(ComponentName admin, boolean disabled) { |
| 2214 | if (mService != null) { |
| 2215 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2216 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2217 | } catch (RemoteException e) { |
| 2218 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2224 | * Determine whether or not the device's cameras have been disabled for this user, |
| 2225 | * either by the current admin, if specified, or all admins. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2226 | * @param admin The name of the admin component to check, or null to check if any admins |
| 2227 | * have disabled the camera |
| 2228 | */ |
| 2229 | public boolean getCameraDisabled(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2230 | return getCameraDisabled(admin, UserHandle.myUserId()); |
| 2231 | } |
| 2232 | |
| 2233 | /** @hide per-user version */ |
| 2234 | public boolean getCameraDisabled(ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2235 | if (mService != null) { |
| 2236 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2237 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2238 | } catch (RemoteException e) { |
| 2239 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2240 | } |
| 2241 | } |
| 2242 | return false; |
| 2243 | } |
| 2244 | |
| 2245 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2246 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2247 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2248 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2249 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2250 | * |
| 2251 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2252 | * security exception will be thrown. |
| 2253 | * |
| 2254 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2255 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2256 | */ |
| 2257 | public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) { |
| 2258 | if (mService != null) { |
| 2259 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2260 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2261 | } catch (RemoteException e) { |
| 2262 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2263 | } |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * Determine whether or not screen capture has been disabled by the current |
| 2269 | * admin, if specified, or all admins. |
| 2270 | * @param admin The name of the admin component to check, or null to check if any admins |
| 2271 | * have disabled screen capture. |
| 2272 | */ |
| 2273 | public boolean getScreenCaptureDisabled(ComponentName admin) { |
| 2274 | return getScreenCaptureDisabled(admin, UserHandle.myUserId()); |
| 2275 | } |
| 2276 | |
| 2277 | /** @hide per-user version */ |
| 2278 | public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) { |
| 2279 | if (mService != null) { |
| 2280 | try { |
| 2281 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2282 | } catch (RemoteException e) { |
| 2283 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2284 | } |
| 2285 | } |
| 2286 | return false; |
| 2287 | } |
| 2288 | |
| 2289 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2290 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2291 | * required the user cannot set the date and time, but has to use network date and time. |
| 2292 | * |
| 2293 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2294 | * |
| 2295 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2296 | * be thrown. |
| 2297 | * |
| 2298 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2299 | * @param required Whether auto time is set required or not. |
| 2300 | */ |
| 2301 | public void setAutoTimeRequired(ComponentName admin, boolean required) { |
| 2302 | if (mService != null) { |
| 2303 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2304 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2305 | } catch (RemoteException e) { |
| 2306 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2307 | } |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | /** |
| 2312 | * @return true if auto time is required. |
| 2313 | */ |
| 2314 | public boolean getAutoTimeRequired() { |
| 2315 | if (mService != null) { |
| 2316 | try { |
| 2317 | return mService.getAutoTimeRequired(); |
| 2318 | } catch (RemoteException e) { |
| 2319 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2320 | } |
| 2321 | } |
| 2322 | return false; |
| 2323 | } |
| 2324 | |
| 2325 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2326 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2327 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2328 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2329 | * |
| 2330 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2331 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2332 | * this method; if it has not, a security exception will be thrown. |
| 2333 | * |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2334 | * <p>Calling this from a managed profile will throw a security exception. |
| 2335 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2336 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2337 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2338 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2339 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 2340 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2341 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2342 | public void setKeyguardDisabledFeatures(ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2343 | if (mService != null) { |
| 2344 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2345 | mService.setKeyguardDisabledFeatures(admin, which); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2346 | } catch (RemoteException e) { |
| 2347 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2348 | } |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2353 | * 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] | 2354 | * admin, if specified, or all admins. |
| 2355 | * @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] | 2356 | * have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2357 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2358 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2359 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2360 | public int getKeyguardDisabledFeatures(ComponentName admin) { |
| 2361 | return getKeyguardDisabledFeatures(admin, UserHandle.myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | /** @hide per-user version */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2365 | public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2366 | if (mService != null) { |
| 2367 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2368 | return mService.getKeyguardDisabledFeatures(admin, userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2369 | } catch (RemoteException e) { |
| 2370 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2371 | } |
| 2372 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2373 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2377 | * @hide |
| 2378 | */ |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2379 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2380 | if (mService != null) { |
| 2381 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2382 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2383 | } catch (RemoteException e) { |
| 2384 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2385 | } |
| 2386 | } |
| 2387 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2388 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2389 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2390 | * @hide |
| 2391 | */ |
| 2392 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) { |
| 2393 | setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId()); |
| 2394 | } |
| 2395 | |
| 2396 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 2397 | * 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] | 2398 | * @hide |
| 2399 | */ |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 2400 | public DeviceAdminInfo getAdminInfo(ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2401 | ActivityInfo ai; |
| 2402 | try { |
| 2403 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2404 | PackageManager.GET_META_DATA); |
| 2405 | } catch (PackageManager.NameNotFoundException e) { |
| 2406 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2407 | return null; |
| 2408 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2409 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2410 | ResolveInfo ri = new ResolveInfo(); |
| 2411 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2412 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2413 | try { |
| 2414 | return new DeviceAdminInfo(mContext, ri); |
| 2415 | } catch (XmlPullParserException e) { |
| 2416 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2417 | return null; |
| 2418 | } catch (IOException e) { |
| 2419 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2420 | return null; |
| 2421 | } |
| 2422 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2423 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2424 | /** |
| 2425 | * @hide |
| 2426 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2427 | public void getRemoveWarning(ComponentName admin, RemoteCallback result) { |
| 2428 | if (mService != null) { |
| 2429 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2430 | mService.getRemoveWarning(admin, result, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2431 | } catch (RemoteException e) { |
| 2432 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | /** |
| 2438 | * @hide |
| 2439 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2440 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2441 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2442 | if (mService != null) { |
| 2443 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2444 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2445 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2446 | } catch (RemoteException e) { |
| 2447 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2448 | } |
| 2449 | } |
| 2450 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2451 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2452 | /** |
| 2453 | * @hide |
| 2454 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2455 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2456 | if (mService != null) { |
| 2457 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2458 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2459 | } catch (RemoteException e) { |
| 2460 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2461 | } |
| 2462 | } |
| 2463 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2464 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2465 | /** |
| 2466 | * @hide |
| 2467 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2468 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2469 | if (mService != null) { |
| 2470 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2471 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2472 | } catch (RemoteException e) { |
| 2473 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2474 | } |
| 2475 | } |
| 2476 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2477 | |
| 2478 | /** |
| 2479 | * @hide |
| 2480 | * Sets the given package as the device owner. The package must already be installed and there |
| 2481 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 2482 | * method must be called before the device is provisioned. |
| 2483 | * @param packageName the package name of the application to be registered as the device owner. |
| 2484 | * @return whether the package was successfully registered as the device owner. |
| 2485 | * @throws IllegalArgumentException if the package name is null or invalid |
| 2486 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 2487 | * already been provisioned. |
| 2488 | */ |
| 2489 | public boolean setDeviceOwner(String packageName) throws IllegalArgumentException, |
| 2490 | IllegalStateException { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2491 | return setDeviceOwner(packageName, null); |
| 2492 | } |
| 2493 | |
| 2494 | /** |
| 2495 | * @hide |
| 2496 | * Sets the given package as the device owner. The package must already be installed and there |
| 2497 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 2498 | * method must be called before the device is provisioned. |
| 2499 | * @param packageName the package name of the application to be registered as the device owner. |
| 2500 | * @param ownerName the human readable name of the institution that owns this device. |
| 2501 | * @return whether the package was successfully registered as the device owner. |
| 2502 | * @throws IllegalArgumentException if the package name is null or invalid |
| 2503 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 2504 | * already been provisioned. |
| 2505 | */ |
| 2506 | public boolean setDeviceOwner(String packageName, String ownerName) |
| 2507 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2508 | if (mService != null) { |
| 2509 | try { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2510 | return mService.setDeviceOwner(packageName, ownerName); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2511 | } catch (RemoteException re) { |
| 2512 | Log.w(TAG, "Failed to set device owner"); |
| 2513 | } |
| 2514 | } |
| 2515 | return false; |
| 2516 | } |
| 2517 | |
| 2518 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2519 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 2520 | * A device owner app is a special device admin that cannot be deactivated by the user, once |
| 2521 | * activated as a device admin. It also cannot be uninstalled. To check if a particular |
| 2522 | * package is currently registered as the device owner app, pass in the package name from |
| 2523 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
| 2524 | * admin apps that want to check if they are also registered as the device owner app. The |
| 2525 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 2526 | * the setup process. |
| 2527 | * @param packageName the package name of the app, to compare with the registered device owner |
| 2528 | * app, if any. |
| 2529 | * @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] | 2530 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2531 | public boolean isDeviceOwnerApp(String packageName) { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2532 | if (mService != null) { |
| 2533 | try { |
| 2534 | return mService.isDeviceOwner(packageName); |
| 2535 | } catch (RemoteException re) { |
| 2536 | Log.w(TAG, "Failed to check device owner"); |
| 2537 | } |
| 2538 | } |
| 2539 | return false; |
| 2540 | } |
| 2541 | |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2542 | /** |
| 2543 | * @hide |
| 2544 | * Redirect to isDeviceOwnerApp. |
| 2545 | */ |
| 2546 | public boolean isDeviceOwner(String packageName) { |
| 2547 | return isDeviceOwnerApp(packageName); |
| 2548 | } |
| 2549 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2550 | /** |
| 2551 | * Clears the current device owner. The caller must be the device owner. |
| 2552 | * |
| 2553 | * This function should be used cautiously as once it is called it cannot |
| 2554 | * be undone. The device owner can only be set as a part of device setup |
| 2555 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2556 | * |
| 2557 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2558 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2559 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2560 | if (mService != null) { |
| 2561 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2562 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2563 | } catch (RemoteException re) { |
| 2564 | Log.w(TAG, "Failed to clear device owner"); |
| 2565 | } |
| 2566 | } |
| 2567 | } |
| 2568 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2569 | /** @hide */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 2570 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2571 | public String getDeviceOwner() { |
| 2572 | if (mService != null) { |
| 2573 | try { |
| 2574 | return mService.getDeviceOwner(); |
| 2575 | } catch (RemoteException re) { |
| 2576 | Log.w(TAG, "Failed to get device owner"); |
| 2577 | } |
| 2578 | } |
| 2579 | return null; |
| 2580 | } |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2581 | |
| 2582 | /** @hide */ |
| 2583 | public String getDeviceOwnerName() { |
| 2584 | if (mService != null) { |
| 2585 | try { |
| 2586 | return mService.getDeviceOwnerName(); |
| 2587 | } catch (RemoteException re) { |
| 2588 | Log.w(TAG, "Failed to get device owner"); |
| 2589 | } |
| 2590 | } |
| 2591 | return null; |
| 2592 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2593 | |
| 2594 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2595 | * Sets the given component as the device initializer. The package must already be installed and |
| 2596 | * set as an active device administrator, and there must not be an existing device initializer, |
| 2597 | * for this call to succeed. This method can only be called by an app holding the |
| 2598 | * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A |
| 2599 | * device initializer app is granted device owner privileges during device initialization and |
| 2600 | * profile owner privileges during secondary user initialization. |
| 2601 | * @param who Which {@link DeviceAdminReceiver} this request is associated with, or null if not |
| 2602 | * called by the device owner. |
| 2603 | * @param initializer Which {@link DeviceAdminReceiver} to make device initializer. |
| 2604 | * @param initializerName The user-visible name of the device initializer. |
| 2605 | * @return whether the package was successfully registered as the device initializer. |
| 2606 | * @throws IllegalArgumentException if the package name is null or invalid |
| 2607 | * @throws IllegalStateException if the caller is not device owner or the device has |
| 2608 | * already been provisioned or a device initializer already exists. |
| 2609 | */ |
| 2610 | public boolean setDeviceInitializer(ComponentName who, ComponentName initializer, |
| 2611 | String initializerName) throws IllegalArgumentException, IllegalStateException { |
| 2612 | if (mService != null) { |
| 2613 | try { |
| 2614 | return mService.setDeviceInitializer(who, initializer, initializerName); |
| 2615 | } catch (RemoteException re) { |
| 2616 | Log.w(TAG, "Failed to set device initializer"); |
| 2617 | } |
| 2618 | } |
| 2619 | return false; |
| 2620 | } |
| 2621 | |
| 2622 | /** |
| 2623 | * Used to determine if a particular package has been registered as the device initializer. |
| 2624 | * |
| 2625 | * @param packageName the package name of the app, to compare with the registered device |
| 2626 | * initializer app, if any. |
| 2627 | * @return whether or not the caller is registered as the device initializer app. |
| 2628 | */ |
| 2629 | public boolean isDeviceInitializerApp(String packageName) { |
| 2630 | if (mService != null) { |
| 2631 | try { |
| 2632 | return mService.isDeviceInitializer(packageName); |
| 2633 | } catch (RemoteException re) { |
| 2634 | Log.w(TAG, "Failed to check device initializer"); |
| 2635 | } |
| 2636 | } |
| 2637 | return false; |
| 2638 | } |
| 2639 | |
| 2640 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2641 | * Removes the device initializer, so that it will not be invoked on user initialization for any |
| 2642 | * subsequently created users. This method can be called by either the device owner or device |
Julia Reynolds | 1c3754a | 2015-03-05 10:06:41 -0500 | [diff] [blame] | 2643 | * initializer itself. The caller must be an active administrator. |
| 2644 | * |
| 2645 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2646 | */ |
Julia Reynolds | 1c3754a | 2015-03-05 10:06:41 -0500 | [diff] [blame] | 2647 | public void clearDeviceInitializerApp(ComponentName who) { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2648 | if (mService != null) { |
| 2649 | try { |
Julia Reynolds | 1c3754a | 2015-03-05 10:06:41 -0500 | [diff] [blame] | 2650 | mService.clearDeviceInitializer(who); |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2651 | } catch (RemoteException re) { |
| 2652 | Log.w(TAG, "Failed to clear device initializer"); |
| 2653 | } |
| 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | /** |
| 2658 | * @hide |
| 2659 | * Gets the device initializer of the system. |
| 2660 | * |
| 2661 | * @return the package name of the device initializer. |
| 2662 | */ |
| 2663 | @SystemApi |
| 2664 | public String getDeviceInitializerApp() { |
| 2665 | if (mService != null) { |
| 2666 | try { |
| 2667 | return mService.getDeviceInitializer(); |
| 2668 | } catch (RemoteException re) { |
| 2669 | Log.w(TAG, "Failed to get device initializer"); |
| 2670 | } |
| 2671 | } |
| 2672 | return null; |
| 2673 | } |
| 2674 | |
| 2675 | /** |
| 2676 | * Sets the enabled state of the user. A user should be enabled only once it is ready to |
| 2677 | * be used. |
| 2678 | * |
| 2679 | * <p>Device initializer must call this method to mark the user as functional. |
| 2680 | * Only the device initializer agent can call this. |
| 2681 | * |
| 2682 | * <p>When the user is enabled, if the device initializer is not also the device owner, the |
| 2683 | * device initializer will no longer have elevated permissions to call methods in this class. |
| 2684 | * Additionally, it will be removed as an active administrator and its |
| 2685 | * {@link DeviceAdminReceiver} will be disabled. |
| 2686 | * |
| 2687 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2688 | * @return whether the user is now enabled. |
| 2689 | */ |
| 2690 | public boolean setUserEnabled(ComponentName admin) { |
| 2691 | if (mService != null) { |
| 2692 | try { |
| 2693 | return mService.setUserEnabled(admin); |
| 2694 | } catch (RemoteException e) { |
| 2695 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2696 | } |
| 2697 | } |
| 2698 | return false; |
| 2699 | } |
| 2700 | |
| 2701 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2702 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2703 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2704 | * Sets the given component as an active admin and registers the package as the profile |
| 2705 | * owner for this user. The package must already be installed and there shouldn't be |
| 2706 | * an existing profile owner registered for this user. Also, this method must be called |
| 2707 | * before the user setup has been completed. |
| 2708 | * <p> |
| 2709 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 2710 | * MANAGE_DEVICE_ADMINS permission. |
| 2711 | * @param admin The component to register as an active admin and profile owner. |
| 2712 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 2713 | * @return whether the admin was successfully registered as the profile owner. |
| 2714 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 2715 | * the user has already been set up. |
| 2716 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 2717 | @SystemApi |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2718 | public boolean setActiveProfileOwner(ComponentName admin, String ownerName) |
| 2719 | throws IllegalArgumentException { |
| 2720 | if (mService != null) { |
| 2721 | try { |
| 2722 | final int myUserId = UserHandle.myUserId(); |
| 2723 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2724 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2725 | } catch (RemoteException re) { |
| 2726 | Log.w(TAG, "Failed to set profile owner " + re); |
| 2727 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2728 | } |
| 2729 | } |
| 2730 | return false; |
| 2731 | } |
| 2732 | |
| 2733 | /** |
| 2734 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2735 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 2736 | * be from the same package as the active profile owner for this user, otherwise a |
| 2737 | * SecurityException will be thrown. |
| 2738 | * |
| 2739 | * @param admin The component to remove as the profile owner. |
| 2740 | * @return |
| 2741 | */ |
| 2742 | @SystemApi |
| 2743 | public void clearProfileOwner(ComponentName admin) { |
| 2744 | if (mService != null) { |
| 2745 | try { |
| 2746 | mService.clearProfileOwner(admin); |
| 2747 | } catch (RemoteException re) { |
| 2748 | Log.w(TAG, "Failed to clear profile owner " + admin + re); |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2754 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2755 | * Checks if the user was already setup. |
| 2756 | */ |
| 2757 | public boolean hasUserSetupCompleted() { |
| 2758 | if (mService != null) { |
| 2759 | try { |
| 2760 | return mService.hasUserSetupCompleted(); |
| 2761 | } catch (RemoteException re) { |
| 2762 | Log.w(TAG, "Failed to check if user setup has completed"); |
| 2763 | } |
| 2764 | } |
| 2765 | return true; |
| 2766 | } |
| 2767 | |
| 2768 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2769 | * @hide |
| 2770 | * Sets the given component as the profile owner of the given user profile. The package must |
| 2771 | * already be installed and there shouldn't be an existing profile owner registered for this |
| 2772 | * user. Only the system can call this API if the user has already completed setup. |
| 2773 | * @param admin the component name to be registered as profile owner. |
| 2774 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 2775 | * @param userHandle the userId to set the profile owner for. |
| 2776 | * @return whether the component was successfully registered as the profile owner. |
| 2777 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or |
| 2778 | * the user has already been set up. |
| 2779 | */ |
| 2780 | public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle) |
| 2781 | throws IllegalArgumentException { |
| 2782 | if (admin == null) { |
| 2783 | throw new NullPointerException("admin cannot be null"); |
| 2784 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2785 | if (mService != null) { |
| 2786 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2787 | if (ownerName == null) { |
| 2788 | ownerName = ""; |
| 2789 | } |
| 2790 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2791 | } catch (RemoteException re) { |
| 2792 | Log.w(TAG, "Failed to set profile owner", re); |
| 2793 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2794 | } |
| 2795 | } |
| 2796 | return false; |
| 2797 | } |
| 2798 | |
| 2799 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2800 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 2801 | * be used. Only the profile owner can call this. |
| 2802 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2803 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2804 | * |
| 2805 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2806 | */ |
| 2807 | public void setProfileEnabled(ComponentName admin) { |
| 2808 | if (mService != null) { |
| 2809 | try { |
| 2810 | mService.setProfileEnabled(admin); |
| 2811 | } catch (RemoteException e) { |
| 2812 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2813 | } |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2818 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 2819 | * which it is called from. Only a profile owner or device owner can call this. If this is |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 2820 | * never called by the profile or device owner, the name will be set to default values. |
| 2821 | * |
| 2822 | * @see #isProfileOwnerApp |
| 2823 | * @see #isDeviceOwnerApp |
| 2824 | * |
| 2825 | * @param profileName The name of the profile. |
| 2826 | */ |
| 2827 | public void setProfileName(ComponentName who, String profileName) { |
| 2828 | if (mService != null) { |
| 2829 | try { |
| 2830 | mService.setProfileName(who, profileName); |
| 2831 | } catch (RemoteException e) { |
| 2832 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2833 | } |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2838 | * 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] | 2839 | * current user. A profile owner is a special device admin that has additional privileges |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2840 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2841 | * |
| 2842 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 2843 | * @return Whether or not the package is registered as the profile owner. |
| 2844 | */ |
| 2845 | public boolean isProfileOwnerApp(String packageName) { |
| 2846 | if (mService != null) { |
| 2847 | try { |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 2848 | ComponentName profileOwner = mService.getProfileOwner( |
| 2849 | Process.myUserHandle().getIdentifier()); |
| 2850 | return profileOwner != null |
| 2851 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2852 | } catch (RemoteException re) { |
| 2853 | Log.w(TAG, "Failed to check profile owner"); |
| 2854 | } |
| 2855 | } |
| 2856 | return false; |
| 2857 | } |
| 2858 | |
| 2859 | /** |
| 2860 | * @hide |
| 2861 | * @return the packageName of the owner of the given user profile or null if no profile |
| 2862 | * owner has been set for that user. |
| 2863 | * @throws IllegalArgumentException if the userId is invalid. |
| 2864 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 2865 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2866 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 2867 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 2868 | } |
| 2869 | |
| 2870 | /** |
| 2871 | * @see #getProfileOwner() |
| 2872 | * @hide |
| 2873 | */ |
| 2874 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2875 | if (mService != null) { |
| 2876 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 2877 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2878 | } catch (RemoteException re) { |
| 2879 | Log.w(TAG, "Failed to get profile owner"); |
| 2880 | throw new IllegalArgumentException( |
| 2881 | "Requested profile owner for invalid userId", re); |
| 2882 | } |
| 2883 | } |
| 2884 | return null; |
| 2885 | } |
| 2886 | |
| 2887 | /** |
| 2888 | * @hide |
| 2889 | * @return the human readable name of the organisation associated with this DPM or null if |
| 2890 | * one is not set. |
| 2891 | * @throws IllegalArgumentException if the userId is invalid. |
| 2892 | */ |
| 2893 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 2894 | if (mService != null) { |
| 2895 | try { |
| 2896 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 2897 | } catch (RemoteException re) { |
| 2898 | Log.w(TAG, "Failed to get profile owner"); |
| 2899 | throw new IllegalArgumentException( |
| 2900 | "Requested profile owner for invalid userId", re); |
| 2901 | } |
| 2902 | } |
| 2903 | return null; |
| 2904 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2905 | |
| 2906 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 2907 | * @hide |
| 2908 | * @param user The user for whom to fetch the profile owner name, if any. |
| 2909 | * @return the human readable name of the organisation associated with this profile owner or |
| 2910 | * null if one is not set. |
| 2911 | * @throws IllegalArgumentException if the userId is invalid. |
| 2912 | */ |
| 2913 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 2914 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 2915 | if (mService != null) { |
| 2916 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 2917 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 2918 | } catch (RemoteException re) { |
| 2919 | Log.w(TAG, "Failed to get profile owner"); |
| 2920 | throw new IllegalArgumentException( |
| 2921 | "Requested profile owner for invalid userId", re); |
| 2922 | } |
| 2923 | } |
| 2924 | return null; |
| 2925 | } |
| 2926 | |
| 2927 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2928 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 2929 | * intents that match a certain intent filter. This activity will remain the default intent |
| 2930 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 2931 | * the intent preferences are reset. |
| 2932 | * |
| 2933 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 2934 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 2935 | * intent handler for the filter. |
| 2936 | * |
| 2937 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 2938 | * security exception will be thrown. |
| 2939 | * |
| 2940 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2941 | * @param filter The IntentFilter for which a default handler is added. |
| 2942 | * @param activity The Activity that is added as default intent handler. |
| 2943 | */ |
| 2944 | public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, |
| 2945 | ComponentName activity) { |
| 2946 | if (mService != null) { |
| 2947 | try { |
| 2948 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 2949 | } catch (RemoteException e) { |
| 2950 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2951 | } |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | /** |
| 2956 | * 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] | 2957 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2958 | * |
| 2959 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 2960 | * exception will be thrown. |
| 2961 | * |
| 2962 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2963 | * @param packageName The name of the package for which preferences are removed. |
| 2964 | */ |
| 2965 | public void clearPackagePersistentPreferredActivities(ComponentName admin, |
| 2966 | String packageName) { |
| 2967 | if (mService != null) { |
| 2968 | try { |
| 2969 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 2970 | } catch (RemoteException e) { |
| 2971 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2972 | } |
| 2973 | } |
| 2974 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2975 | |
| 2976 | /** |
| 2977 | * Called by a profile or device owner to set the application restrictions for a given target |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 2978 | * application running in the profile. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2979 | * |
| 2980 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be |
Kenny Guy | d00cfc5 | 2014-09-18 16:24:31 +0100 | [diff] [blame] | 2981 | * boolean, int, String, or String[]. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2982 | * |
| 2983 | * <p>The application restrictions are only made visible to the target application and the |
| 2984 | * profile or device owner. |
| 2985 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 2986 | * <p>If the restrictions are not available yet, but may be applied in the near future, |
| 2987 | * the admin can notify the target application of that by adding |
| 2988 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 2989 | * |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2990 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 2991 | * exception will be thrown. |
| 2992 | * |
| 2993 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2994 | * @param packageName The name of the package to update restricted settings for. |
| 2995 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 2996 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 2997 | * |
| 2998 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2999 | */ |
| 3000 | public void setApplicationRestrictions(ComponentName admin, String packageName, |
| 3001 | Bundle settings) { |
| 3002 | if (mService != null) { |
| 3003 | try { |
| 3004 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3005 | } catch (RemoteException e) { |
| 3006 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3007 | } |
| 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3012 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3013 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3014 | * trust agents but those enabled by this function call. If flag |
| 3015 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3016 | * |
| 3017 | * <p>The calling device admin must have requested |
| 3018 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3019 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3020 | * |
| 3021 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3022 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3023 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3024 | * will be strictly disabled according to the state of the |
| 3025 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 3026 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 3027 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 3028 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3029 | */ |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3030 | public void setTrustAgentConfiguration(ComponentName admin, ComponentName target, |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3031 | PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3032 | if (mService != null) { |
| 3033 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3034 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3035 | } catch (RemoteException e) { |
| 3036 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3037 | } |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3042 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 3043 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 3044 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3045 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3046 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3047 | * this function returns a list of configurations for all admins that declare |
| 3048 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 3049 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 3050 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 3051 | * for this {@param agent} or calls it with a null configuration, null is returned. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3052 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3053 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3054 | */ |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3055 | public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin, |
| 3056 | ComponentName agent) { |
| 3057 | return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId()); |
| 3058 | } |
| 3059 | |
| 3060 | /** @hide per-user version */ |
| 3061 | public List<PersistableBundle> getTrustAgentConfiguration(ComponentName admin, |
| 3062 | ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3063 | if (mService != null) { |
| 3064 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3065 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3066 | } catch (RemoteException e) { |
| 3067 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3068 | } |
| 3069 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3070 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3074 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 3075 | * the managed profile will be shown in the parent profile, for incoming calls. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3076 | * |
| 3077 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3078 | * security exception will be thrown. |
| 3079 | * |
| 3080 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 3081 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 3082 | */ |
| 3083 | public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) { |
| 3084 | if (mService != null) { |
| 3085 | try { |
| 3086 | mService.setCrossProfileCallerIdDisabled(who, disabled); |
| 3087 | } catch (RemoteException e) { |
| 3088 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3089 | } |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3094 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 3095 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3096 | * |
| 3097 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3098 | * security exception will be thrown. |
| 3099 | * |
| 3100 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 3101 | */ |
| 3102 | public boolean getCrossProfileCallerIdDisabled(ComponentName who) { |
| 3103 | if (mService != null) { |
| 3104 | try { |
| 3105 | return mService.getCrossProfileCallerIdDisabled(who); |
| 3106 | } catch (RemoteException e) { |
| 3107 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3108 | } |
| 3109 | } |
| 3110 | return false; |
| 3111 | } |
| 3112 | |
| 3113 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3114 | * Determine whether or not caller-Id information has been disabled. |
| 3115 | * |
| 3116 | * @param userHandle The user for whom to check the caller-id permission |
| 3117 | * @hide |
| 3118 | */ |
| 3119 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 3120 | if (mService != null) { |
| 3121 | try { |
| 3122 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 3123 | } catch (RemoteException e) { |
| 3124 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3125 | } |
| 3126 | } |
| 3127 | return false; |
| 3128 | } |
| 3129 | |
| 3130 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3131 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 3132 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 3133 | * Only activity intents are supported. |
| 3134 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3135 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3136 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 3137 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 3138 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 3139 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3140 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3141 | public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3142 | if (mService != null) { |
| 3143 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3144 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3145 | } catch (RemoteException e) { |
| 3146 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3147 | } |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3152 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 3153 | * that go from the managed profile to the parent, or from the parent to the managed profile. |
Nicolas Prevot | 3f7777f | 2014-07-24 15:58:39 +0100 | [diff] [blame] | 3154 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3155 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3156 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3157 | public void clearCrossProfileIntentFilters(ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3158 | if (mService != null) { |
| 3159 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3160 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3161 | } catch (RemoteException e) { |
| 3162 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3168 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 3169 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 3170 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 3171 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3172 | * By default the user can use any accessiblity service. When zero or more packages have |
| 3173 | * been added, accessiblity services that are not in the list and not part of the system |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 3174 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3175 | * |
| 3176 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 3177 | * can be used, calling with an empty list only allows the builtin system's services. |
| 3178 | * |
| 3179 | * <p> System accesibility services are always available to the user the list can't modify |
| 3180 | * this. |
| 3181 | * |
| 3182 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3183 | * @param packageNames List of accessibility service package names. |
| 3184 | * |
| 3185 | * @return true if setting the restriction succeeded. It fail if there is |
| 3186 | * one or more non-system accessibility services enabled, that are not in the list. |
| 3187 | */ |
| 3188 | public boolean setPermittedAccessibilityServices(ComponentName admin, |
| 3189 | List<String> packageNames) { |
| 3190 | if (mService != null) { |
| 3191 | try { |
| 3192 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 3193 | } catch (RemoteException e) { |
| 3194 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3195 | } |
| 3196 | } |
| 3197 | return false; |
| 3198 | } |
| 3199 | |
| 3200 | /** |
| 3201 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 3202 | * |
| 3203 | * <p>An empty list means no accessibility services except system services are allowed. |
| 3204 | * Null means all accessibility services are allowed. |
| 3205 | * |
| 3206 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3207 | * @return List of accessiblity service package names. |
| 3208 | */ |
| 3209 | public List<String> getPermittedAccessibilityServices(ComponentName admin) { |
| 3210 | if (mService != null) { |
| 3211 | try { |
| 3212 | return mService.getPermittedAccessibilityServices(admin); |
| 3213 | } catch (RemoteException e) { |
| 3214 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3215 | } |
| 3216 | } |
| 3217 | return null; |
| 3218 | } |
| 3219 | |
| 3220 | /** |
| 3221 | * Returns the list of accessibility services permitted by the device or profiles |
| 3222 | * owners of this user. |
| 3223 | * |
| 3224 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 3225 | * it will contain the intersection of the permitted lists for any device or profile |
| 3226 | * owners that apply to this user. It will also include any system accessibility services. |
| 3227 | * |
| 3228 | * @param userId which user to check for. |
| 3229 | * @return List of accessiblity service package names. |
| 3230 | * @hide |
| 3231 | */ |
| 3232 | @SystemApi |
| 3233 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 3234 | if (mService != null) { |
| 3235 | try { |
| 3236 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 3237 | } catch (RemoteException e) { |
| 3238 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3239 | } |
| 3240 | } |
| 3241 | return null; |
| 3242 | } |
| 3243 | |
| 3244 | /** |
| 3245 | * Called by a profile or device owner to set the permitted input methods services. When |
| 3246 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 3247 | * user the device owner or profile owner is an admin for. |
| 3248 | * |
| 3249 | * By default the user can use any input method. When zero or more packages have |
| 3250 | * been added, input method that are not in the list and not part of the system |
| 3251 | * can not be enabled by the user. |
| 3252 | * |
| 3253 | * This method will fail if it is called for a admin that is not for the foreground user |
| 3254 | * or a profile of the foreground user. |
| 3255 | * |
| 3256 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 3257 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 3258 | * |
| 3259 | * <p> System input methods are always available to the user this method can't modify this. |
| 3260 | * |
| 3261 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3262 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 3263 | * @return true if setting the restriction succeeded. It will fail if there are |
| 3264 | * one or more non-system input methods currently enabled that are not in |
| 3265 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3266 | */ |
| 3267 | public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) { |
| 3268 | if (mService != null) { |
| 3269 | try { |
| 3270 | return mService.setPermittedInputMethods(admin, packageNames); |
| 3271 | } catch (RemoteException e) { |
| 3272 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3273 | } |
| 3274 | } |
| 3275 | return false; |
| 3276 | } |
| 3277 | |
| 3278 | |
| 3279 | /** |
| 3280 | * Returns the list of permitted input methods set by this device or profile owner. |
| 3281 | * |
| 3282 | * <p>An empty list means no input methods except system input methods are allowed. |
| 3283 | * Null means all input methods are allowed. |
| 3284 | * |
| 3285 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3286 | * @return List of input method package names. |
| 3287 | */ |
| 3288 | public List<String> getPermittedInputMethods(ComponentName admin) { |
| 3289 | if (mService != null) { |
| 3290 | try { |
| 3291 | return mService.getPermittedInputMethods(admin); |
| 3292 | } catch (RemoteException e) { |
| 3293 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3294 | } |
| 3295 | } |
| 3296 | return null; |
| 3297 | } |
| 3298 | |
| 3299 | /** |
| 3300 | * Returns the list of input methods permitted by the device or profiles |
| 3301 | * owners of the current user. |
| 3302 | * |
| 3303 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 3304 | * it will contain the intersection of the permitted lists for any device or profile |
| 3305 | * owners that apply to this user. It will also include any system input methods. |
| 3306 | * |
| 3307 | * @return List of input method package names. |
| 3308 | * @hide |
| 3309 | */ |
| 3310 | @SystemApi |
| 3311 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 3312 | if (mService != null) { |
| 3313 | try { |
| 3314 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 3315 | } catch (RemoteException e) { |
| 3316 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3317 | } |
| 3318 | } |
| 3319 | return null; |
| 3320 | } |
| 3321 | |
| 3322 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3323 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 3324 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 3325 | * created. If you need to persist an identifier for this user, use |
| 3326 | * {@link UserManager#getSerialNumberForUser}. |
| 3327 | * |
| 3328 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3329 | * @param name the user's name |
| 3330 | * @see UserHandle |
| 3331 | * @return the UserHandle object for the created user, or null if the user could not be created. |
| 3332 | */ |
| 3333 | public UserHandle createUser(ComponentName admin, String name) { |
| 3334 | try { |
| 3335 | return mService.createUser(admin, name); |
| 3336 | } catch (RemoteException re) { |
| 3337 | Log.w(TAG, "Could not create a user", re); |
| 3338 | } |
| 3339 | return null; |
| 3340 | } |
| 3341 | |
| 3342 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 3343 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 3344 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 3345 | * created. If you need to persist an identifier for this user, use |
| 3346 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 3347 | * immediately. |
| 3348 | * |
| 3349 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 3350 | * as registered as an active admin on the new user. The profile owner package will be |
| 3351 | * installed on the new user if it already is installed on the device. |
| 3352 | * |
| 3353 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 3354 | * profileOwnerComponent when onEnable is called. |
| 3355 | * |
| 3356 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3357 | * @param name the user's name |
| 3358 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3359 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 3360 | * the user. |
| 3361 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 3362 | * on the new user. |
| 3363 | * @see UserHandle |
| 3364 | * @return the UserHandle object for the created user, or null if the user could not be created. |
| 3365 | */ |
| 3366 | public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName, |
| 3367 | ComponentName profileOwnerComponent, Bundle adminExtras) { |
| 3368 | try { |
| 3369 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 3370 | adminExtras); |
| 3371 | } catch (RemoteException re) { |
| 3372 | Log.w(TAG, "Could not create a user", re); |
| 3373 | } |
| 3374 | return null; |
| 3375 | } |
| 3376 | |
| 3377 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3378 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 3379 | * not be removed. |
| 3380 | * |
| 3381 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3382 | * @param userHandle the user to remove. |
| 3383 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 3384 | */ |
| 3385 | public boolean removeUser(ComponentName admin, UserHandle userHandle) { |
| 3386 | try { |
| 3387 | return mService.removeUser(admin, userHandle); |
| 3388 | } catch (RemoteException re) { |
| 3389 | Log.w(TAG, "Could not remove user ", re); |
| 3390 | return false; |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 3395 | * Called by a device owner to switch the specified user to the foreground. |
| 3396 | * |
| 3397 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3398 | * @param userHandle the user to switch to; null will switch to primary. |
| 3399 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 3400 | * |
| 3401 | * @see Intent#ACTION_USER_FOREGROUND |
| 3402 | */ |
| 3403 | public boolean switchUser(ComponentName admin, UserHandle userHandle) { |
| 3404 | try { |
| 3405 | return mService.switchUser(admin, userHandle); |
| 3406 | } catch (RemoteException re) { |
| 3407 | Log.w(TAG, "Could not switch user ", re); |
| 3408 | return false; |
| 3409 | } |
| 3410 | } |
| 3411 | |
| 3412 | /** |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3413 | * Called by a profile or device owner to get the application restrictions for a given target |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3414 | * application running in the profile. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3415 | * |
| 3416 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 3417 | * exception will be thrown. |
| 3418 | * |
| 3419 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3420 | * @param packageName The name of the package to fetch restricted settings of. |
| 3421 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 3422 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 3423 | * if no restrictions have been set. |
| 3424 | */ |
| 3425 | public Bundle getApplicationRestrictions(ComponentName admin, String packageName) { |
| 3426 | if (mService != null) { |
| 3427 | try { |
| 3428 | return mService.getApplicationRestrictions(admin, packageName); |
| 3429 | } catch (RemoteException e) { |
| 3430 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3431 | } |
| 3432 | } |
| 3433 | return null; |
| 3434 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3435 | |
| 3436 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3437 | * Called by a profile or device owner to set a user restriction specified by the key. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3438 | * <p> |
| 3439 | * The calling device admin must be a profile or device owner; if it is not, |
| 3440 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 3441 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3442 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 3443 | * with. |
| 3444 | * @param key The key of the restriction. See the constants in |
| 3445 | * {@link android.os.UserManager} for the list of keys. |
| 3446 | */ |
| 3447 | public void addUserRestriction(ComponentName admin, String key) { |
| 3448 | if (mService != null) { |
| 3449 | try { |
| 3450 | mService.setUserRestriction(admin, key, true); |
| 3451 | } catch (RemoteException e) { |
| 3452 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3453 | } |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3458 | * Called by a profile or device owner to clear a user restriction specified by the key. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3459 | * <p> |
| 3460 | * The calling device admin must be a profile or device owner; if it is not, |
| 3461 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 3462 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3463 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 3464 | * with. |
| 3465 | * @param key The key of the restriction. See the constants in |
| 3466 | * {@link android.os.UserManager} for the list of keys. |
| 3467 | */ |
| 3468 | public void clearUserRestriction(ComponentName admin, String key) { |
| 3469 | if (mService != null) { |
| 3470 | try { |
| 3471 | mService.setUserRestriction(admin, key, false); |
| 3472 | } catch (RemoteException e) { |
| 3473 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3474 | } |
| 3475 | } |
| 3476 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 3477 | |
| 3478 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3479 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3480 | * is unavailable for use, but the data and actual package file remain. |
| 3481 | * |
| 3482 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3483 | * @param packageName The name of the package to hide or unhide. |
| 3484 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 3485 | * unhidden. |
| 3486 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3487 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3488 | public boolean setApplicationHidden(ComponentName admin, String packageName, |
| 3489 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3490 | if (mService != null) { |
| 3491 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3492 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3493 | } catch (RemoteException e) { |
| 3494 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3495 | } |
| 3496 | } |
| 3497 | return false; |
| 3498 | } |
| 3499 | |
| 3500 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3501 | * Called by profile or device owners to determine if a package is hidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3502 | * |
| 3503 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3504 | * @param packageName The name of the package to retrieve the hidden status of. |
| 3505 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3506 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3507 | public boolean isApplicationHidden(ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3508 | if (mService != null) { |
| 3509 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3510 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3511 | } catch (RemoteException e) { |
| 3512 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3513 | } |
| 3514 | } |
| 3515 | return false; |
| 3516 | } |
| 3517 | |
| 3518 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3519 | * Called by profile or device owners to re-enable a system app that was disabled by default |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3520 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3521 | * |
| 3522 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3523 | * @param packageName The package to be re-enabled in the current profile. |
| 3524 | */ |
| 3525 | public void enableSystemApp(ComponentName admin, String packageName) { |
| 3526 | if (mService != null) { |
| 3527 | try { |
| 3528 | mService.enableSystemApp(admin, packageName); |
| 3529 | } catch (RemoteException e) { |
| 3530 | Log.w(TAG, "Failed to install package: " + packageName); |
| 3531 | } |
| 3532 | } |
| 3533 | } |
| 3534 | |
| 3535 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3536 | * Called by profile or device owners to re-enable system apps by intent that were disabled |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3537 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3538 | * |
| 3539 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3540 | * @param intent An intent matching the app(s) to be installed. All apps that resolve for this |
| 3541 | * intent will be re-enabled in the current profile. |
| 3542 | * @return int The number of activities that matched the intent and were installed. |
| 3543 | */ |
| 3544 | public int enableSystemApp(ComponentName admin, Intent intent) { |
| 3545 | if (mService != null) { |
| 3546 | try { |
| 3547 | return mService.enableSystemAppWithIntent(admin, intent); |
| 3548 | } catch (RemoteException e) { |
| 3549 | Log.w(TAG, "Failed to install packages matching filter: " + intent); |
| 3550 | } |
| 3551 | } |
| 3552 | return 0; |
| 3553 | } |
| 3554 | |
| 3555 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 3556 | * Called by a device owner or profile owner to disable account management for a specific type |
| 3557 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 3558 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 3559 | * <p>The calling device admin must be a device owner or profile owner. If it is not, a |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 3560 | * security exception will be thrown. |
| 3561 | * |
| 3562 | * <p>When account management is disabled for an account type, adding or removing an account |
| 3563 | * of that type will not be possible. |
| 3564 | * |
| 3565 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3566 | * @param accountType For which account management is disabled or enabled. |
| 3567 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 3568 | * enabled (false). |
| 3569 | */ |
| 3570 | public void setAccountManagementDisabled(ComponentName admin, String accountType, |
| 3571 | boolean disabled) { |
| 3572 | if (mService != null) { |
| 3573 | try { |
| 3574 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 3575 | } catch (RemoteException e) { |
| 3576 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3577 | } |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3582 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 3583 | * |
| 3584 | * <p> Account management can be disabled/enabled by calling |
| 3585 | * {@link #setAccountManagementDisabled}. |
| 3586 | * |
| 3587 | * @return a list of account types for which account management has been disabled. |
| 3588 | * |
| 3589 | * @see #setAccountManagementDisabled |
| 3590 | */ |
| 3591 | public String[] getAccountTypesWithManagementDisabled() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3592 | return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | /** |
| 3596 | * @see #getAccountTypesWithManagementDisabled() |
| 3597 | * @hide |
| 3598 | */ |
| 3599 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3600 | if (mService != null) { |
| 3601 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 3602 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3603 | } catch (RemoteException e) { |
| 3604 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3605 | } |
| 3606 | } |
| 3607 | |
| 3608 | return null; |
| 3609 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3610 | |
| 3611 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3612 | * Sets which packages may enter lock task mode. |
| 3613 | * |
| 3614 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 3615 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3616 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 3617 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3618 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3619 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3620 | * |
| 3621 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 3622 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 3623 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 3624 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3625 | */ |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3626 | public void setLockTaskPackages(ComponentName admin, String[] packages) |
| 3627 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3628 | if (mService != null) { |
| 3629 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3630 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3631 | } catch (RemoteException e) { |
| 3632 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3633 | } |
| 3634 | } |
| 3635 | } |
| 3636 | |
| 3637 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3638 | * This function returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3639 | * |
| 3640 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3641 | * @hide |
| 3642 | */ |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3643 | public String[] getLockTaskPackages(ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3644 | if (mService != null) { |
| 3645 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3646 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3647 | } catch (RemoteException e) { |
| 3648 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3649 | } |
| 3650 | } |
| 3651 | return null; |
| 3652 | } |
| 3653 | |
| 3654 | /** |
| 3655 | * This function lets the caller know whether the given component is allowed to start the |
| 3656 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3657 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3658 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3659 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3660 | if (mService != null) { |
| 3661 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3662 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3663 | } catch (RemoteException e) { |
| 3664 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3665 | } |
| 3666 | } |
| 3667 | return false; |
| 3668 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3669 | |
| 3670 | /** |
| 3671 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 3672 | * of the setting is in the correct form for the setting type should be performed by the caller. |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3673 | * <p>The settings that can be updated with this method are: |
| 3674 | * <ul> |
| 3675 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 3676 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 3677 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Nicolas Prevot | 41916d4 | 2015-02-24 18:41:50 +0000 | [diff] [blame] | 3678 | * <li>{@link Settings.Global#BLUETOOTH_ON} |
| 3679 | * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use |
| 3680 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 3681 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3682 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
| 3683 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 3684 | * <li>{@link Settings.Global#MODE_RINGER}</li> |
| 3685 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 3686 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Nicolas Prevot | 41916d4 | 2015-02-24 18:41:50 +0000 | [diff] [blame] | 3687 | * <li>{@link Settings.Global#WIFI_ON} |
| 3688 | * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use |
| 3689 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3690 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 3691 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
| 3692 | * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards |
| 3693 | * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3694 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3695 | * |
| 3696 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3697 | * @param setting The name of the setting to update. |
| 3698 | * @param value The value to update the setting to. |
| 3699 | */ |
| 3700 | public void setGlobalSetting(ComponentName admin, String setting, String value) { |
| 3701 | if (mService != null) { |
| 3702 | try { |
| 3703 | mService.setGlobalSetting(admin, setting, value); |
| 3704 | } catch (RemoteException e) { |
| 3705 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3706 | } |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | /** |
| 3711 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 3712 | * that the value of the setting is in the correct form for the setting type should be performed |
| 3713 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 3714 | * <p>The settings that can be updated by a profile or device owner with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3715 | * <ul> |
| 3716 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 3717 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3718 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 3719 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 3720 | * <p>A device owner can additionally update the following settings: |
| 3721 | * <ul> |
| 3722 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 3723 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3724 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3725 | * @param setting The name of the setting to update. |
| 3726 | * @param value The value to update the setting to. |
| 3727 | */ |
| 3728 | public void setSecureSetting(ComponentName admin, String setting, String value) { |
| 3729 | if (mService != null) { |
| 3730 | try { |
| 3731 | mService.setSecureSetting(admin, setting, value); |
| 3732 | } catch (RemoteException e) { |
| 3733 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3734 | } |
| 3735 | } |
| 3736 | } |
| 3737 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3738 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3739 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3740 | * making permission requests of a local or remote administrator of the user. |
| 3741 | * <p/> |
| 3742 | * Only a profile owner can designate the restrictions provider. |
| 3743 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3744 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 3745 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3746 | * it removes the restrictions provider previously assigned. |
| 3747 | */ |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3748 | public void setRestrictionsProvider(ComponentName admin, ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3749 | if (mService != null) { |
| 3750 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3751 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3752 | } catch (RemoteException re) { |
| 3753 | Log.w(TAG, "Failed to set permission provider on device policy service"); |
| 3754 | } |
| 3755 | } |
| 3756 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 3757 | |
| 3758 | /** |
| 3759 | * Called by profile or device owners to set the master volume mute on or off. |
| 3760 | * |
| 3761 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3762 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 3763 | */ |
| 3764 | public void setMasterVolumeMuted(ComponentName admin, boolean on) { |
| 3765 | if (mService != null) { |
| 3766 | try { |
| 3767 | mService.setMasterVolumeMuted(admin, on); |
| 3768 | } catch (RemoteException re) { |
| 3769 | Log.w(TAG, "Failed to setMasterMute on device policy service"); |
| 3770 | } |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | /** |
| 3775 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 3776 | * |
| 3777 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3778 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 3779 | */ |
| 3780 | public boolean isMasterVolumeMuted(ComponentName admin) { |
| 3781 | if (mService != null) { |
| 3782 | try { |
| 3783 | return mService.isMasterVolumeMuted(admin); |
| 3784 | } catch (RemoteException re) { |
| 3785 | Log.w(TAG, "Failed to get isMasterMute on device policy service"); |
| 3786 | } |
| 3787 | } |
| 3788 | return false; |
| 3789 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3790 | |
| 3791 | /** |
| 3792 | * Called by profile or device owners to change whether a user can uninstall |
| 3793 | * a package. |
| 3794 | * |
| 3795 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3796 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 3797 | * @param uninstallBlocked true if the user shouldn't be able to uninstall the package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3798 | */ |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 3799 | public void setUninstallBlocked(ComponentName admin, String packageName, |
| 3800 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3801 | if (mService != null) { |
| 3802 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 3803 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3804 | } catch (RemoteException re) { |
| 3805 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 3806 | } |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | /** |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 3811 | * Check whether the current user has been blocked by device policy from uninstalling a package. |
| 3812 | * Requires the caller to be the profile owner if checking a specific admin's policy. |
Rubin Xu | e1e6faa | 2015-03-10 10:51:59 +0000 | [diff] [blame] | 3813 | * <p> |
| 3814 | * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the |
| 3815 | * behavior of this API is changed such that passing <code>null</code> as the <code>admin</code> |
| 3816 | * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing |
| 3817 | * <code>null</code> will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3818 | * |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 3819 | * @param admin The name of the admin component whose blocking policy will be checked, or null |
Rubin Xu | e1e6faa | 2015-03-10 10:51:59 +0000 | [diff] [blame] | 3820 | * to check if any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3821 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 3822 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3823 | */ |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 3824 | public boolean isUninstallBlocked(ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3825 | if (mService != null) { |
| 3826 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 3827 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3828 | } catch (RemoteException re) { |
| 3829 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 3830 | } |
| 3831 | } |
| 3832 | return false; |
| 3833 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3834 | |
| 3835 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3836 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 3837 | * given package to be available in the parent profile. As a result the user will be able to |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3838 | * add widgets from the white-listed package running under the profile to a widget |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3839 | * host which runs under the parent profile, for example the home screen. Note that |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3840 | * a package may have zero or more provider components, where each component |
| 3841 | * provides a different widget type. |
| 3842 | * <p> |
| 3843 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
| 3844 | * </p> |
| 3845 | * |
| 3846 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3847 | * @param packageName The package from which widget providers are white-listed. |
| 3848 | * @return Whether the package was added. |
| 3849 | * |
| 3850 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3851 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 3852 | */ |
| 3853 | public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) { |
| 3854 | if (mService != null) { |
| 3855 | try { |
| 3856 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 3857 | } catch (RemoteException re) { |
| 3858 | Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re); |
| 3859 | } |
| 3860 | } |
| 3861 | return false; |
| 3862 | } |
| 3863 | |
| 3864 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3865 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 3866 | * package to be available in the parent profile. For this method to take effect the |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3867 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 3868 | * android.content.ComponentName, String)}. |
| 3869 | * <p> |
| 3870 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
| 3871 | * </p> |
| 3872 | * |
| 3873 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3874 | * @param packageName The package from which widget providers are no longer |
| 3875 | * white-listed. |
| 3876 | * @return Whether the package was removed. |
| 3877 | * |
| 3878 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3879 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 3880 | */ |
| 3881 | public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) { |
| 3882 | if (mService != null) { |
| 3883 | try { |
| 3884 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 3885 | } catch (RemoteException re) { |
| 3886 | Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re); |
| 3887 | } |
| 3888 | } |
| 3889 | return false; |
| 3890 | } |
| 3891 | |
| 3892 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3893 | * Called by the profile owner of a managed profile to query providers from which packages are |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3894 | * available in the parent profile. |
| 3895 | * |
| 3896 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3897 | * @return The white-listed package list. |
| 3898 | * |
| 3899 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3900 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3901 | */ |
| 3902 | public List<String> getCrossProfileWidgetProviders(ComponentName admin) { |
| 3903 | if (mService != null) { |
| 3904 | try { |
| 3905 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 3906 | if (providers != null) { |
| 3907 | return providers; |
| 3908 | } |
| 3909 | } catch (RemoteException re) { |
| 3910 | Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re); |
| 3911 | } |
| 3912 | } |
| 3913 | return Collections.emptyList(); |
| 3914 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 3915 | |
| 3916 | /** |
| 3917 | * Called by profile or device owners to set the current user's photo. |
| 3918 | * |
| 3919 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3920 | * @param icon the bitmap to set as the photo. |
| 3921 | */ |
| 3922 | public void setUserIcon(ComponentName admin, Bitmap icon) { |
| 3923 | try { |
| 3924 | mService.setUserIcon(admin, icon); |
| 3925 | } catch (RemoteException re) { |
| 3926 | Log.w(TAG, "Could not set the user icon ", re); |
| 3927 | } |
| 3928 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3929 | } |