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