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