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