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; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 27 | import android.app.Activity; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 28 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 29 | import android.content.ComponentName; |
| 30 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 31 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 32 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 34 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 35 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 36 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 38 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 39 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 40 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 41 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 42 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 43 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 44 | import android.os.RemoteException; |
| 45 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 46 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 47 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 48 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 49 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 50 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 51 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 52 | import android.telephony.TelephonyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 53 | import android.util.Log; |
| 54 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 55 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 56 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 57 | |
| 58 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 59 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 60 | import java.lang.annotation.Retention; |
| 61 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 62 | import java.net.InetSocketAddress; |
| 63 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 64 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 65 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 66 | import java.security.PrivateKey; |
| 67 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 68 | import java.security.cert.CertificateException; |
| 69 | import java.security.cert.CertificateFactory; |
| 70 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 71 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 72 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 73 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 74 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 75 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 76 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 77 | |
| 78 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 79 | * 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] | 80 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 81 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 82 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 83 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 84 | * application calling an api may only pass as an argument a device administrator component it |
| 85 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 86 | * <div class="special reference"> |
| 87 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 88 | * <p> |
| 89 | * For more information about managing policies for device administration, read the <a href= |
| 90 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 91 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 92 | */ |
| 93 | public class DevicePolicyManager { |
| 94 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 95 | |
| 96 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 97 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 98 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 99 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 100 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 101 | this(context, |
| 102 | IDevicePolicyManager.Stub.asInterface( |
| 103 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 104 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 107 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 108 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 109 | protected DevicePolicyManager( |
| 110 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 111 | mContext = context; |
| 112 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 113 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** @hide */ |
| 117 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 118 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 119 | return me.mService != null ? me : null; |
| 120 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 121 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 122 | /** @hide test will override it. */ |
| 123 | @VisibleForTesting |
| 124 | protected int myUserId() { |
| 125 | return UserHandle.myUserId(); |
| 126 | } |
| 127 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 128 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 129 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 130 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 131 | * <p>A managed profile allows data separation for example for the usage of a |
| 132 | * device as a personal and corporate device. The user which provisioning is started from and |
| 133 | * the managed profile share a launcher. |
| 134 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 135 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 136 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 137 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 138 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 139 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 140 | * {@link #isProvisioningAllowed(String)}. |
| 141 | * |
| 142 | * <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] | 143 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 144 | * 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] | 145 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 146 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 147 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 148 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 149 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 150 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 152 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 153 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 154 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 155 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 156 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 157 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 158 | * <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] | 159 | * in the provisioning intent. The |
| 160 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 161 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 162 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 163 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 164 | * <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] | 165 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 166 | * |
| 167 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 168 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 169 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 170 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 171 | * 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] | 172 | */ |
| 173 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 174 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 175 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 176 | |
| 177 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 178 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 179 | * |
| 180 | * <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] | 181 | * 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] | 182 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 183 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 184 | * allowed. |
| 185 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 186 | * <p>The intent contains the following extras: |
| 187 | * <ul> |
| 188 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 189 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 190 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 191 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 192 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 193 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 194 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 195 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 196 | * |
| 197 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 198 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 199 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 200 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 201 | * 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] | 202 | * |
| 203 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 204 | */ |
| 205 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 206 | public static final String ACTION_PROVISION_MANAGED_USER |
| 207 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 208 | |
| 209 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 210 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 211 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 212 | * |
| 213 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 214 | * A device owner has full control over the device. The device owner can not be modified by the |
| 215 | * user. |
| 216 | * |
| 217 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 218 | * employee or client. |
| 219 | * |
| 220 | * <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] | 221 | * It is possible to check if provisioning is allowed or not by querying the method |
| 222 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 223 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 224 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 225 | * <ul> |
| 226 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 227 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 228 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 229 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 230 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 231 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 232 | * </ul> |
| 233 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 234 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 235 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 236 | * device owner. |
| 237 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 238 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 239 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 240 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 241 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 242 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 243 | * 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] | 244 | */ |
| 245 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 246 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 247 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 248 | |
| 249 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 250 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 251 | * |
| 252 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 253 | * the device. A device owner has full control over the device. The device owner can not be |
| 254 | * modified by the user and the only way of resetting the device is via factory reset. |
| 255 | * |
| 256 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 257 | * employee or client. |
| 258 | * |
| 259 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 260 | * |
| 261 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 262 | * by a privileged app with the permission |
| 263 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 264 | * |
| 265 | * <p>The provisioning intent contains the following properties: |
| 266 | * <ul> |
| 267 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 279 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 280 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 281 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 282 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 283 | * |
| 284 | * @hide |
| 285 | */ |
| 286 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 287 | @SystemApi |
| 288 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 289 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 290 | |
| 291 | /** |
| 292 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 293 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 294 | * |
| 295 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 296 | * management state that is distinct from that reached by |
| 297 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 298 | * user, and only has control over device-wide policies, not individual users and their data. |
| 299 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 300 | * this form of device management. |
| 301 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 302 | * <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] | 303 | * A device owner has full control over the device. The device owner can not be modified by the |
| 304 | * user. |
| 305 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 306 | * <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] | 307 | * employee or client. |
| 308 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 309 | * <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] | 310 | * It is possible to check if provisioning is allowed or not by querying the method |
| 311 | * {@link #isProvisioningAllowed(String)}. |
| 312 | * |
| 313 | * <p>The intent contains the following extras: |
| 314 | * <ul> |
| 315 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 316 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 317 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 318 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 319 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 320 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 321 | * </ul> |
| 322 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 323 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 324 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 325 | * device owner. |
| 326 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 327 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 328 | * |
| 329 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 330 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 331 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 332 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 333 | * |
| 334 | * @hide |
| 335 | */ |
| 336 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 337 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 338 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 339 | |
| 340 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 341 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 342 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 343 | * <ul> |
| 344 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 345 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 346 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 347 | * </ul> |
| 348 | * |
| 349 | * @hide |
| 350 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 351 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 352 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 353 | public static final String ACTION_PROVISION_FINALIZATION |
| 354 | = "android.app.action.PROVISION_FINALIZATION"; |
| 355 | |
| 356 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 357 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 358 | * |
| 359 | * @hide |
| 360 | */ |
| 361 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 362 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 363 | |
| 364 | /** |
| 365 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 366 | * |
| 367 | * @hide |
| 368 | */ |
| 369 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 370 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 371 | |
| 372 | /** |
| 373 | * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}. |
| 374 | * |
| 375 | * @hide |
| 376 | */ |
| 377 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 378 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 379 | |
| 380 | /** |
| 381 | * Extra for shared bugreport's SHA-256 hash. |
| 382 | * |
| 383 | * @hide |
| 384 | */ |
| 385 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 386 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 387 | |
| 388 | /** |
| 389 | * Extra for remote bugreport notification shown type. |
| 390 | * |
| 391 | * @hide |
| 392 | */ |
| 393 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 394 | "android.app.extra.bugreport_notification_type"; |
| 395 | |
| 396 | /** |
| 397 | * Notification type for a started remote bugreport flow. |
| 398 | * |
| 399 | * @hide |
| 400 | */ |
| 401 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 402 | |
| 403 | /** |
| 404 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 405 | * being taken. |
| 406 | * |
| 407 | * @hide |
| 408 | */ |
| 409 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 410 | |
| 411 | /** |
| 412 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 413 | * |
| 414 | * @hide |
| 415 | */ |
| 416 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 417 | |
| 418 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 419 | * 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] | 420 | * allows a mobile device management application or NFC programmer application which starts |
| 421 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 422 | * <p> |
| 423 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 424 | * sends the intent to pass data to itself on the newly created profile. |
| 425 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 426 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 427 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 428 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 429 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 430 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 431 | * management application after provisioning. |
| 432 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 433 | * <p> |
| 434 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 435 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 436 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 437 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 438 | */ |
| 439 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 440 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 441 | |
| 442 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 443 | * A String extra holding the package name of the mobile device management application that |
| 444 | * will be set as the profile owner or device owner. |
| 445 | * |
| 446 | * <p>If an application starts provisioning directly via an intent with action |
| 447 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 448 | * application that started provisioning. The package will be set as profile owner in that case. |
| 449 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 450 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 451 | * 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] | 452 | * |
| 453 | * <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] | 454 | * 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] | 455 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 456 | * @see DeviceAdminReceiver |
| 457 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 458 | * supported, but only if there is only one device admin receiver in the package that requires |
| 459 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 460 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 461 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 462 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 463 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 464 | |
| 465 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 466 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 467 | * application that will be set as the profile owner or device owner and active admin. |
| 468 | * |
| 469 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 470 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 471 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 472 | * 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] | 473 | * |
| 474 | * <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] | 475 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 476 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 477 | * {@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] | 478 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 479 | * |
| 480 | * @see DeviceAdminReceiver |
| 481 | */ |
| 482 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 483 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 484 | |
| 485 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 486 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 487 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 488 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 489 | * |
| 490 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 491 | */ |
| 492 | |
| 493 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 494 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 495 | |
| 496 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 497 | * A String extra that, holds the email address of the account which a managed profile is |
| 498 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 499 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 500 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 501 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 502 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 503 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 504 | * contains this extra, it is forwarded in the |
| 505 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 506 | * device management application that was set as the profile owner during provisioning. |
| 507 | * 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] | 508 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 509 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 510 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 511 | |
| 512 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 513 | * A integer extra indicating the predominant color to show during the provisioning. |
| 514 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 515 | * |
| 516 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 517 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 518 | */ |
| 519 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 520 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 521 | |
| 522 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 523 | * 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] | 524 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 525 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 526 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 527 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 528 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 529 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 530 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 531 | |
| 532 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 533 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 534 | * will be set to. |
| 535 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 536 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 537 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 538 | */ |
| 539 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 540 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 541 | |
| 542 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 543 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 544 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 545 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 546 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 547 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 548 | */ |
| 549 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 550 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 551 | |
| 552 | /** |
| 553 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 554 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 555 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 556 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 557 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 558 | */ |
| 559 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 560 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 561 | |
| 562 | /** |
| 563 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 564 | * owner provisioning for downloading the mobile device management application. |
| 565 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 566 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 567 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 568 | */ |
| 569 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 570 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 571 | |
| 572 | /** |
| 573 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 574 | * is hidden or not. |
| 575 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 576 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 577 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 578 | */ |
| 579 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 580 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 581 | |
| 582 | /** |
| 583 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 584 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 585 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 586 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 587 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 588 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 589 | */ |
| 590 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 591 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * A String extra holding the password of the wifi network in |
| 595 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 596 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 597 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 598 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 599 | */ |
| 600 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 601 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | |
| 603 | /** |
| 604 | * A String extra holding the proxy host for the wifi network in |
| 605 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 606 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 607 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 608 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 609 | */ |
| 610 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 611 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | |
| 613 | /** |
| 614 | * An int extra holding the proxy port for the wifi network in |
| 615 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 616 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 617 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 618 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 619 | */ |
| 620 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 621 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * A String extra holding the proxy bypass for the wifi network in |
| 625 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 626 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 627 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 628 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 629 | */ |
| 630 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 631 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 632 | |
| 633 | /** |
| 634 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 635 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 636 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 637 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 638 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 639 | */ |
| 640 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 641 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 642 | |
| 643 | /** |
| 644 | * A String extra holding a url that specifies the download location of the device admin |
| 645 | * package. When not provided it is assumed that the device admin package is already installed. |
| 646 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 647 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 648 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 649 | */ |
| 650 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 651 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 652 | |
| 653 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 654 | * An int extra holding a minimum required version code for the device admin package. If the |
| 655 | * device admin is already installed on the device, it will only be re-downloaded from |
| 656 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 657 | * installed package is less than this version code. |
| 658 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 659 | * <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] | 660 | * provisioning via an NFC bump. |
| 661 | */ |
| 662 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 663 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 664 | |
| 665 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 666 | * A String extra holding a http cookie header which should be used in the http request to the |
| 667 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 668 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 669 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 670 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 671 | */ |
| 672 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 673 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 674 | |
| 675 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 676 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 677 | * the file at download location specified in |
| 678 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 679 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 680 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 681 | * 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] | 682 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 683 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 684 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 685 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 686 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 687 | * |
| 688 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 689 | * 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] | 690 | * 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] | 691 | * 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] | 692 | */ |
| 693 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 694 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 695 | |
| 696 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 697 | * 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] | 698 | * android package archive at the download location specified in {@link |
| 699 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 700 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 701 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 702 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 703 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 704 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 705 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 706 | * 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] | 707 | * the download location. If the checksum does not match an error will be shown to the user and |
| 708 | * the user will be asked to factory reset the device. |
| 709 | * |
| 710 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 711 | * provisioning via an NFC bump. |
| 712 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 713 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 714 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 715 | |
| 716 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 717 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 718 | * has completed successfully. |
| 719 | * |
| 720 | * <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] | 721 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 722 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 723 | * <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] | 724 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 725 | */ |
| 726 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 727 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 728 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 729 | |
| 730 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 731 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 732 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 733 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 734 | * <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] | 735 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 736 | * |
| 737 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 738 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 739 | */ |
| 740 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 741 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 742 | |
| 743 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 744 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 745 | * provisioning. If this extra is not passed, a default image will be shown. |
| 746 | * <h5>The following URI schemes are accepted:</h5> |
| 747 | * <ul> |
| 748 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 749 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 750 | * </ul> |
| 751 | * |
| 752 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 753 | * pixed density for the device. |
| 754 | * |
| 755 | * <p> If a content: URI is passed, the intent should have the flag |
| 756 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 757 | * {@link android.content.ClipData} of the intent too. |
| 758 | * |
| 759 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 760 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 761 | */ |
| 762 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 763 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 764 | |
| 765 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 766 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 767 | * during setup-wizard. |
| 768 | * |
| 769 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 770 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 771 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 772 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 773 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 774 | * |
| 775 | * @hide |
| 776 | */ |
| 777 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 778 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 779 | |
| 780 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 781 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 782 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 783 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 784 | * A device owner has full control over the device. The device owner can not be modified by the |
| 785 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 786 | * reset. |
| 787 | * |
| 788 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 789 | * employee or client. |
| 790 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 791 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 792 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 793 | * <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] | 794 | * contains the following properties: |
| 795 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 796 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 797 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 798 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 799 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 800 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 801 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 802 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 803 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 804 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 805 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 806 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 807 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 808 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 809 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 810 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 811 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 812 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 813 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 814 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 815 | * 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] | 816 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 817 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 818 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 819 | */ |
| 820 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 821 | = "application/com.android.managedprovisioning"; |
| 822 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 823 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 824 | * Activity action: ask the user to add a new device administrator to the system. |
| 825 | * The desired policy is the ComponentName of the policy in the |
| 826 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 827 | * bring the user through adding the device administrator to the system (or |
| 828 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 829 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 830 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 831 | * field to provide the user with additional explanation (in addition |
| 832 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 833 | * |
| 834 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 835 | * user intervention). However, if your administrator has been updated and is requesting |
| 836 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 837 | * 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] | 838 | */ |
| 839 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 840 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 841 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 842 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 843 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 844 | * @hide |
| 845 | * 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] | 846 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 847 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 848 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 849 | * 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] | 850 | * to remotely control restrictions on the user. |
| 851 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 852 | * <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] | 853 | * result of whether or not the user approved the action. If approved, the result will |
| 854 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 855 | * as a profile owner. |
| 856 | * |
| 857 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 858 | * field to provide the user with additional explanation (in addition |
| 859 | * to your component's description) about what is being added. |
| 860 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 861 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 862 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 863 | */ |
| 864 | @SystemApi |
| 865 | public static final String ACTION_SET_PROFILE_OWNER |
| 866 | = "android.app.action.SET_PROFILE_OWNER"; |
| 867 | |
| 868 | /** |
| 869 | * @hide |
| 870 | * Name of the profile owner admin that controls the user. |
| 871 | */ |
| 872 | @SystemApi |
| 873 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 874 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 875 | |
| 876 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 877 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 878 | * 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] | 879 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 880 | * @hide |
| 881 | */ |
| 882 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 883 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 884 | |
| 885 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 886 | * Broadcast action: sent when the device owner is set or changed. |
| 887 | * |
| 888 | * This broadcast is sent only to the primary user. |
| 889 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 890 | */ |
| 891 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 892 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 893 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 894 | |
| 895 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 896 | * The ComponentName of the administrator component. |
| 897 | * |
| 898 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 899 | */ |
| 900 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 901 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 902 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 903 | * An optional CharSequence providing additional explanation for why the |
| 904 | * admin is being added. |
| 905 | * |
| 906 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 907 | */ |
| 908 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 909 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 910 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 911 | * Activity action: have the user enter a new password. This activity should |
| 912 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 913 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 914 | * enter a new password that meets the current requirements. You can use |
| 915 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 916 | * have the user select a new password in order to meet the current |
| 917 | * constraints. Upon being resumed from this activity, you can check the new |
| 918 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 919 | * |
| 920 | * If the intent is launched from within a managed profile with a profile |
| 921 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 922 | * this will trigger entering a new password for the parent of the profile. |
| 923 | * For all other cases it will trigger entering a new password for the user |
| 924 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 925 | * |
| 926 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 927 | */ |
| 928 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 929 | public static final String ACTION_SET_NEW_PASSWORD |
| 930 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 931 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 932 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 933 | * Activity action: have the user enter a new password for the parent profile. |
| 934 | * If the intent is launched from within a managed profile, this will trigger |
| 935 | * entering a new password for the parent of the profile. In all other cases |
| 936 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 937 | */ |
| 938 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 939 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 940 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 941 | |
| 942 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 943 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 944 | * the parent profile to access intents sent from the managed profile. |
| 945 | * That is, when an app in the managed profile calls |
| 946 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 947 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 948 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 949 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 950 | |
| 951 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 952 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 953 | * the managed profile to access intents sent from the parent profile. |
| 954 | * That is, when an app in the parent profile calls |
| 955 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 956 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 957 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 958 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 959 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 960 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 961 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 962 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 963 | */ |
| 964 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 965 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 966 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 967 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 968 | /** |
| 969 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 970 | * Already granted or denied permissions are not affected by this. |
| 971 | */ |
| 972 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 973 | |
| 974 | /** |
| 975 | * Permission policy to always grant new permission requests for runtime permissions. |
| 976 | * Already granted or denied permissions are not affected by this. |
| 977 | */ |
| 978 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 979 | |
| 980 | /** |
| 981 | * Permission policy to always deny new permission requests for runtime permissions. |
| 982 | * Already granted or denied permissions are not affected by this. |
| 983 | */ |
| 984 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 985 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 986 | /** |
| 987 | * Runtime permission state: The user can manage the permission |
| 988 | * through the UI. |
| 989 | */ |
| 990 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 991 | |
| 992 | /** |
| 993 | * Runtime permission state: The permission is granted to the app |
| 994 | * and the user cannot manage the permission through the UI. |
| 995 | */ |
| 996 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 997 | |
| 998 | /** |
| 999 | * Runtime permission state: The permission is denied to the app |
| 1000 | * and the user cannot manage the permission through the UI. |
| 1001 | */ |
| 1002 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1003 | |
| 1004 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1005 | * No management for current user in-effect. This is the default. |
| 1006 | * @hide |
| 1007 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1008 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1009 | public static final int STATE_USER_UNMANAGED = 0; |
| 1010 | |
| 1011 | /** |
| 1012 | * Management partially setup, user setup needs to be completed. |
| 1013 | * @hide |
| 1014 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1015 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1016 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1017 | |
| 1018 | /** |
| 1019 | * Management partially setup, user setup completed. |
| 1020 | * @hide |
| 1021 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1022 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1023 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1024 | |
| 1025 | /** |
| 1026 | * Management setup and active on current user. |
| 1027 | * @hide |
| 1028 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1029 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1030 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1031 | |
| 1032 | /** |
| 1033 | * Management partially setup on a managed profile. |
| 1034 | * @hide |
| 1035 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1036 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1037 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1038 | |
| 1039 | /** |
| 1040 | * @hide |
| 1041 | */ |
| 1042 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1043 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1044 | @Retention(RetentionPolicy.SOURCE) |
| 1045 | public @interface UserProvisioningState {} |
| 1046 | |
| 1047 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1048 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1049 | * |
| 1050 | * @param admin The administrator component to check for. |
| 1051 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1052 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1053 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1054 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1055 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * @see #isAdminActive(ComponentName) |
| 1060 | * @hide |
| 1061 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1062 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1063 | if (mService != null) { |
| 1064 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1065 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1066 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1067 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | return false; |
| 1071 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1072 | /** |
| 1073 | * Return true if the given administrator component is currently being removed |
| 1074 | * for the user. |
| 1075 | * @hide |
| 1076 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1077 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1078 | if (mService != null) { |
| 1079 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1080 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1081 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1082 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | return false; |
| 1086 | } |
| 1087 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1088 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1089 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1090 | * Return a list of all currently active device administrators' component |
| 1091 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1092 | * returned. |
| 1093 | */ |
| 1094 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1095 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * @see #getActiveAdmins() |
| 1100 | * @hide |
| 1101 | */ |
| 1102 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1103 | if (mService != null) { |
| 1104 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1105 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1106 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1107 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | return null; |
| 1111 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1112 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1113 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1114 | * Used by package administration code to determine if a package can be stopped |
| 1115 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1116 | * @hide |
| 1117 | */ |
| 1118 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1119 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1120 | } |
| 1121 | |
| 1122 | /** |
| 1123 | * Used by package administration code to determine if a package can be stopped |
| 1124 | * or uninstalled. |
| 1125 | * @hide |
| 1126 | */ |
| 1127 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1128 | if (mService != null) { |
| 1129 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1130 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1131 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1132 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | return false; |
| 1136 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1137 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1138 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1139 | * Remove a current administration component. This can only be called |
| 1140 | * by the application that owns the administration component; if you |
| 1141 | * try to remove someone else's component, a security exception will be |
| 1142 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1143 | * |
| 1144 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1145 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1146 | * |
| 1147 | * @param admin The administration compononent to remove. |
| 1148 | * @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] | 1149 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1150 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1151 | if (mService != null) { |
| 1152 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1153 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1154 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1155 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1159 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1160 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1161 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1162 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1163 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1164 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1165 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1166 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1167 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1168 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1169 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1170 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1171 | if (mService != null) { |
| 1172 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1173 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1174 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1175 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | return false; |
| 1179 | } |
| 1180 | |
| 1181 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1182 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1183 | * |
| 1184 | * @hide |
| 1185 | */ |
| 1186 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1187 | if (mService != null) { |
| 1188 | try { |
| 1189 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1190 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1191 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | return false; |
| 1195 | } |
| 1196 | |
| 1197 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1198 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1199 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1200 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1201 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1202 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1203 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1204 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1205 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1206 | * recognition technology. This implies technologies that can recognize the identity of |
| 1207 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1208 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1209 | */ |
| 1210 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1211 | |
| 1212 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1213 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1214 | * 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] | 1215 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1216 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1217 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1218 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1219 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1220 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1221 | * password containing at least numeric characters. Note that quality |
| 1222 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1223 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1224 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1225 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1226 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1227 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1228 | * password containing at least numeric characters with no repeating (4444) |
| 1229 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1230 | * constants are ordered so that higher values are more restrictive. |
| 1231 | */ |
| 1232 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1233 | |
| 1234 | /** |
| 1235 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1236 | * password containing at least alphabetic (or other symbol) characters. |
| 1237 | * Note that quality constants are ordered so that higher values are more |
| 1238 | * restrictive. |
| 1239 | */ |
| 1240 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1241 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1242 | /** |
| 1243 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1244 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1245 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1246 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1247 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1248 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1249 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1250 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1251 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1252 | * password containing at least a letter, a numerical digit and a special |
| 1253 | * symbol, by default. With this password quality, passwords can be |
| 1254 | * restricted to contain various sets of characters, like at least an |
| 1255 | * uppercase letter, etc. These are specified using various methods, |
| 1256 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1257 | * that quality constants are ordered so that higher values are more |
| 1258 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1259 | */ |
| 1260 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1261 | |
| 1262 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1263 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1264 | * modify password. In case this password quality is set, the password is |
| 1265 | * managed by a profile owner. The profile owner can set any password, |
| 1266 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1267 | * that quality constants are ordered so that higher values are more |
| 1268 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1269 | * the highest. |
| 1270 | * @hide |
| 1271 | */ |
| 1272 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1273 | |
| 1274 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1275 | * Called by an application that is administering the device to set the password restrictions it |
| 1276 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1277 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1278 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1279 | * 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] | 1280 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1281 | * <p> |
| 1282 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1283 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1284 | * considerations) is the one that is in effect. |
| 1285 | * <p> |
| 1286 | * The calling device admin must have requested |
| 1287 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1288 | * not, a security exception will be thrown. |
| 1289 | * <p> |
| 1290 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1291 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1292 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1293 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1294 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1295 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1296 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1297 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1298 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1299 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1300 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1301 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1302 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1303 | if (mService != null) { |
| 1304 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1305 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1306 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1307 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1311 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1312 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1313 | * Retrieve the current minimum password quality for a particular admin or all admins that set |
| 1314 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1315 | * a separate challenge are not taken into account. |
| 1316 | * |
| 1317 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1318 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1319 | * restrictions on the parent profile. |
| 1320 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1321 | * @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] | 1322 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1323 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1324 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1325 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1329 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1330 | if (mService != null) { |
| 1331 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1332 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1333 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1334 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1335 | } |
| 1336 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1337 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1338 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1339 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1340 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1341 | * Called by an application that is administering the device to set the minimum allowed password |
| 1342 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1343 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1344 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1345 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1346 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1347 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1348 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1349 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1350 | * {@link #setPasswordQuality}. |
| 1351 | * <p> |
| 1352 | * The calling device admin must have requested |
| 1353 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1354 | * not, a security exception will be thrown. |
| 1355 | * <p> |
| 1356 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1357 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1358 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1359 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1360 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1361 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1362 | * restriction. |
| 1363 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1364 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1365 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1366 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1367 | if (mService != null) { |
| 1368 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1369 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1370 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1371 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1372 | } |
| 1373 | } |
| 1374 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1375 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1376 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1377 | * Retrieve the current minimum password length for a particular admin or all admins that set |
| 1378 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1379 | * a separate challenge are not taken into account. |
| 1380 | * |
| 1381 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1382 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1383 | * restrictions on the parent profile. |
| 1384 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1385 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1386 | * @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] | 1387 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1388 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1389 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1390 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1394 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1395 | if (mService != null) { |
| 1396 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1397 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1398 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1399 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | return 0; |
| 1403 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1404 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1405 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1406 | * Called by an application that is administering the device to set the minimum number of upper |
| 1407 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1408 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1409 | * current password will remain until the user has set a new one, so the change does not take |
| 1410 | * place immediately. To prompt the user for a new password, use |
| 1411 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1412 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1413 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1414 | * <p> |
| 1415 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1416 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1417 | * not, a security exception will be thrown. |
| 1418 | * <p> |
| 1419 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1420 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1421 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1422 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1423 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1424 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1425 | * A value of 0 means there is no restriction. |
| 1426 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1427 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1429 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1430 | if (mService != null) { |
| 1431 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1432 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1433 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1434 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1435 | } |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1440 | * Retrieve the current number of upper case letters required in the password |
| 1441 | * for a particular admin or all admins that set retrictions on this user and |
| 1442 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1443 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1444 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1445 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1446 | * and only applies when the password quality is |
| 1447 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1448 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1449 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1450 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1451 | * restrictions on the parent profile. |
| 1452 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1453 | * @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] | 1454 | * aggregate all admins. |
| 1455 | * @return The minimum number of upper case letters required in the |
| 1456 | * password. |
| 1457 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1458 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1459 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1463 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1464 | if (mService != null) { |
| 1465 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1466 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1467 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1468 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
| 1474 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1475 | * Called by an application that is administering the device to set the minimum number of lower |
| 1476 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1477 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1478 | * current password will remain until the user has set a new one, so the change does not take |
| 1479 | * place immediately. To prompt the user for a new password, use |
| 1480 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1481 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1482 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1483 | * <p> |
| 1484 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1485 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1486 | * not, a security exception will be thrown. |
| 1487 | * <p> |
| 1488 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1489 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1490 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1491 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1492 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1493 | * @param length The new desired minimum number of lower case letters required in the password. |
| 1494 | * A value of 0 means there is no restriction. |
| 1495 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1496 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1497 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1498 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1499 | if (mService != null) { |
| 1500 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1501 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1502 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1503 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1509 | * Retrieve the current number of lower case letters required in the password |
| 1510 | * for a particular admin or all admins that set retrictions on this user |
| 1511 | * and its participating profiles. Restrictions on profiles that have |
| 1512 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1513 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1514 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1515 | * and only applies when the password quality is |
| 1516 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1517 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1518 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1519 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1520 | * restrictions on the parent profile. |
| 1521 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1522 | * @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] | 1523 | * aggregate all admins. |
| 1524 | * @return The minimum number of lower case letters required in the |
| 1525 | * password. |
| 1526 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1527 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1528 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1532 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1533 | if (mService != null) { |
| 1534 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1535 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1536 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1537 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
| 1543 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1544 | * Called by an application that is administering the device to set the minimum number of |
| 1545 | * letters required in the password. After setting this, the user will not be able to enter a |
| 1546 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1547 | * password will remain until the user has set a new one, so the change does not take place |
| 1548 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1549 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1550 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1551 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1552 | * <p> |
| 1553 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1554 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1555 | * not, a security exception will be thrown. |
| 1556 | * <p> |
| 1557 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1558 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1559 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1560 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1561 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1562 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1563 | * 0 means there is no restriction. |
| 1564 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1565 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1566 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1567 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1568 | if (mService != null) { |
| 1569 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1570 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1571 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1572 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1578 | * Retrieve the current number of letters required in the password |
| 1579 | * for a particular admin or all admins that set retrictions on this user |
| 1580 | * and its participating profiles. Restrictions on profiles that have |
| 1581 | * a separate challenge are not taken into account. |
| 1582 | * This is the same value as set by |
| 1583 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1584 | * and only applies when the password quality is |
| 1585 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1586 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1587 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1588 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1589 | * restrictions on the parent profile. |
| 1590 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1591 | * @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] | 1592 | * aggregate all admins. |
| 1593 | * @return The minimum number of letters required in the password. |
| 1594 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1595 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1596 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1600 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
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 | return mService.getPasswordMinimumLetters(admin, userHandle, 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 | return 0; |
| 1609 | } |
| 1610 | |
| 1611 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1612 | * Called by an application that is administering the device to set the minimum number of |
| 1613 | * numerical digits required in the password. After setting this, the user will not be able to |
| 1614 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 1615 | * current password will remain until the user has set a new one, so the change does not take |
| 1616 | * place immediately. To prompt the user for a new password, use |
| 1617 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1618 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1619 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1620 | * <p> |
| 1621 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1622 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1623 | * not, a security exception will be thrown. |
| 1624 | * <p> |
| 1625 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1626 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1627 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1628 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1629 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1630 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 1631 | * value of 0 means there is no restriction. |
| 1632 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1633 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1634 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1635 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1636 | if (mService != null) { |
| 1637 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1638 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1639 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1640 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | /** |
| 1646 | * Retrieve the current number of numerical digits required in the password |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1647 | * for a particular admin or all admins that set retrictions on this user |
| 1648 | * and its participating profiles. Restrictions on profiles that have |
| 1649 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1650 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1651 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1652 | * and only applies when the password quality is |
| 1653 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1654 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1655 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1656 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1657 | * restrictions on the parent profile. |
| 1658 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1659 | * @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] | 1660 | * aggregate all admins. |
| 1661 | * @return The minimum number of numerical digits required in the password. |
| 1662 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1663 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1664 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1668 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
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 | return mService.getPasswordMinimumNumeric(admin, userHandle, 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 | return 0; |
| 1677 | } |
| 1678 | |
| 1679 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1680 | * Called by an application that is administering the device to set the minimum number of |
| 1681 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 1682 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1683 | * password will remain until the user has set a new one, so the change does not take place |
| 1684 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1685 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1686 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1687 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1688 | * <p> |
| 1689 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1690 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1691 | * not, a security exception will be thrown. |
| 1692 | * <p> |
| 1693 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1694 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1695 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1696 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1697 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1698 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 1699 | * 0 means there is no restriction. |
| 1700 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1701 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1702 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1703 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1704 | if (mService != null) { |
| 1705 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1706 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1707 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1708 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1714 | * Retrieve the current number of symbols required in the password |
| 1715 | * for a particular admin or all admins that set retrictions on this user |
| 1716 | * and its participating profiles. Restrictions on profiles that have |
| 1717 | * a separate challenge are not taken into account. This is the same value as |
| 1718 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1719 | * and only applies when the password quality is |
| 1720 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1721 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1722 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1723 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1724 | * restrictions on the parent profile. |
| 1725 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1726 | * @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] | 1727 | * aggregate all admins. |
| 1728 | * @return The minimum number of symbols required in the password. |
| 1729 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1730 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1731 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1735 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1736 | if (mService != null) { |
| 1737 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1738 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1739 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1740 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1746 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1747 | * Called by an application that is administering the device to set the minimum number of |
| 1748 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 1749 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 1750 | * as what has been set. Note that the current password will remain until the user has set a new |
| 1751 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 1752 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1753 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1754 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1755 | * <p> |
| 1756 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1757 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1758 | * not, a security exception will be thrown. |
| 1759 | * <p> |
| 1760 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1761 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1762 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1763 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1764 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1765 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1766 | * 0 means there is no restriction. |
| 1767 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1768 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1769 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1770 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1771 | if (mService != null) { |
| 1772 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1773 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1774 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1775 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1781 | * Retrieve the current number of non-letter characters required in the password |
| 1782 | * for a particular admin or all admins that set retrictions on this user |
| 1783 | * and its participating profiles. Restrictions on profiles that have |
| 1784 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1785 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1786 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1787 | * and only applies when the password quality is |
| 1788 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1789 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1790 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1791 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1792 | * restrictions on the parent profile. |
| 1793 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1794 | * @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] | 1795 | * aggregate all admins. |
| 1796 | * @return The minimum number of letters required in the password. |
| 1797 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1798 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1799 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1803 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
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 | return mService.getPasswordMinimumNonLetter(admin, userHandle, 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 | return 0; |
| 1812 | } |
| 1813 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1814 | /** |
| 1815 | * Called by an application that is administering the device to set the length of the password |
| 1816 | * history. After setting this, the user will not be able to enter a new password that is the |
| 1817 | * same as any password in the history. Note that the current password will remain until the |
| 1818 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 1819 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1820 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1821 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1822 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 1823 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 1824 | * <p> |
| 1825 | * The calling device admin must have requested |
| 1826 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1827 | * not, a security exception will be thrown. |
| 1828 | * <p> |
| 1829 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1830 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1831 | * profile. |
| 1832 | * |
| 1833 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1834 | * @param length The new desired length of password history. A value of 0 means there is no |
| 1835 | * restriction. |
| 1836 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1837 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 1838 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1839 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1840 | if (mService != null) { |
| 1841 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1842 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1843 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1844 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1850 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 1851 | * restart the countdown for password expiration for the given admin, as will changing the |
| 1852 | * device password (for all admins). |
| 1853 | * <p> |
| 1854 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 1855 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 1856 | * 432000000 ms for timeout. |
| 1857 | * <p> |
| 1858 | * To disable password expiration, a value of 0 may be used for timeout. |
| 1859 | * <p> |
| 1860 | * The calling device admin must have requested |
| 1861 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 1862 | * not, a security exception will be thrown. |
| 1863 | * <p> |
| 1864 | * Note that setting the password will automatically reset the expiration time for all active |
| 1865 | * admins. Active admins do not need to explicitly call this method in that case. |
| 1866 | * <p> |
| 1867 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1868 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1869 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1870 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1872 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 1873 | * there is no restriction (unlimited). |
| 1874 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1875 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1876 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1877 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1878 | if (mService != null) { |
| 1879 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1880 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1881 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1882 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1888 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1889 | * recurring expiration timeout provided in the call to |
| 1890 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1891 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 1892 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 1893 | * |
| 1894 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1895 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1896 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1897 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1898 | * @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] | 1899 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1900 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1901 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1902 | if (mService != null) { |
| 1903 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1904 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1905 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1906 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | return 0; |
| 1910 | } |
| 1911 | |
| 1912 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1913 | * Get the current password expiration time for a particular admin or all admins that set |
| 1914 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1915 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 1916 | * of all expiration times is returned - which will be the minimum of all of them. |
| 1917 | * |
| 1918 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1919 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1920 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1921 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1922 | * @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] | 1923 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1924 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1925 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1926 | if (mService != null) { |
| 1927 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1928 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1929 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1930 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1931 | } |
| 1932 | } |
| 1933 | return 0; |
| 1934 | } |
| 1935 | |
| 1936 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1937 | * Retrieve the current password history length for a particular admin or all admins that |
| 1938 | * set retrictions on this user and its participating profiles. Restrictions on profiles that |
| 1939 | * have a separate challenge are not taken into account. |
| 1940 | * |
| 1941 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1942 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1943 | * restrictions on the parent profile. |
| 1944 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1945 | * @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] | 1946 | * all admins. |
| 1947 | * @return The length of the password history |
| 1948 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1949 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1950 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1954 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1955 | if (mService != null) { |
| 1956 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1957 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1958 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1959 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1965 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1966 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1967 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1968 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1969 | * @return Returns the maximum length that the user can enter. |
| 1970 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1971 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1972 | // Kind-of arbitrary. |
| 1973 | return 16; |
| 1974 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1975 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1976 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1977 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 1978 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 1979 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
| 1980 | * are not taken into account. |
| 1981 | * <p> |
| 1982 | * The calling device admin must have requested |
| 1983 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1984 | * not, a security exception will be thrown. |
| 1985 | * <p> |
| 1986 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1987 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 1988 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1989 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1990 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1991 | * @throws SecurityException if the calling application does not own an active administrator |
| 1992 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1993 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1994 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1995 | if (mService != null) { |
| 1996 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1997 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1998 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1999 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2000 | } |
| 2001 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2002 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2003 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2004 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2005 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2006 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2007 | * 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] | 2008 | * requested by the admins of the parent user and its profiles. |
| 2009 | * |
| 2010 | * @param userHandle the userId of the profile to check the password for. |
| 2011 | * @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] | 2012 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2013 | * @hide |
| 2014 | */ |
| 2015 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2016 | if (mService != null) { |
| 2017 | try { |
| 2018 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2019 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2020 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | return false; |
| 2024 | } |
| 2025 | |
| 2026 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2027 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2028 | * successful password entry. |
| 2029 | * <p> |
| 2030 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2031 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2032 | * password attemts for the parent user. |
| 2033 | * <p> |
| 2034 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2035 | * 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] | 2036 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2037 | * @return The number of times user has entered an incorrect password since the last correct |
| 2038 | * password entry. |
| 2039 | * @throws SecurityException if the calling application does not own an active administrator |
| 2040 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2041 | */ |
| 2042 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2043 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2044 | } |
| 2045 | |
| 2046 | /** |
| 2047 | * Retrieve the number of times the given user has failed at entering a |
| 2048 | * password since that last successful password entry. |
| 2049 | * |
| 2050 | * <p>The calling device admin must have requested |
| 2051 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2052 | * not and it is not the system uid, a security exception will be thrown. |
| 2053 | * |
| 2054 | * @hide |
| 2055 | */ |
| 2056 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2057 | if (mService != null) { |
| 2058 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2059 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2060 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2061 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | return -1; |
| 2065 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2066 | |
| 2067 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2068 | * 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] | 2069 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2070 | * @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] | 2071 | * @hide |
| 2072 | */ |
| 2073 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2074 | if (mService != null) { |
| 2075 | try { |
| 2076 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2077 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2078 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | return false; |
| 2082 | } |
| 2083 | |
| 2084 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2085 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2086 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2087 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2088 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2089 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2090 | * <p> |
| 2091 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2092 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2093 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2094 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2095 | * immediately, and your callback will not be invoked. |
| 2096 | * <p> |
| 2097 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2098 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2099 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2100 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2101 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2102 | * @param num The number of failed password attempts at which point the device or profile will |
| 2103 | * be wiped. |
| 2104 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2105 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2106 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2107 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2108 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2109 | if (mService != null) { |
| 2110 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2111 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2112 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2113 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2117 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2118 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2119 | * Retrieve the current maximum number of login attempts that are allowed before the device |
| 2120 | * or profile is wiped, for a particular admin or all admins that set retrictions on this user |
| 2121 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2122 | * not taken into account. |
| 2123 | * |
| 2124 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2125 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2126 | * the value for the parent profile. |
| 2127 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2128 | * @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] | 2129 | * all admins. |
| 2130 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2131 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2132 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2136 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2137 | if (mService != null) { |
| 2138 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2139 | return mService.getMaximumFailedPasswordsForWipe( |
| 2140 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2141 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2142 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2143 | } |
| 2144 | } |
| 2145 | return 0; |
| 2146 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2147 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2148 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2149 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2150 | * for the given user. So for primary user, it might return the primary or |
| 2151 | * a managed profile. For a secondary user, it would be the same as the |
| 2152 | * user passed in. |
| 2153 | * @hide Used only by Keyguard |
| 2154 | */ |
| 2155 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2156 | if (mService != null) { |
| 2157 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2158 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2159 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2160 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2161 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2162 | } |
| 2163 | } |
| 2164 | return UserHandle.USER_NULL; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2168 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2169 | * the password again until the user has entered it. |
| 2170 | */ |
| 2171 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2172 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2173 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2174 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2175 | * If the flag is set, the device can be booted without asking for user password. |
| 2176 | * The absence of this flag does not change the current boot requirements. This flag |
| 2177 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2178 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2179 | * device to factory defaults. |
| 2180 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2181 | 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] | 2182 | |
| 2183 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2184 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2185 | * individual accounts) on the user. This takes effect immediately. |
| 2186 | * <p> |
| 2187 | * Calling this from a managed profile that shares the password with the owner profile will |
| 2188 | * throw a security exception. |
| 2189 | * <p> |
| 2190 | * <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] | 2191 | * device admins that are not device owner and not profile owner. |
| 2192 | * The password can now only be changed if there is currently no password set. Device owner |
| 2193 | * and profile owner can still do this.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2194 | * <p> |
| 2195 | * The given password must be sufficient for the current password quality and length constraints |
| 2196 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2197 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2198 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2199 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2200 | * case the currently active quality will be increased to match. |
| 2201 | * <p> |
| 2202 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
| 2203 | * current password constraints allow it. <em>Note: This will not |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2204 | * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not |
| 2205 | * device owner and not profile owner. Once set, the password cannot be changed to null or |
| 2206 | * empty, except by device owner or profile owner.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2207 | * <p> |
| 2208 | * The calling device admin must have requested |
| 2209 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2210 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2211 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2212 | * @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] | 2213 | * @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] | 2214 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2215 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2216 | * current constraints or if the user has not been decrypted yet. |
| 2217 | * @throws SecurityException if the calling application does not own an active administrator |
| 2218 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2219 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2220 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2221 | if (mParentInstance) { |
| 2222 | throw new SecurityException("Reset password does not work across profiles."); |
| 2223 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2224 | if (mService != null) { |
| 2225 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2226 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2227 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2228 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | return false; |
| 2232 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2233 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2234 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2235 | * Called by an application that is administering the device to set the maximum time for user |
| 2236 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2237 | * effect immediately. |
| 2238 | * <p> |
| 2239 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2240 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2241 | * <p> |
| 2242 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2243 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2244 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2245 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2246 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2247 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2248 | * is no restriction. |
| 2249 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2250 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2251 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2252 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2253 | if (mService != null) { |
| 2254 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2255 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2256 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2257 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2261 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2262 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2263 | * Retrieve the current maximum time to unlock for a particular admin or all admins that set |
| 2264 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 2265 | * a separate challenge are not taken into account. |
| 2266 | * |
| 2267 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2268 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2269 | * restrictions on the parent profile. |
| 2270 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2271 | * @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] | 2272 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2273 | * @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] | 2274 | * 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] | 2275 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2276 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2277 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2281 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2282 | if (mService != null) { |
| 2283 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2284 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2285 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2286 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2287 | } |
| 2288 | } |
| 2289 | return 0; |
| 2290 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2291 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2292 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2293 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2294 | * this call. |
| 2295 | * <p> |
| 2296 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2297 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2298 | * <p> |
| 2299 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2300 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2301 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2302 | * @throws SecurityException if the calling application does not own an active administrator |
| 2303 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2304 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2305 | public void lockNow() { |
| 2306 | if (mService != null) { |
| 2307 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2308 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2309 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2310 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2314 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2315 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2316 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2317 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2318 | */ |
| 2319 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2320 | |
| 2321 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2322 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2323 | * data. |
| 2324 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2325 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2326 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2327 | */ |
| 2328 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2329 | |
| 2330 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2331 | * Ask the user data be wiped. Wiping the primary user will cause the device to reboot, erasing |
| 2332 | * all user data while next booting up. |
| 2333 | * <p> |
| 2334 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2335 | * 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] | 2336 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2337 | * @param flags Bit mask of additional options: currently supported flags are |
| 2338 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2339 | * @throws SecurityException if the calling application does not own an active administrator |
| 2340 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2341 | */ |
| 2342 | public void wipeData(int flags) { |
| 2343 | if (mService != null) { |
| 2344 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2345 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2346 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2347 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2348 | } |
| 2349 | } |
| 2350 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2351 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2352 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2353 | * Called by an application that is administering the device to set the |
| 2354 | * global proxy and exclusion list. |
| 2355 | * <p> |
| 2356 | * The calling device admin must have requested |
| 2357 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2358 | * this method; if it has not, a security exception will be thrown. |
| 2359 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2360 | * 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] | 2361 | * 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] | 2362 | * be returned. |
| 2363 | * The method can be called repeatedly by the device admin alrady setting the |
| 2364 | * proxy to update the proxy and exclusion list. |
| 2365 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2366 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2367 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2368 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2369 | * @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] | 2370 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2371 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2372 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2373 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2374 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2375 | List<String> exclusionList ) { |
| 2376 | if (proxySpec == null) { |
| 2377 | throw new NullPointerException(); |
| 2378 | } |
| 2379 | if (mService != null) { |
| 2380 | try { |
| 2381 | String hostSpec; |
| 2382 | String exclSpec; |
| 2383 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2384 | hostSpec = null; |
| 2385 | exclSpec = null; |
| 2386 | } else { |
| 2387 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2388 | throw new IllegalArgumentException(); |
| 2389 | } |
| 2390 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2391 | String hostName = sa.getHostName(); |
| 2392 | int port = sa.getPort(); |
| 2393 | StringBuilder hostBuilder = new StringBuilder(); |
| 2394 | hostSpec = hostBuilder.append(hostName) |
| 2395 | .append(":").append(Integer.toString(port)).toString(); |
| 2396 | if (exclusionList == null) { |
| 2397 | exclSpec = ""; |
| 2398 | } else { |
| 2399 | StringBuilder listBuilder = new StringBuilder(); |
| 2400 | boolean firstDomain = true; |
| 2401 | for (String exclDomain : exclusionList) { |
| 2402 | if (!firstDomain) { |
| 2403 | listBuilder = listBuilder.append(","); |
| 2404 | } else { |
| 2405 | firstDomain = false; |
| 2406 | } |
| 2407 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2408 | } |
| 2409 | exclSpec = listBuilder.toString(); |
| 2410 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2411 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2412 | != android.net.Proxy.PROXY_VALID) |
| 2413 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2414 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2415 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2416 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2417 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2418 | } |
| 2419 | } |
| 2420 | return null; |
| 2421 | } |
| 2422 | |
| 2423 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2424 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 2425 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 2426 | * unusual like general internal filtering this may be useful. On a private network where the |
| 2427 | * proxy is not accessible, you may break HTTP using this. |
| 2428 | * <p> |
| 2429 | * This method requires the caller to be the device owner. |
| 2430 | * <p> |
| 2431 | * 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] | 2432 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2433 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2434 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2435 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 2436 | * {@code null} value will clear the global HTTP proxy. |
| 2437 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2438 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2439 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2440 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2441 | if (mService != null) { |
| 2442 | try { |
| 2443 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2444 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2445 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2451 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2452 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2453 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2454 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2455 | */ |
| 2456 | public ComponentName getGlobalProxyAdmin() { |
| 2457 | if (mService != null) { |
| 2458 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2459 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2460 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2461 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2462 | } |
| 2463 | } |
| 2464 | return null; |
| 2465 | } |
| 2466 | |
| 2467 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2468 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2469 | * indicating that encryption is not supported. |
| 2470 | */ |
| 2471 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2472 | |
| 2473 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2474 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2475 | * indicating that encryption is supported, but is not currently active. |
| 2476 | */ |
| 2477 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2478 | |
| 2479 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2480 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2481 | * indicating that encryption is not currently active, but is currently |
| 2482 | * being activated. This is only reported by devices that support |
| 2483 | * encryption of data and only when the storage is currently |
| 2484 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2485 | * to become encrypted will never return this value. |
| 2486 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2487 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2488 | |
| 2489 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2490 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2491 | * indicating that encryption is active. |
| 2492 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2493 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2494 | |
| 2495 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2496 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2497 | * indicating that encryption is active, but an encryption key has not |
| 2498 | * been set by the user. |
| 2499 | */ |
| 2500 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2501 | |
| 2502 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2503 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2504 | * indicating that encryption is active and the encryption key is tied to the user. |
| 2505 | */ |
| 2506 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 2507 | |
| 2508 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2509 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2510 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2511 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2512 | * to check encryption status. However, on some devices this activity may never return, as |
| 2513 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2514 | */ |
| 2515 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2516 | public static final String ACTION_START_ENCRYPTION |
| 2517 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2518 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2519 | * Widgets are enabled in keyguard |
| 2520 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2521 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2522 | |
| 2523 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2524 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2525 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2526 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2527 | |
| 2528 | /** |
| 2529 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2530 | */ |
| 2531 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2532 | |
| 2533 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2534 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2535 | */ |
| 2536 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2537 | |
| 2538 | /** |
| 2539 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2540 | */ |
| 2541 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2542 | |
| 2543 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2544 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2545 | * (e.g. PIN/Pattern/Password). |
| 2546 | */ |
| 2547 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2548 | |
| 2549 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2550 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2551 | */ |
| 2552 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2553 | |
| 2554 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2555 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2556 | */ |
| 2557 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2558 | |
| 2559 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2560 | * Called by an application that is administering the device to request that the storage system |
| 2561 | * be encrypted. |
| 2562 | * <p> |
| 2563 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 2564 | * supported setting will always be used. If any device administrator requests device |
| 2565 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 2566 | * 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] | 2567 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2568 | * <p> |
| 2569 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 2570 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 2571 | * control the encryption of any other storage areas. There is one exception: If |
| 2572 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 2573 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 2574 | * written to disk within the encrypted storage area. |
| 2575 | * <p> |
| 2576 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 2577 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 2578 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 2579 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2580 | * |
| 2581 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2582 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2583 | * @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] | 2584 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2585 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2586 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 2587 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2588 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2589 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2590 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2591 | if (mService != null) { |
| 2592 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2593 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2594 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2595 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2599 | } |
| 2600 | |
| 2601 | /** |
| 2602 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2603 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2604 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2605 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2606 | * this will return the requested encryption setting as an aggregate of all active |
| 2607 | * administrators. |
| 2608 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2609 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2610 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2611 | if (mService != null) { |
| 2612 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2613 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2614 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2615 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2616 | } |
| 2617 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2618 | return false; |
| 2619 | } |
| 2620 | |
| 2621 | /** |
| 2622 | * Called by an application that is administering the device to |
| 2623 | * determine the current encryption status of the device. |
| 2624 | * |
| 2625 | * Depending on the returned status code, the caller may proceed in different |
| 2626 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2627 | * storage system does not support encryption. If the |
| 2628 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2629 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2630 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2631 | * storage system has enabled encryption but no password is set so further action |
| 2632 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2633 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2634 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2635 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2636 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2637 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2638 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2639 | */ |
| 2640 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2641 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | /** @hide per-user version */ |
| 2645 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2646 | if (mService != null) { |
| 2647 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2648 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2649 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2650 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2651 | } |
| 2652 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2653 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2654 | } |
| 2655 | |
| 2656 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame^] | 2657 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 2658 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 2659 | * keep the certificate on the device. |
| 2660 | * |
| 2661 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 2662 | * this certificate. |
| 2663 | * |
| 2664 | * @hide |
| 2665 | */ |
| 2666 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 2667 | if (mService != null) { |
| 2668 | try { |
| 2669 | return mService.approveCaCert(alias, userHandle, approval); |
| 2670 | } catch (RemoteException e) { |
| 2671 | throw e.rethrowFromSystemServer(); |
| 2672 | } |
| 2673 | } |
| 2674 | return false; |
| 2675 | } |
| 2676 | |
| 2677 | /** |
| 2678 | * Check whether a CA certificate has been approved by the device user. |
| 2679 | * |
| 2680 | * @hide |
| 2681 | */ |
| 2682 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 2683 | if (mService != null) { |
| 2684 | try { |
| 2685 | return mService.isCaCertApproved(alias, userHandle); |
| 2686 | } catch (RemoteException e) { |
| 2687 | throw e.rethrowFromSystemServer(); |
| 2688 | } |
| 2689 | } |
| 2690 | return false; |
| 2691 | } |
| 2692 | |
| 2693 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2694 | * Installs the given certificate as a user CA. |
| 2695 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2696 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2697 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2698 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2699 | * |
| 2700 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2701 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2702 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2703 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2704 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2705 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2706 | if (mService != null) { |
| 2707 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2708 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2709 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2710 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | return false; |
| 2714 | } |
| 2715 | |
| 2716 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2717 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2718 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2719 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2720 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2721 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2722 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2723 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2724 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2725 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2726 | if (mService != null) { |
| 2727 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2728 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2729 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2730 | } catch (CertificateException e) { |
| 2731 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2732 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2733 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2739 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2740 | * If a user has installed any certificates by other means than device policy these will be |
| 2741 | * included too. |
| 2742 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2743 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2744 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2745 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2746 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2747 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2748 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2749 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2750 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2751 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2752 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2753 | mService.enforceCanManageCaCerts(admin); |
| 2754 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2755 | for (String alias : certStore.userAliases()) { |
| 2756 | try { |
| 2757 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2758 | } catch (CertificateException ce) { |
| 2759 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2760 | } |
| 2761 | } |
| 2762 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2763 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2764 | } |
| 2765 | } |
| 2766 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2770 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2771 | * means other than device policy will also be removed, except for system CA certificates. |
| 2772 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2773 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2774 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2775 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2776 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2777 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2778 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2779 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2780 | try { |
| 2781 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2782 | .toArray(new String[0])); |
| 2783 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2784 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | /** |
| 2790 | * Returns whether this certificate is installed as a trusted CA. |
| 2791 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2792 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2793 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2794 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2795 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2796 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2797 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2798 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2799 | if (mService != null) { |
| 2800 | try { |
| 2801 | mService.enforceCanManageCaCerts(admin); |
| 2802 | return getCaCertAlias(certBuffer) != null; |
| 2803 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2804 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2805 | } catch (CertificateException ce) { |
| 2806 | Log.w(TAG, "Could not parse certificate", ce); |
| 2807 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2808 | } |
| 2809 | return false; |
| 2810 | } |
| 2811 | |
| 2812 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2813 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2814 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2815 | * the certificate and use the private key, given direct user approval. |
| 2816 | * |
| 2817 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 2818 | * direct user approval. This is for security - should a certificate installer become |
| 2819 | * compromised, certificates it had already installed will be protected. |
| 2820 | * |
| 2821 | * <p>If the installer must have access to the credentials, call |
| 2822 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate, String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2823 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2824 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2825 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2826 | * @param privKey The private key to install. |
| 2827 | * @param cert The certificate to install. |
| 2828 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2829 | * with that alias already exists, it will be overwritten. |
| 2830 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2831 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2832 | * owner. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2833 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2834 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2835 | @NonNull Certificate cert, @NonNull String alias) { |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2836 | return installKeyPair(admin, privKey, cert, alias, false); |
| 2837 | } |
| 2838 | |
| 2839 | /** |
| 2840 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2841 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2842 | * the certificate and use the private key, given direct user approval. |
| 2843 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2844 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 2845 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 2846 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2847 | * |
| 2848 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2849 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2850 | * @param privKey The private key to install. |
| 2851 | * @param cert The certificate to install. |
| 2852 | * @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] | 2853 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2854 | * @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] | 2855 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 2856 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2857 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2858 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2859 | * owner. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2860 | */ |
| 2861 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2862 | @NonNull Certificate cert, @NonNull String alias, boolean requestAccess) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2863 | try { |
| 2864 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2865 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2866 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2867 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2868 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2869 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2870 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2871 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2872 | } catch (CertificateException | IOException e) { |
| 2873 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2874 | } |
| 2875 | return false; |
| 2876 | } |
| 2877 | |
| 2878 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2879 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 2880 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2881 | * |
| 2882 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2883 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2884 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2885 | * @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] | 2886 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2887 | * owner. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2888 | */ |
| 2889 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2890 | try { |
| 2891 | return mService.removeKeyPair(admin, alias); |
| 2892 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2893 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2894 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2898 | * @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] | 2899 | * doesn't exist. |
| 2900 | */ |
| 2901 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2902 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2903 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2904 | new ByteArrayInputStream(certBuffer)); |
| 2905 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2906 | } |
| 2907 | |
| 2908 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2909 | * 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] | 2910 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2911 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2912 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2913 | * <p> |
| 2914 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2915 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2916 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2917 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 2918 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 2919 | * 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] | 2920 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 2921 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2922 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2923 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2924 | * @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] | 2925 | * access. If {@code null} is given the current package will be cleared. |
| 2926 | * @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] | 2927 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2928 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2929 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2930 | if (mService != null) { |
| 2931 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2932 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2933 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2934 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2935 | } |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2940 | * Called by a profile owner or device owner to retrieve the certificate installer for the user. |
| 2941 | * null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2942 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2943 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2944 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 2945 | * none is set. |
| 2946 | * @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] | 2947 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2948 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2949 | if (mService != null) { |
| 2950 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2951 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2952 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2953 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2954 | } |
| 2955 | } |
| 2956 | return null; |
| 2957 | } |
| 2958 | |
| 2959 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2960 | * 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] | 2961 | * specific application for the current user. This connection is automatically granted and |
| 2962 | * persisted after a reboot. |
| 2963 | * <p> |
| 2964 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 2965 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 2966 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2967 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2968 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to |
| 2969 | * remove an existing always-on VPN configuration. |
| 2970 | * @return {@code true} if the package is set as always-on VPN controller; {@code false} |
| 2971 | * otherwise. |
| 2972 | * @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] | 2973 | */ |
| 2974 | public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin, |
| 2975 | @Nullable String vpnPackage) { |
| 2976 | if (mService != null) { |
| 2977 | try { |
| 2978 | return mService.setAlwaysOnVpnPackage(admin, vpnPackage); |
| 2979 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2980 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2981 | } |
| 2982 | } |
| 2983 | return false; |
| 2984 | } |
| 2985 | |
| 2986 | /** |
| 2987 | * 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] | 2988 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 2989 | * 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] | 2990 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2991 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 2992 | * is set. |
| 2993 | * @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] | 2994 | */ |
| 2995 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 2996 | if (mService != null) { |
| 2997 | try { |
| 2998 | return mService.getAlwaysOnVpnPackage(admin); |
| 2999 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3000 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | return null; |
| 3004 | } |
| 3005 | |
| 3006 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3007 | * Called by an application that is administering the device to disable all cameras on the |
| 3008 | * device, for this user. After setting this, no applications running as this user will be able |
| 3009 | * to access any cameras on the device. |
| 3010 | * <p> |
| 3011 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3012 | * <p> |
| 3013 | * The calling device admin must have requested |
| 3014 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3015 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3016 | * |
| 3017 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3018 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3019 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3020 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3021 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3022 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3023 | if (mService != null) { |
| 3024 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3025 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3026 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3027 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3028 | } |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3033 | * 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] | 3034 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3035 | * @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] | 3036 | * have disabled the camera |
| 3037 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3038 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3039 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3043 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3044 | if (mService != null) { |
| 3045 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3046 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3047 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3048 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | return false; |
| 3052 | } |
| 3053 | |
| 3054 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3055 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3056 | * <p> |
| 3057 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 3058 | * {@link SecurityException} will be thrown. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3059 | * |
| 3060 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3061 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3062 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3063 | * bugreport is still running or waiting for the user to share or decline) |
| 3064 | * @throws SecurityException if {@code admin} is not a device owner, or if there are users other |
| 3065 | * than the one managed by the device owner. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3066 | */ |
| 3067 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 3068 | if (mService != null) { |
| 3069 | try { |
| 3070 | return mService.requestBugreport(admin); |
| 3071 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3072 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3073 | } |
| 3074 | } |
| 3075 | return false; |
| 3076 | } |
| 3077 | |
| 3078 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3079 | * Determine whether or not creating a guest user has been disabled for the device |
| 3080 | * |
| 3081 | * @hide |
| 3082 | */ |
| 3083 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3084 | // Currently guest users can always be created if multi-user is enabled |
| 3085 | // TODO introduce a policy for guest user creation |
| 3086 | return false; |
| 3087 | } |
| 3088 | |
| 3089 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3090 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3091 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3092 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3093 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3094 | * <p> |
| 3095 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3096 | * exception will be thrown. |
| 3097 | * <p> |
| 3098 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3099 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3100 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3101 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3102 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3103 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3104 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3105 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3106 | if (mService != null) { |
| 3107 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3108 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3109 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3110 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3111 | } |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3116 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3117 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3118 | * @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] | 3119 | * have disabled screen capture. |
| 3120 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3121 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3122 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3126 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3127 | if (mService != null) { |
| 3128 | try { |
| 3129 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3130 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3131 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3132 | } |
| 3133 | } |
| 3134 | return false; |
| 3135 | } |
| 3136 | |
| 3137 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3138 | * Called by a device owner to set whether auto time is required. If auto time is required the |
| 3139 | * user cannot set the date and time, but has to use network date and time. |
| 3140 | * <p> |
| 3141 | * Note: if auto time is required the user can still manually set the time zone. |
| 3142 | * <p> |
| 3143 | * The calling device admin must be a device owner. If it is not, a security exception will be |
| 3144 | * thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3145 | * |
| 3146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3147 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3148 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3149 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3150 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3151 | if (mService != null) { |
| 3152 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3153 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3154 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3155 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3156 | } |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | /** |
| 3161 | * @return true if auto time is required. |
| 3162 | */ |
| 3163 | public boolean getAutoTimeRequired() { |
| 3164 | if (mService != null) { |
| 3165 | try { |
| 3166 | return mService.getAutoTimeRequired(); |
| 3167 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3168 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | return false; |
| 3172 | } |
| 3173 | |
| 3174 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3175 | * 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] | 3176 | * <p> |
| 3177 | * The system user is exempt from this policy - it is never ephemeral. |
| 3178 | * <p> |
| 3179 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 3180 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3181 | * |
| 3182 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3183 | * @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] | 3184 | * subsequently created users will be ephemeral. |
| 3185 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3186 | * @hide |
| 3187 | */ |
| 3188 | public void setForceEphemeralUsers( |
| 3189 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 3190 | if (mService != null) { |
| 3191 | try { |
| 3192 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3193 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3194 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | /** |
| 3200 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3201 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3202 | * @hide |
| 3203 | */ |
| 3204 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 3205 | if (mService != null) { |
| 3206 | try { |
| 3207 | return mService.getForceEphemeralUsers(admin); |
| 3208 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3209 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | return false; |
| 3213 | } |
| 3214 | |
| 3215 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3216 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3217 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3218 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3219 | * <p> |
| 3220 | * The calling device admin must have requested |
| 3221 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 3222 | * if it has not, a security exception will be thrown. |
| 3223 | * <p> |
| 3224 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 3225 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 3226 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3227 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3228 | * <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] | 3229 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3230 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3231 | * there is one, or the parent user otherwise. |
| 3232 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 3233 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3234 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3235 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3236 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3237 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3238 | * profile. |
| 3239 | * <p> |
| 3240 | * Requests to disable other features on a managed profile will be ignored. |
| 3241 | * <p> |
| 3242 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3243 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3244 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3245 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3246 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3247 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 3248 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 3249 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 3250 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 3251 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 3252 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 3253 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3254 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3255 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3256 | if (mService != null) { |
| 3257 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3258 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3259 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3260 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3261 | } |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3266 | * Determine whether or not features have been disabled in keyguard either by the calling |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3267 | * admin, if specified, or all admins that set retrictions on this user and its participating |
| 3268 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3269 | * |
| 3270 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3271 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3272 | * restrictions on the parent profile. |
| 3273 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3274 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3275 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3276 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3277 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3278 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3279 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3280 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3284 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3285 | if (mService != null) { |
| 3286 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3287 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3288 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3289 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3290 | } |
| 3291 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3292 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3296 | * @hide |
| 3297 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3298 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3299 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3300 | if (mService != null) { |
| 3301 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3302 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3303 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3304 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3305 | } |
| 3306 | } |
| 3307 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3308 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3309 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3310 | * @hide |
| 3311 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3312 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3313 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3317 | * @hide |
| 3318 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3319 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3320 | if (mService != null) { |
| 3321 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3322 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3323 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3324 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | /** |
| 3330 | * @hide |
| 3331 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3332 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3333 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3334 | if (mService != null) { |
| 3335 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3336 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3337 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3338 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3339 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3340 | } |
| 3341 | } |
| 3342 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3343 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3344 | /** |
| 3345 | * @hide |
| 3346 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3347 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3348 | if (mService != null) { |
| 3349 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3350 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3351 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3352 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3356 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3357 | /** |
| 3358 | * @hide |
| 3359 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3360 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3361 | if (mService != null) { |
| 3362 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3363 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3364 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3365 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3366 | } |
| 3367 | } |
| 3368 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3369 | |
| 3370 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3371 | * @hide |
| 3372 | */ |
| 3373 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3374 | if (mService != null) { |
| 3375 | try { |
| 3376 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3377 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3378 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3379 | } |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | /** |
| 3384 | * @hide |
| 3385 | */ |
| 3386 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3387 | if (mService != null) { |
| 3388 | try { |
| 3389 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3390 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3391 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3392 | } |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3397 | * Should be called when keyguard has been dismissed. |
| 3398 | * @hide |
| 3399 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3400 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3401 | if (mService != null) { |
| 3402 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3403 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3404 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3405 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | /** |
| 3411 | * Should be called when keyguard view has been shown to the user. |
| 3412 | * @hide |
| 3413 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3414 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3415 | if (mService != null) { |
| 3416 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3417 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3418 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3419 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3420 | } |
| 3421 | } |
| 3422 | } |
| 3423 | |
| 3424 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3425 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3426 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3427 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3428 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3429 | * @return whether the package was successfully registered as the device owner. |
| 3430 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3431 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3432 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3433 | public boolean setDeviceOwner(ComponentName who) { |
| 3434 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | /** |
| 3438 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3439 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3440 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3441 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | /** |
| 3445 | * @hide |
| 3446 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3447 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3448 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | /** |
| 3452 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3453 | * Sets the given package as the device owner. The package must already be installed. There |
| 3454 | * must not already be a device owner. |
| 3455 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3456 | * this method. |
| 3457 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3458 | * 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] | 3459 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3460 | * @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] | 3461 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3462 | * @return whether the package was successfully registered as the device owner. |
| 3463 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3464 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3465 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3466 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3467 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3468 | if (mService != null) { |
| 3469 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3470 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3471 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3472 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3473 | } |
| 3474 | } |
| 3475 | return false; |
| 3476 | } |
| 3477 | |
| 3478 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3479 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3480 | * 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] | 3481 | * 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] | 3482 | * package is currently registered as the device owner app, pass in the package name from |
| 3483 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3484 | * 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] | 3485 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3486 | * the setup process. |
| 3487 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3488 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3489 | * @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] | 3490 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3491 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3492 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3493 | } |
| 3494 | |
| 3495 | /** |
| 3496 | * @return true if a package is registered as device owner, only when it's running on the |
| 3497 | * calling user. |
| 3498 | * |
| 3499 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3500 | * @hide |
| 3501 | */ |
| 3502 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3503 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3504 | } |
| 3505 | |
| 3506 | /** |
| 3507 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3508 | * user. |
| 3509 | * |
| 3510 | * <p>Requires the MANAGE_USERS permission. |
| 3511 | * |
| 3512 | * @hide |
| 3513 | */ |
| 3514 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3515 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * @return device owner component name, only when it's running on the calling user. |
| 3520 | * |
| 3521 | * @hide |
| 3522 | */ |
| 3523 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3524 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3525 | } |
| 3526 | |
| 3527 | /** |
| 3528 | * @return device owner component name, even if it's running on a different user. |
| 3529 | * |
| 3530 | * <p>Requires the MANAGE_USERS permission. |
| 3531 | * |
| 3532 | * @hide |
| 3533 | */ |
| 3534 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3535 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3536 | } |
| 3537 | |
| 3538 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3539 | if (packageName == null) { |
| 3540 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3541 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3542 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3543 | if (deviceOwner == null) { |
| 3544 | return false; |
| 3545 | } |
| 3546 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3549 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3550 | if (mService != null) { |
| 3551 | try { |
| 3552 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3553 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3554 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3560 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3561 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3562 | * no device owner. |
| 3563 | * |
| 3564 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3565 | * |
| 3566 | * @hide |
| 3567 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3568 | public int getDeviceOwnerUserId() { |
| 3569 | if (mService != null) { |
| 3570 | try { |
| 3571 | return mService.getDeviceOwnerUserId(); |
| 3572 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3573 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3580 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 3581 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 3582 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3583 | * |
| 3584 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3585 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 3586 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3587 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3588 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3589 | if (mService != null) { |
| 3590 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3591 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3592 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3593 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3594 | } |
| 3595 | } |
| 3596 | } |
| 3597 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3598 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3599 | * Returns the device owner package name, only if it's running on the calling user. |
| 3600 | * |
| 3601 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3602 | * |
| 3603 | * @hide |
| 3604 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3605 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3606 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3607 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3608 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3612 | * @return true if the device is managed by any device owner. |
| 3613 | * |
| 3614 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3615 | * |
| 3616 | * @hide |
| 3617 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3618 | public boolean isDeviceManaged() { |
| 3619 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3620 | } |
| 3621 | |
| 3622 | /** |
| 3623 | * Returns the device owner name. Note this method *will* return the device owner |
| 3624 | * name when it's running on a different user. |
| 3625 | * |
| 3626 | * <p>Requires the MANAGE_USERS permission. |
| 3627 | * |
| 3628 | * @hide |
| 3629 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3630 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3631 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3632 | if (mService != null) { |
| 3633 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3634 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3635 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3636 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3637 | } |
| 3638 | } |
| 3639 | return null; |
| 3640 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3641 | |
| 3642 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3643 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3644 | * @deprecated Do not use |
| 3645 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3646 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3647 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3648 | @SystemApi |
| 3649 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3650 | return null; |
| 3651 | } |
| 3652 | |
| 3653 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3654 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3655 | * @deprecated Do not use |
| 3656 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3657 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3658 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3659 | @SystemApi |
| 3660 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3661 | return null; |
| 3662 | } |
| 3663 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3664 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3665 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3666 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3667 | * Sets the given component as an active admin and registers the package as the profile |
| 3668 | * owner for this user. The package must already be installed and there shouldn't be |
| 3669 | * an existing profile owner registered for this user. Also, this method must be called |
| 3670 | * before the user setup has been completed. |
| 3671 | * <p> |
| 3672 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3673 | * MANAGE_DEVICE_ADMINS permission. |
| 3674 | * @param admin The component to register as an active admin and profile owner. |
| 3675 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3676 | * @return whether the admin was successfully registered as the profile owner. |
| 3677 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3678 | * the user has already been set up. |
| 3679 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3680 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3681 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3682 | throws IllegalArgumentException { |
| 3683 | if (mService != null) { |
| 3684 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3685 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3686 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3687 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3688 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3689 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | return false; |
| 3693 | } |
| 3694 | |
| 3695 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3696 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 3697 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 3698 | * will be thrown. |
| 3699 | * <p> |
| 3700 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3701 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3702 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3703 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3704 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3705 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3706 | if (mService != null) { |
| 3707 | try { |
| 3708 | mService.clearProfileOwner(admin); |
| 3709 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3710 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3711 | } |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3716 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3717 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3718 | */ |
| 3719 | public boolean hasUserSetupCompleted() { |
| 3720 | if (mService != null) { |
| 3721 | try { |
| 3722 | return mService.hasUserSetupCompleted(); |
| 3723 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3724 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | return true; |
| 3728 | } |
| 3729 | |
| 3730 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3731 | * @hide |
| 3732 | * 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] | 3733 | * already be installed. There must not already be a profile owner for this user. |
| 3734 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3735 | * this method. |
| 3736 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3737 | * - the caller is SYSTEM_UID. |
| 3738 | * - 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] | 3739 | * @param admin the component name to be registered as profile owner. |
| 3740 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3741 | * @param userHandle the userId to set the profile owner for. |
| 3742 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3743 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3744 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3745 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3746 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3747 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3748 | if (mService != null) { |
| 3749 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3750 | if (ownerName == null) { |
| 3751 | ownerName = ""; |
| 3752 | } |
| 3753 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3754 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3755 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3756 | } |
| 3757 | } |
| 3758 | return false; |
| 3759 | } |
| 3760 | |
| 3761 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3762 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3763 | * <p> |
| 3764 | * 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] | 3765 | * 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] | 3766 | * <p> |
| 3767 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 3768 | * will be blank and the user will not be allowed to change it. |
| 3769 | * <p> |
| 3770 | * 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] | 3771 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3772 | * and set a new version of this string accordingly. |
| 3773 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3774 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3775 | * @param info Device owner information which will be displayed instead of the user owner info. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3776 | * @return Whether the device owner information has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3777 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3778 | */ |
| 3779 | public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) { |
| 3780 | if (mService != null) { |
| 3781 | try { |
| 3782 | return mService.setDeviceOwnerLockScreenInfo(admin, info); |
| 3783 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3784 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3785 | } |
| 3786 | } |
| 3787 | return false; |
| 3788 | } |
| 3789 | |
| 3790 | /** |
| 3791 | * @return The device owner information. If it is not set returns {@code null}. |
| 3792 | */ |
| 3793 | public String getDeviceOwnerLockScreenInfo() { |
| 3794 | if (mService != null) { |
| 3795 | try { |
| 3796 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3797 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3798 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | return null; |
| 3802 | } |
| 3803 | |
| 3804 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3805 | * Called by device or profile owners to suspend packages for this user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3806 | * <p> |
| 3807 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 3808 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 3809 | * device. |
| 3810 | * <p> |
| 3811 | * The package must already be installed. If the package is uninstalled while suspended the |
| 3812 | * 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] | 3813 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3814 | * |
| 3815 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3816 | * @param packageNames The package names to suspend or unsuspend. |
| 3817 | * @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] | 3818 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3819 | * @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] | 3820 | * this method. |
| 3821 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3822 | */ |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3823 | public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames, |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3824 | boolean suspended) { |
| 3825 | if (mService != null) { |
| 3826 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3827 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3828 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3829 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3830 | } |
| 3831 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3832 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | /** |
| 3836 | * Called by device or profile owners to determine if a package is suspended. |
| 3837 | * |
| 3838 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3839 | * @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] | 3840 | * @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] | 3841 | * suspended, could not be found or an error occurred. |
| 3842 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3843 | */ |
| 3844 | public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) { |
| 3845 | if (mService != null) { |
| 3846 | try { |
| 3847 | return mService.getPackageSuspended(admin, packageName); |
| 3848 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3849 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3850 | } |
| 3851 | } |
| 3852 | return false; |
| 3853 | } |
| 3854 | |
| 3855 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3856 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3857 | * be used. Only the profile owner can call this. |
| 3858 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3859 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3860 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3861 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3862 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3863 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3864 | if (mService != null) { |
| 3865 | try { |
| 3866 | mService.setProfileEnabled(admin); |
| 3867 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3868 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3869 | } |
| 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3874 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 3875 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 3876 | * 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] | 3877 | * |
| 3878 | * @see #isProfileOwnerApp |
| 3879 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3880 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3881 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3882 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3883 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3884 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3885 | if (mService != null) { |
| 3886 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3887 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3888 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3889 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3890 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3891 | } |
| 3892 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3893 | |
| 3894 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3895 | * 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] | 3896 | * 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] | 3897 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3898 | * |
| 3899 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3900 | * @return Whether or not the package is registered as the profile owner. |
| 3901 | */ |
| 3902 | public boolean isProfileOwnerApp(String packageName) { |
| 3903 | if (mService != null) { |
| 3904 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 3905 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3906 | return profileOwner != null |
| 3907 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3908 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3909 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | return false; |
| 3913 | } |
| 3914 | |
| 3915 | /** |
| 3916 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3917 | * @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] | 3918 | * owner has been set for that user. |
| 3919 | * @throws IllegalArgumentException if the userId is invalid. |
| 3920 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3921 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3922 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3923 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3924 | } |
| 3925 | |
| 3926 | /** |
| 3927 | * @see #getProfileOwner() |
| 3928 | * @hide |
| 3929 | */ |
| 3930 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3931 | if (mService != null) { |
| 3932 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3933 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3934 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3935 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | return null; |
| 3939 | } |
| 3940 | |
| 3941 | /** |
| 3942 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3943 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3944 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3945 | * @throws IllegalArgumentException if the userId is invalid. |
| 3946 | */ |
| 3947 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3948 | if (mService != null) { |
| 3949 | try { |
| 3950 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3951 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3952 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3953 | } |
| 3954 | } |
| 3955 | return null; |
| 3956 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3957 | |
| 3958 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3959 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3960 | * @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] | 3961 | * @return the human readable name of the organisation associated with this profile owner or |
| 3962 | * null if one is not set. |
| 3963 | * @throws IllegalArgumentException if the userId is invalid. |
| 3964 | */ |
| 3965 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3966 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3967 | if (mService != null) { |
| 3968 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3969 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3970 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3971 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3972 | } |
| 3973 | } |
| 3974 | return null; |
| 3975 | } |
| 3976 | |
| 3977 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3978 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3979 | * 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] | 3980 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 3981 | * intent preferences are reset. |
| 3982 | * <p> |
| 3983 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 3984 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 3985 | * the filter. |
| 3986 | * <p> |
| 3987 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 3988 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3989 | * |
| 3990 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3991 | * @param filter The IntentFilter for which a default handler is added. |
| 3992 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3993 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3994 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3995 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3996 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3997 | if (mService != null) { |
| 3998 | try { |
| 3999 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4000 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4001 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4002 | } |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * 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] | 4008 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4009 | * <p> |
| 4010 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4011 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4012 | * |
| 4013 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4014 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4015 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4016 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4017 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4018 | String packageName) { |
| 4019 | if (mService != null) { |
| 4020 | try { |
| 4021 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4022 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4023 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4024 | } |
| 4025 | } |
| 4026 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4027 | |
| 4028 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4029 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4030 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4031 | * {@link #getApplicationRestrictions}. |
| 4032 | * <p> |
| 4033 | * This permission is persistent until it is later cleared by calling this method with a |
| 4034 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4035 | * <p> |
| 4036 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4037 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4038 | * |
| 4039 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4040 | * @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] | 4041 | * APIs. If {@code null} is given the current package will be cleared. |
| 4042 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4043 | * @throws NameNotFoundException if {@code packageName} is not found |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4044 | */ |
| 4045 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4046 | @Nullable String packageName) throws NameNotFoundException { |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4047 | if (mService != null) { |
| 4048 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4049 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4050 | throw new NameNotFoundException(packageName); |
| 4051 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4052 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4053 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4054 | } |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 4060 | * package for the current user, or {@code null} if none is set. |
| 4061 | * |
| 4062 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4063 | * @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] | 4064 | * {@code null} if none is set. |
| 4065 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4066 | */ |
| 4067 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 4068 | if (mService != null) { |
| 4069 | try { |
| 4070 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4071 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4072 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | return null; |
| 4076 | } |
| 4077 | |
| 4078 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4079 | * Called by any application to find out whether it has been granted permission via |
| 4080 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4081 | * for the calling user. |
| 4082 | * |
| 4083 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4084 | * that method. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4085 | */ |
| 4086 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 4087 | if (mService != null) { |
| 4088 | try { |
| 4089 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 4090 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4091 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4092 | } |
| 4093 | } |
| 4094 | return false; |
| 4095 | } |
| 4096 | |
| 4097 | /** |
| 4098 | * 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] | 4099 | * <p> |
| 4100 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4101 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4102 | * security exception will be thrown. |
| 4103 | * <p> |
| 4104 | * 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] | 4105 | * <ul> |
| 4106 | * <li>{@code boolean} |
| 4107 | * <li>{@code int} |
| 4108 | * <li>{@code String} or {@code String[]} |
| 4109 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4110 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4111 | * <p> |
| 4112 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 4113 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4114 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4115 | * <p> |
| 4116 | * The application restrictions are only made visible to the target application via |
| 4117 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 4118 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4119 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4120 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4121 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4122 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4123 | * @param packageName The name of the package to update restricted settings for. |
| 4124 | * @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] | 4125 | * set of active restrictions. |
| 4126 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4127 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4128 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4129 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4130 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4131 | Bundle settings) { |
| 4132 | if (mService != null) { |
| 4133 | try { |
| 4134 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 4135 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4136 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4137 | } |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4142 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 4143 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 4144 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4145 | * {@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] | 4146 | * <p> |
| 4147 | * The calling device admin must have requested |
| 4148 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4149 | * if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4150 | * |
| 4151 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4152 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4153 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 4154 | * strictly disabled according to the state of the |
| 4155 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4156 | * <p> |
| 4157 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 4158 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 4159 | * device admins. |
| 4160 | * <p> |
| 4161 | * Consult documentation for the specific TrustAgent to determine legal options |
| 4162 | * parameters. |
| 4163 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4164 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4165 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4166 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4167 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4168 | if (mService != null) { |
| 4169 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 4170 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4171 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4172 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4173 | } |
| 4174 | } |
| 4175 | } |
| 4176 | |
| 4177 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4178 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4179 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4180 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4181 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4182 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4183 | * this function returns a list of configurations for all admins that declare |
| 4184 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4185 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4186 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4187 | * 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] | 4188 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4189 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4190 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4191 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4192 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4193 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4197 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4198 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4199 | if (mService != null) { |
| 4200 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4201 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4202 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4203 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4204 | } |
| 4205 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4206 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4210 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 4211 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4212 | * <p> |
| 4213 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4214 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4215 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4216 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4217 | * @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] | 4218 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4219 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4220 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4221 | if (mService != null) { |
| 4222 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4223 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4224 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4225 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4226 | } |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4231 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4232 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4233 | * <p> |
| 4234 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4235 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4236 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4237 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4238 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4239 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4240 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4241 | if (mService != null) { |
| 4242 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4243 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4244 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4245 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4246 | } |
| 4247 | } |
| 4248 | return false; |
| 4249 | } |
| 4250 | |
| 4251 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4252 | * Determine whether or not caller-Id information has been disabled. |
| 4253 | * |
| 4254 | * @param userHandle The user for whom to check the caller-id permission |
| 4255 | * @hide |
| 4256 | */ |
| 4257 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4258 | if (mService != null) { |
| 4259 | try { |
| 4260 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4261 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4262 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4263 | } |
| 4264 | } |
| 4265 | return false; |
| 4266 | } |
| 4267 | |
| 4268 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4269 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 4270 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4271 | * <p> |
| 4272 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4273 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4274 | * |
| 4275 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4276 | * @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] | 4277 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4278 | */ |
| 4279 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4280 | boolean disabled) { |
| 4281 | if (mService != null) { |
| 4282 | try { |
| 4283 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 4284 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4285 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4286 | } |
| 4287 | } |
| 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4292 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4293 | * <p> |
| 4294 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4295 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4296 | * |
| 4297 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4298 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4299 | */ |
| 4300 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 4301 | if (mService != null) { |
| 4302 | try { |
| 4303 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4304 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4305 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4306 | } |
| 4307 | } |
| 4308 | return false; |
| 4309 | } |
| 4310 | |
| 4311 | |
| 4312 | /** |
| 4313 | * Determine whether or not contacts search has been disabled. |
| 4314 | * |
| 4315 | * @param userHandle The user for whom to check the contacts search permission |
| 4316 | * @hide |
| 4317 | */ |
| 4318 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4319 | if (mService != null) { |
| 4320 | try { |
| 4321 | return mService |
| 4322 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4323 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4324 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4325 | } |
| 4326 | } |
| 4327 | return false; |
| 4328 | } |
| 4329 | |
| 4330 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4331 | * 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] | 4332 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4333 | * @hide |
| 4334 | */ |
| 4335 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4336 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4337 | if (mService != null) { |
| 4338 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4339 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 4340 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4341 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4342 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4348 | * 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] | 4349 | * @hide |
| 4350 | */ |
| 4351 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4352 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4353 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4354 | originalIntent); |
| 4355 | } |
| 4356 | |
| 4357 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4358 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 4359 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4360 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4361 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4362 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4363 | * <p> |
| 4364 | * This API works on managed profile only. |
| 4365 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4366 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4367 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 4368 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4369 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4370 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4371 | if (mService != null) { |
| 4372 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4373 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4374 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4375 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4381 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 4382 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4383 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4384 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4385 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4386 | * <p> |
| 4387 | * This API works on managed profile only. |
| 4388 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4389 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4390 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4391 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4392 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4393 | if (mService != null) { |
| 4394 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4395 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4396 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4397 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4398 | } |
| 4399 | } |
| 4400 | return true; |
| 4401 | } |
| 4402 | |
| 4403 | /** |
| 4404 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4405 | * <p> |
| 4406 | * This API works on managed profile UserHandle only. |
| 4407 | * |
| 4408 | * @param userHandle The user for whom to check the caller-id permission |
| 4409 | * @hide |
| 4410 | */ |
| 4411 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4412 | if (mService != null) { |
| 4413 | try { |
| 4414 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4415 | .getIdentifier()); |
| 4416 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4417 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4418 | } |
| 4419 | } |
| 4420 | return true; |
| 4421 | } |
| 4422 | |
| 4423 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4424 | * 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] | 4425 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 4426 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4427 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4428 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4429 | * @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] | 4430 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4431 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4432 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 4433 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4434 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4435 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4436 | if (mService != null) { |
| 4437 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4438 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4439 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4440 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4441 | } |
| 4442 | } |
| 4443 | } |
| 4444 | |
| 4445 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4446 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4447 | * 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] | 4448 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4449 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4450 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4451 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4452 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4453 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4454 | if (mService != null) { |
| 4455 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4456 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4457 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4458 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4459 | } |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4464 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 4465 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4466 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 4467 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 4468 | * the list and not part of the system can not be enabled by the user. |
| 4469 | * <p> |
| 4470 | * Calling with a null value for the list disables the restriction so that all services can be |
| 4471 | * used, calling with an empty list only allows the builtin system's services. |
| 4472 | * <p> |
| 4473 | * 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] | 4474 | * |
| 4475 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4476 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4477 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 4478 | * accessibility services enabled, that are not in the list. |
| 4479 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4480 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4481 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4482 | List<String> packageNames) { |
| 4483 | if (mService != null) { |
| 4484 | try { |
| 4485 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4486 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4487 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4488 | } |
| 4489 | } |
| 4490 | return false; |
| 4491 | } |
| 4492 | |
| 4493 | /** |
| 4494 | * 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] | 4495 | * <p> |
| 4496 | * An empty list means no accessibility services except system services are allowed. Null means |
| 4497 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4498 | * |
| 4499 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4500 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4501 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4502 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4503 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4504 | if (mService != null) { |
| 4505 | try { |
| 4506 | return mService.getPermittedAccessibilityServices(admin); |
| 4507 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4508 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4509 | } |
| 4510 | } |
| 4511 | return null; |
| 4512 | } |
| 4513 | |
| 4514 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4515 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4516 | * |
| 4517 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4518 | * @param packageName Accessibility service package name that needs to be checked. |
| 4519 | * @param userHandle user id the admin is running as. |
| 4520 | * @return true if the accessibility service is permitted, otherwise false. |
| 4521 | * |
| 4522 | * @hide |
| 4523 | */ |
| 4524 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4525 | @NonNull String packageName, int userHandle) { |
| 4526 | if (mService != null) { |
| 4527 | try { |
| 4528 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4529 | userHandle); |
| 4530 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4531 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | return false; |
| 4535 | } |
| 4536 | |
| 4537 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4538 | * Returns the list of accessibility services permitted by the device or profiles |
| 4539 | * owners of this user. |
| 4540 | * |
| 4541 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4542 | * it will contain the intersection of the permitted lists for any device or profile |
| 4543 | * owners that apply to this user. It will also include any system accessibility services. |
| 4544 | * |
| 4545 | * @param userId which user to check for. |
| 4546 | * @return List of accessiblity service package names. |
| 4547 | * @hide |
| 4548 | */ |
| 4549 | @SystemApi |
| 4550 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4551 | if (mService != null) { |
| 4552 | try { |
| 4553 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4554 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4555 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4556 | } |
| 4557 | } |
| 4558 | return null; |
| 4559 | } |
| 4560 | |
| 4561 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4562 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 4563 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4564 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 4565 | * When zero or more packages have been added, input method that are not in the list and not |
| 4566 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 4567 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 4568 | * <p> |
| 4569 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 4570 | * be used, calling with an empty list disables all but the system's own input methods. |
| 4571 | * <p> |
| 4572 | * 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] | 4573 | * |
| 4574 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4575 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4576 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 4577 | * non-system input methods currently enabled that are not in the packageNames list. |
| 4578 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4579 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4580 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4581 | if (mService != null) { |
| 4582 | try { |
| 4583 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4584 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4585 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4586 | } |
| 4587 | } |
| 4588 | return false; |
| 4589 | } |
| 4590 | |
| 4591 | |
| 4592 | /** |
| 4593 | * 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] | 4594 | * <p> |
| 4595 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 4596 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4597 | * |
| 4598 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4599 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4600 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4601 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4602 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4603 | if (mService != null) { |
| 4604 | try { |
| 4605 | return mService.getPermittedInputMethods(admin); |
| 4606 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4607 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | return null; |
| 4611 | } |
| 4612 | |
| 4613 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4614 | * Called by the system to check if a specific input method is disabled by admin. |
| 4615 | * |
| 4616 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4617 | * @param packageName Input method package name that needs to be checked. |
| 4618 | * @param userHandle user id the admin is running as. |
| 4619 | * @return true if the input method is permitted, otherwise false. |
| 4620 | * |
| 4621 | * @hide |
| 4622 | */ |
| 4623 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4624 | @NonNull String packageName, int userHandle) { |
| 4625 | if (mService != null) { |
| 4626 | try { |
| 4627 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4628 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4629 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4630 | } |
| 4631 | } |
| 4632 | return false; |
| 4633 | } |
| 4634 | |
| 4635 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4636 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4637 | * 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] | 4638 | * |
| 4639 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4640 | * it will contain the intersection of the permitted lists for any device or profile |
| 4641 | * owners that apply to this user. It will also include any system input methods. |
| 4642 | * |
| 4643 | * @return List of input method package names. |
| 4644 | * @hide |
| 4645 | */ |
| 4646 | @SystemApi |
| 4647 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4648 | if (mService != null) { |
| 4649 | try { |
| 4650 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4651 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4652 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4653 | } |
| 4654 | } |
| 4655 | return null; |
| 4656 | } |
| 4657 | |
| 4658 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4659 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4660 | * currently installed it. |
| 4661 | * |
| 4662 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4663 | * |
| 4664 | * @return List of package names to keep cached. |
| 4665 | * @hide |
| 4666 | */ |
| 4667 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4668 | if (mService != null) { |
| 4669 | try { |
| 4670 | return mService.getKeepUninstalledPackages(admin); |
| 4671 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4672 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | return null; |
| 4676 | } |
| 4677 | |
| 4678 | /** |
| 4679 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4680 | * currently installed it. |
| 4681 | * |
| 4682 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4683 | * automatically pre-cached.</p> |
| 4684 | * |
| 4685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4686 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4687 | * @throws SecurityException if {@code admin} is not a device owner. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4688 | * @hide |
| 4689 | */ |
| 4690 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4691 | @NonNull List<String> packageNames) { |
| 4692 | if (mService != null) { |
| 4693 | try { |
| 4694 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4695 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4696 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4697 | } |
| 4698 | } |
| 4699 | } |
| 4700 | |
| 4701 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4702 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4703 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4704 | * created. If you need to persist an identifier for this user, use |
| 4705 | * {@link UserManager#getSerialNumberForUser}. |
| 4706 | * |
| 4707 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4708 | * @param name the user's name |
| 4709 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4710 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4711 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4712 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4713 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4714 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4715 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4716 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4717 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4718 | return null; |
| 4719 | } |
| 4720 | |
| 4721 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4722 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4723 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4724 | * created. If you need to persist an identifier for this user, use |
| 4725 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4726 | * immediately. |
| 4727 | * |
| 4728 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4729 | * as registered as an active admin on the new user. The profile owner package will be |
| 4730 | * installed on the new user if it already is installed on the device. |
| 4731 | * |
| 4732 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4733 | * profileOwnerComponent when onEnable is called. |
| 4734 | * |
| 4735 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4736 | * @param name the user's name |
| 4737 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4738 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4739 | * the user. |
| 4740 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4741 | * on the new user. |
| 4742 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4743 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4744 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4745 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4746 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4747 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4748 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4749 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4750 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4751 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4752 | return null; |
| 4753 | } |
| 4754 | |
| 4755 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4756 | * 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] | 4757 | */ |
| 4758 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4759 | |
| 4760 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4761 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4762 | * ephemeral. |
| 4763 | * @hide |
| 4764 | */ |
| 4765 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4766 | |
| 4767 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4768 | * Called by a device owner to create a user with the specified name and a given component of |
| 4769 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4770 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4771 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4772 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4773 | * <p> |
| 4774 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 4775 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 4776 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 4777 | * on the new user. |
| 4778 | * <p> |
| 4779 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 4780 | * 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] | 4781 | * |
| 4782 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4783 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4784 | * @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] | 4785 | * same package as admin, otherwise no user is created and an |
| 4786 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4787 | * @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] | 4788 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4789 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4790 | * @see UserHandle |
| 4791 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4792 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4793 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4794 | */ |
| 4795 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4796 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4797 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4798 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4799 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4800 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4801 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4802 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4806 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 4807 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4808 | * |
| 4809 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4810 | * @param userHandle the user to remove. |
| 4811 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4812 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4813 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4814 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4815 | try { |
| 4816 | return mService.removeUser(admin, userHandle); |
| 4817 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4818 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4823 | * Called by a device owner to switch the specified user to the foreground. |
| 4824 | * |
| 4825 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4826 | * @param userHandle the user to switch to; null will switch to primary. |
| 4827 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4828 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4829 | * @see Intent#ACTION_USER_FOREGROUND |
| 4830 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4831 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4832 | try { |
| 4833 | return mService.switchUser(admin, userHandle); |
| 4834 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4835 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4840 | * Retrieves the application restrictions for a given target application running in the calling |
| 4841 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4842 | * <p> |
| 4843 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4844 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4845 | * security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4846 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4847 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4848 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4849 | * @param packageName The name of the package to fetch restricted settings of. |
| 4850 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4851 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 4852 | * {@link Bundle} if no restrictions have been set. |
| 4853 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4854 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4855 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4856 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4857 | if (mService != null) { |
| 4858 | try { |
| 4859 | return mService.getApplicationRestrictions(admin, packageName); |
| 4860 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4861 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4862 | } |
| 4863 | } |
| 4864 | return null; |
| 4865 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4866 | |
| 4867 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4868 | * 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] | 4869 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4870 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 4871 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4872 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4873 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4874 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 4875 | * for the list of keys. |
| 4876 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4877 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4878 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4879 | if (mService != null) { |
| 4880 | try { |
| 4881 | mService.setUserRestriction(admin, key, true); |
| 4882 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4883 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4884 | } |
| 4885 | } |
| 4886 | } |
| 4887 | |
| 4888 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4889 | * 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] | 4890 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4891 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 4892 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4893 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4894 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4895 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 4896 | * for the list of keys. |
| 4897 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4898 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4899 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4900 | if (mService != null) { |
| 4901 | try { |
| 4902 | mService.setUserRestriction(admin, key, false); |
| 4903 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4904 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4908 | |
| 4909 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4910 | * Called by a profile or device owner to get user restrictions set with |
| 4911 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4912 | * <p> |
| 4913 | * 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] | 4914 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4915 | * {@link UserManager#getUserRestrictions()}. |
| 4916 | * |
| 4917 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4918 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4919 | */ |
| 4920 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4921 | return getUserRestrictions(admin, myUserId()); |
| 4922 | } |
| 4923 | |
| 4924 | /** @hide per-user version */ |
| 4925 | public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) { |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4926 | Bundle ret = null; |
| 4927 | if (mService != null) { |
| 4928 | try { |
Sudheer Shanka | 1c277a5 | 2015-11-11 21:58:24 +0000 | [diff] [blame] | 4929 | ret = mService.getUserRestrictions(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4930 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4931 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4932 | } |
| 4933 | } |
| 4934 | return ret == null ? new Bundle() : ret; |
| 4935 | } |
| 4936 | |
| 4937 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4938 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it is |
| 4939 | * unavailable for use, but the data and actual package file remain. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4940 | * |
| 4941 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4942 | * @param packageName The name of the package to hide or unhide. |
| 4943 | * @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] | 4944 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4945 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4946 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4947 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4948 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4949 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4950 | if (mService != null) { |
| 4951 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4952 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4953 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4954 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | return false; |
| 4958 | } |
| 4959 | |
| 4960 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4961 | * 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] | 4962 | * |
| 4963 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4964 | * @param packageName The name of the package to retrieve the hidden status of. |
| 4965 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4966 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4967 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4968 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4969 | if (mService != null) { |
| 4970 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4971 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4972 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4973 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4974 | } |
| 4975 | } |
| 4976 | return false; |
| 4977 | } |
| 4978 | |
| 4979 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4980 | * 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] | 4981 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4982 | * |
| 4983 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4984 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4985 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4986 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4987 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4988 | if (mService != null) { |
| 4989 | try { |
| 4990 | mService.enableSystemApp(admin, packageName); |
| 4991 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4992 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 4993 | } |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4998 | * Called by profile or device owners to re-enable system apps by intent that were disabled by |
| 4999 | * default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5000 | * |
| 5001 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5002 | * @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] | 5003 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5004 | * @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] | 5005 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5006 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5007 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5008 | if (mService != null) { |
| 5009 | try { |
| 5010 | return mService.enableSystemAppWithIntent(admin, intent); |
| 5011 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5012 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | return 0; |
| 5016 | } |
| 5017 | |
| 5018 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 5019 | * Called by a device owner or profile owner to disable account management for a specific type |
| 5020 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5021 | * <p> |
| 5022 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 5023 | * exception will be thrown. |
| 5024 | * <p> |
| 5025 | * When account management is disabled for an account type, adding or removing an account of |
| 5026 | * that type will not be possible. |
| 5027 | * <p> |
| 5028 | * 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] | 5029 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 5030 | * management for a specific type is disabled. |
| 5031 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5032 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5033 | * @param accountType For which account management is disabled or enabled. |
| 5034 | * @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] | 5035 | * enabled (false). |
| 5036 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5037 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5038 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5039 | boolean disabled) { |
| 5040 | if (mService != null) { |
| 5041 | try { |
| 5042 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 5043 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5044 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5045 | } |
| 5046 | } |
| 5047 | } |
| 5048 | |
| 5049 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5050 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 5051 | * |
| 5052 | * <p> Account management can be disabled/enabled by calling |
| 5053 | * {@link #setAccountManagementDisabled}. |
| 5054 | * |
| 5055 | * @return a list of account types for which account management has been disabled. |
| 5056 | * |
| 5057 | * @see #setAccountManagementDisabled |
| 5058 | */ |
| 5059 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5060 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | /** |
| 5064 | * @see #getAccountTypesWithManagementDisabled() |
| 5065 | * @hide |
| 5066 | */ |
| 5067 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5068 | if (mService != null) { |
| 5069 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5070 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5071 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5072 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5073 | } |
| 5074 | } |
| 5075 | |
| 5076 | return null; |
| 5077 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5078 | |
| 5079 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5080 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5081 | * <p> |
| 5082 | * Any packages that shares uid with an allowed package will also be allowed to activate lock |
| 5083 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
| 5084 | * package list results in locked tasks belonging to those packages to be finished. This |
| 5085 | * function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5086 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5087 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5088 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5089 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5090 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 5091 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 5092 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 5093 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5094 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5095 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5096 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5097 | if (mService != null) { |
| 5098 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5099 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5100 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5101 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | } |
| 5105 | |
| 5106 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5107 | * 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] | 5108 | * |
| 5109 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5110 | * @hide |
| 5111 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5112 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5113 | if (mService != null) { |
| 5114 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5115 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5116 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5117 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5118 | } |
| 5119 | } |
| 5120 | return null; |
| 5121 | } |
| 5122 | |
| 5123 | /** |
| 5124 | * This function lets the caller know whether the given component is allowed to start the |
| 5125 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5126 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5127 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5128 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5129 | if (mService != null) { |
| 5130 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5131 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5132 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5133 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5134 | } |
| 5135 | } |
| 5136 | return false; |
| 5137 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5138 | |
| 5139 | /** |
| 5140 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 5141 | * 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] | 5142 | * <p> |
| 5143 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5144 | * <ul> |
| 5145 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 5146 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 5147 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5148 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5149 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5150 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5151 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 5152 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 5153 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 5154 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 5155 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5156 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5157 | * <p> |
| 5158 | * 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] | 5159 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5160 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 5161 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5162 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5163 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5164 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 5165 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5166 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5167 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 5168 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5169 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5170 | * |
| 5171 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5172 | * @param setting The name of the setting to update. |
| 5173 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5174 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5175 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5176 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5177 | if (mService != null) { |
| 5178 | try { |
| 5179 | mService.setGlobalSetting(admin, setting, value); |
| 5180 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5181 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5182 | } |
| 5183 | } |
| 5184 | } |
| 5185 | |
| 5186 | /** |
| 5187 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5188 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5189 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5190 | * <p> |
| 5191 | * 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] | 5192 | * <ul> |
| 5193 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5194 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5195 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5196 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5197 | * <p> |
| 5198 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5199 | * <ul> |
| 5200 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5201 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5202 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5203 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5204 | * @param setting The name of the setting to update. |
| 5205 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5206 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5207 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5208 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5209 | if (mService != null) { |
| 5210 | try { |
| 5211 | mService.setSecureSetting(admin, setting, value); |
| 5212 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5213 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5214 | } |
| 5215 | } |
| 5216 | } |
| 5217 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5218 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5219 | * Designates a specific service component as the provider for making permission requests of a |
| 5220 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5221 | * <p/> |
| 5222 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5223 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5224 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5225 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5226 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 5227 | * provider previously assigned. |
| 5228 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5229 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5230 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5231 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5232 | if (mService != null) { |
| 5233 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5234 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5235 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5236 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5237 | } |
| 5238 | } |
| 5239 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5240 | |
| 5241 | /** |
| 5242 | * Called by profile or device owners to set the master volume mute on or off. |
| 5243 | * |
| 5244 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5245 | * @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] | 5246 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5247 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5248 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5249 | if (mService != null) { |
| 5250 | try { |
| 5251 | mService.setMasterVolumeMuted(admin, on); |
| 5252 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5253 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5254 | } |
| 5255 | } |
| 5256 | } |
| 5257 | |
| 5258 | /** |
| 5259 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5260 | * |
| 5261 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5262 | * @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] | 5263 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5264 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5265 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5266 | if (mService != null) { |
| 5267 | try { |
| 5268 | return mService.isMasterVolumeMuted(admin); |
| 5269 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5270 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5271 | } |
| 5272 | } |
| 5273 | return false; |
| 5274 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5275 | |
| 5276 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5277 | * 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] | 5278 | * |
| 5279 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5280 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5281 | * @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] | 5282 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5283 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5284 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5285 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5286 | if (mService != null) { |
| 5287 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5288 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5289 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5290 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5291 | } |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5296 | * 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] | 5297 | * 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] | 5298 | * <p> |
| 5299 | * <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] | 5300 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 5301 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 5302 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5303 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5304 | * @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] | 5305 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5306 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5307 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5308 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5309 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5310 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5311 | if (mService != null) { |
| 5312 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 5313 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5314 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5315 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | return false; |
| 5319 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5320 | |
| 5321 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5322 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 5323 | * package to be available in the parent profile. As a result the user will be able to add |
| 5324 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 5325 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 5326 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5327 | * <p> |
| 5328 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5329 | * |
| 5330 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5331 | * @param packageName The package from which widget providers are white-listed. |
| 5332 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5333 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5334 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5335 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5336 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5337 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5338 | if (mService != null) { |
| 5339 | try { |
| 5340 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 5341 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5342 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5343 | } |
| 5344 | } |
| 5345 | return false; |
| 5346 | } |
| 5347 | |
| 5348 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5349 | * 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] | 5350 | * package to be available in the parent profile. For this method to take effect the package |
| 5351 | * should have been added via |
| 5352 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5353 | * <p> |
| 5354 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5355 | * |
| 5356 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5357 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5358 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5359 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5360 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5361 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5362 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5363 | public boolean removeCrossProfileWidgetProvider( |
| 5364 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5365 | if (mService != null) { |
| 5366 | try { |
| 5367 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5368 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5369 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5370 | } |
| 5371 | } |
| 5372 | return false; |
| 5373 | } |
| 5374 | |
| 5375 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5376 | * 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] | 5377 | * available in the parent profile. |
| 5378 | * |
| 5379 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5380 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5381 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5382 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5383 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5384 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5385 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5386 | if (mService != null) { |
| 5387 | try { |
| 5388 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5389 | if (providers != null) { |
| 5390 | return providers; |
| 5391 | } |
| 5392 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5393 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5394 | } |
| 5395 | } |
| 5396 | return Collections.emptyList(); |
| 5397 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5398 | |
| 5399 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5400 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5401 | * |
| 5402 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5403 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5404 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5405 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5406 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5407 | try { |
| 5408 | mService.setUserIcon(admin, icon); |
| 5409 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5410 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5411 | } |
| 5412 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5413 | |
| 5414 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5415 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5416 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5417 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5418 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5419 | * components in the device owner package can set system update policies and the most |
| 5420 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5421 | * @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] | 5422 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5423 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5424 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5425 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5426 | if (mService != null) { |
| 5427 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5428 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5429 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5430 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5431 | } |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5436 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5437 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5438 | * @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] | 5439 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5440 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5441 | if (mService != null) { |
| 5442 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5443 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5444 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5445 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5446 | } |
| 5447 | } |
| 5448 | return null; |
| 5449 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5450 | |
| 5451 | /** |
| 5452 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5453 | * <p> |
| 5454 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 5455 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 5456 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 5457 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5458 | * |
| 5459 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5460 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5461 | * @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] | 5462 | * place. {@code true} otherwise. |
| 5463 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5464 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5465 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5466 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5467 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5468 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5469 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5470 | } |
| 5471 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5472 | |
| 5473 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5474 | * 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] | 5475 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 5476 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5477 | * |
| 5478 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5479 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5480 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 5481 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5482 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5483 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5484 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5485 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5486 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5487 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5488 | } |
| 5489 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5490 | |
| 5491 | /** |
| 5492 | * Callable by the system update service to notify device owners about pending updates. |
| 5493 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5494 | * permission. |
| 5495 | * |
| 5496 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5497 | * when the current pending update was first available. -1 if no update is available. |
| 5498 | * @hide |
| 5499 | */ |
| 5500 | @SystemApi |
| 5501 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5502 | if (mService != null) { |
| 5503 | try { |
| 5504 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5505 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5506 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5507 | } |
| 5508 | } |
| 5509 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5510 | |
| 5511 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5512 | * 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] | 5513 | * requests by applications. The policy can allow for normal operation which prompts the user to |
| 5514 | * grant a permission, or can allow automatic granting or denying of runtime permission requests |
| 5515 | * by an application. This also applies to new permissions declared by app updates. When a |
| 5516 | * permission is denied or granted this way, the effect is equivalent to setting the permission |
| 5517 | * grant state via {@link #setPermissionGrantState}. |
| 5518 | * <p/> |
| 5519 | * 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] | 5520 | * 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] | 5521 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5522 | * @param admin Which profile or device owner this request is associated with. |
| 5523 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5524 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 5525 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5526 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5527 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5528 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5529 | try { |
| 5530 | mService.setPermissionPolicy(admin, policy); |
| 5531 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5532 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | /** |
| 5537 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5538 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5539 | * @param admin Which profile or device owner this request is associated with. |
| 5540 | * @return the current policy for future permission requests. |
| 5541 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5542 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5543 | try { |
| 5544 | return mService.getPermissionPolicy(admin); |
| 5545 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5546 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5547 | } |
| 5548 | } |
| 5549 | |
| 5550 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5551 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 5552 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 5553 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 5554 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 5555 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 5556 | * 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] | 5557 | * by a profile or device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5558 | * <p/> |
| 5559 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 5560 | * the permission. It retains the previous grant, if any. |
| 5561 | * <p/> |
| 5562 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5563 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5564 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5565 | * @param admin Which profile or device owner this request is associated with. |
| 5566 | * @param packageName The application to grant or revoke a permission to. |
| 5567 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5568 | * @param grantState The permission grant state which is one of |
| 5569 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5570 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5571 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5572 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5573 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5574 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5575 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5576 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5577 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5578 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5579 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5580 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5581 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5582 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5583 | } |
| 5584 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5585 | |
| 5586 | /** |
| 5587 | * Returns the current grant state of a runtime permission for a specific application. |
| 5588 | * |
| 5589 | * @param admin Which profile or device owner this request is associated with. |
| 5590 | * @param packageName The application to check the grant state for. |
| 5591 | * @param permission The permission to check for. |
| 5592 | * @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] | 5593 | * has not set a grant state, the return value is |
| 5594 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 5595 | * permission is currently granted for the package. |
| 5596 | * <p/> |
| 5597 | * If a grant state was set by the profile or device owner, then the return value will |
| 5598 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 5599 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 5600 | * currently denied or granted. |
| 5601 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5602 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5603 | * @see PackageManager#checkPermission(String, String) |
| 5604 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5605 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5606 | String permission) { |
| 5607 | try { |
| 5608 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5609 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5610 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5611 | } |
| 5612 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5613 | |
| 5614 | /** |
| 5615 | * Returns if provisioning a managed profile or device is possible or not. |
| 5616 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5617 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5618 | * @return if provisioning a managed profile or device is possible or not. |
| 5619 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5620 | */ |
| 5621 | public boolean isProvisioningAllowed(String action) { |
| 5622 | try { |
| 5623 | return mService.isProvisioningAllowed(action); |
| 5624 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5625 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5626 | } |
| 5627 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5628 | |
| 5629 | /** |
| 5630 | * @hide |
| 5631 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5632 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
| 5633 | * user with {@link #ACTION_PROVISION_MANAGED_USER}. |
| 5634 | * @param admin Which profile owner this request is associated with. |
| 5635 | * @return if this user is a managed profile of another user. |
| 5636 | */ |
| 5637 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5638 | try { |
| 5639 | return mService.isManagedProfile(admin); |
| 5640 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5641 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | /** |
| 5646 | * @hide |
| 5647 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5648 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5649 | * @param admin Which device owner this request is associated with. |
| 5650 | * @return if this user is a system-only user. |
| 5651 | */ |
| 5652 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5653 | try { |
| 5654 | return mService.isSystemOnlyUser(admin); |
| 5655 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5656 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5657 | } |
| 5658 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5659 | |
| 5660 | /** |
| 5661 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5662 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5663 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5664 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 5665 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5666 | * <p> |
| 5667 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5668 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5669 | */ |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5670 | public String getWifiMacAddress(@NonNull ComponentName admin) { |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5671 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5672 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5673 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5674 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5675 | } |
| 5676 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5677 | |
| 5678 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5679 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 5680 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5681 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5682 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5683 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5684 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5685 | */ |
| 5686 | public void reboot(@NonNull ComponentName admin) { |
| 5687 | try { |
| 5688 | mService.reboot(admin); |
| 5689 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5690 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5691 | } |
| 5692 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5693 | |
| 5694 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5695 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 5696 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 5697 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 5698 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 5699 | * truncated. |
| 5700 | * <p> |
| 5701 | * 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] | 5702 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5703 | * and set a new version of this string accordingly. |
| 5704 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5705 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5706 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5707 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 5708 | * existing message. |
| 5709 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5710 | */ |
| 5711 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5712 | @Nullable String message) { |
| 5713 | if (mService != null) { |
| 5714 | try { |
| 5715 | mService.setShortSupportMessage(admin, message); |
| 5716 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5717 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5718 | } |
| 5719 | } |
| 5720 | } |
| 5721 | |
| 5722 | /** |
| 5723 | * Called by a device admin to get the short support message. |
| 5724 | * |
| 5725 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5726 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} or null if |
| 5727 | * no message has been set. |
| 5728 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5729 | */ |
| 5730 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5731 | if (mService != null) { |
| 5732 | try { |
| 5733 | return mService.getShortSupportMessage(admin); |
| 5734 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5735 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5736 | } |
| 5737 | } |
| 5738 | return null; |
| 5739 | } |
| 5740 | |
| 5741 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5742 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 5743 | * in the device administators settings screen. |
| 5744 | * <p> |
| 5745 | * 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] | 5746 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5747 | * and set a new version of this string accordingly. |
| 5748 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5749 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5750 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5751 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 5752 | * existing message. |
| 5753 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5754 | */ |
| 5755 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5756 | @Nullable String message) { |
| 5757 | if (mService != null) { |
| 5758 | try { |
| 5759 | mService.setLongSupportMessage(admin, message); |
| 5760 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5761 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5762 | } |
| 5763 | } |
| 5764 | } |
| 5765 | |
| 5766 | /** |
| 5767 | * Called by a device admin to get the long support message. |
| 5768 | * |
| 5769 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5770 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} or null if |
| 5771 | * no message has been set. |
| 5772 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5773 | */ |
| 5774 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5775 | if (mService != null) { |
| 5776 | try { |
| 5777 | return mService.getLongSupportMessage(admin); |
| 5778 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5779 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5780 | } |
| 5781 | } |
| 5782 | return null; |
| 5783 | } |
| 5784 | |
| 5785 | /** |
| 5786 | * Called by the system to get the short support message. |
| 5787 | * |
| 5788 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5789 | * @param userHandle user id the admin is running as. |
| 5790 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5791 | * |
| 5792 | * @hide |
| 5793 | */ |
| 5794 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5795 | if (mService != null) { |
| 5796 | try { |
| 5797 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5798 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5799 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5800 | } |
| 5801 | } |
| 5802 | return null; |
| 5803 | } |
| 5804 | |
| 5805 | |
| 5806 | /** |
| 5807 | * Called by the system to get the long support message. |
| 5808 | * |
| 5809 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5810 | * @param userHandle user id the admin is running as. |
| 5811 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5812 | * |
| 5813 | * @hide |
| 5814 | */ |
| 5815 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5816 | if (mService != null) { |
| 5817 | try { |
| 5818 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5819 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5820 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5821 | } |
| 5822 | } |
| 5823 | return null; |
| 5824 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5825 | |
| 5826 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5827 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5828 | * whose calls act on the parent profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5829 | * <p> |
| 5830 | * Note only some methods will work on the parent Manager. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5831 | * |
| 5832 | * @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] | 5833 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5834 | */ |
| 5835 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5836 | try { |
| 5837 | if (!mService.isManagedProfile(admin)) { |
| 5838 | throw new SecurityException("The current user does not have a parent profile."); |
| 5839 | } |
| 5840 | return new DevicePolicyManager(mContext, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5841 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5842 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5843 | } |
| 5844 | } |
| 5845 | |
| 5846 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5847 | * Called by device owner to control the security logging feature. Logging can only be |
| 5848 | * enabled on single user devices where the sole user is managed by the device owner. |
| 5849 | * |
| 5850 | * <p> Security logs contain various information intended for security auditing purposes. |
| 5851 | * See {@link SecurityEvent} for details. |
| 5852 | * |
| 5853 | * <p>There must be only one user on the device, managed by the device owner. |
| 5854 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5855 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5856 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5857 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5858 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5859 | * @see #retrieveSecurityLogs |
| 5860 | */ |
| 5861 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 5862 | try { |
| 5863 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 5864 | } catch (RemoteException re) { |
| 5865 | throw re.rethrowFromSystemServer(); |
| 5866 | } |
| 5867 | } |
| 5868 | |
| 5869 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5870 | * Return whether security logging is enabled or not by the device owner. |
| 5871 | * |
| 5872 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 5873 | * thrown. |
| 5874 | * |
| 5875 | * @param admin Which device owner this request is associated with. |
| 5876 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 5877 | * @throws SecurityException if {@code admin} is not a device owner. |
| 5878 | */ |
| 5879 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5880 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5881 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5882 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5883 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5884 | } |
| 5885 | } |
| 5886 | |
| 5887 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5888 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 5889 | * this API after device boots. |
| 5890 | * |
| 5891 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 5892 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 5893 | * |
| 5894 | * <p>There must be only one user on the device, managed by the device owner. |
| 5895 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5896 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5897 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5898 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 5899 | * 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] | 5900 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5901 | */ |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5902 | public List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5903 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5904 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5905 | if (list != null) { |
| 5906 | return list.getList(); |
| 5907 | } else { |
| 5908 | // Rate limit exceeded. |
| 5909 | return null; |
| 5910 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5911 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5912 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5913 | } |
| 5914 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5915 | |
| 5916 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 5917 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 5918 | * profile. |
| 5919 | * |
| 5920 | * @hide |
| 5921 | */ |
| 5922 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 5923 | mContext.checkSelfPermission( |
| 5924 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 5925 | if (!uInfo.isManagedProfile()) { |
| 5926 | throw new SecurityException("The user " + uInfo.id |
| 5927 | + " does not have a parent profile."); |
| 5928 | } |
| 5929 | return new DevicePolicyManager(mContext, true); |
| 5930 | } |
| 5931 | |
| 5932 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5933 | * 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] | 5934 | * <p> |
| 5935 | * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5936 | * corruption-free during power cycles, due to hardware variations and limitations. As a result, |
| 5937 | * this API is provided as best-effort and the returned logs may contain corrupted |
| 5938 | * data. </strong> |
| 5939 | * <p> |
| 5940 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 5941 | * {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5942 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5943 | * @param admin Which device owner this request is associated with. |
| 5944 | * @return Device logs from before the latest reboot of the system. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5945 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5946 | */ |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5947 | public List<SecurityEvent> retrievePreRebootSecurityLogs(@NonNull ComponentName admin) { |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5948 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5949 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5950 | return list.getList(); |
| 5951 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5952 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5953 | } |
| 5954 | } |
| 5955 | |
| 5956 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5957 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 5958 | * color is used as background color of the confirm credentials screen for that user. The |
| 5959 | * default color is {@link android.graphics.Color#GRAY}. |
| 5960 | * <p> |
| 5961 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5962 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 5963 | * |
| 5964 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5965 | * @param color The 32bit representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5966 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5967 | */ |
| 5968 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 5969 | try { |
| 5970 | mService.setOrganizationColor(admin, color); |
| 5971 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5972 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5973 | } |
| 5974 | } |
| 5975 | |
| 5976 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 5977 | * @hide |
| 5978 | * |
| 5979 | * Sets the color used for customization. |
| 5980 | * |
| 5981 | * @param color The 32bit representation of the color to be used. |
| 5982 | * @param userId which user to set the color to. |
| 5983 | * @RequiresPermission(allOf = { |
| 5984 | * Manifest.permission.MANAGE_USERS, |
| 5985 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 5986 | */ |
| 5987 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 5988 | try { |
| 5989 | mService.setOrganizationColorForUser(color, userId); |
| 5990 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5991 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 5996 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 5997 | * This color is used as background color of the confirm credentials screen for that user. |
| 5998 | * |
| 5999 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6000 | * @return The 32bit representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6001 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6002 | */ |
| 6003 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 6004 | try { |
| 6005 | return mService.getOrganizationColor(admin); |
| 6006 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6007 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6008 | } |
| 6009 | } |
| 6010 | |
| 6011 | /** |
| 6012 | * @hide |
| 6013 | * Retrieve the customization color for a given user. |
| 6014 | * |
| 6015 | * @param userHandle The user id of the user we're interested in. |
| 6016 | * @return The 32bit representation of the color to be used. |
| 6017 | */ |
| 6018 | public int getOrganizationColorForUser(int userHandle) { |
| 6019 | try { |
| 6020 | return mService.getOrganizationColorForUser(userHandle); |
| 6021 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6022 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6023 | } |
| 6024 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6025 | |
| 6026 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6027 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 6028 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6029 | * <p> |
| 6030 | * 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] | 6031 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6032 | * and set a new version of this string accordingly. |
| 6033 | * |
| 6034 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6035 | * @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] | 6036 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6037 | */ |
| 6038 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 6039 | try { |
| 6040 | mService.setOrganizationName(admin, title); |
| 6041 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6042 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6047 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 6048 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6049 | * |
| 6050 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6051 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6052 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6053 | */ |
| 6054 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 6055 | try { |
| 6056 | return mService.getOrganizationName(admin); |
| 6057 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6058 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | /** |
| 6063 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 6064 | * |
| 6065 | * @param userHandle The user id of the user we're interested in. |
| 6066 | * @return The organization name or {@code null} if none is set. |
| 6067 | * |
| 6068 | * @hide |
| 6069 | */ |
| 6070 | public String getOrganizationNameForUser(int userHandle) { |
| 6071 | try { |
| 6072 | return mService.getOrganizationNameForUser(userHandle); |
| 6073 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6074 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6075 | } |
| 6076 | } |
| 6077 | |
| 6078 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6079 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 6080 | * return {@link #STATE_USER_UNMANAGED} |
| 6081 | * @hide |
| 6082 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 6083 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6084 | @UserProvisioningState |
| 6085 | public int getUserProvisioningState() { |
| 6086 | if (mService != null) { |
| 6087 | try { |
| 6088 | return mService.getUserProvisioningState(); |
| 6089 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6090 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6091 | } |
| 6092 | } |
| 6093 | return STATE_USER_UNMANAGED; |
| 6094 | } |
| 6095 | |
| 6096 | /** |
| 6097 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 6098 | * |
| 6099 | * @param state to store |
| 6100 | * @param userHandle for user |
| 6101 | * @hide |
| 6102 | */ |
| 6103 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 6104 | if (mService != null) { |
| 6105 | try { |
| 6106 | mService.setUserProvisioningState(state, userHandle); |
| 6107 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6108 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6109 | } |
| 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6114 | * @hide |
| 6115 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 6116 | * affiliated if it is managed by the same entity as the device. |
| 6117 | * |
| 6118 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 6119 | * user/profile is considered affiliated if the following conditions are both met: |
| 6120 | * <ul> |
| 6121 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 6122 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 6123 | * and a profile owner intersect, they must have come from the same source, which means that |
| 6124 | * the device owner and profile owner are controlled by the same entity.</li> |
| 6125 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 6126 | * </ul> |
| 6127 | * |
| 6128 | * @param admin Which profile or device owner this request is associated with. |
| 6129 | * @param ids A set of opaque affiliation ids. |
| 6130 | */ |
| 6131 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 6132 | try { |
| 6133 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 6134 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6135 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | /** |
| 6140 | * @hide |
| 6141 | * Returns whether this user/profile is affiliated with the device. See |
| 6142 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 6143 | * |
| 6144 | * @return whether this user/profile is affiliated with the device. |
| 6145 | */ |
| 6146 | public boolean isAffiliatedUser() { |
| 6147 | try { |
| 6148 | return mService != null && mService.isAffiliatedUser(); |
| 6149 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6150 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6151 | } |
| 6152 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6153 | |
| 6154 | /** |
| 6155 | * @hide |
| 6156 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 6157 | * to be started |
| 6158 | * @param packageName the package to check for |
| 6159 | * @return whether the uninstall intent for {@code packageName} is pending |
| 6160 | */ |
| 6161 | public boolean isUninstallInQueue(String packageName) { |
| 6162 | try { |
| 6163 | return mService.isUninstallInQueue(packageName); |
| 6164 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6165 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | |
| 6169 | /** |
| 6170 | * @hide |
| 6171 | * @param packageName the package containing active DAs to be uninstalled |
| 6172 | */ |
| 6173 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 6174 | try { |
| 6175 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 6176 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6177 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6178 | } |
| 6179 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 6180 | } |