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