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 | |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 23 | import android.annotation.SdkConstant; |
| 24 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 26 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 27 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 28 | import android.app.Activity; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 29 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 30 | import android.content.ComponentName; |
| 31 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 32 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 33 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 35 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 36 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 37 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 38 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 39 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 40 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 41 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 42 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 43 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 44 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 45 | import android.os.RemoteException; |
| 46 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 47 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 48 | import android.os.UserManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 49 | import android.os.ServiceManager.ServiceNotFoundException; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 50 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 51 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 52 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 53 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 54 | import android.telephony.TelephonyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 55 | import android.util.Log; |
| 56 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 57 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 58 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 59 | |
| 60 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 61 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 62 | import java.lang.annotation.Retention; |
| 63 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 64 | import java.net.InetSocketAddress; |
| 65 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 66 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 67 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 68 | import java.security.PrivateKey; |
| 69 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 70 | import java.security.cert.CertificateException; |
| 71 | import java.security.cert.CertificateFactory; |
| 72 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 73 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 74 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 75 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 76 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 77 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 78 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 79 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 82 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 83 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 84 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 85 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 86 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 87 | * application calling an api may only pass as an argument a device administrator component it |
| 88 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 89 | * <div class="special reference"> |
| 90 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 91 | * <p> |
| 92 | * For more information about managing policies for device administration, read the <a href= |
| 93 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 94 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 95 | */ |
| 96 | public class DevicePolicyManager { |
| 97 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | |
| 99 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 100 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 101 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 102 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 103 | /** @hide */ |
| 104 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 105 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 108 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 109 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 110 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 111 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 112 | mContext = context; |
| 113 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 114 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | /** @hide test will override it. */ |
| 118 | @VisibleForTesting |
| 119 | protected int myUserId() { |
| 120 | return UserHandle.myUserId(); |
| 121 | } |
| 122 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 123 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 124 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 125 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 126 | * <p>A managed profile allows data separation for example for the usage of a |
| 127 | * device as a personal and corporate device. The user which provisioning is started from and |
| 128 | * the managed profile share a launcher. |
| 129 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 130 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 131 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 132 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 133 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 134 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 135 | * {@link #isProvisioningAllowed(String)}. |
| 136 | * |
| 137 | * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 138 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 139 | * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 140 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 141 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 142 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 143 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 144 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 145 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 146 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 147 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 148 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 149 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 150 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 151 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 152 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 153 | * <p>When managed provisioning has completed, broadcasts are sent to the application specified |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 154 | * in the provisioning intent. The |
| 155 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 156 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 157 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 158 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 159 | * <p>If provisioning fails, the managedProfile is removed so the device returns to its |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 160 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 161 | * |
| 162 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 163 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 164 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 165 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 166 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 167 | */ |
| 168 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 169 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 170 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 171 | |
| 172 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 173 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 174 | * |
| 175 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 176 | * Provisioning configures the user as managed user and sets the MDM as the profile |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 177 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 178 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 179 | * allowed. |
| 180 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 181 | * <p>The intent contains the following extras: |
| 182 | * <ul> |
| 183 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 184 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 185 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 186 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 187 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 188 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 189 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 190 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 191 | * |
| 192 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 193 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 194 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 195 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 196 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 197 | * |
| 198 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 199 | */ |
| 200 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 201 | public static final String ACTION_PROVISION_MANAGED_USER |
| 202 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 203 | |
| 204 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 205 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 206 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 207 | * |
| 208 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 209 | * A device owner has full control over the device. The device owner can not be modified by the |
| 210 | * user. |
| 211 | * |
| 212 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 213 | * employee or client. |
| 214 | * |
| 215 | * <p> An intent with this action can be sent only on an unprovisioned device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 216 | * It is possible to check if provisioning is allowed or not by querying the method |
| 217 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 218 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 219 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 220 | * <ul> |
| 221 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 222 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 223 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 224 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 225 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 226 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 227 | * </ul> |
| 228 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 229 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 230 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 231 | * device owner. |
| 232 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 233 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 234 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 235 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 236 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 237 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 238 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 239 | */ |
| 240 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 241 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 242 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 243 | |
| 244 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 245 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 246 | * |
| 247 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 248 | * the device. A device owner has full control over the device. The device owner can not be |
| 249 | * modified by the user and the only way of resetting the device is via factory reset. |
| 250 | * |
| 251 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 252 | * employee or client. |
| 253 | * |
| 254 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 255 | * |
| 256 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 257 | * by a privileged app with the permission |
| 258 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 259 | * |
| 260 | * <p>The provisioning intent contains the following properties: |
| 261 | * <ul> |
| 262 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 263 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 264 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 265 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 266 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 278 | * |
| 279 | * @hide |
| 280 | */ |
| 281 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 282 | @SystemApi |
| 283 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 284 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 285 | |
| 286 | /** |
| 287 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 288 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 289 | * |
| 290 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 291 | * management state that is distinct from that reached by |
| 292 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 293 | * user, and only has control over device-wide policies, not individual users and their data. |
| 294 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 295 | * this form of device management. |
| 296 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 297 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 298 | * A device owner has full control over the device. The device owner can not be modified by the |
| 299 | * user. |
| 300 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 301 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 302 | * employee or client. |
| 303 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 304 | * <p>An intent with this action can be sent only on an unprovisioned device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 305 | * It is possible to check if provisioning is allowed or not by querying the method |
| 306 | * {@link #isProvisioningAllowed(String)}. |
| 307 | * |
| 308 | * <p>The intent contains the following extras: |
| 309 | * <ul> |
| 310 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 311 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 312 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 314 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 315 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 316 | * </ul> |
| 317 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 318 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 319 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 320 | * device owner. |
| 321 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 322 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 323 | * |
| 324 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 325 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 326 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 327 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 328 | * |
| 329 | * @hide |
| 330 | */ |
| 331 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 332 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 333 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 334 | |
| 335 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 336 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 337 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 338 | * <ul> |
| 339 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 340 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 341 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 342 | * </ul> |
| 343 | * |
| 344 | * @hide |
| 345 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 346 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 347 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 348 | public static final String ACTION_PROVISION_FINALIZATION |
| 349 | = "android.app.action.PROVISION_FINALIZATION"; |
| 350 | |
| 351 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 352 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 353 | * |
| 354 | * @hide |
| 355 | */ |
| 356 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 357 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 358 | |
| 359 | /** |
| 360 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 361 | * |
| 362 | * @hide |
| 363 | */ |
| 364 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 365 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 366 | |
| 367 | /** |
| 368 | * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}. |
| 369 | * |
| 370 | * @hide |
| 371 | */ |
| 372 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 373 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 374 | |
| 375 | /** |
| 376 | * Extra for shared bugreport's SHA-256 hash. |
| 377 | * |
| 378 | * @hide |
| 379 | */ |
| 380 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 381 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 382 | |
| 383 | /** |
| 384 | * Extra for remote bugreport notification shown type. |
| 385 | * |
| 386 | * @hide |
| 387 | */ |
| 388 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 389 | "android.app.extra.bugreport_notification_type"; |
| 390 | |
| 391 | /** |
| 392 | * Notification type for a started remote bugreport flow. |
| 393 | * |
| 394 | * @hide |
| 395 | */ |
| 396 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 397 | |
| 398 | /** |
| 399 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 400 | * being taken. |
| 401 | * |
| 402 | * @hide |
| 403 | */ |
| 404 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 405 | |
| 406 | /** |
| 407 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 408 | * |
| 409 | * @hide |
| 410 | */ |
| 411 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 412 | |
| 413 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 414 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 415 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 416 | * |
| 417 | * @hide |
| 418 | */ |
| 419 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 420 | |
| 421 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 422 | * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 423 | * allows a mobile device management application or NFC programmer application which starts |
| 424 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 425 | * <p> |
| 426 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 427 | * sends the intent to pass data to itself on the newly created profile. |
| 428 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 429 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 430 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 431 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 432 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 433 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 434 | * management application after provisioning. |
| 435 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 436 | * <p> |
| 437 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 438 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 439 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 440 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 441 | */ |
| 442 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 443 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 444 | |
| 445 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 446 | * A String extra holding the package name of the mobile device management application that |
| 447 | * will be set as the profile owner or device owner. |
| 448 | * |
| 449 | * <p>If an application starts provisioning directly via an intent with action |
| 450 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 451 | * application that started provisioning. The package will be set as profile owner in that case. |
| 452 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 453 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 454 | * 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] | 455 | * |
| 456 | * <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] | 457 | * This receiver will be set as the profile or device owner and active admin. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 458 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 459 | * @see DeviceAdminReceiver |
| 460 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a8 | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 461 | * supported, but only if there is only one device admin receiver in the package that requires |
| 462 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 463 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 464 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 465 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 466 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 467 | |
| 468 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 469 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 470 | * application that will be set as the profile owner or device owner and active admin. |
| 471 | * |
| 472 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 473 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 474 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 475 | * component has to match the package name of the application that started provisioning. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 476 | * |
| 477 | * <p>This component is set as device owner and active admin when device owner provisioning is |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 478 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 479 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 480 | * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be |
Rubin Xu | 44ef750b | 2015-03-23 16:51:33 +0000 | [diff] [blame] | 481 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 482 | * |
| 483 | * @see DeviceAdminReceiver |
| 484 | */ |
| 485 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 486 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 487 | |
| 488 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 489 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 490 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 491 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 492 | * |
| 493 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 494 | */ |
| 495 | |
| 496 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 497 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 498 | |
| 499 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 500 | * A String extra that, holds the email address of the account which a managed profile is |
| 501 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 502 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 503 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 504 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 505 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 506 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 507 | * contains this extra, it is forwarded in the |
| 508 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 509 | * device management application that was set as the profile owner during provisioning. |
| 510 | * 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] | 511 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 512 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 513 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 514 | |
| 515 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 516 | * A integer extra indicating the predominant color to show during the provisioning. |
| 517 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 518 | * |
| 519 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 520 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 521 | */ |
| 522 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 523 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 524 | |
| 525 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 526 | * 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] | 527 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 528 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 529 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 530 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 531 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 532 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 533 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 534 | |
| 535 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 536 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 537 | * will be set to. |
| 538 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 539 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 540 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 541 | */ |
| 542 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 543 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 544 | |
| 545 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 546 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 547 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 548 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 549 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 550 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 551 | */ |
| 552 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 553 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 554 | |
| 555 | /** |
| 556 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 557 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 558 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 559 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 560 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 561 | */ |
| 562 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 563 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 564 | |
| 565 | /** |
| 566 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 567 | * owner provisioning for downloading the mobile device management application. |
| 568 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 569 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 570 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 571 | */ |
| 572 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 573 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 574 | |
| 575 | /** |
| 576 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 577 | * is hidden or not. |
| 578 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 579 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 580 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 581 | */ |
| 582 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 583 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 584 | |
| 585 | /** |
| 586 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 587 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 588 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 589 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 590 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 591 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 592 | */ |
| 593 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 594 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 595 | |
| 596 | /** |
| 597 | * A String extra holding the password of the wifi network in |
| 598 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 599 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 600 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 601 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | */ |
| 603 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 604 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 605 | |
| 606 | /** |
| 607 | * A String extra holding the proxy host for the wifi network in |
| 608 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 609 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 610 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 611 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | */ |
| 613 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 614 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 615 | |
| 616 | /** |
| 617 | * An int extra holding the proxy port for the wifi network in |
| 618 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 619 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 620 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 621 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 622 | */ |
| 623 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 624 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 625 | |
| 626 | /** |
| 627 | * A String extra holding the proxy bypass for the wifi network in |
| 628 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 629 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 630 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 631 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 632 | */ |
| 633 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 634 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 635 | |
| 636 | /** |
| 637 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 638 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 639 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 640 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 641 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 642 | */ |
| 643 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 644 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 645 | |
| 646 | /** |
| 647 | * A String extra holding a url that specifies the download location of the device admin |
| 648 | * package. When not provided it is assumed that the device admin package is already installed. |
| 649 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 650 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 651 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 652 | */ |
| 653 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 654 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 655 | |
| 656 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 657 | * An int extra holding a minimum required version code for the device admin package. If the |
| 658 | * device admin is already installed on the device, it will only be re-downloaded from |
| 659 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 660 | * installed package is less than this version code. |
| 661 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 662 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 663 | * provisioning via an NFC bump. |
| 664 | */ |
| 665 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 666 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 667 | |
| 668 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 669 | * A String extra holding a http cookie header which should be used in the http request to the |
| 670 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 671 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 672 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 673 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 674 | */ |
| 675 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 676 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 677 | |
| 678 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 679 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 680 | * the file at download location specified in |
| 681 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 682 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 683 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 684 | * present. The provided checksum must match the checksum of the file at the download |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 685 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 686 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 687 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 688 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 689 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 690 | * |
| 691 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 692 | * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 693 | * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 694 | * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 695 | */ |
| 696 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 697 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 698 | |
| 699 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 700 | * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 701 | * android package archive at the download location specified in {@link |
| 702 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 703 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 704 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 705 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 706 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 707 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 708 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 709 | * present. The provided checksum must match the checksum of any signature of the file at |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 710 | * the download location. If the checksum does not match an error will be shown to the user and |
| 711 | * the user will be asked to factory reset the device. |
| 712 | * |
| 713 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 714 | * provisioning via an NFC bump. |
| 715 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 716 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 717 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 718 | |
| 719 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 720 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 721 | * has completed successfully. |
| 722 | * |
| 723 | * <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] | 724 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 725 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 726 | * <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] | 727 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 728 | */ |
| 729 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 730 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 731 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 732 | |
| 733 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 734 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 735 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 736 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 737 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 738 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 739 | * |
| 740 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 741 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 742 | */ |
| 743 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 744 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 745 | |
| 746 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 747 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 748 | * provisioning. If this extra is not passed, a default image will be shown. |
| 749 | * <h5>The following URI schemes are accepted:</h5> |
| 750 | * <ul> |
| 751 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 752 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 753 | * </ul> |
| 754 | * |
| 755 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 756 | * pixed density for the device. |
| 757 | * |
| 758 | * <p> If a content: URI is passed, the intent should have the flag |
| 759 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 760 | * {@link android.content.ClipData} of the intent too. |
| 761 | * |
| 762 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 763 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 764 | */ |
| 765 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 766 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 767 | |
| 768 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 769 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 770 | * during setup-wizard. |
| 771 | * |
| 772 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 773 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 774 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 775 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 776 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 777 | * |
| 778 | * @hide |
| 779 | */ |
| 780 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 781 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 782 | |
| 783 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 784 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 785 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 786 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 787 | * A device owner has full control over the device. The device owner can not be modified by the |
| 788 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 789 | * reset. |
| 790 | * |
| 791 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 792 | * employee or client. |
| 793 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 794 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 795 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 796 | * <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] | 797 | * contains the following properties: |
| 798 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 799 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 800 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 801 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 802 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 803 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 804 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 805 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 806 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 807 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 808 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 809 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 810 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 811 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 812 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 813 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 814 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 815 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 816 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 817 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 818 | * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 819 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 820 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 821 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 822 | */ |
| 823 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 824 | = "application/com.android.managedprovisioning"; |
| 825 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 826 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 827 | * Activity action: ask the user to add a new device administrator to the system. |
| 828 | * The desired policy is the ComponentName of the policy in the |
| 829 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 830 | * bring the user through adding the device administrator to the system (or |
| 831 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 832 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 833 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 834 | * field to provide the user with additional explanation (in addition |
| 835 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 836 | * |
| 837 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 838 | * user intervention). However, if your administrator has been updated and is requesting |
| 839 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 840 | * 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] | 841 | */ |
| 842 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 843 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 844 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 845 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 846 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 847 | * @hide |
| 848 | * 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] | 849 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 850 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 851 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 852 | * 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] | 853 | * to remotely control restrictions on the user. |
| 854 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 855 | * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 856 | * result of whether or not the user approved the action. If approved, the result will |
| 857 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 858 | * as a profile owner. |
| 859 | * |
| 860 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 861 | * field to provide the user with additional explanation (in addition |
| 862 | * to your component's description) about what is being added. |
| 863 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 864 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 865 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 866 | */ |
| 867 | @SystemApi |
| 868 | public static final String ACTION_SET_PROFILE_OWNER |
| 869 | = "android.app.action.SET_PROFILE_OWNER"; |
| 870 | |
| 871 | /** |
| 872 | * @hide |
| 873 | * Name of the profile owner admin that controls the user. |
| 874 | */ |
| 875 | @SystemApi |
| 876 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 877 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 878 | |
| 879 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 880 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 881 | * 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] | 882 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 883 | * @hide |
| 884 | */ |
| 885 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 886 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 887 | |
| 888 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 889 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 890 | * |
| 891 | * This broadcast is sent only to the primary user. |
| 892 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 893 | */ |
| 894 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 895 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 896 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 897 | |
| 898 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 899 | * The ComponentName of the administrator component. |
| 900 | * |
| 901 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 902 | */ |
| 903 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 904 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 905 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 906 | * An optional CharSequence providing additional explanation for why the |
| 907 | * admin is being added. |
| 908 | * |
| 909 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 910 | */ |
| 911 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 912 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 913 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 914 | * Activity action: have the user enter a new password. This activity should |
| 915 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 916 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 917 | * enter a new password that meets the current requirements. You can use |
| 918 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 919 | * have the user select a new password in order to meet the current |
| 920 | * constraints. Upon being resumed from this activity, you can check the new |
| 921 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 922 | * |
| 923 | * If the intent is launched from within a managed profile with a profile |
| 924 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 925 | * this will trigger entering a new password for the parent of the profile. |
| 926 | * For all other cases it will trigger entering a new password for the user |
| 927 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 928 | * |
| 929 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 930 | */ |
| 931 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 932 | public static final String ACTION_SET_NEW_PASSWORD |
| 933 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 934 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 935 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 936 | * Activity action: have the user enter a new password for the parent profile. |
| 937 | * If the intent is launched from within a managed profile, this will trigger |
| 938 | * entering a new password for the parent of the profile. In all other cases |
| 939 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 940 | */ |
| 941 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 942 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 943 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 944 | |
| 945 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 946 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 947 | * the parent profile to access intents sent from the managed profile. |
| 948 | * That is, when an app in the managed profile calls |
| 949 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 950 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 951 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 952 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 953 | |
| 954 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 955 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 956 | * the managed profile to access intents sent from the parent profile. |
| 957 | * That is, when an app in the parent profile calls |
| 958 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 959 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 960 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 961 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 962 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 963 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 964 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 965 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 966 | */ |
| 967 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 968 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 969 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 970 | |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 971 | /** |
| 972 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 973 | * Already granted or denied permissions are not affected by this. |
| 974 | */ |
| 975 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 976 | |
| 977 | /** |
| 978 | * Permission policy to always grant new permission requests for runtime permissions. |
| 979 | * Already granted or denied permissions are not affected by this. |
| 980 | */ |
| 981 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 982 | |
| 983 | /** |
| 984 | * Permission policy to always deny new permission requests for runtime permissions. |
| 985 | * Already granted or denied permissions are not affected by this. |
| 986 | */ |
| 987 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 988 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 989 | /** |
| 990 | * Runtime permission state: The user can manage the permission |
| 991 | * through the UI. |
| 992 | */ |
| 993 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 994 | |
| 995 | /** |
| 996 | * Runtime permission state: The permission is granted to the app |
| 997 | * and the user cannot manage the permission through the UI. |
| 998 | */ |
| 999 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1000 | |
| 1001 | /** |
| 1002 | * Runtime permission state: The permission is denied to the app |
| 1003 | * and the user cannot manage the permission through the UI. |
| 1004 | */ |
| 1005 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1006 | |
| 1007 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1008 | * No management for current user in-effect. This is the default. |
| 1009 | * @hide |
| 1010 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1011 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1012 | public static final int STATE_USER_UNMANAGED = 0; |
| 1013 | |
| 1014 | /** |
| 1015 | * Management partially setup, user setup needs to be completed. |
| 1016 | * @hide |
| 1017 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1018 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1019 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1020 | |
| 1021 | /** |
| 1022 | * Management partially setup, user setup completed. |
| 1023 | * @hide |
| 1024 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1025 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1026 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1027 | |
| 1028 | /** |
| 1029 | * Management setup and active on current user. |
| 1030 | * @hide |
| 1031 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1032 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1033 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1034 | |
| 1035 | /** |
| 1036 | * Management partially setup on a managed profile. |
| 1037 | * @hide |
| 1038 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1039 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1040 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1041 | |
| 1042 | /** |
| 1043 | * @hide |
| 1044 | */ |
| 1045 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1046 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1047 | @Retention(RetentionPolicy.SOURCE) |
| 1048 | public @interface UserProvisioningState {} |
| 1049 | |
| 1050 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1051 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1052 | * |
| 1053 | * @param admin The administrator component to check for. |
| 1054 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1055 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1056 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1057 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1058 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | /** |
| 1062 | * @see #isAdminActive(ComponentName) |
| 1063 | * @hide |
| 1064 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1065 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1066 | if (mService != null) { |
| 1067 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1068 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1069 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1070 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | return false; |
| 1074 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1075 | /** |
| 1076 | * Return true if the given administrator component is currently being removed |
| 1077 | * for the user. |
| 1078 | * @hide |
| 1079 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1080 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1081 | if (mService != null) { |
| 1082 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1083 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1084 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1085 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1091 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1092 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1093 | * Return a list of all currently active device administrators' component |
| 1094 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1095 | * returned. |
| 1096 | */ |
| 1097 | public List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1098 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1099 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * @see #getActiveAdmins() |
| 1104 | * @hide |
| 1105 | */ |
| 1106 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1107 | if (mService != null) { |
| 1108 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1109 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1110 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1111 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | return null; |
| 1115 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1116 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1117 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1118 | * Used by package administration code to determine if a package can be stopped |
| 1119 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1120 | * @hide |
| 1121 | */ |
| 1122 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1123 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * Used by package administration code to determine if a package can be stopped |
| 1128 | * or uninstalled. |
| 1129 | * @hide |
| 1130 | */ |
| 1131 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1132 | if (mService != null) { |
| 1133 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1134 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1135 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1136 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | return false; |
| 1140 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1141 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1142 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1143 | * Remove a current administration component. This can only be called |
| 1144 | * by the application that owns the administration component; if you |
| 1145 | * try to remove someone else's component, a security exception will be |
| 1146 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1147 | * |
| 1148 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1149 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1150 | * |
| 1151 | * @param admin The administration compononent to remove. |
| 1152 | * @throws SecurityException if the caller is not in the owner application of {@code admin}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1153 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1154 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1155 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1156 | if (mService != null) { |
| 1157 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1158 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1159 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1160 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1164 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1165 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1166 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1167 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1168 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1169 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1170 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1171 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1172 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1173 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1174 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1175 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1176 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1177 | if (mService != null) { |
| 1178 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1179 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1180 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1181 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | return false; |
| 1185 | } |
| 1186 | |
| 1187 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1188 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1189 | * |
| 1190 | * @hide |
| 1191 | */ |
| 1192 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1193 | if (mService != null) { |
| 1194 | try { |
| 1195 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1196 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1197 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | return false; |
| 1201 | } |
| 1202 | |
| 1203 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1204 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1205 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1206 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1207 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1208 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1209 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1210 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1211 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1212 | * recognition technology. This implies technologies that can recognize the identity of |
| 1213 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1214 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1215 | */ |
| 1216 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1217 | |
| 1218 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1219 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1220 | * of password or pattern, but doesn't care what it is. Note that quality constants |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1221 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1222 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1223 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1224 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1225 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1226 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1227 | * password containing at least numeric characters. Note that quality |
| 1228 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1229 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1230 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1231 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1232 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1233 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1234 | * password containing at least numeric characters with no repeating (4444) |
| 1235 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1236 | * constants are ordered so that higher values are more restrictive. |
| 1237 | */ |
| 1238 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1239 | |
| 1240 | /** |
| 1241 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1242 | * password containing at least alphabetic (or other symbol) characters. |
| 1243 | * Note that quality constants are ordered so that higher values are more |
| 1244 | * restrictive. |
| 1245 | */ |
| 1246 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1247 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1248 | /** |
| 1249 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1250 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1251 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1252 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1253 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1254 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1255 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1256 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1257 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1258 | * password containing at least a letter, a numerical digit and a special |
| 1259 | * symbol, by default. With this password quality, passwords can be |
| 1260 | * restricted to contain various sets of characters, like at least an |
| 1261 | * uppercase letter, etc. These are specified using various methods, |
| 1262 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1263 | * that quality constants are ordered so that higher values are more |
| 1264 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1265 | */ |
| 1266 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1267 | |
| 1268 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1269 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1270 | * modify password. In case this password quality is set, the password is |
| 1271 | * managed by a profile owner. The profile owner can set any password, |
| 1272 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1273 | * that quality constants are ordered so that higher values are more |
| 1274 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1275 | * the highest. |
| 1276 | * @hide |
| 1277 | */ |
| 1278 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1279 | |
| 1280 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1281 | * @hide |
| 1282 | * |
| 1283 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1284 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1285 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1286 | * used by authenticator to exempt their accounts from this: |
| 1287 | * |
| 1288 | * <ul> |
| 1289 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1290 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1291 | * <application> tag in the manifest. |
| 1292 | * |
| 1293 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1294 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1295 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1296 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1297 | * if any of the accounts have it. |
| 1298 | * </ul> |
| 1299 | */ |
| 1300 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1301 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1302 | |
| 1303 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
| 1304 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1305 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1306 | |
| 1307 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1308 | * Called by an application that is administering the device to set the password restrictions it |
| 1309 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1310 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1311 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1312 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1313 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1314 | * <p> |
| 1315 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1316 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1317 | * considerations) is the one that is in effect. |
| 1318 | * <p> |
| 1319 | * The calling device admin must have requested |
| 1320 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1321 | * not, a security exception will be thrown. |
| 1322 | * <p> |
| 1323 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1324 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1325 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1326 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1327 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1328 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1329 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1330 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1331 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1332 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1333 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1334 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1335 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1336 | if (mService != null) { |
| 1337 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1338 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1339 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1340 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1344 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1345 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1346 | * Retrieve the current minimum password quality for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1347 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1348 | * a separate challenge are not taken into account. |
| 1349 | * |
| 1350 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1351 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1352 | * restrictions on the parent profile. |
| 1353 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1354 | * @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] | 1355 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1356 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1357 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1358 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1362 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1363 | if (mService != null) { |
| 1364 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1365 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1366 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1367 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1368 | } |
| 1369 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1370 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1371 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1372 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1373 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1374 | * Called by an application that is administering the device to set the minimum allowed password |
| 1375 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1376 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1377 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1378 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1379 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1380 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1381 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1382 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1383 | * {@link #setPasswordQuality}. |
| 1384 | * <p> |
| 1385 | * The calling device admin must have requested |
| 1386 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1387 | * not, a security exception will be thrown. |
| 1388 | * <p> |
| 1389 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1390 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1391 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1392 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1393 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1394 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1395 | * restriction. |
| 1396 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1397 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1398 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1399 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1400 | if (mService != null) { |
| 1401 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1402 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1403 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1404 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1408 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1409 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1410 | * Retrieve the current minimum password length for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1411 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1412 | * a separate challenge are not taken into account. |
| 1413 | * |
| 1414 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1415 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1416 | * restrictions on the parent profile. |
| 1417 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1418 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1419 | * @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] | 1420 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1421 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1422 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1423 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1427 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1428 | if (mService != null) { |
| 1429 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1430 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1431 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1432 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | return 0; |
| 1436 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1437 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1438 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1439 | * Called by an application that is administering the device to set the minimum number of upper |
| 1440 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1441 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1442 | * current password will remain until the user has set a new one, so the change does not take |
| 1443 | * place immediately. To prompt the user for a new password, use |
| 1444 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1445 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1446 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1447 | * <p> |
| 1448 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1449 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1450 | * not, a security exception will be thrown. |
| 1451 | * <p> |
| 1452 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1453 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1454 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1455 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1456 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1457 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1458 | * A value of 0 means there is no restriction. |
| 1459 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1460 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1461 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1462 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1463 | if (mService != null) { |
| 1464 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1465 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1466 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1467 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1468 | } |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1473 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1474 | * for a particular admin or all admins that set restrictions on this user and |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1475 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1476 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1477 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1478 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1479 | * and only applies when the password quality is |
| 1480 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1481 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1482 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1483 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1484 | * restrictions on the parent profile. |
| 1485 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1486 | * @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] | 1487 | * aggregate all admins. |
| 1488 | * @return The minimum number of upper case letters required in the |
| 1489 | * password. |
| 1490 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1491 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1492 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1496 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1497 | if (mService != null) { |
| 1498 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1499 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1500 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1501 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
| 1507 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1508 | * Called by an application that is administering the device to set the minimum number of lower |
| 1509 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1510 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1511 | * current password will remain until the user has set a new one, so the change does not take |
| 1512 | * place immediately. To prompt the user for a new password, use |
| 1513 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1514 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1515 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1516 | * <p> |
| 1517 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1518 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1519 | * not, a security exception will be thrown. |
| 1520 | * <p> |
| 1521 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1522 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1523 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1524 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1525 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1526 | * @param length The new desired minimum number of lower case letters required in the password. |
| 1527 | * A value of 0 means there is no restriction. |
| 1528 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1529 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1530 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1531 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1532 | if (mService != null) { |
| 1533 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1534 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1535 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1536 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1542 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1543 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1544 | * and its participating profiles. Restrictions on profiles that have |
| 1545 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1546 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1547 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1548 | * and only applies when the password quality is |
| 1549 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1550 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1551 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1552 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1553 | * restrictions on the parent profile. |
| 1554 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1555 | * @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] | 1556 | * aggregate all admins. |
| 1557 | * @return The minimum number of lower case letters required in the |
| 1558 | * password. |
| 1559 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1560 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1561 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1565 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1566 | if (mService != null) { |
| 1567 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1568 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1569 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1570 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1571 | } |
| 1572 | } |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1577 | * Called by an application that is administering the device to set the minimum number of |
| 1578 | * letters required in the password. After setting this, the user will not be able to enter a |
| 1579 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1580 | * password will remain until the user has set a new one, so the change does not take place |
| 1581 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1582 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1583 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1584 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1585 | * <p> |
| 1586 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1587 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1588 | * not, a security exception will be thrown. |
| 1589 | * <p> |
| 1590 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1591 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1592 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1593 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1594 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1595 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1596 | * 0 means there is no restriction. |
| 1597 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1598 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1599 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1600 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1601 | if (mService != null) { |
| 1602 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1603 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1604 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1605 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1611 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1612 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1613 | * and its participating profiles. Restrictions on profiles that have |
| 1614 | * a separate challenge are not taken into account. |
| 1615 | * This is the same value as set by |
| 1616 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1617 | * and only applies when the password quality is |
| 1618 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1619 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1620 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1621 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1622 | * restrictions on the parent profile. |
| 1623 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1624 | * @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] | 1625 | * aggregate all admins. |
| 1626 | * @return The minimum number of letters required in the password. |
| 1627 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1628 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1629 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1633 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1634 | if (mService != null) { |
| 1635 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1636 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1637 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1638 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1645 | * Called by an application that is administering the device to set the minimum number of |
| 1646 | * numerical digits required in the password. After setting this, the user will not be able to |
| 1647 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 1648 | * current password will remain until the user has set a new one, so the change does not take |
| 1649 | * place immediately. To prompt the user for a new password, use |
| 1650 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1651 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1652 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1653 | * <p> |
| 1654 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1655 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1656 | * not, a security exception will be thrown. |
| 1657 | * <p> |
| 1658 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1659 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1660 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1661 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1662 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1663 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 1664 | * value of 0 means there is no restriction. |
| 1665 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1666 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1667 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1668 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1669 | if (mService != null) { |
| 1670 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1671 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1672 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1673 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1674 | } |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1680 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1681 | * and its participating profiles. Restrictions on profiles that have |
| 1682 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1683 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1684 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1685 | * and only applies when the password quality is |
| 1686 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1687 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1688 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1689 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1690 | * restrictions on the parent profile. |
| 1691 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1692 | * @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] | 1693 | * aggregate all admins. |
| 1694 | * @return The minimum number of numerical digits required in the password. |
| 1695 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1696 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1697 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1701 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1702 | if (mService != null) { |
| 1703 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1704 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1705 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1706 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1713 | * Called by an application that is administering the device to set the minimum number of |
| 1714 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 1715 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1716 | * password will remain until the user has set a new one, so the change does not take place |
| 1717 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1718 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1719 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1720 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1721 | * <p> |
| 1722 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1723 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1724 | * not, a security exception will be thrown. |
| 1725 | * <p> |
| 1726 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1727 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1728 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1729 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1730 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1731 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 1732 | * 0 means there is no restriction. |
| 1733 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1734 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1735 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1736 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1737 | if (mService != null) { |
| 1738 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1739 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1740 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1741 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1747 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1748 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1749 | * and its participating profiles. Restrictions on profiles that have |
| 1750 | * a separate challenge are not taken into account. This is the same value as |
| 1751 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1752 | * and only applies when the password quality is |
| 1753 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1754 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1755 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1756 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1757 | * restrictions on the parent profile. |
| 1758 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1759 | * @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] | 1760 | * aggregate all admins. |
| 1761 | * @return The minimum number of symbols required in the password. |
| 1762 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1763 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1764 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1768 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1769 | if (mService != null) { |
| 1770 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1771 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1772 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1773 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1774 | } |
| 1775 | } |
| 1776 | return 0; |
| 1777 | } |
| 1778 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1779 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1780 | * Called by an application that is administering the device to set the minimum number of |
| 1781 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 1782 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 1783 | * as what has been set. Note that the current password will remain until the user has set a new |
| 1784 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 1785 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1786 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1787 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1788 | * <p> |
| 1789 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1790 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1791 | * not, a security exception will be thrown. |
| 1792 | * <p> |
| 1793 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1794 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1795 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1796 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1797 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1798 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1799 | * 0 means there is no restriction. |
| 1800 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1801 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1802 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1803 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1804 | if (mService != null) { |
| 1805 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1806 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1807 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1808 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1814 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1815 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1816 | * and its participating profiles. Restrictions on profiles that have |
| 1817 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1818 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1819 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1820 | * and only applies when the password quality is |
| 1821 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1822 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1823 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1824 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1825 | * restrictions on the parent profile. |
| 1826 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1827 | * @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] | 1828 | * aggregate all admins. |
| 1829 | * @return The minimum number of letters required in the password. |
| 1830 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1831 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1832 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1836 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1837 | if (mService != null) { |
| 1838 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1839 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1840 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1841 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1842 | } |
| 1843 | } |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1847 | /** |
| 1848 | * Called by an application that is administering the device to set the length of the password |
| 1849 | * history. After setting this, the user will not be able to enter a new password that is the |
| 1850 | * same as any password in the history. Note that the current password will remain until the |
| 1851 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 1852 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1853 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1854 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1855 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 1856 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 1857 | * <p> |
| 1858 | * The calling device admin must have requested |
| 1859 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1860 | * not, a security exception will be thrown. |
| 1861 | * <p> |
| 1862 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1863 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1864 | * profile. |
| 1865 | * |
| 1866 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1867 | * @param length The new desired length of password history. A value of 0 means there is no |
| 1868 | * restriction. |
| 1869 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1870 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 1871 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1872 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1873 | if (mService != null) { |
| 1874 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1875 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1876 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1877 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1883 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 1884 | * restart the countdown for password expiration for the given admin, as will changing the |
| 1885 | * device password (for all admins). |
| 1886 | * <p> |
| 1887 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 1888 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 1889 | * 432000000 ms for timeout. |
| 1890 | * <p> |
| 1891 | * To disable password expiration, a value of 0 may be used for timeout. |
| 1892 | * <p> |
| 1893 | * The calling device admin must have requested |
| 1894 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 1895 | * not, a security exception will be thrown. |
| 1896 | * <p> |
| 1897 | * Note that setting the password will automatically reset the expiration time for all active |
| 1898 | * admins. Active admins do not need to explicitly call this method in that case. |
| 1899 | * <p> |
| 1900 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1901 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1902 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1903 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1904 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1905 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 1906 | * there is no restriction (unlimited). |
| 1907 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1908 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1909 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1910 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1911 | if (mService != null) { |
| 1912 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1913 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1914 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1915 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1921 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1922 | * recurring expiration timeout provided in the call to |
| 1923 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1924 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 1925 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 1926 | * |
| 1927 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1928 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1929 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1930 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1931 | * @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] | 1932 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1933 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1934 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1935 | if (mService != null) { |
| 1936 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1937 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1938 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1939 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1940 | } |
| 1941 | } |
| 1942 | return 0; |
| 1943 | } |
| 1944 | |
| 1945 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1946 | * Get the current password expiration time for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1947 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1948 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 1949 | * of all expiration times is returned - which will be the minimum of all of them. |
| 1950 | * |
| 1951 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1952 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1953 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1954 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1955 | * @param admin The name of the admin component to check, or {@code null} to aggregate all admins. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1956 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1957 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1958 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1959 | if (mService != null) { |
| 1960 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1961 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1962 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1963 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | return 0; |
| 1967 | } |
| 1968 | |
| 1969 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1970 | * Retrieve the current password history length for a particular admin or all admins that |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1971 | * set restrictions on this user and its participating profiles. Restrictions on profiles that |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1972 | * have a separate challenge are not taken into account. |
| 1973 | * |
| 1974 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1975 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1976 | * restrictions on the parent profile. |
| 1977 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1978 | * @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] | 1979 | * all admins. |
| 1980 | * @return The length of the password history |
| 1981 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1982 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1983 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1987 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1988 | if (mService != null) { |
| 1989 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1990 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1991 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1992 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1998 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1999 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2000 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2001 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2002 | * @return Returns the maximum length that the user can enter. |
| 2003 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2004 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2005 | // Kind-of arbitrary. |
| 2006 | return 16; |
| 2007 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2008 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2009 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2010 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2011 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2012 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
| 2013 | * are not taken into account. |
| 2014 | * <p> |
| 2015 | * The calling device admin must have requested |
| 2016 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2017 | * not, a security exception will be thrown. |
| 2018 | * <p> |
| 2019 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2020 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2021 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2022 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2023 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2024 | * @throws SecurityException if the calling application does not own an active administrator |
| 2025 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2026 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2027 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2028 | if (mService != null) { |
| 2029 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2030 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2031 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2032 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2033 | } |
| 2034 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2035 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2036 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2037 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2038 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2039 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2040 | * to meet the policy requirements (e.g. quality, minimum length) that have been |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2041 | * requested by the admins of the parent user and its profiles. |
| 2042 | * |
| 2043 | * @param userHandle the userId of the profile to check the password for. |
| 2044 | * @return Returns true if the password would meet the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2045 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2046 | * @hide |
| 2047 | */ |
| 2048 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2049 | if (mService != null) { |
| 2050 | try { |
| 2051 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2052 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2053 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2054 | } |
| 2055 | } |
| 2056 | return false; |
| 2057 | } |
| 2058 | |
| 2059 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2060 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2061 | * successful password entry. |
| 2062 | * <p> |
| 2063 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2064 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2065 | * password attemts for the parent user. |
| 2066 | * <p> |
| 2067 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2068 | * to be able to call this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2069 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2070 | * @return The number of times user has entered an incorrect password since the last correct |
| 2071 | * password entry. |
| 2072 | * @throws SecurityException if the calling application does not own an active administrator |
| 2073 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2074 | */ |
| 2075 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2076 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2077 | } |
| 2078 | |
| 2079 | /** |
| 2080 | * Retrieve the number of times the given user has failed at entering a |
| 2081 | * password since that last successful password entry. |
| 2082 | * |
| 2083 | * <p>The calling device admin must have requested |
| 2084 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2085 | * not and it is not the system uid, a security exception will be thrown. |
| 2086 | * |
| 2087 | * @hide |
| 2088 | */ |
| 2089 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2090 | if (mService != null) { |
| 2091 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2092 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2093 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2094 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2095 | } |
| 2096 | } |
| 2097 | return -1; |
| 2098 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2099 | |
| 2100 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2101 | * 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] | 2102 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2103 | * @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] | 2104 | * @hide |
| 2105 | */ |
| 2106 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2107 | if (mService != null) { |
| 2108 | try { |
| 2109 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2110 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2111 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2112 | } |
| 2113 | } |
| 2114 | return false; |
| 2115 | } |
| 2116 | |
| 2117 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2118 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2119 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2120 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2121 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2122 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2123 | * <p> |
| 2124 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2125 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2126 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2127 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2128 | * immediately, and your callback will not be invoked. |
| 2129 | * <p> |
| 2130 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2131 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2132 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2133 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2134 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2135 | * @param num The number of failed password attempts at which point the device or profile will |
| 2136 | * be wiped. |
| 2137 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2138 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2139 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2140 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2141 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2142 | if (mService != null) { |
| 2143 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2144 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2145 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2146 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2147 | } |
| 2148 | } |
| 2149 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2150 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2151 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2152 | * Retrieve the current maximum number of login attempts that are allowed before the device |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2153 | * or profile is wiped, for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2154 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2155 | * not taken into account. |
| 2156 | * |
| 2157 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2158 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2159 | * the value for the parent profile. |
| 2160 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2161 | * @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] | 2162 | * all admins. |
| 2163 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2164 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2165 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2169 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2170 | if (mService != null) { |
| 2171 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2172 | return mService.getMaximumFailedPasswordsForWipe( |
| 2173 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2174 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2175 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2176 | } |
| 2177 | } |
| 2178 | return 0; |
| 2179 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2180 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2181 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2182 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2183 | * for the given user. So for primary user, it might return the primary or |
| 2184 | * a managed profile. For a secondary user, it would be the same as the |
| 2185 | * user passed in. |
| 2186 | * @hide Used only by Keyguard |
| 2187 | */ |
| 2188 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2189 | if (mService != null) { |
| 2190 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2191 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2192 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2193 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2194 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | return UserHandle.USER_NULL; |
| 2198 | } |
| 2199 | |
| 2200 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2201 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2202 | * the password again until the user has entered it. |
| 2203 | */ |
| 2204 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2205 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2206 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2207 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2208 | * If the flag is set, the device can be booted without asking for user password. |
| 2209 | * The absence of this flag does not change the current boot requirements. This flag |
| 2210 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2211 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2212 | * device to factory defaults. |
| 2213 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2214 | 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] | 2215 | |
| 2216 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2217 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2218 | * individual accounts) on the user. This takes effect immediately. |
| 2219 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2220 | * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2221 | * device admins that are not device owner and not profile owner. |
| 2222 | * The password can now only be changed if there is currently no password set. Device owner |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2223 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2224 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2225 | * <p> |
| 2226 | * The given password must be sufficient for the current password quality and length constraints |
| 2227 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2228 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2229 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2230 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2231 | * case the currently active quality will be increased to match. |
| 2232 | * <p> |
| 2233 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
Robin Lee | ce5c400 | 2016-03-23 17:05:03 +0000 | [diff] [blame] | 2234 | * current password constraints allow it. <em>Note: This will not work in |
| 2235 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2236 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2237 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2238 | * <p> |
| 2239 | * The calling device admin must have requested |
| 2240 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2241 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2242 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2243 | * @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] | 2244 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2245 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2246 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2247 | * current constraints or if the user has not been decrypted yet. |
| 2248 | * @throws SecurityException if the calling application does not own an active administrator |
| 2249 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2250 | * @throws IllegalStateException if the calling user is locked or has a managed profile. |
Andrew Scull | 3f81f4e | 2016-07-29 16:29:58 +0100 | [diff] [blame] | 2251 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2252 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2253 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2254 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2255 | if (mService != null) { |
| 2256 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2257 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2258 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2259 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | return false; |
| 2263 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2264 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2265 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2266 | * Called by an application that is administering the device to set the maximum time for user |
| 2267 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2268 | * effect immediately. |
| 2269 | * <p> |
| 2270 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2271 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2272 | * <p> |
| 2273 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2274 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2275 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2276 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2277 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2278 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2279 | * is no restriction. |
| 2280 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2281 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2282 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2283 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2284 | if (mService != null) { |
| 2285 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2286 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2287 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2288 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2292 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2293 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2294 | * Retrieve the current maximum time to unlock for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2295 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2296 | * a separate challenge are not taken into account. |
| 2297 | * |
| 2298 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2299 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2300 | * restrictions on the parent profile. |
| 2301 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2302 | * @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] | 2303 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2304 | * @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] | 2305 | * 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] | 2306 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2307 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2308 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2312 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2313 | if (mService != null) { |
| 2314 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2315 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2316 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2317 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | return 0; |
| 2321 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2322 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2323 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2324 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2325 | * do not have a separate timeout to lock for work challenge only. |
| 2326 | * |
| 2327 | * @hide |
| 2328 | */ |
| 2329 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2330 | if (mService != null) { |
| 2331 | try { |
| 2332 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2333 | } catch (RemoteException e) { |
| 2334 | throw e.rethrowFromSystemServer(); |
| 2335 | } |
| 2336 | } |
| 2337 | return 0; |
| 2338 | } |
| 2339 | |
| 2340 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2341 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2342 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2343 | * authentication method like password, pin or pattern. |
| 2344 | * |
| 2345 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2346 | * specified timeout each time it has been successfully used. |
| 2347 | * |
| 2348 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2349 | * |
| 2350 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2351 | * |
| 2352 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2353 | * a {@link SecurityException} will be thrown. |
| 2354 | * |
| 2355 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2356 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2357 | * profile. |
| 2358 | * |
| 2359 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2360 | * @param timeoutMs The new timeout, after which the user will have to unlock with strong |
| 2361 | * authentication method. If the timeout is lower than 1 hour (minimum) or higher than |
| 2362 | * 72 hours (default and maximum) an {@link IllegalArgumentException} is thrown. |
| 2363 | * |
| 2364 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 2365 | * @throws IllegalArgumentException if the timeout is lower than 1 hour (minimum) or higher than |
| 2366 | * 72 hours (default and maximum) |
| 2367 | * |
| 2368 | * @hide |
| 2369 | */ |
| 2370 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2371 | long timeoutMs) { |
| 2372 | if (mService != null) { |
| 2373 | try { |
| 2374 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2375 | } catch (RemoteException e) { |
| 2376 | throw e.rethrowFromSystemServer(); |
| 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | /** |
| 2382 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 2383 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 2384 | * After the returned timeout the user is required to use strong authentication method. |
| 2385 | * |
| 2386 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2387 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2388 | * restrictions on the parent profile. |
| 2389 | * |
| 2390 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 2391 | * accross all participating admins. |
| 2392 | * @return The timeout or default timeout if not configured |
| 2393 | * |
| 2394 | * @hide |
| 2395 | */ |
| 2396 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 2397 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 2398 | } |
| 2399 | |
| 2400 | /** @hide per-user version */ |
| 2401 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 2402 | if (mService != null) { |
| 2403 | try { |
| 2404 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 2405 | } catch (RemoteException e) { |
| 2406 | throw e.rethrowFromSystemServer(); |
| 2407 | } |
| 2408 | } |
| 2409 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 2410 | } |
| 2411 | |
| 2412 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2413 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2414 | * this call. |
| 2415 | * <p> |
| 2416 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2417 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2418 | * <p> |
| 2419 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2420 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2421 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2422 | * @throws SecurityException if the calling application does not own an active administrator |
| 2423 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2424 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2425 | public void lockNow() { |
| 2426 | if (mService != null) { |
| 2427 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2428 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2429 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2430 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2434 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2435 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2436 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2437 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2438 | */ |
| 2439 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2440 | |
| 2441 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2442 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2443 | * data. |
| 2444 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2445 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2446 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2447 | */ |
| 2448 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2449 | |
| 2450 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 2451 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 2452 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 2453 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 2454 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2455 | * <p> |
| 2456 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2457 | * be able to call this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2458 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2459 | * @param flags Bit mask of additional options: currently supported flags are |
| 2460 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2461 | * @throws SecurityException if the calling application does not own an active administrator |
| 2462 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2463 | */ |
| 2464 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2465 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2466 | if (mService != null) { |
| 2467 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2468 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2469 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2470 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2474 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2475 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2476 | * Called by an application that is administering the device to set the |
| 2477 | * global proxy and exclusion list. |
| 2478 | * <p> |
| 2479 | * The calling device admin must have requested |
| 2480 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2481 | * this method; if it has not, a security exception will be thrown. |
| 2482 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2483 | * 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] | 2484 | * 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] | 2485 | * be returned. |
| 2486 | * The method can be called repeatedly by the device admin alrady setting the |
| 2487 | * proxy to update the proxy and exclusion list. |
| 2488 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2489 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2490 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2491 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2492 | * @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] | 2493 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2494 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2495 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2496 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2497 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2498 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2499 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2500 | if (proxySpec == null) { |
| 2501 | throw new NullPointerException(); |
| 2502 | } |
| 2503 | if (mService != null) { |
| 2504 | try { |
| 2505 | String hostSpec; |
| 2506 | String exclSpec; |
| 2507 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2508 | hostSpec = null; |
| 2509 | exclSpec = null; |
| 2510 | } else { |
| 2511 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2512 | throw new IllegalArgumentException(); |
| 2513 | } |
| 2514 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2515 | String hostName = sa.getHostName(); |
| 2516 | int port = sa.getPort(); |
| 2517 | StringBuilder hostBuilder = new StringBuilder(); |
| 2518 | hostSpec = hostBuilder.append(hostName) |
| 2519 | .append(":").append(Integer.toString(port)).toString(); |
| 2520 | if (exclusionList == null) { |
| 2521 | exclSpec = ""; |
| 2522 | } else { |
| 2523 | StringBuilder listBuilder = new StringBuilder(); |
| 2524 | boolean firstDomain = true; |
| 2525 | for (String exclDomain : exclusionList) { |
| 2526 | if (!firstDomain) { |
| 2527 | listBuilder = listBuilder.append(","); |
| 2528 | } else { |
| 2529 | firstDomain = false; |
| 2530 | } |
| 2531 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2532 | } |
| 2533 | exclSpec = listBuilder.toString(); |
| 2534 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2535 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2536 | != android.net.Proxy.PROXY_VALID) |
| 2537 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2538 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2539 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2540 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2541 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2542 | } |
| 2543 | } |
| 2544 | return null; |
| 2545 | } |
| 2546 | |
| 2547 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2548 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 2549 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 2550 | * unusual like general internal filtering this may be useful. On a private network where the |
| 2551 | * proxy is not accessible, you may break HTTP using this. |
| 2552 | * <p> |
| 2553 | * This method requires the caller to be the device owner. |
| 2554 | * <p> |
| 2555 | * This proxy is only a recommendation and it is possible that some apps will ignore it. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2556 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2557 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2558 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2559 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 2560 | * {@code null} value will clear the global HTTP proxy. |
| 2561 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2562 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2563 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2564 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2565 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2566 | if (mService != null) { |
| 2567 | try { |
| 2568 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2569 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2570 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2571 | } |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2576 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2577 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2578 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2579 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2580 | */ |
| 2581 | public ComponentName getGlobalProxyAdmin() { |
| 2582 | if (mService != null) { |
| 2583 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2584 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2585 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2586 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | return null; |
| 2590 | } |
| 2591 | |
| 2592 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2593 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2594 | * indicating that encryption is not supported. |
| 2595 | */ |
| 2596 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2597 | |
| 2598 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2599 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2600 | * indicating that encryption is supported, but is not currently active. |
| 2601 | */ |
| 2602 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2603 | |
| 2604 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2605 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2606 | * indicating that encryption is not currently active, but is currently |
| 2607 | * being activated. This is only reported by devices that support |
| 2608 | * encryption of data and only when the storage is currently |
| 2609 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2610 | * to become encrypted will never return this value. |
| 2611 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2612 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2613 | |
| 2614 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2615 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2616 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2617 | * <p> |
| 2618 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2619 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2620 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2621 | |
| 2622 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2623 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2624 | * indicating that encryption is active, but an encryption key has not |
| 2625 | * been set by the user. |
| 2626 | */ |
| 2627 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2628 | |
| 2629 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2630 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2631 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 2632 | * <p> |
| 2633 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 2634 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 2635 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2636 | */ |
| 2637 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 2638 | |
| 2639 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2640 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2641 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2642 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2643 | * to check encryption status. However, on some devices this activity may never return, as |
| 2644 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2645 | */ |
| 2646 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2647 | public static final String ACTION_START_ENCRYPTION |
| 2648 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2649 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2650 | * Widgets are enabled in keyguard |
| 2651 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2652 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2653 | |
| 2654 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2655 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2656 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2657 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2658 | |
| 2659 | /** |
| 2660 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2661 | */ |
| 2662 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2663 | |
| 2664 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2665 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2666 | */ |
| 2667 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2668 | |
| 2669 | /** |
| 2670 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2671 | */ |
| 2672 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2673 | |
| 2674 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2675 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2676 | * (e.g. PIN/Pattern/Password). |
| 2677 | */ |
| 2678 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2679 | |
| 2680 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2681 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2682 | */ |
| 2683 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2684 | |
| 2685 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 2686 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 2687 | */ |
| 2688 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 2689 | |
| 2690 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2691 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2692 | */ |
| 2693 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2694 | |
| 2695 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2696 | * Called by an application that is administering the device to request that the storage system |
| 2697 | * be encrypted. |
| 2698 | * <p> |
| 2699 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 2700 | * supported setting will always be used. If any device administrator requests device |
| 2701 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 2702 | * device encryption while another device administrator has enabled it, the call to disable will |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2703 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2704 | * <p> |
| 2705 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 2706 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 2707 | * control the encryption of any other storage areas. There is one exception: If |
| 2708 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 2709 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 2710 | * written to disk within the encrypted storage area. |
| 2711 | * <p> |
| 2712 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 2713 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 2714 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 2715 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2716 | * |
| 2717 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2718 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2719 | * @return the new request status (for all active admins) - will be one of |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2720 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2721 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2722 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 2723 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2724 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2725 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2726 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2727 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2728 | if (mService != null) { |
| 2729 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2730 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2731 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2732 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2733 | } |
| 2734 | } |
| 2735 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2736 | } |
| 2737 | |
| 2738 | /** |
| 2739 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2740 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2741 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2742 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2743 | * this will return the requested encryption setting as an aggregate of all active |
| 2744 | * administrators. |
| 2745 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2746 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2747 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2748 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2749 | if (mService != null) { |
| 2750 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2751 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2752 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2753 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2754 | } |
| 2755 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2756 | return false; |
| 2757 | } |
| 2758 | |
| 2759 | /** |
| 2760 | * Called by an application that is administering the device to |
| 2761 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2762 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2763 | * Depending on the returned status code, the caller may proceed in different |
| 2764 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2765 | * storage system does not support encryption. If the |
| 2766 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2767 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2768 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2769 | * storage system has enabled encryption but no password is set so further action |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2770 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 2771 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 2772 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2773 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2774 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2775 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2776 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2777 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2778 | */ |
| 2779 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2780 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2781 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | /** @hide per-user version */ |
| 2785 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2786 | if (mService != null) { |
| 2787 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2788 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2789 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2790 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2791 | } |
| 2792 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2793 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2794 | } |
| 2795 | |
| 2796 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 2797 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 2798 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 2799 | * keep the certificate on the device. |
| 2800 | * |
| 2801 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 2802 | * this certificate. |
| 2803 | * |
| 2804 | * @hide |
| 2805 | */ |
| 2806 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 2807 | if (mService != null) { |
| 2808 | try { |
| 2809 | return mService.approveCaCert(alias, userHandle, approval); |
| 2810 | } catch (RemoteException e) { |
| 2811 | throw e.rethrowFromSystemServer(); |
| 2812 | } |
| 2813 | } |
| 2814 | return false; |
| 2815 | } |
| 2816 | |
| 2817 | /** |
| 2818 | * Check whether a CA certificate has been approved by the device user. |
| 2819 | * |
| 2820 | * @hide |
| 2821 | */ |
| 2822 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 2823 | if (mService != null) { |
| 2824 | try { |
| 2825 | return mService.isCaCertApproved(alias, userHandle); |
| 2826 | } catch (RemoteException e) { |
| 2827 | throw e.rethrowFromSystemServer(); |
| 2828 | } |
| 2829 | } |
| 2830 | return false; |
| 2831 | } |
| 2832 | |
| 2833 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2834 | * Installs the given certificate as a user CA. |
| 2835 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2836 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2837 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2838 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2839 | * |
| 2840 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2841 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2842 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2843 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2844 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2845 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2846 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2847 | if (mService != null) { |
| 2848 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2849 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2850 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2851 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2852 | } |
| 2853 | } |
| 2854 | return false; |
| 2855 | } |
| 2856 | |
| 2857 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2858 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2859 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2860 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2861 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2862 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2863 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2864 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2865 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2866 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2867 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2868 | if (mService != null) { |
| 2869 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2870 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2871 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2872 | } catch (CertificateException e) { |
| 2873 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2874 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2875 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2876 | } |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2881 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2882 | * If a user has installed any certificates by other means than device policy these will be |
| 2883 | * included too. |
| 2884 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2885 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2886 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2887 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2888 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2889 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2890 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2891 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2892 | List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2893 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2894 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2895 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2896 | mService.enforceCanManageCaCerts(admin); |
| 2897 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2898 | for (String alias : certStore.userAliases()) { |
| 2899 | try { |
| 2900 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2901 | } catch (CertificateException ce) { |
| 2902 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2903 | } |
| 2904 | } |
| 2905 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2906 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2913 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2914 | * means other than device policy will also be removed, except for system CA certificates. |
| 2915 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2916 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2917 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2918 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2919 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2920 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2921 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2922 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2923 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2924 | try { |
| 2925 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2926 | .toArray(new String[0])); |
| 2927 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2928 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | /** |
| 2934 | * Returns whether this certificate is installed as a trusted CA. |
| 2935 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2936 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2937 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2938 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2939 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2940 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2941 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2942 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2943 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2944 | if (mService != null) { |
| 2945 | try { |
| 2946 | mService.enforceCanManageCaCerts(admin); |
| 2947 | return getCaCertAlias(certBuffer) != null; |
| 2948 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2949 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2950 | } catch (CertificateException ce) { |
| 2951 | Log.w(TAG, "Could not parse certificate", ce); |
| 2952 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2953 | } |
| 2954 | return false; |
| 2955 | } |
| 2956 | |
| 2957 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2958 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2959 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2960 | * the certificate and use the private key, given direct user approval. |
| 2961 | * |
| 2962 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 2963 | * direct user approval. This is for security - should a certificate installer become |
| 2964 | * compromised, certificates it had already installed will be protected. |
| 2965 | * |
| 2966 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2967 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2968 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2969 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2970 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2971 | * @param privKey The private key to install. |
| 2972 | * @param cert The certificate to install. |
| 2973 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2974 | * with that alias already exists, it will be overwritten. |
| 2975 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2976 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2977 | * owner. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2978 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2979 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2980 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2981 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | /** |
| 2985 | * Called by a device or profile owner, or delegated certificate installer, to install a |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2986 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 2987 | * profile will be able to access the certificate chain and use the private key, given direct |
| 2988 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2989 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2990 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 2991 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 2992 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2993 | * |
| 2994 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2995 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2996 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2997 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 2998 | * certificate and include the chain of trust in order. This will be returned by |
| 2999 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3000 | * @param alias The private key alias under which to install the certificate. If a certificate |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3001 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3002 | * @param requestAccess {@code true} to request that the calling app be granted access to the |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3003 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3004 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3005 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3006 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3007 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3008 | * @see android.security.KeyChain#getCertificateChain |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3009 | */ |
| 3010 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3011 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3012 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3013 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3014 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3015 | byte[] pemChain = null; |
| 3016 | if (certs.length > 1) { |
| 3017 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3018 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3019 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3020 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3021 | return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias, |
| 3022 | requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3023 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3024 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3025 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3026 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3027 | } catch (CertificateException | IOException e) { |
| 3028 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3029 | } |
| 3030 | return false; |
| 3031 | } |
| 3032 | |
| 3033 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3034 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3035 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3036 | * |
| 3037 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3038 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3039 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3040 | * @return {@code true} if the private key alias no longer exists, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3041 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3042 | * owner. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3043 | */ |
| 3044 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3045 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3046 | try { |
| 3047 | return mService.removeKeyPair(admin, alias); |
| 3048 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3049 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3050 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3054 | * @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] | 3055 | * doesn't exist. |
| 3056 | */ |
| 3057 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3058 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3059 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3060 | new ByteArrayInputStream(certBuffer)); |
| 3061 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3062 | } |
| 3063 | |
| 3064 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3065 | * 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] | 3066 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3067 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3068 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3069 | * <p> |
| 3070 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3071 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3072 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3073 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3074 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3075 | * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3076 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3077 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3078 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3079 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3080 | * @param installerPackage The package name of the certificate installer which will be given |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3081 | * access. If {@code null} is given the current package will be cleared. |
| 3082 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3083 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3084 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3085 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3086 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3087 | if (mService != null) { |
| 3088 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3089 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3090 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3091 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3092 | } |
| 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3097 | * Called by a profile owner or device owner to retrieve the certificate installer for the user. |
| 3098 | * null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3099 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3100 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3101 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3102 | * none is set. |
| 3103 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3104 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3105 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3106 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3107 | if (mService != null) { |
| 3108 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3109 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3110 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3111 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | return null; |
| 3115 | } |
| 3116 | |
| 3117 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3118 | * Called by a device or profile owner to configure an always-on VPN connection through a |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3119 | * specific application for the current user. |
| 3120 | * |
| 3121 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3122 | * TODO: delete once there are no longer any live references. |
| 3123 | * @hide |
| 3124 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3125 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3126 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3127 | throws NameNotFoundException, UnsupportedOperationException { |
| 3128 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3129 | } |
| 3130 | |
| 3131 | /** |
| 3132 | * Called by a device or profile owner to configure an always-on VPN connection through a |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3133 | * specific application for the current user. This connection is automatically granted and |
| 3134 | * persisted after a reboot. |
| 3135 | * <p> |
| 3136 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3137 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3138 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3139 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3140 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3141 | * remove an existing always-on VPN configuration. |
| 3142 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3143 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3144 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3145 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3146 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3147 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3148 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3149 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3150 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3151 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3152 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3153 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3154 | if (mService != null) { |
| 3155 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3156 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3157 | throw new NameNotFoundException(vpnPackage); |
| 3158 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3159 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3160 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3161 | } |
| 3162 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | /** |
| 3166 | * Called by a device or profile owner to read the name of the package administering an |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3167 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3168 | * VPN is provided by the system instead of by an application, {@code null} will be returned. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3169 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3170 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3171 | * is set. |
| 3172 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3173 | */ |
| 3174 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3175 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3176 | if (mService != null) { |
| 3177 | try { |
| 3178 | return mService.getAlwaysOnVpnPackage(admin); |
| 3179 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3180 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3181 | } |
| 3182 | } |
| 3183 | return null; |
| 3184 | } |
| 3185 | |
| 3186 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3187 | * Called by an application that is administering the device to disable all cameras on the |
| 3188 | * device, for this user. After setting this, no applications running as this user will be able |
| 3189 | * to access any cameras on the device. |
| 3190 | * <p> |
| 3191 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3192 | * <p> |
| 3193 | * The calling device admin must have requested |
| 3194 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3195 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3196 | * |
| 3197 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3198 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3199 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3200 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3201 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3202 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3203 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3204 | if (mService != null) { |
| 3205 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3206 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3207 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3208 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3209 | } |
| 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3214 | * Determine whether or not the device's cameras have been disabled for this user, |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3215 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3216 | * @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] | 3217 | * have disabled the camera |
| 3218 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3219 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3220 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3221 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3225 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3226 | if (mService != null) { |
| 3227 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3228 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3229 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3230 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3231 | } |
| 3232 | } |
| 3233 | return false; |
| 3234 | } |
| 3235 | |
| 3236 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3237 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3238 | * <p> |
| 3239 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 3240 | * {@link SecurityException} will be thrown. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3241 | * |
| 3242 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3243 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3244 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3245 | * bugreport is still running or waiting for the user to share or decline) |
| 3246 | * @throws SecurityException if {@code admin} is not a device owner, or if there are users other |
| 3247 | * than the one managed by the device owner. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3248 | */ |
| 3249 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3250 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3251 | if (mService != null) { |
| 3252 | try { |
| 3253 | return mService.requestBugreport(admin); |
| 3254 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3255 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3256 | } |
| 3257 | } |
| 3258 | return false; |
| 3259 | } |
| 3260 | |
| 3261 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3262 | * Determine whether or not creating a guest user has been disabled for the device |
| 3263 | * |
| 3264 | * @hide |
| 3265 | */ |
| 3266 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3267 | // Currently guest users can always be created if multi-user is enabled |
| 3268 | // TODO introduce a policy for guest user creation |
| 3269 | return false; |
| 3270 | } |
| 3271 | |
| 3272 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3273 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3274 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3275 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3276 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3277 | * <p> |
| 3278 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3279 | * exception will be thrown. |
| 3280 | * <p> |
| 3281 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3282 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3283 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3284 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3285 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3286 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3287 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3288 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3289 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3290 | if (mService != null) { |
| 3291 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3292 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3293 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3294 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3295 | } |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3300 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3301 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3302 | * @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] | 3303 | * have disabled screen capture. |
| 3304 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3305 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3306 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3307 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3311 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3312 | if (mService != null) { |
| 3313 | try { |
| 3314 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3315 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3316 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3317 | } |
| 3318 | } |
| 3319 | return false; |
| 3320 | } |
| 3321 | |
| 3322 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3323 | * Called by a device owner to set whether auto time is required. If auto time is required the |
| 3324 | * user cannot set the date and time, but has to use network date and time. |
| 3325 | * <p> |
| 3326 | * Note: if auto time is required the user can still manually set the time zone. |
| 3327 | * <p> |
| 3328 | * The calling device admin must be a device owner. If it is not, a security exception will be |
| 3329 | * thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3330 | * |
| 3331 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3332 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3333 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3334 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3335 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3336 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3337 | if (mService != null) { |
| 3338 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3339 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3340 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3341 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3342 | } |
| 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | /** |
| 3347 | * @return true if auto time is required. |
| 3348 | */ |
| 3349 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3350 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3351 | if (mService != null) { |
| 3352 | try { |
| 3353 | return mService.getAutoTimeRequired(); |
| 3354 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3355 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3356 | } |
| 3357 | } |
| 3358 | return false; |
| 3359 | } |
| 3360 | |
| 3361 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3362 | * Called by a device owner to set whether all users created on the device should be ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3363 | * <p> |
| 3364 | * The system user is exempt from this policy - it is never ephemeral. |
| 3365 | * <p> |
| 3366 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 3367 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3368 | * |
| 3369 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3370 | * @param forceEphemeralUsers If true, all the existing users will be deleted and all |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3371 | * subsequently created users will be ephemeral. |
| 3372 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3373 | * @hide |
| 3374 | */ |
| 3375 | public void setForceEphemeralUsers( |
| 3376 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3377 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3378 | if (mService != null) { |
| 3379 | try { |
| 3380 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3381 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3382 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3383 | } |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | /** |
| 3388 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3389 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3390 | * @hide |
| 3391 | */ |
| 3392 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3393 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3394 | if (mService != null) { |
| 3395 | try { |
| 3396 | return mService.getForceEphemeralUsers(admin); |
| 3397 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3398 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | return false; |
| 3402 | } |
| 3403 | |
| 3404 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3405 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3406 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3407 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3408 | * <p> |
| 3409 | * The calling device admin must have requested |
| 3410 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 3411 | * if it has not, a security exception will be thrown. |
| 3412 | * <p> |
| 3413 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 3414 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 3415 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3416 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3417 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3418 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3419 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3420 | * there is one, or the parent user otherwise. |
| 3421 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 3422 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3423 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3424 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3425 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3426 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3427 | * profile. |
| 3428 | * <p> |
| 3429 | * Requests to disable other features on a managed profile will be ignored. |
| 3430 | * <p> |
| 3431 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3432 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3433 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3434 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3435 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3436 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 3437 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 3438 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 3439 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 3440 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 3441 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 3442 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3443 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3444 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3445 | if (mService != null) { |
| 3446 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3447 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3448 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3449 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3455 | * Determine whether or not features have been disabled in keyguard either by the calling |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 3456 | * admin, if specified, or all admins that set restrictions on this user and its participating |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3457 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3458 | * |
| 3459 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3460 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3461 | * restrictions on the parent profile. |
| 3462 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3463 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3464 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3465 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3466 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3467 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3468 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3469 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3473 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3474 | if (mService != null) { |
| 3475 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3476 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3477 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3478 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3479 | } |
| 3480 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3481 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3485 | * @hide |
| 3486 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3487 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3488 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3489 | if (mService != null) { |
| 3490 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3491 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3492 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3493 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3494 | } |
| 3495 | } |
| 3496 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3497 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3498 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3499 | * @hide |
| 3500 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3501 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3502 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3506 | * @hide |
| 3507 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3508 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3509 | if (mService != null) { |
| 3510 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3511 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3512 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3513 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * @hide |
| 3520 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3521 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3522 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3523 | if (mService != null) { |
| 3524 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3525 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3526 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3527 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3528 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3529 | } |
| 3530 | } |
| 3531 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3532 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3533 | /** |
| 3534 | * @hide |
| 3535 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3536 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3537 | if (mService != null) { |
| 3538 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3539 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3540 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3541 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3545 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3546 | /** |
| 3547 | * @hide |
| 3548 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3549 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3550 | if (mService != null) { |
| 3551 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3552 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3553 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3554 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3558 | |
| 3559 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3560 | * @hide |
| 3561 | */ |
| 3562 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3563 | if (mService != null) { |
| 3564 | try { |
| 3565 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3566 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3567 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * @hide |
| 3574 | */ |
| 3575 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3576 | if (mService != null) { |
| 3577 | try { |
| 3578 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3579 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3580 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3581 | } |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3586 | * Should be called when keyguard has been dismissed. |
| 3587 | * @hide |
| 3588 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3589 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3590 | if (mService != null) { |
| 3591 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3592 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3593 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3594 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | /** |
| 3600 | * Should be called when keyguard view has been shown to the user. |
| 3601 | * @hide |
| 3602 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3603 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3604 | if (mService != null) { |
| 3605 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3606 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3607 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3608 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3609 | } |
| 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3614 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3615 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3616 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3617 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3618 | * @return whether the package was successfully registered as the device owner. |
| 3619 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3620 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3621 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3622 | public boolean setDeviceOwner(ComponentName who) { |
| 3623 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3628 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3629 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3630 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | /** |
| 3634 | * @hide |
| 3635 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3636 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3637 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | /** |
| 3641 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3642 | * Sets the given package as the device owner. The package must already be installed. There |
| 3643 | * must not already be a device owner. |
| 3644 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3645 | * this method. |
| 3646 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3647 | * the caller is the shell uid, and there are no additional users and no accounts. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3648 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3649 | * @param ownerName the human readable name of the institution that owns this device. |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3650 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3651 | * @return whether the package was successfully registered as the device owner. |
| 3652 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3653 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3654 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3655 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3656 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3657 | if (mService != null) { |
| 3658 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3659 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3660 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3661 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | return false; |
| 3665 | } |
| 3666 | |
| 3667 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3668 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3669 | * 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] | 3670 | * 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] | 3671 | * package is currently registered as the device owner app, pass in the package name from |
| 3672 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3673 | * 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] | 3674 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3675 | * the setup process. |
| 3676 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3677 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3678 | * @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] | 3679 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3680 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3681 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3682 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3683 | } |
| 3684 | |
| 3685 | /** |
| 3686 | * @return true if a package is registered as device owner, only when it's running on the |
| 3687 | * calling user. |
| 3688 | * |
| 3689 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3690 | * @hide |
| 3691 | */ |
| 3692 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3693 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3694 | } |
| 3695 | |
| 3696 | /** |
| 3697 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3698 | * user. |
| 3699 | * |
| 3700 | * <p>Requires the MANAGE_USERS permission. |
| 3701 | * |
| 3702 | * @hide |
| 3703 | */ |
| 3704 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3705 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3706 | } |
| 3707 | |
| 3708 | /** |
| 3709 | * @return device owner component name, only when it's running on the calling user. |
| 3710 | * |
| 3711 | * @hide |
| 3712 | */ |
| 3713 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3714 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3715 | } |
| 3716 | |
| 3717 | /** |
| 3718 | * @return device owner component name, even if it's running on a different user. |
| 3719 | * |
| 3720 | * <p>Requires the MANAGE_USERS permission. |
| 3721 | * |
| 3722 | * @hide |
| 3723 | */ |
| 3724 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3725 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3726 | } |
| 3727 | |
| 3728 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3729 | if (packageName == null) { |
| 3730 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3731 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3732 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3733 | if (deviceOwner == null) { |
| 3734 | return false; |
| 3735 | } |
| 3736 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3737 | } |
| 3738 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3739 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3740 | if (mService != null) { |
| 3741 | try { |
| 3742 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3743 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3744 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3745 | } |
| 3746 | } |
| 3747 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3750 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3751 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3752 | * no device owner. |
| 3753 | * |
| 3754 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3755 | * |
| 3756 | * @hide |
| 3757 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3758 | public int getDeviceOwnerUserId() { |
| 3759 | if (mService != null) { |
| 3760 | try { |
| 3761 | return mService.getDeviceOwnerUserId(); |
| 3762 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3763 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3764 | } |
| 3765 | } |
| 3766 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3770 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 3771 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 3772 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3773 | * |
| 3774 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3775 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 3776 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3777 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3778 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3779 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3780 | if (mService != null) { |
| 3781 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3782 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3783 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3784 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3785 | } |
| 3786 | } |
| 3787 | } |
| 3788 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3789 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3790 | * Returns the device owner package name, only if it's running on the calling user. |
| 3791 | * |
| 3792 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3793 | * |
| 3794 | * @hide |
| 3795 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3796 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3797 | public String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3798 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3799 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3800 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3804 | * @return true if the device is managed by any device owner. |
| 3805 | * |
| 3806 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3807 | * |
| 3808 | * @hide |
| 3809 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3810 | public boolean isDeviceManaged() { |
| 3811 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3812 | } |
| 3813 | |
| 3814 | /** |
| 3815 | * Returns the device owner name. Note this method *will* return the device owner |
| 3816 | * name when it's running on a different user. |
| 3817 | * |
| 3818 | * <p>Requires the MANAGE_USERS permission. |
| 3819 | * |
| 3820 | * @hide |
| 3821 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3822 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3823 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3824 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3825 | if (mService != null) { |
| 3826 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3827 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3828 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3829 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | return null; |
| 3833 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3834 | |
| 3835 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3836 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3837 | * @deprecated Do not use |
| 3838 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3839 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3840 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3841 | @SystemApi |
| 3842 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3843 | return null; |
| 3844 | } |
| 3845 | |
| 3846 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3847 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3848 | * @deprecated Do not use |
| 3849 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3850 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3851 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3852 | @SystemApi |
| 3853 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3854 | return null; |
| 3855 | } |
| 3856 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3857 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3858 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3859 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3860 | * Sets the given component as an active admin and registers the package as the profile |
| 3861 | * owner for this user. The package must already be installed and there shouldn't be |
| 3862 | * an existing profile owner registered for this user. Also, this method must be called |
| 3863 | * before the user setup has been completed. |
| 3864 | * <p> |
| 3865 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3866 | * MANAGE_DEVICE_ADMINS permission. |
| 3867 | * @param admin The component to register as an active admin and profile owner. |
| 3868 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3869 | * @return whether the admin was successfully registered as the profile owner. |
| 3870 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3871 | * the user has already been set up. |
| 3872 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3873 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3874 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3875 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3876 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3877 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3878 | if (mService != null) { |
| 3879 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3880 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3881 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3882 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3883 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3884 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | return false; |
| 3888 | } |
| 3889 | |
| 3890 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3891 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 3892 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 3893 | * will be thrown. |
| 3894 | * <p> |
| 3895 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3896 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3897 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3898 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3899 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3900 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3901 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3902 | if (mService != null) { |
| 3903 | try { |
| 3904 | mService.clearProfileOwner(admin); |
| 3905 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3906 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3912 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3913 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3914 | */ |
| 3915 | public boolean hasUserSetupCompleted() { |
| 3916 | if (mService != null) { |
| 3917 | try { |
| 3918 | return mService.hasUserSetupCompleted(); |
| 3919 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3920 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3921 | } |
| 3922 | } |
| 3923 | return true; |
| 3924 | } |
| 3925 | |
| 3926 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3927 | * @hide |
| 3928 | * 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] | 3929 | * already be installed. There must not already be a profile owner for this user. |
| 3930 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3931 | * this method. |
| 3932 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3933 | * - the caller is SYSTEM_UID. |
| 3934 | * - 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] | 3935 | * @param admin the component name to be registered as profile owner. |
| 3936 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3937 | * @param userHandle the userId to set the profile owner for. |
| 3938 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3939 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3940 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3941 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3942 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3943 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3944 | if (mService != null) { |
| 3945 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3946 | if (ownerName == null) { |
| 3947 | ownerName = ""; |
| 3948 | } |
| 3949 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3950 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3951 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | return false; |
| 3955 | } |
| 3956 | |
| 3957 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3958 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3959 | * <p> |
| 3960 | * If the device owner information is {@code null} or empty then the device owner info is |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3961 | * cleared and the user owner info is shown on the lock screen if it is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3962 | * <p> |
| 3963 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 3964 | * will be blank and the user will not be allowed to change it. |
| 3965 | * <p> |
| 3966 | * If the device owner information needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 3967 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3968 | * and set a new version of this string accordingly. |
| 3969 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3970 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3971 | * @param info Device owner information which will be displayed instead of the user owner info. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3972 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3973 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3974 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3975 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3976 | if (mService != null) { |
| 3977 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3978 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3979 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3980 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3981 | } |
| 3982 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | /** |
| 3986 | * @return The device owner information. If it is not set returns {@code null}. |
| 3987 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3988 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3989 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3990 | if (mService != null) { |
| 3991 | try { |
| 3992 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3993 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3994 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3995 | } |
| 3996 | } |
| 3997 | return null; |
| 3998 | } |
| 3999 | |
| 4000 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4001 | * Called by device or profile owners to suspend packages for this user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4002 | * <p> |
| 4003 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4004 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4005 | * device. |
| 4006 | * <p> |
| 4007 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4008 | * package will no longer be suspended. The admin can block this by using |
Kenny Guy | 871f3eb | 2016-03-09 20:06:16 +0000 | [diff] [blame] | 4009 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4010 | * |
| 4011 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4012 | * @param packageNames The package names to suspend or unsuspend. |
| 4013 | * @param suspended If set to {@code true} than the packages will be suspended, if set to |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4014 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4015 | * @return an array of package names for which the suspended status is not set as requested in |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4016 | * this method. |
| 4017 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4018 | */ |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4019 | public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames, |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4020 | boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4021 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4022 | if (mService != null) { |
| 4023 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4024 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4025 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4026 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4027 | } |
| 4028 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4029 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4030 | } |
| 4031 | |
| 4032 | /** |
| 4033 | * Called by device or profile owners to determine if a package is suspended. |
| 4034 | * |
| 4035 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4036 | * @param packageName The name of the package to retrieve the suspended status of. |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 4037 | * @return {@code true} if the package is suspended or {@code false} if the package is not |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4038 | * suspended, could not be found or an error occurred. |
| 4039 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4040 | * @throws NameNotFoundException if the package could not be found. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4041 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4042 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4043 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4044 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4045 | if (mService != null) { |
| 4046 | try { |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4047 | return mService.isPackageSuspended(admin, packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4048 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4049 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4050 | } catch (IllegalArgumentException ex) { |
| 4051 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4052 | } |
| 4053 | } |
| 4054 | return false; |
| 4055 | } |
| 4056 | |
| 4057 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4058 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4059 | * be used. Only the profile owner can call this. |
| 4060 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4061 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4062 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4063 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4064 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4065 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4066 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4067 | if (mService != null) { |
| 4068 | try { |
| 4069 | mService.setProfileEnabled(admin); |
| 4070 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4071 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4077 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4078 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4079 | * by the profile or device owner, the name will be set to default values. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4080 | * |
| 4081 | * @see #isProfileOwnerApp |
| 4082 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4083 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4084 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4085 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4086 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4087 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4088 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4089 | if (mService != null) { |
| 4090 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4091 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4092 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4093 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4094 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4095 | } |
| 4096 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4097 | |
| 4098 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4099 | * Used to determine if a particular package is registered as the profile owner for the |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4100 | * 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] | 4101 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4102 | * |
| 4103 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4104 | * @return Whether or not the package is registered as the profile owner. |
| 4105 | */ |
| 4106 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4107 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4108 | if (mService != null) { |
| 4109 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4110 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4111 | return profileOwner != null |
| 4112 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4113 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4114 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4115 | } |
| 4116 | } |
| 4117 | return false; |
| 4118 | } |
| 4119 | |
| 4120 | /** |
| 4121 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4122 | * @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] | 4123 | * owner has been set for that user. |
| 4124 | * @throws IllegalArgumentException if the userId is invalid. |
| 4125 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4126 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4127 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4128 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4129 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4130 | } |
| 4131 | |
| 4132 | /** |
| 4133 | * @see #getProfileOwner() |
| 4134 | * @hide |
| 4135 | */ |
| 4136 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4137 | if (mService != null) { |
| 4138 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4139 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4140 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4141 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | return null; |
| 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4149 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4150 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4151 | * @throws IllegalArgumentException if the userId is invalid. |
| 4152 | */ |
| 4153 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 4154 | if (mService != null) { |
| 4155 | try { |
| 4156 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4157 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4158 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4159 | } |
| 4160 | } |
| 4161 | return null; |
| 4162 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4163 | |
| 4164 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4165 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4166 | * @param userId The user for whom to fetch the profile owner name, if any. |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4167 | * @return the human readable name of the organisation associated with this profile owner or |
| 4168 | * null if one is not set. |
| 4169 | * @throws IllegalArgumentException if the userId is invalid. |
| 4170 | */ |
| 4171 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 4172 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4173 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4174 | if (mService != null) { |
| 4175 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 4176 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4177 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4178 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4179 | } |
| 4180 | } |
| 4181 | return null; |
| 4182 | } |
| 4183 | |
| 4184 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4185 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 4186 | * intents that match a certain intent filter. This activity will remain the default intent |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4187 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 4188 | * intent preferences are reset. |
| 4189 | * <p> |
| 4190 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 4191 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 4192 | * the filter. |
| 4193 | * <p> |
| 4194 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 4195 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4196 | * |
| 4197 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4198 | * @param filter The IntentFilter for which a default handler is added. |
| 4199 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4200 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4201 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4202 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 4203 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4204 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4205 | if (mService != null) { |
| 4206 | try { |
| 4207 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4208 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4209 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4210 | } |
| 4211 | } |
| 4212 | } |
| 4213 | |
| 4214 | /** |
| 4215 | * 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] | 4216 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4217 | * <p> |
| 4218 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4219 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4220 | * |
| 4221 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4222 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4223 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4224 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4225 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4226 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4227 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4228 | if (mService != null) { |
| 4229 | try { |
| 4230 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4231 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4232 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4233 | } |
| 4234 | } |
| 4235 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4236 | |
| 4237 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4238 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4239 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4240 | * {@link #getApplicationRestrictions}. |
| 4241 | * <p> |
| 4242 | * This permission is persistent until it is later cleared by calling this method with a |
| 4243 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4244 | * <p> |
| 4245 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4246 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4247 | * |
| 4248 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4249 | * @param packageName The package name which will be given access to application restrictions |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4250 | * APIs. If {@code null} is given the current package will be cleared. |
| 4251 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4252 | * @throws NameNotFoundException if {@code packageName} is not found |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4253 | */ |
| 4254 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4255 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4256 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4257 | if (mService != null) { |
| 4258 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4259 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4260 | throw new NameNotFoundException(packageName); |
| 4261 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4262 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4263 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 4270 | * package for the current user, or {@code null} if none is set. |
| 4271 | * |
| 4272 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4273 | * @return The package name allowed to manage application restrictions on the current user, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4274 | * {@code null} if none is set. |
| 4275 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4276 | */ |
| 4277 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4278 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4279 | if (mService != null) { |
| 4280 | try { |
| 4281 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4282 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4283 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4284 | } |
| 4285 | } |
| 4286 | return null; |
| 4287 | } |
| 4288 | |
| 4289 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4290 | * Called by any application to find out whether it has been granted permission via |
| 4291 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4292 | * for the calling user. |
| 4293 | * |
| 4294 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4295 | * that method. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4296 | */ |
| 4297 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4298 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4299 | if (mService != null) { |
| 4300 | try { |
| 4301 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 4302 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4303 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4304 | } |
| 4305 | } |
| 4306 | return false; |
| 4307 | } |
| 4308 | |
| 4309 | /** |
| 4310 | * Sets the application restrictions for a given target application running in the calling user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4311 | * <p> |
| 4312 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4313 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4314 | * security exception will be thrown. |
| 4315 | * <p> |
| 4316 | * The provided {@link Bundle} consists of key-value pairs, where the types of values may be: |
Esteban Talavera | 6b8e064 | 2015-08-10 17:26:04 +0100 | [diff] [blame] | 4317 | * <ul> |
| 4318 | * <li>{@code boolean} |
| 4319 | * <li>{@code int} |
| 4320 | * <li>{@code String} or {@code String[]} |
| 4321 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4322 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4323 | * <p> |
| 4324 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 4325 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4326 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4327 | * <p> |
| 4328 | * The application restrictions are only made visible to the target application via |
| 4329 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 4330 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4331 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4332 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4333 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 4334 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4335 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4336 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4337 | * @param packageName The name of the package to update restricted settings for. |
| 4338 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4339 | * set of active restrictions. |
| 4340 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4341 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4342 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4343 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4344 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4345 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4346 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4347 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4348 | if (mService != null) { |
| 4349 | try { |
| 4350 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 4351 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4352 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4358 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 4359 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 4360 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4361 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4362 | * <p> |
| 4363 | * The calling device admin must have requested |
| 4364 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4365 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4366 | * <p> |
| 4367 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4368 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 4369 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4370 | * |
| 4371 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4372 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4373 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 4374 | * strictly disabled according to the state of the |
| 4375 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4376 | * <p> |
| 4377 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 4378 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 4379 | * device admins. |
| 4380 | * <p> |
| 4381 | * Consult documentation for the specific TrustAgent to determine legal options |
| 4382 | * parameters. |
| 4383 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4384 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4385 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4386 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4387 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4388 | if (mService != null) { |
| 4389 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4390 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4391 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4392 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4393 | } |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4398 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4399 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4400 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4401 | * <p> |
| 4402 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4403 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 4404 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4405 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4406 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4407 | * this function returns a list of configurations for all admins that declare |
| 4408 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4409 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4410 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4411 | * 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] | 4412 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4413 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4414 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4415 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4416 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4417 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4421 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4422 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4423 | if (mService != null) { |
| 4424 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4425 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 4426 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4427 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4428 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4429 | } |
| 4430 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4431 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4435 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 4436 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4437 | * <p> |
| 4438 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4439 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4440 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4441 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4442 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4443 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4444 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4445 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4446 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4447 | if (mService != null) { |
| 4448 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4449 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4450 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4451 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4457 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4458 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4459 | * <p> |
| 4460 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4461 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4462 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4463 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4464 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4465 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4466 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4467 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4468 | if (mService != null) { |
| 4469 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4470 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4471 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4472 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4473 | } |
| 4474 | } |
| 4475 | return false; |
| 4476 | } |
| 4477 | |
| 4478 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4479 | * Determine whether or not caller-Id information has been disabled. |
| 4480 | * |
| 4481 | * @param userHandle The user for whom to check the caller-id permission |
| 4482 | * @hide |
| 4483 | */ |
| 4484 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4485 | if (mService != null) { |
| 4486 | try { |
| 4487 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4488 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4489 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4490 | } |
| 4491 | } |
| 4492 | return false; |
| 4493 | } |
| 4494 | |
| 4495 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4496 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 4497 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4498 | * <p> |
| 4499 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4500 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4501 | * |
| 4502 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4503 | * @param disabled If true contacts search in the managed profile is not displayed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4504 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4505 | */ |
| 4506 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4507 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4508 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4509 | if (mService != null) { |
| 4510 | try { |
| 4511 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 4512 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4513 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | /** |
| 4519 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4520 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4521 | * <p> |
| 4522 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4523 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4524 | * |
| 4525 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4526 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4527 | */ |
| 4528 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4529 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4530 | if (mService != null) { |
| 4531 | try { |
| 4532 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4533 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4534 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4535 | } |
| 4536 | } |
| 4537 | return false; |
| 4538 | } |
| 4539 | |
| 4540 | |
| 4541 | /** |
| 4542 | * Determine whether or not contacts search has been disabled. |
| 4543 | * |
| 4544 | * @param userHandle The user for whom to check the contacts search permission |
| 4545 | * @hide |
| 4546 | */ |
| 4547 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4548 | if (mService != null) { |
| 4549 | try { |
| 4550 | return mService |
| 4551 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4552 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4553 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4554 | } |
| 4555 | } |
| 4556 | return false; |
| 4557 | } |
| 4558 | |
| 4559 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4560 | * Start Quick Contact on the managed profile for the user, if the policy allows. |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4561 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4562 | * @hide |
| 4563 | */ |
| 4564 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4565 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4566 | if (mService != null) { |
| 4567 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4568 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 4569 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4570 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4571 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4572 | } |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4577 | * Start Quick Contact on the managed profile for the user, if the policy allows. |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4578 | * @hide |
| 4579 | */ |
| 4580 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4581 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4582 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4583 | originalIntent); |
| 4584 | } |
| 4585 | |
| 4586 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4587 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 4588 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4589 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4590 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4591 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4592 | * <p> |
| 4593 | * This API works on managed profile only. |
| 4594 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4595 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4596 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 4597 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4598 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4599 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4600 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4601 | if (mService != null) { |
| 4602 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4603 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4604 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4605 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4611 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 4612 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4613 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4614 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4615 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4616 | * <p> |
| 4617 | * This API works on managed profile only. |
| 4618 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4619 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4620 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4621 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4622 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4623 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4624 | if (mService != null) { |
| 4625 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4626 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4627 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4628 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4629 | } |
| 4630 | } |
| 4631 | return true; |
| 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4636 | * <p> |
| 4637 | * This API works on managed profile UserHandle only. |
| 4638 | * |
| 4639 | * @param userHandle The user for whom to check the caller-id permission |
| 4640 | * @hide |
| 4641 | */ |
| 4642 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4643 | if (mService != null) { |
| 4644 | try { |
| 4645 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4646 | .getIdentifier()); |
| 4647 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4648 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4649 | } |
| 4650 | } |
| 4651 | return true; |
| 4652 | } |
| 4653 | |
| 4654 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4655 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4656 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 4657 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4658 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4659 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4660 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4661 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4662 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4663 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 4664 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4665 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4666 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4667 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4668 | if (mService != null) { |
| 4669 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4670 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4671 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4672 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | } |
| 4676 | |
| 4677 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4678 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4679 | * 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] | 4680 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4681 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4682 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4683 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4684 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4685 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4686 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4687 | if (mService != null) { |
| 4688 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4689 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4690 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4691 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4692 | } |
| 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4697 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 4698 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4699 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 4700 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 4701 | * the list and not part of the system can not be enabled by the user. |
| 4702 | * <p> |
| 4703 | * Calling with a null value for the list disables the restriction so that all services can be |
| 4704 | * used, calling with an empty list only allows the builtin system's services. |
| 4705 | * <p> |
| 4706 | * System accesibility services are always available to the user the list can't modify this. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4707 | * |
| 4708 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4709 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4710 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 4711 | * accessibility services enabled, that are not in the list. |
| 4712 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4713 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4714 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4715 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4716 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4717 | if (mService != null) { |
| 4718 | try { |
| 4719 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4720 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4721 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | return false; |
| 4725 | } |
| 4726 | |
| 4727 | /** |
| 4728 | * Returns the list of permitted accessibility services set by this device or profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4729 | * <p> |
| 4730 | * An empty list means no accessibility services except system services are allowed. Null means |
| 4731 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4732 | * |
| 4733 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4734 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4735 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4736 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4737 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4738 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4739 | if (mService != null) { |
| 4740 | try { |
| 4741 | return mService.getPermittedAccessibilityServices(admin); |
| 4742 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4743 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4744 | } |
| 4745 | } |
| 4746 | return null; |
| 4747 | } |
| 4748 | |
| 4749 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4750 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4751 | * |
| 4752 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4753 | * @param packageName Accessibility service package name that needs to be checked. |
| 4754 | * @param userHandle user id the admin is running as. |
| 4755 | * @return true if the accessibility service is permitted, otherwise false. |
| 4756 | * |
| 4757 | * @hide |
| 4758 | */ |
| 4759 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4760 | @NonNull String packageName, int userHandle) { |
| 4761 | if (mService != null) { |
| 4762 | try { |
| 4763 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4764 | userHandle); |
| 4765 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4766 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | return false; |
| 4770 | } |
| 4771 | |
| 4772 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4773 | * Returns the list of accessibility services permitted by the device or profiles |
| 4774 | * owners of this user. |
| 4775 | * |
| 4776 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4777 | * it will contain the intersection of the permitted lists for any device or profile |
| 4778 | * owners that apply to this user. It will also include any system accessibility services. |
| 4779 | * |
| 4780 | * @param userId which user to check for. |
| 4781 | * @return List of accessiblity service package names. |
| 4782 | * @hide |
| 4783 | */ |
| 4784 | @SystemApi |
| 4785 | public List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4786 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4787 | if (mService != null) { |
| 4788 | try { |
| 4789 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4790 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4791 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4792 | } |
| 4793 | } |
| 4794 | return null; |
| 4795 | } |
| 4796 | |
| 4797 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4798 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 4799 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4800 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 4801 | * When zero or more packages have been added, input method that are not in the list and not |
| 4802 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 4803 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 4804 | * <p> |
| 4805 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 4806 | * be used, calling with an empty list disables all but the system's own input methods. |
| 4807 | * <p> |
| 4808 | * System input methods are always available to the user this method can't modify this. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4809 | * |
| 4810 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4811 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4812 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 4813 | * non-system input methods currently enabled that are not in the packageNames list. |
| 4814 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4815 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4816 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4817 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4818 | if (mService != null) { |
| 4819 | try { |
| 4820 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4821 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4822 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4823 | } |
| 4824 | } |
| 4825 | return false; |
| 4826 | } |
| 4827 | |
| 4828 | |
| 4829 | /** |
| 4830 | * Returns the list of permitted input methods set by this device or profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4831 | * <p> |
| 4832 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 4833 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4834 | * |
| 4835 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4836 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4837 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4838 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4839 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4840 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4841 | if (mService != null) { |
| 4842 | try { |
| 4843 | return mService.getPermittedInputMethods(admin); |
| 4844 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4845 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4846 | } |
| 4847 | } |
| 4848 | return null; |
| 4849 | } |
| 4850 | |
| 4851 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4852 | * Called by the system to check if a specific input method is disabled by admin. |
| 4853 | * |
| 4854 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4855 | * @param packageName Input method package name that needs to be checked. |
| 4856 | * @param userHandle user id the admin is running as. |
| 4857 | * @return true if the input method is permitted, otherwise false. |
| 4858 | * |
| 4859 | * @hide |
| 4860 | */ |
| 4861 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4862 | @NonNull String packageName, int userHandle) { |
| 4863 | if (mService != null) { |
| 4864 | try { |
| 4865 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4866 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4867 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4868 | } |
| 4869 | } |
| 4870 | return false; |
| 4871 | } |
| 4872 | |
| 4873 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4874 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4875 | * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.) |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4876 | * |
| 4877 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4878 | * it will contain the intersection of the permitted lists for any device or profile |
| 4879 | * owners that apply to this user. It will also include any system input methods. |
| 4880 | * |
| 4881 | * @return List of input method package names. |
| 4882 | * @hide |
| 4883 | */ |
| 4884 | @SystemApi |
| 4885 | public List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4886 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4887 | if (mService != null) { |
| 4888 | try { |
| 4889 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4890 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4891 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4892 | } |
| 4893 | } |
| 4894 | return null; |
| 4895 | } |
| 4896 | |
| 4897 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4898 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4899 | * currently installed it. |
| 4900 | * |
| 4901 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4902 | * |
| 4903 | * @return List of package names to keep cached. |
| 4904 | * @hide |
| 4905 | */ |
| 4906 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4907 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4908 | if (mService != null) { |
| 4909 | try { |
| 4910 | return mService.getKeepUninstalledPackages(admin); |
| 4911 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4912 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4913 | } |
| 4914 | } |
| 4915 | return null; |
| 4916 | } |
| 4917 | |
| 4918 | /** |
| 4919 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4920 | * currently installed it. |
| 4921 | * |
| 4922 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4923 | * automatically pre-cached.</p> |
| 4924 | * |
| 4925 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4926 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4927 | * @throws SecurityException if {@code admin} is not a device owner. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4928 | * @hide |
| 4929 | */ |
| 4930 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4931 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4932 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4933 | if (mService != null) { |
| 4934 | try { |
| 4935 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4936 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4937 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4938 | } |
| 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4943 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4944 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4945 | * created. If you need to persist an identifier for this user, use |
| 4946 | * {@link UserManager#getSerialNumberForUser}. |
| 4947 | * |
| 4948 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4949 | * @param name the user's name |
| 4950 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4951 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4952 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4953 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4954 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4955 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4956 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4957 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4958 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4959 | return null; |
| 4960 | } |
| 4961 | |
| 4962 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4963 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4964 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4965 | * created. If you need to persist an identifier for this user, use |
| 4966 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4967 | * immediately. |
| 4968 | * |
| 4969 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4970 | * as registered as an active admin on the new user. The profile owner package will be |
| 4971 | * installed on the new user if it already is installed on the device. |
| 4972 | * |
| 4973 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4974 | * profileOwnerComponent when onEnable is called. |
| 4975 | * |
| 4976 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4977 | * @param name the user's name |
| 4978 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4979 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4980 | * the user. |
| 4981 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4982 | * on the new user. |
| 4983 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4984 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4985 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4986 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4987 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4988 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4989 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4990 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4991 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4992 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4993 | return null; |
| 4994 | } |
| 4995 | |
| 4996 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4997 | * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4998 | */ |
| 4999 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5000 | |
| 5001 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5002 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5003 | * ephemeral. |
| 5004 | * @hide |
| 5005 | */ |
| 5006 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5007 | |
| 5008 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5009 | * Called by a device owner to create a user with the specified name and a given component of |
| 5010 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5011 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5012 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5013 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5014 | * <p> |
| 5015 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5016 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5017 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5018 | * on the new user. |
| 5019 | * <p> |
| 5020 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5021 | * for the first time. Then the extras will be passed to the admin when onEnable is called. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5022 | * |
| 5023 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5024 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5025 | * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5026 | * same package as admin, otherwise no user is created and an |
| 5027 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5028 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5029 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5030 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5031 | * @see UserHandle |
| 5032 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5033 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5034 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5035 | */ |
| 5036 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5037 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5038 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5039 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5040 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5041 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5042 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5043 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5044 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5048 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5049 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5050 | * |
| 5051 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5052 | * @param userHandle the user to remove. |
| 5053 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5054 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5055 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5056 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5057 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5058 | try { |
| 5059 | return mService.removeUser(admin, userHandle); |
| 5060 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5061 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5062 | } |
| 5063 | } |
| 5064 | |
| 5065 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5066 | * Called by a device owner to switch the specified user to the foreground. |
| 5067 | * |
| 5068 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5069 | * @param userHandle the user to switch to; null will switch to primary. |
| 5070 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5071 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5072 | * @see Intent#ACTION_USER_FOREGROUND |
| 5073 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5074 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5075 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5076 | try { |
| 5077 | return mService.switchUser(admin, userHandle); |
| 5078 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5079 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5084 | * Retrieves the application restrictions for a given target application running in the calling |
| 5085 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5086 | * <p> |
| 5087 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 5088 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 5089 | * security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5090 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5091 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5092 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5093 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5094 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5095 | * @param packageName The name of the package to fetch restricted settings of. |
| 5096 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5097 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 5098 | * {@link Bundle} if no restrictions have been set. |
| 5099 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5100 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5101 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5102 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5103 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5104 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5105 | if (mService != null) { |
| 5106 | try { |
| 5107 | return mService.getApplicationRestrictions(admin, packageName); |
| 5108 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5109 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5110 | } |
| 5111 | } |
| 5112 | return null; |
| 5113 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5114 | |
| 5115 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5116 | * 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] | 5117 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5118 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5119 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5120 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5121 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5122 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5123 | * for the list of keys. |
| 5124 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5125 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5126 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5127 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5128 | if (mService != null) { |
| 5129 | try { |
| 5130 | mService.setUserRestriction(admin, key, true); |
| 5131 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5132 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5133 | } |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5138 | * 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] | 5139 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5140 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5141 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5142 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5143 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5144 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5145 | * for the list of keys. |
| 5146 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5147 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5148 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5149 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5150 | if (mService != null) { |
| 5151 | try { |
| 5152 | mService.setUserRestriction(admin, key, false); |
| 5153 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5154 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5155 | } |
| 5156 | } |
| 5157 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 5158 | |
| 5159 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5160 | * Called by a profile or device owner to get user restrictions set with |
| 5161 | * {@link #addUserRestriction(ComponentName, String)}. |
| 5162 | * <p> |
| 5163 | * The target user may have more restrictions set by the system or other device owner / profile |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5164 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5165 | * {@link UserManager#getUserRestrictions()}. |
| 5166 | * |
| 5167 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5168 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5169 | */ |
| 5170 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5171 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5172 | Bundle ret = null; |
| 5173 | if (mService != null) { |
| 5174 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 5175 | ret = mService.getUserRestrictions(admin); |
| 5176 | } catch (RemoteException e) { |
| 5177 | throw e.rethrowFromSystemServer(); |
| 5178 | } |
| 5179 | } |
| 5180 | return ret == null ? new Bundle() : ret; |
| 5181 | } |
| 5182 | |
| 5183 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5184 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it is |
| 5185 | * unavailable for use, but the data and actual package file remain. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5186 | * |
| 5187 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5188 | * @param packageName The name of the package to hide or unhide. |
| 5189 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5190 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5191 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5192 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5193 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5194 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5195 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5196 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5197 | if (mService != null) { |
| 5198 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5199 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5200 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5201 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5202 | } |
| 5203 | } |
| 5204 | return false; |
| 5205 | } |
| 5206 | |
| 5207 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5208 | * 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] | 5209 | * |
| 5210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5211 | * @param packageName The name of the package to retrieve the hidden status of. |
| 5212 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5213 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5214 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5215 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5216 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5217 | if (mService != null) { |
| 5218 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5219 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5220 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5221 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5222 | } |
| 5223 | } |
| 5224 | return false; |
| 5225 | } |
| 5226 | |
| 5227 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5228 | * 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] | 5229 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5230 | * |
| 5231 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5232 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5233 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5234 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5235 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5236 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5237 | if (mService != null) { |
| 5238 | try { |
| 5239 | mService.enableSystemApp(admin, packageName); |
| 5240 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5241 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5242 | } |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5247 | * Called by profile or device owners to re-enable system apps by intent that were disabled by |
| 5248 | * default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5249 | * |
| 5250 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5251 | * @param intent An intent matching the app(s) to be installed. All apps that resolve for this |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5252 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5253 | * @return int The number of activities that matched the intent and were installed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5254 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5255 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5256 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5257 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5258 | if (mService != null) { |
| 5259 | try { |
| 5260 | return mService.enableSystemAppWithIntent(admin, intent); |
| 5261 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5262 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5263 | } |
| 5264 | } |
| 5265 | return 0; |
| 5266 | } |
| 5267 | |
| 5268 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 5269 | * Called by a device owner or profile owner to disable account management for a specific type |
| 5270 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5271 | * <p> |
| 5272 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 5273 | * exception will be thrown. |
| 5274 | * <p> |
| 5275 | * When account management is disabled for an account type, adding or removing an account of |
| 5276 | * that type will not be possible. |
| 5277 | * <p> |
| 5278 | * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use |
Benjamin Franz | b6c0ce4 | 2015-11-05 10:06:51 +0000 | [diff] [blame] | 5279 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 5280 | * management for a specific type is disabled. |
| 5281 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5282 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5283 | * @param accountType For which account management is disabled or enabled. |
| 5284 | * @param disabled The boolean indicating that account management will be disabled (true) or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5285 | * enabled (false). |
| 5286 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5287 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5288 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5289 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5290 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5291 | if (mService != null) { |
| 5292 | try { |
| 5293 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 5294 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5295 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5296 | } |
| 5297 | } |
| 5298 | } |
| 5299 | |
| 5300 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5301 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 5302 | * |
| 5303 | * <p> Account management can be disabled/enabled by calling |
| 5304 | * {@link #setAccountManagementDisabled}. |
| 5305 | * |
| 5306 | * @return a list of account types for which account management has been disabled. |
| 5307 | * |
| 5308 | * @see #setAccountManagementDisabled |
| 5309 | */ |
| 5310 | public String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5311 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5312 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * @see #getAccountTypesWithManagementDisabled() |
| 5317 | * @hide |
| 5318 | */ |
| 5319 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5320 | if (mService != null) { |
| 5321 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5322 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5323 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5324 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5325 | } |
| 5326 | } |
| 5327 | |
| 5328 | return null; |
| 5329 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5330 | |
| 5331 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5332 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5333 | * <p> |
| 5334 | * Any packages that shares uid with an allowed package will also be allowed to activate lock |
| 5335 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
| 5336 | * package list results in locked tasks belonging to those packages to be finished. This |
| 5337 | * function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5338 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5339 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5340 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5341 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5342 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 5343 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 5344 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 5345 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5346 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5347 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5348 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5349 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5350 | if (mService != null) { |
| 5351 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5352 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5353 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5354 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5355 | } |
| 5356 | } |
| 5357 | } |
| 5358 | |
| 5359 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5360 | * 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] | 5361 | * |
| 5362 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5363 | * @hide |
| 5364 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5365 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5366 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5367 | if (mService != null) { |
| 5368 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5369 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5370 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5371 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5372 | } |
| 5373 | } |
| 5374 | return null; |
| 5375 | } |
| 5376 | |
| 5377 | /** |
| 5378 | * This function lets the caller know whether the given component is allowed to start the |
| 5379 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5380 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5381 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5382 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5383 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5384 | if (mService != null) { |
| 5385 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5386 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5387 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5388 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5389 | } |
| 5390 | } |
| 5391 | return false; |
| 5392 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5393 | |
| 5394 | /** |
| 5395 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 5396 | * of the setting is in the correct form for the setting type should be performed by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5397 | * <p> |
| 5398 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5399 | * <ul> |
| 5400 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 5401 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 5402 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5403 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5404 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5405 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5406 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 5407 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 5408 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 5409 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 5410 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5411 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5412 | * <p> |
| 5413 | * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}: |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5414 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5415 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 5416 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5417 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5418 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5419 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 5420 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5421 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5422 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 5423 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5424 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5425 | * |
| 5426 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5427 | * @param setting The name of the setting to update. |
| 5428 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5429 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5430 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5431 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5432 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5433 | if (mService != null) { |
| 5434 | try { |
| 5435 | mService.setGlobalSetting(admin, setting, value); |
| 5436 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5437 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5438 | } |
| 5439 | } |
| 5440 | } |
| 5441 | |
| 5442 | /** |
| 5443 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5444 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5445 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5446 | * <p> |
| 5447 | * 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] | 5448 | * <ul> |
| 5449 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5450 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5451 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5452 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5453 | * <p> |
| 5454 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5455 | * <ul> |
| 5456 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5457 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5458 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5459 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5460 | * @param setting The name of the setting to update. |
| 5461 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5462 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5463 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5464 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5465 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5466 | if (mService != null) { |
| 5467 | try { |
| 5468 | mService.setSecureSetting(admin, setting, value); |
| 5469 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5470 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5471 | } |
| 5472 | } |
| 5473 | } |
| 5474 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5475 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5476 | * Designates a specific service component as the provider for making permission requests of a |
| 5477 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5478 | * <p/> |
| 5479 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5480 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5481 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5482 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5483 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 5484 | * provider previously assigned. |
| 5485 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5486 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5487 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5488 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5489 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5490 | if (mService != null) { |
| 5491 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5492 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5493 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5494 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5495 | } |
| 5496 | } |
| 5497 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5498 | |
| 5499 | /** |
| 5500 | * Called by profile or device owners to set the master volume mute on or off. |
Nicolas Prevot | aef3ce2 | 2016-09-22 12:00:25 +0100 | [diff] [blame^] | 5501 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5502 | * |
| 5503 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5504 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5505 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5506 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5507 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5508 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5509 | if (mService != null) { |
| 5510 | try { |
| 5511 | mService.setMasterVolumeMuted(admin, on); |
| 5512 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5513 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5514 | } |
| 5515 | } |
| 5516 | } |
| 5517 | |
| 5518 | /** |
| 5519 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5520 | * |
| 5521 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5522 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5523 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5524 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5525 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5526 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5527 | if (mService != null) { |
| 5528 | try { |
| 5529 | return mService.isMasterVolumeMuted(admin); |
| 5530 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5531 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5532 | } |
| 5533 | } |
| 5534 | return false; |
| 5535 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5536 | |
| 5537 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5538 | * Called by profile or device owners to change whether a user can uninstall a package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5539 | * |
| 5540 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5541 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5542 | * @param uninstallBlocked true if the user shouldn't be able to uninstall the package. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5543 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5544 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5545 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5546 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5547 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5548 | if (mService != null) { |
| 5549 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5550 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5551 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5552 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5553 | } |
| 5554 | } |
| 5555 | } |
| 5556 | |
| 5557 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5558 | * Check whether the user has been blocked by device policy from uninstalling a package. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5559 | * 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] | 5560 | * <p> |
| 5561 | * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5562 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 5563 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 5564 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5565 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5566 | * @param admin The name of the admin component whose blocking policy will be checked, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5567 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5568 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5569 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5570 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5571 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5572 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5573 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5574 | if (mService != null) { |
| 5575 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 5576 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5577 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5578 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5579 | } |
| 5580 | } |
| 5581 | return false; |
| 5582 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5583 | |
| 5584 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5585 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 5586 | * package to be available in the parent profile. As a result the user will be able to add |
| 5587 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 5588 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 5589 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5590 | * <p> |
| 5591 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5592 | * |
| 5593 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5594 | * @param packageName The package from which widget providers are white-listed. |
| 5595 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5596 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5597 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5598 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5599 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5600 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5601 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5602 | if (mService != null) { |
| 5603 | try { |
| 5604 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 5605 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5606 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5607 | } |
| 5608 | } |
| 5609 | return false; |
| 5610 | } |
| 5611 | |
| 5612 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5613 | * Called by the profile owner of a managed profile to disable widget providers from a given |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5614 | * package to be available in the parent profile. For this method to take effect the package |
| 5615 | * should have been added via |
| 5616 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5617 | * <p> |
| 5618 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5619 | * |
| 5620 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5621 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5622 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5623 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5624 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5625 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5626 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5627 | public boolean removeCrossProfileWidgetProvider( |
| 5628 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5629 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5630 | if (mService != null) { |
| 5631 | try { |
| 5632 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5633 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5634 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5635 | } |
| 5636 | } |
| 5637 | return false; |
| 5638 | } |
| 5639 | |
| 5640 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5641 | * 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] | 5642 | * available in the parent profile. |
| 5643 | * |
| 5644 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5645 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5646 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5647 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5648 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5649 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5650 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5651 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5652 | if (mService != null) { |
| 5653 | try { |
| 5654 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5655 | if (providers != null) { |
| 5656 | return providers; |
| 5657 | } |
| 5658 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5659 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5660 | } |
| 5661 | } |
| 5662 | return Collections.emptyList(); |
| 5663 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5664 | |
| 5665 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5666 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5667 | * |
| 5668 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5669 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5670 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5671 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5672 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5673 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5674 | try { |
| 5675 | mService.setUserIcon(admin, icon); |
| 5676 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5677 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5678 | } |
| 5679 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5680 | |
| 5681 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5682 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5683 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5684 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5686 | * components in the device owner package can set system update policies and the most |
| 5687 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5688 | * @param policy the new policy, or {@code null} to clear the current policy. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5689 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5690 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5691 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5692 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5693 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5694 | if (mService != null) { |
| 5695 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5696 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5697 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5698 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5699 | } |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5704 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5705 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5706 | * @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] | 5707 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5708 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5709 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5710 | if (mService != null) { |
| 5711 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5712 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5713 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5714 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5715 | } |
| 5716 | } |
| 5717 | return null; |
| 5718 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5719 | |
| 5720 | /** |
| 5721 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5722 | * <p> |
| 5723 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 5724 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 5725 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 5726 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5727 | * |
| 5728 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5729 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5730 | * @return {@code false} if attempting to disable the keyguard while a lock password was in |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5731 | * place. {@code true} otherwise. |
| 5732 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5733 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5734 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5735 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5736 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5737 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5738 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5739 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5740 | } |
| 5741 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5742 | |
| 5743 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5744 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5745 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 5746 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5747 | * |
| 5748 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5749 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5750 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 5751 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5752 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5753 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5754 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5755 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5756 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5757 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5758 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5759 | } |
| 5760 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5761 | |
| 5762 | /** |
| 5763 | * Callable by the system update service to notify device owners about pending updates. |
| 5764 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5765 | * permission. |
| 5766 | * |
| 5767 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5768 | * when the current pending update was first available. -1 if no update is available. |
| 5769 | * @hide |
| 5770 | */ |
| 5771 | @SystemApi |
| 5772 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5773 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5774 | if (mService != null) { |
| 5775 | try { |
| 5776 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5777 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5778 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5779 | } |
| 5780 | } |
| 5781 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5782 | |
| 5783 | /** |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5784 | * Called by profile or device owners to set the default response for future runtime permission |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5785 | * requests by applications. The policy can allow for normal operation which prompts the user to |
| 5786 | * grant a permission, or can allow automatic granting or denying of runtime permission requests |
| 5787 | * by an application. This also applies to new permissions declared by app updates. When a |
| 5788 | * permission is denied or granted this way, the effect is equivalent to setting the permission |
| 5789 | * grant state via {@link #setPermissionGrantState}. |
| 5790 | * <p/> |
| 5791 | * As this policy only acts on runtime permission requests, it only applies to applications |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5792 | * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5793 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5794 | * @param admin Which profile or device owner this request is associated with. |
| 5795 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5796 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 5797 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5798 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5799 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5800 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5801 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5802 | try { |
| 5803 | mService.setPermissionPolicy(admin, policy); |
| 5804 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5805 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | /** |
| 5810 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5811 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5812 | * @param admin Which profile or device owner this request is associated with. |
| 5813 | * @return the current policy for future permission requests. |
| 5814 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5815 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5816 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5817 | try { |
| 5818 | return mService.getPermissionPolicy(admin); |
| 5819 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5820 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5825 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 5826 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 5827 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 5828 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 5829 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 5830 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5831 | * by a profile or device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5832 | * <p/> |
| 5833 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 5834 | * the permission. It retains the previous grant, if any. |
| 5835 | * <p/> |
| 5836 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5837 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5838 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5839 | * @param admin Which profile or device owner this request is associated with. |
| 5840 | * @param packageName The application to grant or revoke a permission to. |
| 5841 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5842 | * @param grantState The permission grant state which is one of |
| 5843 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5844 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5845 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5846 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5847 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5848 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5849 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5850 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5851 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5852 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5853 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5854 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5855 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5856 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5857 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5858 | } |
| 5859 | } |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5860 | |
| 5861 | /** |
| 5862 | * Returns the current grant state of a runtime permission for a specific application. |
| 5863 | * |
| 5864 | * @param admin Which profile or device owner this request is associated with. |
| 5865 | * @param packageName The application to check the grant state for. |
| 5866 | * @param permission The permission to check for. |
| 5867 | * @return the current grant state specified by device policy. If the profile or device owner |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5868 | * has not set a grant state, the return value is |
| 5869 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 5870 | * permission is currently granted for the package. |
| 5871 | * <p/> |
| 5872 | * If a grant state was set by the profile or device owner, then the return value will |
| 5873 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 5874 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 5875 | * currently denied or granted. |
| 5876 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5877 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5878 | * @see PackageManager#checkPermission(String, String) |
| 5879 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5880 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5881 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5882 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5883 | try { |
| 5884 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5885 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5886 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5887 | } |
| 5888 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5889 | |
| 5890 | /** |
| 5891 | * Returns if provisioning a managed profile or device is possible or not. |
| 5892 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5893 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5894 | * @return if provisioning a managed profile or device is possible or not. |
| 5895 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5896 | */ |
| 5897 | public boolean isProvisioningAllowed(String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5898 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5899 | try { |
| 5900 | return mService.isProvisioningAllowed(action); |
| 5901 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5902 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5903 | } |
| 5904 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5905 | |
| 5906 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5907 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5908 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
Kenny Guy | ffa3840 | 2016-03-31 16:40:57 +0100 | [diff] [blame] | 5909 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5910 | * @param admin Which profile owner this request is associated with. |
| 5911 | * @return if this user is a managed profile of another user. |
| 5912 | */ |
| 5913 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5914 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5915 | try { |
| 5916 | return mService.isManagedProfile(admin); |
| 5917 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5918 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5919 | } |
| 5920 | } |
| 5921 | |
| 5922 | /** |
| 5923 | * @hide |
| 5924 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5925 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5926 | * @param admin Which device owner this request is associated with. |
| 5927 | * @return if this user is a system-only user. |
| 5928 | */ |
| 5929 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5930 | try { |
| 5931 | return mService.isSystemOnlyUser(admin); |
| 5932 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5933 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5934 | } |
| 5935 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5936 | |
| 5937 | /** |
| 5938 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5939 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5940 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5941 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 5942 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5943 | * <p> |
| 5944 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5945 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5946 | */ |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5947 | public String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5948 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5949 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5950 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5951 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5952 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5953 | } |
| 5954 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5955 | |
| 5956 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5957 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 5958 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5959 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5960 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5961 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5962 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5963 | */ |
| 5964 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5965 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5966 | try { |
| 5967 | mService.reboot(admin); |
| 5968 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5969 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5970 | } |
| 5971 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5972 | |
| 5973 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5974 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 5975 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 5976 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 5977 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 5978 | * truncated. |
| 5979 | * <p> |
| 5980 | * If the short support message needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 5981 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5982 | * and set a new version of this string accordingly. |
| 5983 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5984 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5985 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5986 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 5987 | * existing message. |
| 5988 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5989 | */ |
| 5990 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 5991 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5992 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5993 | if (mService != null) { |
| 5994 | try { |
| 5995 | mService.setShortSupportMessage(admin, message); |
| 5996 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5997 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5998 | } |
| 5999 | } |
| 6000 | } |
| 6001 | |
| 6002 | /** |
| 6003 | * Called by a device admin to get the short support message. |
| 6004 | * |
| 6005 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6006 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 6007 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6008 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6009 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6010 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6011 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6012 | if (mService != null) { |
| 6013 | try { |
| 6014 | return mService.getShortSupportMessage(admin); |
| 6015 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6016 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6017 | } |
| 6018 | } |
| 6019 | return null; |
| 6020 | } |
| 6021 | |
| 6022 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6023 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 6024 | * in the device administators settings screen. |
| 6025 | * <p> |
| 6026 | * If the long support message needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6027 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6028 | * and set a new version of this string accordingly. |
| 6029 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6030 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6031 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6032 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 6033 | * existing message. |
| 6034 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6035 | */ |
| 6036 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6037 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6038 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6039 | if (mService != null) { |
| 6040 | try { |
| 6041 | mService.setLongSupportMessage(admin, message); |
| 6042 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6043 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6044 | } |
| 6045 | } |
| 6046 | } |
| 6047 | |
| 6048 | /** |
| 6049 | * Called by a device admin to get the long support message. |
| 6050 | * |
| 6051 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6052 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 6053 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6054 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6055 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6056 | public CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6057 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6058 | if (mService != null) { |
| 6059 | try { |
| 6060 | return mService.getLongSupportMessage(admin); |
| 6061 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6062 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6063 | } |
| 6064 | } |
| 6065 | return null; |
| 6066 | } |
| 6067 | |
| 6068 | /** |
| 6069 | * Called by the system to get the short support message. |
| 6070 | * |
| 6071 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6072 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6073 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6074 | * |
| 6075 | * @hide |
| 6076 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6077 | public CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
| 6078 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6079 | if (mService != null) { |
| 6080 | try { |
| 6081 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 6082 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6083 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6084 | } |
| 6085 | } |
| 6086 | return null; |
| 6087 | } |
| 6088 | |
| 6089 | |
| 6090 | /** |
| 6091 | * Called by the system to get the long support message. |
| 6092 | * |
| 6093 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6094 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6095 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6096 | * |
| 6097 | * @hide |
| 6098 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6099 | public CharSequence getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6100 | if (mService != null) { |
| 6101 | try { |
| 6102 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 6103 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6104 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6105 | } |
| 6106 | } |
| 6107 | return null; |
| 6108 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6109 | |
| 6110 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6111 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 6112 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6113 | * |
| 6114 | * <p>The following methods are supported for the parent instance, all other methods will |
| 6115 | * throw a SecurityException when called on the parent instance: |
| 6116 | * <ul> |
| 6117 | * <li>{@link #getPasswordQuality}</li> |
| 6118 | * <li>{@link #setPasswordQuality}</li> |
| 6119 | * <li>{@link #getPasswordMinimumLength}</li> |
| 6120 | * <li>{@link #setPasswordMinimumLength}</li> |
| 6121 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 6122 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 6123 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 6124 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 6125 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 6126 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 6127 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 6128 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 6129 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 6130 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 6131 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 6132 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 6133 | * <li>{@link #getPasswordHistoryLength}</li> |
| 6134 | * <li>{@link #setPasswordHistoryLength}</li> |
| 6135 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 6136 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 6137 | * <li>{@link #getPasswordExpiration}</li> |
| 6138 | * <li>{@link #isActivePasswordSufficient}</li> |
| 6139 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 6140 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 6141 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 6142 | * <li>{@link #getMaximumTimeToLock}</li> |
| 6143 | * <li>{@link #setMaximumTimeToLock}</li> |
| 6144 | * <li>{@link #lockNow}</li> |
| 6145 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 6146 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 6147 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 6148 | * <li>{@link #setTrustAgentConfiguration}</li> |
| 6149 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6150 | * |
| 6151 | * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6152 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6153 | */ |
| 6154 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6155 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6156 | try { |
| 6157 | if (!mService.isManagedProfile(admin)) { |
| 6158 | throw new SecurityException("The current user does not have a parent profile."); |
| 6159 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6160 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6161 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6162 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6167 | * Called by device owner to control the security logging feature. Logging can only be |
| 6168 | * enabled on single user devices where the sole user is managed by the device owner. |
| 6169 | * |
| 6170 | * <p> Security logs contain various information intended for security auditing purposes. |
| 6171 | * See {@link SecurityEvent} for details. |
| 6172 | * |
| 6173 | * <p>There must be only one user on the device, managed by the device owner. |
| 6174 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6175 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6176 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6177 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6178 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6179 | * @see #retrieveSecurityLogs |
| 6180 | */ |
| 6181 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6182 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6183 | try { |
| 6184 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 6185 | } catch (RemoteException re) { |
| 6186 | throw re.rethrowFromSystemServer(); |
| 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6191 | * Return whether security logging is enabled or not by the device owner. |
| 6192 | * |
| 6193 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 6194 | * thrown. |
| 6195 | * |
| 6196 | * @param admin Which device owner this request is associated with. |
| 6197 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 6198 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6199 | */ |
| 6200 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6201 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6202 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6203 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6204 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6205 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6206 | } |
| 6207 | } |
| 6208 | |
| 6209 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6210 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 6211 | * this API after device boots. |
| 6212 | * |
| 6213 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 6214 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 6215 | * |
| 6216 | * <p>There must be only one user on the device, managed by the device owner. |
| 6217 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6218 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6219 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6220 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 6221 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6222 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6223 | */ |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6224 | public List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6225 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6226 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6227 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6228 | if (list != null) { |
| 6229 | return list.getList(); |
| 6230 | } else { |
| 6231 | // Rate limit exceeded. |
| 6232 | return null; |
| 6233 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6234 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6235 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6236 | } |
| 6237 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6238 | |
| 6239 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6240 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 6241 | * profile. |
| 6242 | * |
| 6243 | * @hide |
| 6244 | */ |
| 6245 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 6246 | mContext.checkSelfPermission( |
| 6247 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 6248 | if (!uInfo.isManagedProfile()) { |
| 6249 | throw new SecurityException("The user " + uInfo.id |
| 6250 | + " does not have a parent profile."); |
| 6251 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6252 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6256 | * Called by device owners to retrieve device logs from before the device's last reboot. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6257 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6258 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 6259 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 6260 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 6261 | * about data corruption when parsing. </strong> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6262 | * <p> |
| 6263 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 6264 | * {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6265 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6266 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6267 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 6268 | * is not supported on the device. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6269 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6270 | */ |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6271 | public List<SecurityEvent> retrievePreRebootSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6272 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6273 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6274 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6275 | if (list != null) { |
| 6276 | return list.getList(); |
| 6277 | } else { |
| 6278 | return null; |
| 6279 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6280 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6281 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6282 | } |
| 6283 | } |
| 6284 | |
| 6285 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6286 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 6287 | * color is used as background color of the confirm credentials screen for that user. The |
Clara Bayarri | 8d0bd7fa | 2016-03-30 14:59:58 +0100 | [diff] [blame] | 6288 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6289 | * <p> |
| 6290 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6291 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 6292 | * |
| 6293 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6294 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6295 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6296 | */ |
| 6297 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6298 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6299 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6300 | // always enforce alpha channel to have 100% opacity |
| 6301 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6302 | mService.setOrganizationColor(admin, color); |
| 6303 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6304 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6309 | * @hide |
| 6310 | * |
| 6311 | * Sets the color used for customization. |
| 6312 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6313 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6314 | * @param userId which user to set the color to. |
| 6315 | * @RequiresPermission(allOf = { |
| 6316 | * Manifest.permission.MANAGE_USERS, |
| 6317 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 6318 | */ |
| 6319 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 6320 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6321 | // always enforce alpha channel to have 100% opacity |
| 6322 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6323 | mService.setOrganizationColorForUser(color, userId); |
| 6324 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6325 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6326 | } |
| 6327 | } |
| 6328 | |
| 6329 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6330 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 6331 | * This color is used as background color of the confirm credentials screen for that user. |
| 6332 | * |
| 6333 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6334 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6335 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6336 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6337 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6338 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6339 | try { |
| 6340 | return mService.getOrganizationColor(admin); |
| 6341 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6342 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6343 | } |
| 6344 | } |
| 6345 | |
| 6346 | /** |
| 6347 | * @hide |
| 6348 | * Retrieve the customization color for a given user. |
| 6349 | * |
| 6350 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6351 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6352 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6353 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6354 | try { |
| 6355 | return mService.getOrganizationColorForUser(userHandle); |
| 6356 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6357 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6358 | } |
| 6359 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6360 | |
| 6361 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6362 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 6363 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6364 | * <p> |
| 6365 | * If the organization name needs to be localized, it is the responsibility of the |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6366 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6367 | * and set a new version of this string accordingly. |
| 6368 | * |
| 6369 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6370 | * @param title The organization name or {@code null} to clear a previously set name. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6371 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6372 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6373 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6374 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6375 | try { |
| 6376 | mService.setOrganizationName(admin, title); |
| 6377 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6378 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6379 | } |
| 6380 | } |
| 6381 | |
| 6382 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6383 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 6384 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6385 | * |
| 6386 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6387 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6388 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6389 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6390 | public CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6391 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6392 | try { |
| 6393 | return mService.getOrganizationName(admin); |
| 6394 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6395 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | /** |
| 6400 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 6401 | * |
| 6402 | * @param userHandle The user id of the user we're interested in. |
| 6403 | * @return The organization name or {@code null} if none is set. |
| 6404 | * |
| 6405 | * @hide |
| 6406 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6407 | public CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6408 | try { |
| 6409 | return mService.getOrganizationNameForUser(userHandle); |
| 6410 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6411 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6416 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 6417 | * return {@link #STATE_USER_UNMANAGED} |
| 6418 | * @hide |
| 6419 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 6420 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6421 | @UserProvisioningState |
| 6422 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6423 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6424 | if (mService != null) { |
| 6425 | try { |
| 6426 | return mService.getUserProvisioningState(); |
| 6427 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6428 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6429 | } |
| 6430 | } |
| 6431 | return STATE_USER_UNMANAGED; |
| 6432 | } |
| 6433 | |
| 6434 | /** |
| 6435 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 6436 | * |
| 6437 | * @param state to store |
| 6438 | * @param userHandle for user |
| 6439 | * @hide |
| 6440 | */ |
| 6441 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 6442 | if (mService != null) { |
| 6443 | try { |
| 6444 | mService.setUserProvisioningState(state, userHandle); |
| 6445 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6446 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6447 | } |
| 6448 | } |
| 6449 | } |
| 6450 | |
| 6451 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6452 | * @hide |
| 6453 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 6454 | * affiliated if it is managed by the same entity as the device. |
| 6455 | * |
| 6456 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 6457 | * user/profile is considered affiliated if the following conditions are both met: |
| 6458 | * <ul> |
| 6459 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 6460 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 6461 | * and a profile owner intersect, they must have come from the same source, which means that |
| 6462 | * the device owner and profile owner are controlled by the same entity.</li> |
| 6463 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 6464 | * </ul> |
| 6465 | * |
| 6466 | * @param admin Which profile or device owner this request is associated with. |
| 6467 | * @param ids A set of opaque affiliation ids. |
| 6468 | */ |
| 6469 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6470 | throwIfParentInstance("setAffiliationIds"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6471 | try { |
| 6472 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 6473 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6474 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6475 | } |
| 6476 | } |
| 6477 | |
| 6478 | /** |
| 6479 | * @hide |
| 6480 | * Returns whether this user/profile is affiliated with the device. See |
| 6481 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 6482 | * |
| 6483 | * @return whether this user/profile is affiliated with the device. |
| 6484 | */ |
| 6485 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6486 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6487 | try { |
| 6488 | return mService != null && mService.isAffiliatedUser(); |
| 6489 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6490 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6491 | } |
| 6492 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6493 | |
| 6494 | /** |
| 6495 | * @hide |
| 6496 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 6497 | * to be started |
| 6498 | * @param packageName the package to check for |
| 6499 | * @return whether the uninstall intent for {@code packageName} is pending |
| 6500 | */ |
| 6501 | public boolean isUninstallInQueue(String packageName) { |
| 6502 | try { |
| 6503 | return mService.isUninstallInQueue(packageName); |
| 6504 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6505 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6506 | } |
| 6507 | } |
| 6508 | |
| 6509 | /** |
| 6510 | * @hide |
| 6511 | * @param packageName the package containing active DAs to be uninstalled |
| 6512 | */ |
| 6513 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 6514 | try { |
| 6515 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 6516 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6517 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6518 | } |
| 6519 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6520 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 6521 | /** |
| 6522 | * @hide |
| 6523 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 6524 | * If the admin is a profile owner or device owner it will still be removed. |
| 6525 | * |
| 6526 | * @param userHandle user id to remove the admin for. |
| 6527 | * @param admin The administration compononent to remove. |
| 6528 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 6529 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 6530 | */ |
| 6531 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 6532 | try { |
| 6533 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 6534 | } catch (RemoteException re) { |
| 6535 | throw re.rethrowFromSystemServer(); |
| 6536 | } |
| 6537 | } |
| 6538 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 6539 | /** |
| 6540 | * @hide |
| 6541 | * @return whether {@link android.provider.Settings.Global#DEVICE_PROVISIONED} has ever been set |
| 6542 | * to 1. |
| 6543 | */ |
| 6544 | public boolean isDeviceProvisioned() { |
| 6545 | try { |
| 6546 | return mService.isDeviceProvisioned(); |
| 6547 | } catch (RemoteException re) { |
| 6548 | throw re.rethrowFromSystemServer(); |
| 6549 | } |
| 6550 | } |
| 6551 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 6552 | /** |
| 6553 | * @hide |
| 6554 | * Writes that the provisioning configuration has been applied. |
| 6555 | */ |
| 6556 | public void setDeviceProvisioningConfigApplied() { |
| 6557 | try { |
| 6558 | mService.setDeviceProvisioningConfigApplied(); |
| 6559 | } catch (RemoteException re) { |
| 6560 | throw re.rethrowFromSystemServer(); |
| 6561 | } |
| 6562 | } |
| 6563 | |
| 6564 | /** |
| 6565 | * @hide |
| 6566 | * @return whether the provisioning configuration has been applied. |
| 6567 | */ |
| 6568 | public boolean isDeviceProvisioningConfigApplied() { |
| 6569 | try { |
| 6570 | return mService.isDeviceProvisioningConfigApplied(); |
| 6571 | } catch (RemoteException re) { |
| 6572 | throw re.rethrowFromSystemServer(); |
| 6573 | } |
| 6574 | } |
| 6575 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 6576 | /** |
| 6577 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 6578 | * Force update user setup completed status. This API has no effect on user build. |
| 6579 | * @throws {@link SecurityException} if the caller has no |
| 6580 | * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 6581 | * not {@link UserHandle.SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 6582 | */ |
| 6583 | public void forceUpdateUserSetupComplete() { |
| 6584 | try { |
| 6585 | mService.forceUpdateUserSetupComplete(); |
| 6586 | } catch (RemoteException re) { |
| 6587 | throw re.rethrowFromSystemServer(); |
| 6588 | } |
| 6589 | } |
| 6590 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6591 | private void throwIfParentInstance(String functionName) { |
| 6592 | if (mParentInstance) { |
| 6593 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 6594 | } |
| 6595 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 6596 | |
| 6597 | /** |
| 6598 | * @hide |
| 6599 | * Enable backup service. |
| 6600 | * <p>This includes all backup and restore mechanisms. |
| 6601 | * Setting this to {@code false} will make backup service no-op or return empty results. |
| 6602 | * |
| 6603 | * <p>There must be only one user on the device, managed by the device owner. |
| 6604 | * Otherwise a {@link SecurityException} will be thrown. |
| 6605 | * |
| 6606 | * <p>Backup service is off by default when device owner is present. |
| 6607 | */ |
| 6608 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 6609 | try { |
| 6610 | mService.setBackupServiceEnabled(admin, enabled); |
| 6611 | } catch (RemoteException re) { |
| 6612 | throw re.rethrowFromSystemServer(); |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | /** |
| 6617 | * @hide |
| 6618 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
| 6619 | */ |
| 6620 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
| 6621 | try { |
| 6622 | return mService.isBackupServiceEnabled(admin); |
| 6623 | } catch (RemoteException re) { |
| 6624 | throw re.rethrowFromSystemServer(); |
| 6625 | } |
| 6626 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 6627 | } |