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; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 74 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 75 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 76 | import java.util.List; |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 77 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 80 | * 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] | 81 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 82 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 83 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 84 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 85 | * application calling an api may only pass as an argument a device administrator component it |
| 86 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 87 | * <div class="special reference"> |
| 88 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 89 | * <p> |
| 90 | * For more information about managing policies for device administration, read the <a href= |
| 91 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 92 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 93 | */ |
| 94 | public class DevicePolicyManager { |
| 95 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 96 | |
| 97 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 98 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 99 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 100 | |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 101 | private DevicePolicyManager(Context context, boolean parentInstance) { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 102 | this(context, |
| 103 | IDevicePolicyManager.Stub.asInterface( |
| 104 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)), |
| 105 | parentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 108 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 109 | @VisibleForTesting |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 110 | protected DevicePolicyManager( |
| 111 | Context context, IDevicePolicyManager service, boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 112 | mContext = context; |
| 113 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 114 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** @hide */ |
| 118 | public static DevicePolicyManager create(Context context) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 119 | DevicePolicyManager me = new DevicePolicyManager(context, false); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 120 | return me.mService != null ? me : null; |
| 121 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 122 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 123 | /** @hide test will override it. */ |
| 124 | @VisibleForTesting |
| 125 | protected int myUserId() { |
| 126 | return UserHandle.myUserId(); |
| 127 | } |
| 128 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 129 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 130 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 131 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 132 | * <p>A managed profile allows data separation for example for the usage of a |
| 133 | * device as a personal and corporate device. The user which provisioning is started from and |
| 134 | * the managed profile share a launcher. |
| 135 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 136 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 137 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 138 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 139 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 140 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 141 | * {@link #isProvisioningAllowed(String)}. |
| 142 | * |
| 143 | * <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] | 144 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 145 | * 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] | 146 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 147 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 148 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 149 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 150 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 151 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 152 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 153 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 154 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 155 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 156 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 157 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 158 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 159 | * <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] | 160 | * in the provisioning intent. The |
| 161 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 162 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 163 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 164 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 165 | * <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] | 166 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 167 | * |
| 168 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 169 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 170 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 171 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 172 | * 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] | 173 | */ |
| 174 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 175 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 176 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 177 | |
| 178 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 179 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 180 | * |
| 181 | * <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] | 182 | * 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] | 183 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 184 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 185 | * allowed. |
| 186 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 187 | * <p>The intent contains the following extras: |
| 188 | * <ul> |
| 189 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 190 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 191 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 192 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 193 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 194 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 195 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 196 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 197 | * |
| 198 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 199 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 200 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 201 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 202 | * 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] | 203 | * |
| 204 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 205 | */ |
| 206 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 207 | public static final String ACTION_PROVISION_MANAGED_USER |
| 208 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 209 | |
| 210 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 211 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 212 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 213 | * |
| 214 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 215 | * A device owner has full control over the device. The device owner can not be modified by the |
| 216 | * user. |
| 217 | * |
| 218 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 219 | * employee or client. |
| 220 | * |
| 221 | * <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] | 222 | * It is possible to check if provisioning is allowed or not by querying the method |
| 223 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 224 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 225 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 226 | * <ul> |
| 227 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 228 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 229 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 230 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 231 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 232 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 233 | * </ul> |
| 234 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 235 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 236 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 237 | * device owner. |
| 238 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 239 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 240 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 241 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 242 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 243 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 244 | * 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] | 245 | */ |
| 246 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 247 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 248 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 249 | |
| 250 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 251 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 252 | * |
| 253 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 254 | * the device. A device owner has full control over the device. The device owner can not be |
| 255 | * modified by the user and the only way of resetting the device is via factory reset. |
| 256 | * |
| 257 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 258 | * employee or client. |
| 259 | * |
| 260 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 261 | * |
| 262 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 263 | * by a privileged app with the permission |
| 264 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 265 | * |
| 266 | * <p>The provisioning intent contains the following properties: |
| 267 | * <ul> |
| 268 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 269 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 270 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 271 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 272 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 273 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 274 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 279 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 280 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 281 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 282 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 283 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 284 | * |
| 285 | * @hide |
| 286 | */ |
| 287 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 288 | @SystemApi |
| 289 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 290 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 291 | |
| 292 | /** |
| 293 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 294 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 295 | * |
| 296 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 297 | * management state that is distinct from that reached by |
| 298 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 299 | * user, and only has control over device-wide policies, not individual users and their data. |
| 300 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 301 | * this form of device management. |
| 302 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 303 | * <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] | 304 | * A device owner has full control over the device. The device owner can not be modified by the |
| 305 | * user. |
| 306 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 307 | * <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] | 308 | * employee or client. |
| 309 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 310 | * <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] | 311 | * It is possible to check if provisioning is allowed or not by querying the method |
| 312 | * {@link #isProvisioningAllowed(String)}. |
| 313 | * |
| 314 | * <p>The intent contains the following extras: |
| 315 | * <ul> |
| 316 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 317 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 318 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 319 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 320 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 321 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 322 | * </ul> |
| 323 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 324 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 325 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 326 | * device owner. |
| 327 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 328 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 329 | * |
| 330 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 331 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 332 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 333 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 334 | * |
| 335 | * @hide |
| 336 | */ |
| 337 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 338 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 339 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 340 | |
| 341 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 342 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 343 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 344 | * <ul> |
| 345 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 346 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 347 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 348 | * </ul> |
| 349 | * |
| 350 | * @hide |
| 351 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 352 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 353 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 354 | public static final String ACTION_PROVISION_FINALIZATION |
| 355 | = "android.app.action.PROVISION_FINALIZATION"; |
| 356 | |
| 357 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 358 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 359 | * |
| 360 | * @hide |
| 361 | */ |
| 362 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 363 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 364 | |
| 365 | /** |
| 366 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 367 | * |
| 368 | * @hide |
| 369 | */ |
| 370 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 371 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 372 | |
| 373 | /** |
| 374 | * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}. |
| 375 | * |
| 376 | * @hide |
| 377 | */ |
| 378 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 379 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 380 | |
| 381 | /** |
| 382 | * Extra for shared bugreport's SHA-256 hash. |
| 383 | * |
| 384 | * @hide |
| 385 | */ |
| 386 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 387 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 388 | |
| 389 | /** |
| 390 | * Extra for remote bugreport notification shown type. |
| 391 | * |
| 392 | * @hide |
| 393 | */ |
| 394 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 395 | "android.app.extra.bugreport_notification_type"; |
| 396 | |
| 397 | /** |
| 398 | * Notification type for a started remote bugreport flow. |
| 399 | * |
| 400 | * @hide |
| 401 | */ |
| 402 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 403 | |
| 404 | /** |
| 405 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 406 | * being taken. |
| 407 | * |
| 408 | * @hide |
| 409 | */ |
| 410 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 411 | |
| 412 | /** |
| 413 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 414 | * |
| 415 | * @hide |
| 416 | */ |
| 417 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 418 | |
| 419 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 420 | * 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] | 421 | * allows a mobile device management application or NFC programmer application which starts |
| 422 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 423 | * <p> |
| 424 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 425 | * sends the intent to pass data to itself on the newly created profile. |
| 426 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 427 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 428 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 429 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 430 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 431 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 432 | * management application after provisioning. |
| 433 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 434 | * <p> |
| 435 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 436 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 437 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 438 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 439 | */ |
| 440 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 441 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 442 | |
| 443 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 444 | * A String extra holding the package name of the mobile device management application that |
| 445 | * will be set as the profile owner or device owner. |
| 446 | * |
| 447 | * <p>If an application starts provisioning directly via an intent with action |
| 448 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 449 | * application that started provisioning. The package will be set as profile owner in that case. |
| 450 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 451 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 452 | * 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] | 453 | * |
| 454 | * <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] | 455 | * 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] | 456 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 457 | * @see DeviceAdminReceiver |
| 458 | * @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] | 459 | * supported, but only if there is only one device admin receiver in the package that requires |
| 460 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 461 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 462 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 463 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 464 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 465 | |
| 466 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 467 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 468 | * application that will be set as the profile owner or device owner and active admin. |
| 469 | * |
| 470 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 471 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 472 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 473 | * 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] | 474 | * |
| 475 | * <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] | 476 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 477 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 478 | * {@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] | 479 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 480 | * |
| 481 | * @see DeviceAdminReceiver |
| 482 | */ |
| 483 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 484 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 485 | |
| 486 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 487 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 488 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 489 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 490 | * |
| 491 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 492 | */ |
| 493 | |
| 494 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 495 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 496 | |
| 497 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 498 | * A String extra that, holds the email address of the account which a managed profile is |
| 499 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 500 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 501 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 502 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 503 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 504 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 505 | * contains this extra, it is forwarded in the |
| 506 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 507 | * device management application that was set as the profile owner during provisioning. |
| 508 | * 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] | 509 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 510 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 511 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 512 | |
| 513 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 514 | * A integer extra indicating the predominant color to show during the provisioning. |
| 515 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 516 | * |
| 517 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 518 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 519 | */ |
| 520 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 521 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 522 | |
| 523 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 524 | * 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] | 525 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 526 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 527 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 528 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 529 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 530 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 531 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 532 | |
| 533 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 534 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 535 | * will be set to. |
| 536 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 537 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 538 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 539 | */ |
| 540 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 541 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 542 | |
| 543 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 544 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 545 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 546 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 547 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 548 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 549 | */ |
| 550 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 551 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 552 | |
| 553 | /** |
| 554 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 555 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 556 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 557 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 558 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 559 | */ |
| 560 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 561 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 562 | |
| 563 | /** |
| 564 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 565 | * owner provisioning for downloading the mobile device management application. |
| 566 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 567 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 568 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 569 | */ |
| 570 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 571 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 572 | |
| 573 | /** |
| 574 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 575 | * is hidden or not. |
| 576 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 577 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 578 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 579 | */ |
| 580 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 581 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 582 | |
| 583 | /** |
| 584 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 585 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 586 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 587 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 588 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 589 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 590 | */ |
| 591 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 592 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 593 | |
| 594 | /** |
| 595 | * A String extra holding the password of the wifi network in |
| 596 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 597 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 598 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 599 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 600 | */ |
| 601 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 602 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 603 | |
| 604 | /** |
| 605 | * A String extra holding the proxy host for the wifi network in |
| 606 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 607 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 608 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 609 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 610 | */ |
| 611 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 612 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 613 | |
| 614 | /** |
| 615 | * An int extra holding the proxy port for the wifi network in |
| 616 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 617 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 618 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 619 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 620 | */ |
| 621 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 622 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 623 | |
| 624 | /** |
| 625 | * A String extra holding the proxy bypass for the wifi network in |
| 626 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 627 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 628 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 629 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 630 | */ |
| 631 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 632 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 633 | |
| 634 | /** |
| 635 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 636 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 637 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 638 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 639 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 640 | */ |
| 641 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 642 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 643 | |
| 644 | /** |
| 645 | * A String extra holding a url that specifies the download location of the device admin |
| 646 | * package. When not provided it is assumed that the device admin package is already installed. |
| 647 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 648 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 649 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 650 | */ |
| 651 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 652 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 653 | |
| 654 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 655 | * An int extra holding a minimum required version code for the device admin package. If the |
| 656 | * device admin is already installed on the device, it will only be re-downloaded from |
| 657 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 658 | * installed package is less than this version code. |
| 659 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 660 | * <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] | 661 | * provisioning via an NFC bump. |
| 662 | */ |
| 663 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 664 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 665 | |
| 666 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 667 | * A String extra holding a http cookie header which should be used in the http request to the |
| 668 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 669 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 670 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 671 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 672 | */ |
| 673 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 674 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 675 | |
| 676 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 677 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 678 | * the file at download location specified in |
| 679 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 680 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 681 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 682 | * 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] | 683 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 684 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 685 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 686 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 687 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 688 | * |
| 689 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 690 | * 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] | 691 | * 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] | 692 | * 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] | 693 | */ |
| 694 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 695 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 696 | |
| 697 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 698 | * 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] | 699 | * android package archive at the download location specified in {@link |
| 700 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 701 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 702 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 703 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 704 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 705 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 706 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 707 | * 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] | 708 | * the download location. If the checksum does not match an error will be shown to the user and |
| 709 | * the user will be asked to factory reset the device. |
| 710 | * |
| 711 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 712 | * provisioning via an NFC bump. |
| 713 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 714 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 715 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 716 | |
| 717 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 718 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 719 | * has completed successfully. |
| 720 | * |
| 721 | * <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] | 722 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 723 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 724 | * <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] | 725 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 726 | */ |
| 727 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 728 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 729 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 730 | |
| 731 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 732 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 733 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 734 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 735 | * <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] | 736 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 737 | * |
| 738 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 739 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 740 | */ |
| 741 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 742 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 743 | |
| 744 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 745 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 746 | * provisioning. If this extra is not passed, a default image will be shown. |
| 747 | * <h5>The following URI schemes are accepted:</h5> |
| 748 | * <ul> |
| 749 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 750 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 751 | * </ul> |
| 752 | * |
| 753 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 754 | * pixed density for the device. |
| 755 | * |
| 756 | * <p> If a content: URI is passed, the intent should have the flag |
| 757 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 758 | * {@link android.content.ClipData} of the intent too. |
| 759 | * |
| 760 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 761 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 762 | */ |
| 763 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 764 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 765 | |
| 766 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 767 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 768 | * during setup-wizard. |
| 769 | * |
| 770 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 771 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 772 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 773 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 774 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 775 | * |
| 776 | * @hide |
| 777 | */ |
| 778 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 779 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 780 | |
| 781 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 782 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 783 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 784 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 785 | * A device owner has full control over the device. The device owner can not be modified by the |
| 786 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 787 | * reset. |
| 788 | * |
| 789 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 790 | * employee or client. |
| 791 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 792 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 793 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 794 | * <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] | 795 | * contains the following properties: |
| 796 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 797 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 798 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 799 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 800 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 801 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 802 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 803 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 804 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 805 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 806 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 807 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 808 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 809 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 810 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 811 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 812 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 813 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 814 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 815 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 816 | * 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] | 817 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 818 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 819 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 820 | */ |
| 821 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 822 | = "application/com.android.managedprovisioning"; |
| 823 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 824 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 825 | * Activity action: ask the user to add a new device administrator to the system. |
| 826 | * The desired policy is the ComponentName of the policy in the |
| 827 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 828 | * bring the user through adding the device administrator to the system (or |
| 829 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 830 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 831 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 832 | * field to provide the user with additional explanation (in addition |
| 833 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 834 | * |
| 835 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 836 | * user intervention). However, if your administrator has been updated and is requesting |
| 837 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 838 | * 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] | 839 | */ |
| 840 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 841 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 842 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 843 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 844 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 845 | * @hide |
| 846 | * 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] | 847 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 848 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 849 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 850 | * 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] | 851 | * to remotely control restrictions on the user. |
| 852 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 853 | * <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] | 854 | * result of whether or not the user approved the action. If approved, the result will |
| 855 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 856 | * as a profile owner. |
| 857 | * |
| 858 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 859 | * field to provide the user with additional explanation (in addition |
| 860 | * to your component's description) about what is being added. |
| 861 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 862 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 863 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 864 | */ |
| 865 | @SystemApi |
| 866 | public static final String ACTION_SET_PROFILE_OWNER |
| 867 | = "android.app.action.SET_PROFILE_OWNER"; |
| 868 | |
| 869 | /** |
| 870 | * @hide |
| 871 | * Name of the profile owner admin that controls the user. |
| 872 | */ |
| 873 | @SystemApi |
| 874 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 875 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 876 | |
| 877 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 878 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 879 | * 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] | 880 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 881 | * @hide |
| 882 | */ |
| 883 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 884 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 885 | |
| 886 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 887 | * Broadcast action: sent when the device owner is set or changed. |
| 888 | * |
| 889 | * This broadcast is sent only to the primary user. |
| 890 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 891 | */ |
| 892 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 893 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 894 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 895 | |
| 896 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 897 | * The ComponentName of the administrator component. |
| 898 | * |
| 899 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 900 | */ |
| 901 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 902 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 903 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 904 | * An optional CharSequence providing additional explanation for why the |
| 905 | * admin is being added. |
| 906 | * |
| 907 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 908 | */ |
| 909 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 910 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 911 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 912 | * Activity action: have the user enter a new password. This activity should |
| 913 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 914 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 915 | * enter a new password that meets the current requirements. You can use |
| 916 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 917 | * have the user select a new password in order to meet the current |
| 918 | * constraints. Upon being resumed from this activity, you can check the new |
| 919 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 920 | * |
| 921 | * If the intent is launched from within a managed profile with a profile |
| 922 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 923 | * this will trigger entering a new password for the parent of the profile. |
| 924 | * For all other cases it will trigger entering a new password for the user |
| 925 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 926 | * |
| 927 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 928 | */ |
| 929 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 930 | public static final String ACTION_SET_NEW_PASSWORD |
| 931 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 932 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 933 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 934 | * Activity action: have the user enter a new password for the parent profile. |
| 935 | * If the intent is launched from within a managed profile, this will trigger |
| 936 | * entering a new password for the parent of the profile. In all other cases |
| 937 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 938 | */ |
| 939 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 940 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 941 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 942 | |
| 943 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 944 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 945 | * the parent profile to access intents sent from the managed profile. |
| 946 | * That is, when an app in the managed profile calls |
| 947 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 948 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 949 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 950 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 951 | |
| 952 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 953 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 954 | * the managed profile to access intents sent from the parent profile. |
| 955 | * That is, when an app in the parent profile calls |
| 956 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 957 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 958 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 959 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 960 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 961 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 962 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 963 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 964 | */ |
| 965 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 966 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 967 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 968 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 969 | /** |
| 970 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 971 | * Already granted or denied permissions are not affected by this. |
| 972 | */ |
| 973 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 974 | |
| 975 | /** |
| 976 | * Permission policy to always grant new permission requests for runtime permissions. |
| 977 | * Already granted or denied permissions are not affected by this. |
| 978 | */ |
| 979 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 980 | |
| 981 | /** |
| 982 | * Permission policy to always deny new permission requests for runtime permissions. |
| 983 | * Already granted or denied permissions are not affected by this. |
| 984 | */ |
| 985 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 986 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 987 | /** |
| 988 | * Runtime permission state: The user can manage the permission |
| 989 | * through the UI. |
| 990 | */ |
| 991 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 992 | |
| 993 | /** |
| 994 | * Runtime permission state: The permission is granted to the app |
| 995 | * and the user cannot manage the permission through the UI. |
| 996 | */ |
| 997 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 998 | |
| 999 | /** |
| 1000 | * Runtime permission state: The permission is denied to the app |
| 1001 | * and the user cannot manage the permission through the UI. |
| 1002 | */ |
| 1003 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1004 | |
| 1005 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1006 | * No management for current user in-effect. This is the default. |
| 1007 | * @hide |
| 1008 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1009 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1010 | public static final int STATE_USER_UNMANAGED = 0; |
| 1011 | |
| 1012 | /** |
| 1013 | * Management partially setup, user setup needs to be completed. |
| 1014 | * @hide |
| 1015 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1016 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1017 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1018 | |
| 1019 | /** |
| 1020 | * Management partially setup, user setup completed. |
| 1021 | * @hide |
| 1022 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1023 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1024 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1025 | |
| 1026 | /** |
| 1027 | * Management setup and active on current user. |
| 1028 | * @hide |
| 1029 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1030 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1031 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1032 | |
| 1033 | /** |
| 1034 | * Management partially setup on a managed profile. |
| 1035 | * @hide |
| 1036 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1037 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1038 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1039 | |
| 1040 | /** |
| 1041 | * @hide |
| 1042 | */ |
| 1043 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1044 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1045 | @Retention(RetentionPolicy.SOURCE) |
| 1046 | public @interface UserProvisioningState {} |
| 1047 | |
| 1048 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1049 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1050 | * |
| 1051 | * @param admin The administrator component to check for. |
| 1052 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1053 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1054 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1055 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1056 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | /** |
| 1060 | * @see #isAdminActive(ComponentName) |
| 1061 | * @hide |
| 1062 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1063 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1064 | if (mService != null) { |
| 1065 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1066 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1067 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1068 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | return false; |
| 1072 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1073 | /** |
| 1074 | * Return true if the given administrator component is currently being removed |
| 1075 | * for the user. |
| 1076 | * @hide |
| 1077 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1078 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1079 | if (mService != null) { |
| 1080 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1081 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1082 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1083 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | return false; |
| 1087 | } |
| 1088 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1089 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1090 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1091 | * Return a list of all currently active device administrators' component |
| 1092 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1093 | * returned. |
| 1094 | */ |
| 1095 | public List<ComponentName> getActiveAdmins() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1096 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * @see #getActiveAdmins() |
| 1101 | * @hide |
| 1102 | */ |
| 1103 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1104 | if (mService != null) { |
| 1105 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1106 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1107 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1108 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | return null; |
| 1112 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1113 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1114 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1115 | * Used by package administration code to determine if a package can be stopped |
| 1116 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1117 | * @hide |
| 1118 | */ |
| 1119 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1120 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * Used by package administration code to determine if a package can be stopped |
| 1125 | * or uninstalled. |
| 1126 | * @hide |
| 1127 | */ |
| 1128 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1129 | if (mService != null) { |
| 1130 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1131 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1132 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1133 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | return false; |
| 1137 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1138 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1139 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1140 | * Remove a current administration component. This can only be called |
| 1141 | * by the application that owns the administration component; if you |
| 1142 | * try to remove someone else's component, a security exception will be |
| 1143 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1144 | * |
| 1145 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1146 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1147 | * |
| 1148 | * @param admin The administration compononent to remove. |
| 1149 | * @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] | 1150 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1151 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1152 | if (mService != null) { |
| 1153 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1154 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1155 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1156 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1160 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1161 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1162 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1163 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1164 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1165 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1166 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1167 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1168 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1169 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1170 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1171 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1172 | if (mService != null) { |
| 1173 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1174 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1175 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1176 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | return false; |
| 1180 | } |
| 1181 | |
| 1182 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1183 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1184 | * |
| 1185 | * @hide |
| 1186 | */ |
| 1187 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1188 | if (mService != null) { |
| 1189 | try { |
| 1190 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1191 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1192 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | return false; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1199 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1200 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1201 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1202 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1203 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1204 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1205 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1206 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1207 | * recognition technology. This implies technologies that can recognize the identity of |
| 1208 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1209 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1210 | */ |
| 1211 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1212 | |
| 1213 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1214 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1215 | * 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] | 1216 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1217 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1218 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1219 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1220 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1221 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1222 | * password containing at least numeric characters. Note that quality |
| 1223 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1224 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1225 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1226 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1227 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1228 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1229 | * password containing at least numeric characters with no repeating (4444) |
| 1230 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1231 | * constants are ordered so that higher values are more restrictive. |
| 1232 | */ |
| 1233 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1234 | |
| 1235 | /** |
| 1236 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1237 | * password containing at least alphabetic (or other symbol) characters. |
| 1238 | * Note that quality constants are ordered so that higher values are more |
| 1239 | * restrictive. |
| 1240 | */ |
| 1241 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1242 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1243 | /** |
| 1244 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1245 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1246 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1247 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1248 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1249 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1250 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1251 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1252 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1253 | * password containing at least a letter, a numerical digit and a special |
| 1254 | * symbol, by default. With this password quality, passwords can be |
| 1255 | * restricted to contain various sets of characters, like at least an |
| 1256 | * uppercase letter, etc. These are specified using various methods, |
| 1257 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1258 | * that quality constants are ordered so that higher values are more |
| 1259 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1260 | */ |
| 1261 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1262 | |
| 1263 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1264 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1265 | * modify password. In case this password quality is set, the password is |
| 1266 | * managed by a profile owner. The profile owner can set any password, |
| 1267 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1268 | * that quality constants are ordered so that higher values are more |
| 1269 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1270 | * the highest. |
| 1271 | * @hide |
| 1272 | */ |
| 1273 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1274 | |
| 1275 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1276 | * Called by an application that is administering the device to set the password restrictions it |
| 1277 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1278 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1279 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1280 | * 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] | 1281 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1282 | * <p> |
| 1283 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1284 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1285 | * considerations) is the one that is in effect. |
| 1286 | * <p> |
| 1287 | * The calling device admin must have requested |
| 1288 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1289 | * not, a security exception will be thrown. |
| 1290 | * <p> |
| 1291 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1292 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1293 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1294 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1295 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1296 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1297 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1298 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1299 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1300 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1301 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1302 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1303 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1304 | if (mService != null) { |
| 1305 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1306 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1307 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1308 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1312 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1313 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1314 | * Retrieve the current minimum password quality for a particular admin or all admins that set |
| 1315 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1316 | * a separate challenge are not taken into account. |
| 1317 | * |
| 1318 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1319 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1320 | * restrictions on the parent profile. |
| 1321 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1322 | * @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] | 1323 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1324 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1325 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1326 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1330 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1331 | if (mService != null) { |
| 1332 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1333 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1334 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1335 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1336 | } |
| 1337 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1338 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1339 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1340 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1341 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1342 | * Called by an application that is administering the device to set the minimum allowed password |
| 1343 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1344 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1345 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1346 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1347 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1348 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1349 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1350 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1351 | * {@link #setPasswordQuality}. |
| 1352 | * <p> |
| 1353 | * The calling device admin must have requested |
| 1354 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1355 | * not, a security exception will be thrown. |
| 1356 | * <p> |
| 1357 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1358 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1359 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1360 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1361 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1362 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1363 | * restriction. |
| 1364 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1365 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1366 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1367 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1368 | if (mService != null) { |
| 1369 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1370 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1371 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1372 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1376 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1377 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1378 | * Retrieve the current minimum password length for a particular admin or all admins that set |
| 1379 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1380 | * a separate challenge are not taken into account. |
| 1381 | * |
| 1382 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1383 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1384 | * restrictions on the parent profile. |
| 1385 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1386 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1387 | * @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] | 1388 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1389 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1390 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1391 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1395 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1396 | if (mService != null) { |
| 1397 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1398 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1399 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1400 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | return 0; |
| 1404 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1405 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1406 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1407 | * Called by an application that is administering the device to set the minimum number of upper |
| 1408 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1409 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1410 | * current password will remain until the user has set a new one, so the change does not take |
| 1411 | * place immediately. To prompt the user for a new password, use |
| 1412 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1413 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1414 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1415 | * <p> |
| 1416 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1417 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1418 | * not, a security exception will be thrown. |
| 1419 | * <p> |
| 1420 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1421 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1422 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1423 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1424 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1425 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1426 | * A value of 0 means there is no restriction. |
| 1427 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1428 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1429 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1430 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1431 | if (mService != null) { |
| 1432 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1433 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1434 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1435 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1441 | * Retrieve the current number of upper case letters required in the password |
| 1442 | * for a particular admin or all admins that set retrictions on this user and |
| 1443 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1444 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1445 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1446 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1447 | * and only applies when the password quality is |
| 1448 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1449 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1450 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1451 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1452 | * restrictions on the parent profile. |
| 1453 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1454 | * @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] | 1455 | * aggregate all admins. |
| 1456 | * @return The minimum number of upper case letters required in the |
| 1457 | * password. |
| 1458 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1459 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1460 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1464 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1465 | if (mService != null) { |
| 1466 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1467 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1468 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1469 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | return 0; |
| 1473 | } |
| 1474 | |
| 1475 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1476 | * Called by an application that is administering the device to set the minimum number of lower |
| 1477 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1478 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1479 | * current password will remain until the user has set a new one, so the change does not take |
| 1480 | * place immediately. To prompt the user for a new password, use |
| 1481 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1482 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1483 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1484 | * <p> |
| 1485 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1486 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1487 | * not, a security exception will be thrown. |
| 1488 | * <p> |
| 1489 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1490 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1491 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1492 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1493 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1494 | * @param length The new desired minimum number of lower case letters required in the password. |
| 1495 | * A value of 0 means there is no restriction. |
| 1496 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1497 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1498 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1499 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1500 | if (mService != null) { |
| 1501 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1502 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1503 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1504 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1510 | * Retrieve the current number of lower case letters required in the password |
| 1511 | * for a particular admin or all admins that set retrictions on this user |
| 1512 | * and its participating profiles. Restrictions on profiles that have |
| 1513 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1514 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1515 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1516 | * and only applies when the password quality is |
| 1517 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1518 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1519 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1520 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1521 | * restrictions on the parent profile. |
| 1522 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1523 | * @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] | 1524 | * aggregate all admins. |
| 1525 | * @return The minimum number of lower case letters required in the |
| 1526 | * password. |
| 1527 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1528 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1529 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1533 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1534 | if (mService != null) { |
| 1535 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1536 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1537 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1538 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1539 | } |
| 1540 | } |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1545 | * Called by an application that is administering the device to set the minimum number of |
| 1546 | * letters required in the password. After setting this, the user will not be able to enter a |
| 1547 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1548 | * password will remain until the user has set a new one, so the change does not take place |
| 1549 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1550 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1551 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1552 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1553 | * <p> |
| 1554 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1555 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1556 | * not, a security exception will be thrown. |
| 1557 | * <p> |
| 1558 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1559 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1560 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1561 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1562 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1563 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1564 | * 0 means there is no restriction. |
| 1565 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1566 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1567 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1568 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1569 | if (mService != null) { |
| 1570 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1571 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1572 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1573 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1579 | * Retrieve the current number of letters required in the password |
| 1580 | * for a particular admin or all admins that set retrictions on this user |
| 1581 | * and its participating profiles. Restrictions on profiles that have |
| 1582 | * a separate challenge are not taken into account. |
| 1583 | * This is the same value as set by |
| 1584 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1585 | * and only applies when the password quality is |
| 1586 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1587 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1588 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1589 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1590 | * restrictions on the parent profile. |
| 1591 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1592 | * @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] | 1593 | * aggregate all admins. |
| 1594 | * @return The minimum number of letters required in the password. |
| 1595 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1596 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1597 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1601 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1602 | if (mService != null) { |
| 1603 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1604 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1605 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1606 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
| 1612 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1613 | * Called by an application that is administering the device to set the minimum number of |
| 1614 | * numerical digits required in the password. After setting this, the user will not be able to |
| 1615 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 1616 | * current password will remain until the user has set a new one, so the change does not take |
| 1617 | * place immediately. To prompt the user for a new password, use |
| 1618 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1619 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1620 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1621 | * <p> |
| 1622 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1623 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1624 | * not, a security exception will be thrown. |
| 1625 | * <p> |
| 1626 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1627 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1628 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1629 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1630 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1631 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 1632 | * value of 0 means there is no restriction. |
| 1633 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1634 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1635 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1636 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1637 | if (mService != null) { |
| 1638 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1639 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1640 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1641 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | /** |
| 1647 | * Retrieve the current number of numerical digits required in the password |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1648 | * for a particular admin or all admins that set retrictions on this user |
| 1649 | * and its participating profiles. Restrictions on profiles that have |
| 1650 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1651 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1652 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1653 | * and only applies when the password quality is |
| 1654 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1655 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1656 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1657 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1658 | * restrictions on the parent profile. |
| 1659 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1660 | * @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] | 1661 | * aggregate all admins. |
| 1662 | * @return The minimum number of numerical digits required in the password. |
| 1663 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1664 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1665 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1669 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1670 | if (mService != null) { |
| 1671 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1672 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1673 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1674 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
| 1680 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1681 | * Called by an application that is administering the device to set the minimum number of |
| 1682 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 1683 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1684 | * password will remain until the user has set a new one, so the change does not take place |
| 1685 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1686 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1687 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1688 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1689 | * <p> |
| 1690 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1691 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1692 | * not, a security exception will be thrown. |
| 1693 | * <p> |
| 1694 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1695 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1696 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1697 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1698 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1699 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 1700 | * 0 means there is no restriction. |
| 1701 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1702 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1703 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1704 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1705 | if (mService != null) { |
| 1706 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1707 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1708 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1709 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1715 | * Retrieve the current number of symbols required in the password |
| 1716 | * for a particular admin or all admins that set retrictions on this user |
| 1717 | * and its participating profiles. Restrictions on profiles that have |
| 1718 | * a separate challenge are not taken into account. This is the same value as |
| 1719 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1720 | * and only applies when the password quality is |
| 1721 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1722 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1723 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1724 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1725 | * restrictions on the parent profile. |
| 1726 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1727 | * @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] | 1728 | * aggregate all admins. |
| 1729 | * @return The minimum number of symbols required in the password. |
| 1730 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1731 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1732 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1736 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1737 | if (mService != null) { |
| 1738 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1739 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1740 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1741 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | return 0; |
| 1745 | } |
| 1746 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1747 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1748 | * Called by an application that is administering the device to set the minimum number of |
| 1749 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 1750 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 1751 | * as what has been set. Note that the current password will remain until the user has set a new |
| 1752 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 1753 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1754 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1755 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1756 | * <p> |
| 1757 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1758 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1759 | * not, a security exception will be thrown. |
| 1760 | * <p> |
| 1761 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1762 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1763 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1764 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1765 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1766 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1767 | * 0 means there is no restriction. |
| 1768 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1769 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1770 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1771 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1772 | if (mService != null) { |
| 1773 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1774 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1775 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1776 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1782 | * Retrieve the current number of non-letter characters required in the password |
| 1783 | * for a particular admin or all admins that set retrictions on this user |
| 1784 | * and its participating profiles. Restrictions on profiles that have |
| 1785 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1786 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1787 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1788 | * and only applies when the password quality is |
| 1789 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1790 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1791 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1792 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1793 | * restrictions on the parent profile. |
| 1794 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1795 | * @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] | 1796 | * aggregate all admins. |
| 1797 | * @return The minimum number of letters required in the password. |
| 1798 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1799 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1800 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1804 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1805 | if (mService != null) { |
| 1806 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1807 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1808 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1809 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1815 | /** |
| 1816 | * Called by an application that is administering the device to set the length of the password |
| 1817 | * history. After setting this, the user will not be able to enter a new password that is the |
| 1818 | * same as any password in the history. Note that the current password will remain until the |
| 1819 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 1820 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1821 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1822 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1823 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 1824 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 1825 | * <p> |
| 1826 | * The calling device admin must have requested |
| 1827 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1828 | * not, a security exception will be thrown. |
| 1829 | * <p> |
| 1830 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1831 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1832 | * profile. |
| 1833 | * |
| 1834 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1835 | * @param length The new desired length of password history. A value of 0 means there is no |
| 1836 | * restriction. |
| 1837 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1838 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 1839 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1840 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1841 | if (mService != null) { |
| 1842 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1843 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1844 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1845 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1846 | } |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1851 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 1852 | * restart the countdown for password expiration for the given admin, as will changing the |
| 1853 | * device password (for all admins). |
| 1854 | * <p> |
| 1855 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 1856 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 1857 | * 432000000 ms for timeout. |
| 1858 | * <p> |
| 1859 | * To disable password expiration, a value of 0 may be used for timeout. |
| 1860 | * <p> |
| 1861 | * The calling device admin must have requested |
| 1862 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 1863 | * not, a security exception will be thrown. |
| 1864 | * <p> |
| 1865 | * Note that setting the password will automatically reset the expiration time for all active |
| 1866 | * admins. Active admins do not need to explicitly call this method in that case. |
| 1867 | * <p> |
| 1868 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1869 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1870 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1871 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1872 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1873 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 1874 | * there is no restriction (unlimited). |
| 1875 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1876 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1877 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1878 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1879 | if (mService != null) { |
| 1880 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1881 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1882 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1883 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | |
| 1888 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1889 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1890 | * recurring expiration timeout provided in the call to |
| 1891 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1892 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 1893 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 1894 | * |
| 1895 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1896 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1897 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1898 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1899 | * @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] | 1900 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1901 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1902 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1903 | if (mService != null) { |
| 1904 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1905 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1906 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1907 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1908 | } |
| 1909 | } |
| 1910 | return 0; |
| 1911 | } |
| 1912 | |
| 1913 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1914 | * Get the current password expiration time for a particular admin or all admins that set |
| 1915 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 1916 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 1917 | * of all expiration times is returned - which will be the minimum of all of them. |
| 1918 | * |
| 1919 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1920 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1921 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1922 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1923 | * @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] | 1924 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1925 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1926 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1927 | if (mService != null) { |
| 1928 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1929 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1930 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1931 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | return 0; |
| 1935 | } |
| 1936 | |
| 1937 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1938 | * Retrieve the current password history length for a particular admin or all admins that |
| 1939 | * set retrictions on this user and its participating profiles. Restrictions on profiles that |
| 1940 | * have a separate challenge are not taken into account. |
| 1941 | * |
| 1942 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1943 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1944 | * restrictions on the parent profile. |
| 1945 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1946 | * @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] | 1947 | * all admins. |
| 1948 | * @return The length of the password history |
| 1949 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1950 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1951 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1955 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1956 | if (mService != null) { |
| 1957 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1958 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1959 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1960 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1966 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1967 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1968 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1969 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1970 | * @return Returns the maximum length that the user can enter. |
| 1971 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1972 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1973 | // Kind-of arbitrary. |
| 1974 | return 16; |
| 1975 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1976 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1977 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1978 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 1979 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 1980 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
| 1981 | * are not taken into account. |
| 1982 | * <p> |
| 1983 | * The calling device admin must have requested |
| 1984 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1985 | * not, a security exception will be thrown. |
| 1986 | * <p> |
| 1987 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1988 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 1989 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1990 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1991 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1992 | * @throws SecurityException if the calling application does not own an active administrator |
| 1993 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1994 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1995 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1996 | if (mService != null) { |
| 1997 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1998 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1999 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2000 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2001 | } |
| 2002 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2003 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2004 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2005 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2006 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2007 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2008 | * 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] | 2009 | * requested by the admins of the parent user and its profiles. |
| 2010 | * |
| 2011 | * @param userHandle the userId of the profile to check the password for. |
| 2012 | * @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] | 2013 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2014 | * @hide |
| 2015 | */ |
| 2016 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2017 | if (mService != null) { |
| 2018 | try { |
| 2019 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2020 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2021 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | return false; |
| 2025 | } |
| 2026 | |
| 2027 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2028 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2029 | * successful password entry. |
| 2030 | * <p> |
| 2031 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2032 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2033 | * password attemts for the parent user. |
| 2034 | * <p> |
| 2035 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2036 | * 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] | 2037 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2038 | * @return The number of times user has entered an incorrect password since the last correct |
| 2039 | * password entry. |
| 2040 | * @throws SecurityException if the calling application does not own an active administrator |
| 2041 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2042 | */ |
| 2043 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2044 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2045 | } |
| 2046 | |
| 2047 | /** |
| 2048 | * Retrieve the number of times the given user has failed at entering a |
| 2049 | * password since that last successful password entry. |
| 2050 | * |
| 2051 | * <p>The calling device admin must have requested |
| 2052 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2053 | * not and it is not the system uid, a security exception will be thrown. |
| 2054 | * |
| 2055 | * @hide |
| 2056 | */ |
| 2057 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2058 | if (mService != null) { |
| 2059 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2060 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2061 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2062 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | return -1; |
| 2066 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2067 | |
| 2068 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2069 | * 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] | 2070 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2071 | * @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] | 2072 | * @hide |
| 2073 | */ |
| 2074 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2075 | if (mService != null) { |
| 2076 | try { |
| 2077 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2078 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2079 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | return false; |
| 2083 | } |
| 2084 | |
| 2085 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2086 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2087 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2088 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2089 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2090 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2091 | * <p> |
| 2092 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2093 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2094 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2095 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2096 | * immediately, and your callback will not be invoked. |
| 2097 | * <p> |
| 2098 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2099 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2100 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2101 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2102 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2103 | * @param num The number of failed password attempts at which point the device or profile will |
| 2104 | * be wiped. |
| 2105 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2106 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2107 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2108 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2109 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2110 | if (mService != null) { |
| 2111 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2112 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2113 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2114 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2118 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2119 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2120 | * Retrieve the current maximum number of login attempts that are allowed before the device |
| 2121 | * or profile is wiped, for a particular admin or all admins that set retrictions on this user |
| 2122 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2123 | * not taken into account. |
| 2124 | * |
| 2125 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2126 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2127 | * the value for the parent profile. |
| 2128 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2129 | * @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] | 2130 | * all admins. |
| 2131 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2132 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2133 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2137 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2138 | if (mService != null) { |
| 2139 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2140 | return mService.getMaximumFailedPasswordsForWipe( |
| 2141 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2142 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2143 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2144 | } |
| 2145 | } |
| 2146 | return 0; |
| 2147 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2148 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2149 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2150 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2151 | * for the given user. So for primary user, it might return the primary or |
| 2152 | * a managed profile. For a secondary user, it would be the same as the |
| 2153 | * user passed in. |
| 2154 | * @hide Used only by Keyguard |
| 2155 | */ |
| 2156 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2157 | if (mService != null) { |
| 2158 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2159 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2160 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2161 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2162 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2163 | } |
| 2164 | } |
| 2165 | return UserHandle.USER_NULL; |
| 2166 | } |
| 2167 | |
| 2168 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2169 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2170 | * the password again until the user has entered it. |
| 2171 | */ |
| 2172 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2173 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2174 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2175 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2176 | * If the flag is set, the device can be booted without asking for user password. |
| 2177 | * The absence of this flag does not change the current boot requirements. This flag |
| 2178 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2179 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2180 | * device to factory defaults. |
| 2181 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2182 | 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] | 2183 | |
| 2184 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2185 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2186 | * individual accounts) on the user. This takes effect immediately. |
| 2187 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2188 | * <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] | 2189 | * device admins that are not device owner and not profile owner. |
| 2190 | * The password can now only be changed if there is currently no password set. Device owner |
| 2191 | * and profile owner can still do this.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2192 | * <p> |
| 2193 | * The given password must be sufficient for the current password quality and length constraints |
| 2194 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2195 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2196 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2197 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2198 | * case the currently active quality will be increased to match. |
| 2199 | * <p> |
| 2200 | * Calling with a null or empty password will clear any existing PIN, pattern or password if the |
Robin Lee | ce5c400 | 2016-03-23 17:05:03 +0000 | [diff] [blame] | 2201 | * current password constraints allow it. <em>Note: This will not work in |
| 2202 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2203 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2204 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2205 | * <p> |
| 2206 | * The calling device admin must have requested |
| 2207 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2208 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2209 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2210 | * @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] | 2211 | * @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] | 2212 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2213 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2214 | * current constraints or if the user has not been decrypted yet. |
| 2215 | * @throws SecurityException if the calling application does not own an active administrator |
| 2216 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2217 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2218 | public boolean resetPassword(String password, int flags) { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2219 | if (mParentInstance) { |
| 2220 | throw new SecurityException("Reset password does not work across profiles."); |
| 2221 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2222 | if (mService != null) { |
| 2223 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2224 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2225 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2226 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | return false; |
| 2230 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2231 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2232 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2233 | * Called by an application that is administering the device to set the maximum time for user |
| 2234 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2235 | * effect immediately. |
| 2236 | * <p> |
| 2237 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2238 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2239 | * <p> |
| 2240 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2241 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2242 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2243 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2244 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2245 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2246 | * is no restriction. |
| 2247 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2248 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2249 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2250 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2251 | if (mService != null) { |
| 2252 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2253 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2254 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2255 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2256 | } |
| 2257 | } |
| 2258 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2259 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2260 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2261 | * Retrieve the current maximum time to unlock for a particular admin or all admins that set |
| 2262 | * retrictions on this user and its participating profiles. Restrictions on profiles that have |
| 2263 | * a separate challenge are not taken into account. |
| 2264 | * |
| 2265 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2266 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2267 | * restrictions on the parent profile. |
| 2268 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2269 | * @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] | 2270 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2271 | * @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] | 2272 | * 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] | 2273 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2274 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2275 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2279 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2280 | if (mService != null) { |
| 2281 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2282 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2283 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2284 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | return 0; |
| 2288 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2289 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2290 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame^] | 2291 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2292 | * do not have a separate timeout to lock for work challenge only. |
| 2293 | * |
| 2294 | * @hide |
| 2295 | */ |
| 2296 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2297 | if (mService != null) { |
| 2298 | try { |
| 2299 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2300 | } catch (RemoteException e) { |
| 2301 | throw e.rethrowFromSystemServer(); |
| 2302 | } |
| 2303 | } |
| 2304 | return 0; |
| 2305 | } |
| 2306 | |
| 2307 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2308 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2309 | * this call. |
| 2310 | * <p> |
| 2311 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2312 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2313 | * <p> |
| 2314 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2315 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2316 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2317 | * @throws SecurityException if the calling application does not own an active administrator |
| 2318 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2319 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2320 | public void lockNow() { |
| 2321 | if (mService != null) { |
| 2322 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2323 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2324 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2325 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2326 | } |
| 2327 | } |
| 2328 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2329 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2330 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2331 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2332 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2333 | */ |
| 2334 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2335 | |
| 2336 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2337 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2338 | * data. |
| 2339 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2340 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2341 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2342 | */ |
| 2343 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2344 | |
| 2345 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2346 | * Ask the user data be wiped. Wiping the primary user will cause the device to reboot, erasing |
| 2347 | * all user data while next booting up. |
| 2348 | * <p> |
| 2349 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2350 | * 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] | 2351 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2352 | * @param flags Bit mask of additional options: currently supported flags are |
| 2353 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2354 | * @throws SecurityException if the calling application does not own an active administrator |
| 2355 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2356 | */ |
| 2357 | public void wipeData(int flags) { |
| 2358 | if (mService != null) { |
| 2359 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2360 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2361 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2362 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2366 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2367 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2368 | * Called by an application that is administering the device to set the |
| 2369 | * global proxy and exclusion list. |
| 2370 | * <p> |
| 2371 | * The calling device admin must have requested |
| 2372 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2373 | * this method; if it has not, a security exception will be thrown. |
| 2374 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2375 | * 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] | 2376 | * 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] | 2377 | * be returned. |
| 2378 | * The method can be called repeatedly by the device admin alrady setting the |
| 2379 | * proxy to update the proxy and exclusion list. |
| 2380 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2381 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2382 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2383 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2384 | * @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] | 2385 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2386 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2387 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2388 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2389 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2390 | List<String> exclusionList ) { |
| 2391 | if (proxySpec == null) { |
| 2392 | throw new NullPointerException(); |
| 2393 | } |
| 2394 | if (mService != null) { |
| 2395 | try { |
| 2396 | String hostSpec; |
| 2397 | String exclSpec; |
| 2398 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2399 | hostSpec = null; |
| 2400 | exclSpec = null; |
| 2401 | } else { |
| 2402 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2403 | throw new IllegalArgumentException(); |
| 2404 | } |
| 2405 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2406 | String hostName = sa.getHostName(); |
| 2407 | int port = sa.getPort(); |
| 2408 | StringBuilder hostBuilder = new StringBuilder(); |
| 2409 | hostSpec = hostBuilder.append(hostName) |
| 2410 | .append(":").append(Integer.toString(port)).toString(); |
| 2411 | if (exclusionList == null) { |
| 2412 | exclSpec = ""; |
| 2413 | } else { |
| 2414 | StringBuilder listBuilder = new StringBuilder(); |
| 2415 | boolean firstDomain = true; |
| 2416 | for (String exclDomain : exclusionList) { |
| 2417 | if (!firstDomain) { |
| 2418 | listBuilder = listBuilder.append(","); |
| 2419 | } else { |
| 2420 | firstDomain = false; |
| 2421 | } |
| 2422 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2423 | } |
| 2424 | exclSpec = listBuilder.toString(); |
| 2425 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2426 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2427 | != android.net.Proxy.PROXY_VALID) |
| 2428 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2429 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2430 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2431 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2432 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | return null; |
| 2436 | } |
| 2437 | |
| 2438 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2439 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 2440 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 2441 | * unusual like general internal filtering this may be useful. On a private network where the |
| 2442 | * proxy is not accessible, you may break HTTP using this. |
| 2443 | * <p> |
| 2444 | * This method requires the caller to be the device owner. |
| 2445 | * <p> |
| 2446 | * 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] | 2447 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2448 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2449 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2450 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 2451 | * {@code null} value will clear the global HTTP proxy. |
| 2452 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2453 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2454 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2455 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2456 | if (mService != null) { |
| 2457 | try { |
| 2458 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2459 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2460 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2466 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2467 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2468 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2469 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2470 | */ |
| 2471 | public ComponentName getGlobalProxyAdmin() { |
| 2472 | if (mService != null) { |
| 2473 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2474 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2475 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2476 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | return null; |
| 2480 | } |
| 2481 | |
| 2482 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2483 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2484 | * indicating that encryption is not supported. |
| 2485 | */ |
| 2486 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2487 | |
| 2488 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2489 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2490 | * indicating that encryption is supported, but is not currently active. |
| 2491 | */ |
| 2492 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2493 | |
| 2494 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2495 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2496 | * indicating that encryption is not currently active, but is currently |
| 2497 | * being activated. This is only reported by devices that support |
| 2498 | * encryption of data and only when the storage is currently |
| 2499 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2500 | * to become encrypted will never return this value. |
| 2501 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2502 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2503 | |
| 2504 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2505 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2506 | * indicating that encryption is active. |
| 2507 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2508 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2509 | |
| 2510 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2511 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2512 | * indicating that encryption is active, but an encryption key has not |
| 2513 | * been set by the user. |
| 2514 | */ |
| 2515 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2516 | |
| 2517 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2518 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2519 | * indicating that encryption is active and the encryption key is tied to the user. |
| 2520 | */ |
| 2521 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 2522 | |
| 2523 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2524 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2525 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2526 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2527 | * to check encryption status. However, on some devices this activity may never return, as |
| 2528 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2529 | */ |
| 2530 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2531 | public static final String ACTION_START_ENCRYPTION |
| 2532 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2533 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2534 | * Widgets are enabled in keyguard |
| 2535 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2536 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2537 | |
| 2538 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2539 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2540 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2541 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2542 | |
| 2543 | /** |
| 2544 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2545 | */ |
| 2546 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2547 | |
| 2548 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2549 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2550 | */ |
| 2551 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2552 | |
| 2553 | /** |
| 2554 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2555 | */ |
| 2556 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2557 | |
| 2558 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2559 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2560 | * (e.g. PIN/Pattern/Password). |
| 2561 | */ |
| 2562 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2563 | |
| 2564 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2565 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2566 | */ |
| 2567 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2568 | |
| 2569 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2570 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2571 | */ |
| 2572 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2573 | |
| 2574 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2575 | * Called by an application that is administering the device to request that the storage system |
| 2576 | * be encrypted. |
| 2577 | * <p> |
| 2578 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 2579 | * supported setting will always be used. If any device administrator requests device |
| 2580 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 2581 | * 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] | 2582 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2583 | * <p> |
| 2584 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 2585 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 2586 | * control the encryption of any other storage areas. There is one exception: If |
| 2587 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 2588 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 2589 | * written to disk within the encrypted storage area. |
| 2590 | * <p> |
| 2591 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 2592 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 2593 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 2594 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2595 | * |
| 2596 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2597 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2598 | * @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] | 2599 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2600 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2601 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 2602 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2603 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2604 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2605 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2606 | if (mService != null) { |
| 2607 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2608 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2609 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2610 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2611 | } |
| 2612 | } |
| 2613 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2614 | } |
| 2615 | |
| 2616 | /** |
| 2617 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2618 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2619 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2620 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2621 | * this will return the requested encryption setting as an aggregate of all active |
| 2622 | * administrators. |
| 2623 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2624 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2625 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2626 | if (mService != null) { |
| 2627 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2628 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2629 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2630 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2631 | } |
| 2632 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2633 | return false; |
| 2634 | } |
| 2635 | |
| 2636 | /** |
| 2637 | * Called by an application that is administering the device to |
| 2638 | * determine the current encryption status of the device. |
| 2639 | * |
| 2640 | * Depending on the returned status code, the caller may proceed in different |
| 2641 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2642 | * storage system does not support encryption. If the |
| 2643 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2644 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2645 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2646 | * storage system has enabled encryption but no password is set so further action |
| 2647 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2648 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2649 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2650 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2651 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2652 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2653 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2654 | */ |
| 2655 | public int getStorageEncryptionStatus() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2656 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | /** @hide per-user version */ |
| 2660 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2661 | if (mService != null) { |
| 2662 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2663 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2664 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2665 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2666 | } |
| 2667 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2668 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2669 | } |
| 2670 | |
| 2671 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 2672 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 2673 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 2674 | * keep the certificate on the device. |
| 2675 | * |
| 2676 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 2677 | * this certificate. |
| 2678 | * |
| 2679 | * @hide |
| 2680 | */ |
| 2681 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 2682 | if (mService != null) { |
| 2683 | try { |
| 2684 | return mService.approveCaCert(alias, userHandle, approval); |
| 2685 | } catch (RemoteException e) { |
| 2686 | throw e.rethrowFromSystemServer(); |
| 2687 | } |
| 2688 | } |
| 2689 | return false; |
| 2690 | } |
| 2691 | |
| 2692 | /** |
| 2693 | * Check whether a CA certificate has been approved by the device user. |
| 2694 | * |
| 2695 | * @hide |
| 2696 | */ |
| 2697 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 2698 | if (mService != null) { |
| 2699 | try { |
| 2700 | return mService.isCaCertApproved(alias, userHandle); |
| 2701 | } catch (RemoteException e) { |
| 2702 | throw e.rethrowFromSystemServer(); |
| 2703 | } |
| 2704 | } |
| 2705 | return false; |
| 2706 | } |
| 2707 | |
| 2708 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2709 | * Installs the given certificate as a user CA. |
| 2710 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2711 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2712 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2713 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2714 | * |
| 2715 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2716 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2717 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2718 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2719 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2720 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2721 | if (mService != null) { |
| 2722 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2723 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2724 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2725 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | return false; |
| 2729 | } |
| 2730 | |
| 2731 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2732 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2733 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2734 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2735 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2736 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2737 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2738 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2739 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2740 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2741 | if (mService != null) { |
| 2742 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2743 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2744 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2745 | } catch (CertificateException e) { |
| 2746 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2747 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2748 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2754 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2755 | * If a user has installed any certificates by other means than device policy these will be |
| 2756 | * included too. |
| 2757 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2758 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2759 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2760 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2761 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2762 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2763 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2764 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2765 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2766 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2767 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2768 | mService.enforceCanManageCaCerts(admin); |
| 2769 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2770 | for (String alias : certStore.userAliases()) { |
| 2771 | try { |
| 2772 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2773 | } catch (CertificateException ce) { |
| 2774 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2775 | } |
| 2776 | } |
| 2777 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2778 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2779 | } |
| 2780 | } |
| 2781 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2785 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2786 | * means other than device policy will also be removed, except for system CA certificates. |
| 2787 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2788 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2789 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2790 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2791 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2792 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2793 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2794 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2795 | try { |
| 2796 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2797 | .toArray(new String[0])); |
| 2798 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2799 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | /** |
| 2805 | * Returns whether this certificate is installed as a trusted CA. |
| 2806 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2807 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2808 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2809 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2810 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2811 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2812 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2813 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2814 | if (mService != null) { |
| 2815 | try { |
| 2816 | mService.enforceCanManageCaCerts(admin); |
| 2817 | return getCaCertAlias(certBuffer) != null; |
| 2818 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2819 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2820 | } catch (CertificateException ce) { |
| 2821 | Log.w(TAG, "Could not parse certificate", ce); |
| 2822 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2823 | } |
| 2824 | return false; |
| 2825 | } |
| 2826 | |
| 2827 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2828 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 2829 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 2830 | * the certificate and use the private key, given direct user approval. |
| 2831 | * |
| 2832 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 2833 | * direct user approval. This is for security - should a certificate installer become |
| 2834 | * compromised, certificates it had already installed will be protected. |
| 2835 | * |
| 2836 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2837 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2838 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2839 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2840 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2841 | * @param privKey The private key to install. |
| 2842 | * @param cert The certificate to install. |
| 2843 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2844 | * with that alias already exists, it will be overwritten. |
| 2845 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2846 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2847 | * owner. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2848 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2849 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 2850 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2851 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | /** |
| 2855 | * Called by a device or profile owner, or delegated certificate installer, to install a |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2856 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 2857 | * profile will be able to access the certificate chain and use the private key, given direct |
| 2858 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2859 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2860 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 2861 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 2862 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2863 | * |
| 2864 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2865 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2866 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2867 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 2868 | * certificate and include the chain of trust in order. This will be returned by |
| 2869 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2870 | * @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] | 2871 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2872 | * @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] | 2873 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 2874 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2875 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2876 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2877 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2878 | * @see android.security.KeyChain#getCertificateChain |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 2879 | */ |
| 2880 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2881 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2882 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2883 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 2884 | byte[] pemChain = null; |
| 2885 | if (certs.length > 1) { |
| 2886 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 2887 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2888 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2889 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 2890 | return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias, |
| 2891 | requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2892 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2893 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2894 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2895 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2896 | } catch (CertificateException | IOException e) { |
| 2897 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2898 | } |
| 2899 | return false; |
| 2900 | } |
| 2901 | |
| 2902 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2903 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 2904 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2905 | * |
| 2906 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2907 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2908 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 2909 | * @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] | 2910 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 2911 | * owner. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2912 | */ |
| 2913 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
| 2914 | try { |
| 2915 | return mService.removeKeyPair(admin, alias); |
| 2916 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2917 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2918 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2922 | * @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] | 2923 | * doesn't exist. |
| 2924 | */ |
| 2925 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2926 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2927 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2928 | new ByteArrayInputStream(certBuffer)); |
| 2929 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2930 | } |
| 2931 | |
| 2932 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2933 | * 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] | 2934 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2935 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2936 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2937 | * <p> |
| 2938 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2939 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2940 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2941 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 2942 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 2943 | * 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] | 2944 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 2945 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2946 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2947 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2948 | * @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] | 2949 | * access. If {@code null} is given the current package will be cleared. |
| 2950 | * @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] | 2951 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2952 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2953 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2954 | if (mService != null) { |
| 2955 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2956 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2957 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2958 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2959 | } |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2964 | * Called by a profile owner or device owner to retrieve the certificate installer for the user. |
| 2965 | * null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2966 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2967 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2968 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 2969 | * none is set. |
| 2970 | * @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] | 2971 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2972 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2973 | if (mService != null) { |
| 2974 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2975 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2976 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2977 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2978 | } |
| 2979 | } |
| 2980 | return null; |
| 2981 | } |
| 2982 | |
| 2983 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2984 | * 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] | 2985 | * specific application for the current user. This connection is automatically granted and |
| 2986 | * persisted after a reboot. |
| 2987 | * <p> |
| 2988 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 2989 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 2990 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 2991 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2992 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to |
| 2993 | * remove an existing always-on VPN configuration. |
| 2994 | * @return {@code true} if the package is set as always-on VPN controller; {@code false} |
| 2995 | * otherwise. |
| 2996 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 2997 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 2998 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 2999 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3000 | */ |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3001 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3002 | throws NameNotFoundException, UnsupportedOperationException { |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3003 | if (mService != null) { |
| 3004 | try { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3005 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage)) { |
| 3006 | throw new NameNotFoundException(vpnPackage); |
| 3007 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3008 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3009 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3010 | } |
| 3011 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | /** |
| 3015 | * 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] | 3016 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3017 | * 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] | 3018 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3019 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3020 | * is set. |
| 3021 | * @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] | 3022 | */ |
| 3023 | public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
| 3024 | if (mService != null) { |
| 3025 | try { |
| 3026 | return mService.getAlwaysOnVpnPackage(admin); |
| 3027 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3028 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3029 | } |
| 3030 | } |
| 3031 | return null; |
| 3032 | } |
| 3033 | |
| 3034 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3035 | * Called by an application that is administering the device to disable all cameras on the |
| 3036 | * device, for this user. After setting this, no applications running as this user will be able |
| 3037 | * to access any cameras on the device. |
| 3038 | * <p> |
| 3039 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3040 | * <p> |
| 3041 | * The calling device admin must have requested |
| 3042 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3043 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3044 | * |
| 3045 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3046 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3047 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3048 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3049 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3050 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3051 | if (mService != null) { |
| 3052 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3053 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3054 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3055 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3056 | } |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3061 | * 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] | 3062 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3063 | * @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] | 3064 | * have disabled the camera |
| 3065 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3066 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3067 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3071 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3072 | if (mService != null) { |
| 3073 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3074 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3075 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3076 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | return false; |
| 3080 | } |
| 3081 | |
| 3082 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3083 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3084 | * <p> |
| 3085 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 3086 | * {@link SecurityException} will be thrown. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3087 | * |
| 3088 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3089 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3090 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3091 | * bugreport is still running or waiting for the user to share or decline) |
| 3092 | * @throws SecurityException if {@code admin} is not a device owner, or if there are users other |
| 3093 | * than the one managed by the device owner. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3094 | */ |
| 3095 | public boolean requestBugreport(@NonNull ComponentName admin) { |
| 3096 | if (mService != null) { |
| 3097 | try { |
| 3098 | return mService.requestBugreport(admin); |
| 3099 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3100 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3101 | } |
| 3102 | } |
| 3103 | return false; |
| 3104 | } |
| 3105 | |
| 3106 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3107 | * Determine whether or not creating a guest user has been disabled for the device |
| 3108 | * |
| 3109 | * @hide |
| 3110 | */ |
| 3111 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3112 | // Currently guest users can always be created if multi-user is enabled |
| 3113 | // TODO introduce a policy for guest user creation |
| 3114 | return false; |
| 3115 | } |
| 3116 | |
| 3117 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3118 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3119 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3120 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3121 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3122 | * <p> |
| 3123 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3124 | * exception will be thrown. |
| 3125 | * <p> |
| 3126 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3127 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3128 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3129 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3130 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3131 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3132 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3133 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3134 | if (mService != null) { |
| 3135 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3136 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3137 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3138 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3139 | } |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3144 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3145 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3146 | * @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] | 3147 | * have disabled screen capture. |
| 3148 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3149 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3150 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3154 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3155 | if (mService != null) { |
| 3156 | try { |
| 3157 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3158 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3159 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3160 | } |
| 3161 | } |
| 3162 | return false; |
| 3163 | } |
| 3164 | |
| 3165 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3166 | * Called by a device owner to set whether auto time is required. If auto time is required the |
| 3167 | * user cannot set the date and time, but has to use network date and time. |
| 3168 | * <p> |
| 3169 | * Note: if auto time is required the user can still manually set the time zone. |
| 3170 | * <p> |
| 3171 | * The calling device admin must be a device owner. If it is not, a security exception will be |
| 3172 | * thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3173 | * |
| 3174 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3175 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3176 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3177 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3178 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3179 | if (mService != null) { |
| 3180 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3181 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3182 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3183 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | /** |
| 3189 | * @return true if auto time is required. |
| 3190 | */ |
| 3191 | public boolean getAutoTimeRequired() { |
| 3192 | if (mService != null) { |
| 3193 | try { |
| 3194 | return mService.getAutoTimeRequired(); |
| 3195 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3196 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | return false; |
| 3200 | } |
| 3201 | |
| 3202 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3203 | * 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] | 3204 | * <p> |
| 3205 | * The system user is exempt from this policy - it is never ephemeral. |
| 3206 | * <p> |
| 3207 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 3208 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3209 | * |
| 3210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3211 | * @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] | 3212 | * subsequently created users will be ephemeral. |
| 3213 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3214 | * @hide |
| 3215 | */ |
| 3216 | public void setForceEphemeralUsers( |
| 3217 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
| 3218 | if (mService != null) { |
| 3219 | try { |
| 3220 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3221 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3222 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | /** |
| 3228 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3229 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3230 | * @hide |
| 3231 | */ |
| 3232 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
| 3233 | if (mService != null) { |
| 3234 | try { |
| 3235 | return mService.getForceEphemeralUsers(admin); |
| 3236 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3237 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | return false; |
| 3241 | } |
| 3242 | |
| 3243 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3244 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3245 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3246 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3247 | * <p> |
| 3248 | * The calling device admin must have requested |
| 3249 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 3250 | * if it has not, a security exception will be thrown. |
| 3251 | * <p> |
| 3252 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 3253 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 3254 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3255 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3256 | * <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] | 3257 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3258 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3259 | * there is one, or the parent user otherwise. |
| 3260 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 3261 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3262 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3263 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3264 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3265 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3266 | * profile. |
| 3267 | * <p> |
| 3268 | * Requests to disable other features on a managed profile will be ignored. |
| 3269 | * <p> |
| 3270 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3271 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3272 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3273 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3274 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3275 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 3276 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 3277 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 3278 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 3279 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 3280 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 3281 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3282 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3283 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3284 | if (mService != null) { |
| 3285 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3286 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3287 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3288 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | |
| 3293 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3294 | * 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] | 3295 | * admin, if specified, or all admins that set retrictions on this user and its participating |
| 3296 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3297 | * |
| 3298 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3299 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3300 | * restrictions on the parent profile. |
| 3301 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3302 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3303 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3304 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3305 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3306 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3307 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3308 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3312 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3313 | if (mService != null) { |
| 3314 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3315 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3316 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3317 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3318 | } |
| 3319 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3320 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3324 | * @hide |
| 3325 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3326 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3327 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3328 | if (mService != null) { |
| 3329 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3330 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3331 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3332 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3333 | } |
| 3334 | } |
| 3335 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3336 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3337 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3338 | * @hide |
| 3339 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3340 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3341 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3345 | * @hide |
| 3346 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3347 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3348 | if (mService != null) { |
| 3349 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3350 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -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 | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | /** |
| 3358 | * @hide |
| 3359 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3360 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3361 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3362 | if (mService != null) { |
| 3363 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 3364 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3365 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3366 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3367 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3368 | } |
| 3369 | } |
| 3370 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3371 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3372 | /** |
| 3373 | * @hide |
| 3374 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3375 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3376 | if (mService != null) { |
| 3377 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3378 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3379 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3380 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3381 | } |
| 3382 | } |
| 3383 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3384 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3385 | /** |
| 3386 | * @hide |
| 3387 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3388 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3389 | if (mService != null) { |
| 3390 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3391 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3392 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3393 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3394 | } |
| 3395 | } |
| 3396 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3397 | |
| 3398 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3399 | * @hide |
| 3400 | */ |
| 3401 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3402 | if (mService != null) { |
| 3403 | try { |
| 3404 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3405 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3406 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | /** |
| 3412 | * @hide |
| 3413 | */ |
| 3414 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3415 | if (mService != null) { |
| 3416 | try { |
| 3417 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3418 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3419 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3420 | } |
| 3421 | } |
| 3422 | } |
| 3423 | |
| 3424 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3425 | * Should be called when keyguard has been dismissed. |
| 3426 | * @hide |
| 3427 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3428 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3429 | if (mService != null) { |
| 3430 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3431 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3432 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3433 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | /** |
| 3439 | * Should be called when keyguard view has been shown to the user. |
| 3440 | * @hide |
| 3441 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3442 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3443 | if (mService != null) { |
| 3444 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3445 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3446 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3447 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3448 | } |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3453 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3454 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3455 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3456 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3457 | * @return whether the package was successfully registered as the device owner. |
| 3458 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3459 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3460 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3461 | public boolean setDeviceOwner(ComponentName who) { |
| 3462 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | /** |
| 3466 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3467 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3468 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3469 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | /** |
| 3473 | * @hide |
| 3474 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3475 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3476 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | /** |
| 3480 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3481 | * Sets the given package as the device owner. The package must already be installed. There |
| 3482 | * must not already be a device owner. |
| 3483 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3484 | * this method. |
| 3485 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3486 | * 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] | 3487 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3488 | * @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] | 3489 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3490 | * @return whether the package was successfully registered as the device owner. |
| 3491 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3492 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3493 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3494 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3495 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3496 | if (mService != null) { |
| 3497 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3498 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3499 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3500 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3501 | } |
| 3502 | } |
| 3503 | return false; |
| 3504 | } |
| 3505 | |
| 3506 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3507 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3508 | * 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] | 3509 | * 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] | 3510 | * package is currently registered as the device owner app, pass in the package name from |
| 3511 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3512 | * 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] | 3513 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3514 | * the setup process. |
| 3515 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3516 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3517 | * @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] | 3518 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3519 | public boolean isDeviceOwnerApp(String packageName) { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3520 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3521 | } |
| 3522 | |
| 3523 | /** |
| 3524 | * @return true if a package is registered as device owner, only when it's running on the |
| 3525 | * calling user. |
| 3526 | * |
| 3527 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3528 | * @hide |
| 3529 | */ |
| 3530 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3531 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3532 | } |
| 3533 | |
| 3534 | /** |
| 3535 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3536 | * user. |
| 3537 | * |
| 3538 | * <p>Requires the MANAGE_USERS permission. |
| 3539 | * |
| 3540 | * @hide |
| 3541 | */ |
| 3542 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3543 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3544 | } |
| 3545 | |
| 3546 | /** |
| 3547 | * @return device owner component name, only when it's running on the calling user. |
| 3548 | * |
| 3549 | * @hide |
| 3550 | */ |
| 3551 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3552 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3553 | } |
| 3554 | |
| 3555 | /** |
| 3556 | * @return device owner component name, even if it's running on a different user. |
| 3557 | * |
| 3558 | * <p>Requires the MANAGE_USERS permission. |
| 3559 | * |
| 3560 | * @hide |
| 3561 | */ |
| 3562 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3563 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3564 | } |
| 3565 | |
| 3566 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3567 | if (packageName == null) { |
| 3568 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3569 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3570 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3571 | if (deviceOwner == null) { |
| 3572 | return false; |
| 3573 | } |
| 3574 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3577 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3578 | if (mService != null) { |
| 3579 | try { |
| 3580 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3581 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3582 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3588 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3589 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3590 | * no device owner. |
| 3591 | * |
| 3592 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3593 | * |
| 3594 | * @hide |
| 3595 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3596 | public int getDeviceOwnerUserId() { |
| 3597 | if (mService != null) { |
| 3598 | try { |
| 3599 | return mService.getDeviceOwnerUserId(); |
| 3600 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3601 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3602 | } |
| 3603 | } |
| 3604 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3608 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 3609 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 3610 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3611 | * |
| 3612 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3613 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 3614 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3615 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3616 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3617 | if (mService != null) { |
| 3618 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 3619 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3620 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3621 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | } |
| 3625 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3626 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3627 | * Returns the device owner package name, only if it's running on the calling user. |
| 3628 | * |
| 3629 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3630 | * |
| 3631 | * @hide |
| 3632 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3633 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3634 | public String getDeviceOwner() { |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3635 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 3636 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3640 | * @return true if the device is managed by any device owner. |
| 3641 | * |
| 3642 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3643 | * |
| 3644 | * @hide |
| 3645 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3646 | public boolean isDeviceManaged() { |
| 3647 | return getDeviceOwnerComponentOnAnyUser() != null; |
| 3648 | } |
| 3649 | |
| 3650 | /** |
| 3651 | * Returns the device owner name. Note this method *will* return the device owner |
| 3652 | * name when it's running on a different user. |
| 3653 | * |
| 3654 | * <p>Requires the MANAGE_USERS permission. |
| 3655 | * |
| 3656 | * @hide |
| 3657 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 3658 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3659 | public String getDeviceOwnerNameOnAnyUser() { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3660 | if (mService != null) { |
| 3661 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3662 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3663 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3664 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3665 | } |
| 3666 | } |
| 3667 | return null; |
| 3668 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3669 | |
| 3670 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 3671 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3672 | * @deprecated Do not use |
| 3673 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3674 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3675 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3676 | @SystemApi |
| 3677 | public String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3678 | return null; |
| 3679 | } |
| 3680 | |
| 3681 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3682 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3683 | * @deprecated Do not use |
| 3684 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3685 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 3686 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3687 | @SystemApi |
| 3688 | public ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 3689 | return null; |
| 3690 | } |
| 3691 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3692 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3693 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3694 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3695 | * Sets the given component as an active admin and registers the package as the profile |
| 3696 | * owner for this user. The package must already be installed and there shouldn't be |
| 3697 | * an existing profile owner registered for this user. Also, this method must be called |
| 3698 | * before the user setup has been completed. |
| 3699 | * <p> |
| 3700 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 3701 | * MANAGE_DEVICE_ADMINS permission. |
| 3702 | * @param admin The component to register as an active admin and profile owner. |
| 3703 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 3704 | * @return whether the admin was successfully registered as the profile owner. |
| 3705 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 3706 | * the user has already been set up. |
| 3707 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 3708 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3709 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3710 | throws IllegalArgumentException { |
| 3711 | if (mService != null) { |
| 3712 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3713 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3714 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3715 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3716 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3717 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 3718 | } |
| 3719 | } |
| 3720 | return false; |
| 3721 | } |
| 3722 | |
| 3723 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3724 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 3725 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 3726 | * will be thrown. |
| 3727 | * <p> |
| 3728 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 3729 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3730 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3731 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3732 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3733 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3734 | if (mService != null) { |
| 3735 | try { |
| 3736 | mService.clearProfileOwner(admin); |
| 3737 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3738 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3739 | } |
| 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3744 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3745 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3746 | */ |
| 3747 | public boolean hasUserSetupCompleted() { |
| 3748 | if (mService != null) { |
| 3749 | try { |
| 3750 | return mService.hasUserSetupCompleted(); |
| 3751 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3752 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3753 | } |
| 3754 | } |
| 3755 | return true; |
| 3756 | } |
| 3757 | |
| 3758 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3759 | * @hide |
| 3760 | * 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] | 3761 | * already be installed. There must not already be a profile owner for this user. |
| 3762 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3763 | * this method. |
| 3764 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 3765 | * - the caller is SYSTEM_UID. |
| 3766 | * - 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] | 3767 | * @param admin the component name to be registered as profile owner. |
| 3768 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3769 | * @param userHandle the userId to set the profile owner for. |
| 3770 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3771 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 3772 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3773 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3774 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 3775 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3776 | if (mService != null) { |
| 3777 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3778 | if (ownerName == null) { |
| 3779 | ownerName = ""; |
| 3780 | } |
| 3781 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3782 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3783 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | return false; |
| 3787 | } |
| 3788 | |
| 3789 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3790 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3791 | * <p> |
| 3792 | * 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] | 3793 | * 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] | 3794 | * <p> |
| 3795 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 3796 | * will be blank and the user will not be allowed to change it. |
| 3797 | * <p> |
| 3798 | * 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] | 3799 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 3800 | * and set a new version of this string accordingly. |
| 3801 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3802 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3803 | * @param info Device owner information which will be displayed instead of the user owner info. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3804 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3805 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3806 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3807 | if (mService != null) { |
| 3808 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3809 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3810 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3811 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3812 | } |
| 3813 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | /** |
| 3817 | * @return The device owner information. If it is not set returns {@code null}. |
| 3818 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 3819 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3820 | if (mService != null) { |
| 3821 | try { |
| 3822 | return mService.getDeviceOwnerLockScreenInfo(); |
| 3823 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3824 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 3825 | } |
| 3826 | } |
| 3827 | return null; |
| 3828 | } |
| 3829 | |
| 3830 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3831 | * Called by device or profile owners to suspend packages for this user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3832 | * <p> |
| 3833 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 3834 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 3835 | * device. |
| 3836 | * <p> |
| 3837 | * The package must already be installed. If the package is uninstalled while suspended the |
| 3838 | * 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] | 3839 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3840 | * |
| 3841 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3842 | * @param packageNames The package names to suspend or unsuspend. |
| 3843 | * @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] | 3844 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3845 | * @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] | 3846 | * this method. |
| 3847 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3848 | */ |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3849 | public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames, |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3850 | boolean suspended) { |
| 3851 | if (mService != null) { |
| 3852 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3853 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3854 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3855 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3856 | } |
| 3857 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 3858 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | /** |
| 3862 | * Called by device or profile owners to determine if a package is suspended. |
| 3863 | * |
| 3864 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3865 | * @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] | 3866 | * @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] | 3867 | * suspended, could not be found or an error occurred. |
| 3868 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 3869 | * @throws NameNotFoundException if the package could not be found. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3870 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 3871 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 3872 | throws NameNotFoundException { |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3873 | if (mService != null) { |
| 3874 | try { |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 3875 | return mService.isPackageSuspended(admin, packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3876 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3877 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 3878 | } catch (IllegalArgumentException ex) { |
| 3879 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | return false; |
| 3883 | } |
| 3884 | |
| 3885 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3886 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 3887 | * be used. Only the profile owner can call this. |
| 3888 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 3889 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3890 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3891 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3892 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3893 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3894 | if (mService != null) { |
| 3895 | try { |
| 3896 | mService.setProfileEnabled(admin); |
| 3897 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3898 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 3899 | } |
| 3900 | } |
| 3901 | } |
| 3902 | |
| 3903 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3904 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 3905 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 3906 | * 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] | 3907 | * |
| 3908 | * @see #isProfileOwnerApp |
| 3909 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3910 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3911 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3912 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3913 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3914 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3915 | if (mService != null) { |
| 3916 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3917 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3918 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3919 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3920 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3921 | } |
| 3922 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3923 | |
| 3924 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3925 | * 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] | 3926 | * 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] | 3927 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3928 | * |
| 3929 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3930 | * @return Whether or not the package is registered as the profile owner. |
| 3931 | */ |
| 3932 | public boolean isProfileOwnerApp(String packageName) { |
| 3933 | if (mService != null) { |
| 3934 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 3935 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3936 | return profileOwner != null |
| 3937 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3938 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3939 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | return false; |
| 3943 | } |
| 3944 | |
| 3945 | /** |
| 3946 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3947 | * @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] | 3948 | * owner has been set for that user. |
| 3949 | * @throws IllegalArgumentException if the userId is invalid. |
| 3950 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3951 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3952 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3953 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3954 | } |
| 3955 | |
| 3956 | /** |
| 3957 | * @see #getProfileOwner() |
| 3958 | * @hide |
| 3959 | */ |
| 3960 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3961 | if (mService != null) { |
| 3962 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3963 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3964 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3965 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3966 | } |
| 3967 | } |
| 3968 | return null; |
| 3969 | } |
| 3970 | |
| 3971 | /** |
| 3972 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3973 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3974 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3975 | * @throws IllegalArgumentException if the userId is invalid. |
| 3976 | */ |
| 3977 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3978 | if (mService != null) { |
| 3979 | try { |
| 3980 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3981 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3982 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | return null; |
| 3986 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3987 | |
| 3988 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3989 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3990 | * @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] | 3991 | * @return the human readable name of the organisation associated with this profile owner or |
| 3992 | * null if one is not set. |
| 3993 | * @throws IllegalArgumentException if the userId is invalid. |
| 3994 | */ |
| 3995 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3996 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3997 | if (mService != null) { |
| 3998 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3999 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4000 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4001 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4002 | } |
| 4003 | } |
| 4004 | return null; |
| 4005 | } |
| 4006 | |
| 4007 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4008 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 4009 | * 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] | 4010 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 4011 | * intent preferences are reset. |
| 4012 | * <p> |
| 4013 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 4014 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 4015 | * the filter. |
| 4016 | * <p> |
| 4017 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 4018 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4019 | * |
| 4020 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4021 | * @param filter The IntentFilter for which a default handler is added. |
| 4022 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4023 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4024 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4025 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 4026 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4027 | if (mService != null) { |
| 4028 | try { |
| 4029 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4030 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4031 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4032 | } |
| 4033 | } |
| 4034 | } |
| 4035 | |
| 4036 | /** |
| 4037 | * 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] | 4038 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4039 | * <p> |
| 4040 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4041 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4042 | * |
| 4043 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4044 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4045 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4046 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4047 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4048 | String packageName) { |
| 4049 | if (mService != null) { |
| 4050 | try { |
| 4051 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4052 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4053 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4054 | } |
| 4055 | } |
| 4056 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4057 | |
| 4058 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4059 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4060 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4061 | * {@link #getApplicationRestrictions}. |
| 4062 | * <p> |
| 4063 | * This permission is persistent until it is later cleared by calling this method with a |
| 4064 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4065 | * <p> |
| 4066 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4067 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4068 | * |
| 4069 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4070 | * @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] | 4071 | * APIs. If {@code null} is given the current package will be cleared. |
| 4072 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4073 | * @throws NameNotFoundException if {@code packageName} is not found |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4074 | */ |
| 4075 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4076 | @Nullable String packageName) throws NameNotFoundException { |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4077 | if (mService != null) { |
| 4078 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4079 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4080 | throw new NameNotFoundException(packageName); |
| 4081 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4082 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4083 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4084 | } |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | /** |
| 4089 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 4090 | * package for the current user, or {@code null} if none is set. |
| 4091 | * |
| 4092 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4093 | * @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] | 4094 | * {@code null} if none is set. |
| 4095 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4096 | */ |
| 4097 | public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) { |
| 4098 | if (mService != null) { |
| 4099 | try { |
| 4100 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4101 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4102 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4103 | } |
| 4104 | } |
| 4105 | return null; |
| 4106 | } |
| 4107 | |
| 4108 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4109 | * Called by any application to find out whether it has been granted permission via |
| 4110 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4111 | * for the calling user. |
| 4112 | * |
| 4113 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4114 | * that method. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4115 | */ |
| 4116 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
| 4117 | if (mService != null) { |
| 4118 | try { |
| 4119 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 4120 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4121 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4122 | } |
| 4123 | } |
| 4124 | return false; |
| 4125 | } |
| 4126 | |
| 4127 | /** |
| 4128 | * 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] | 4129 | * <p> |
| 4130 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4131 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4132 | * security exception will be thrown. |
| 4133 | * <p> |
| 4134 | * 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] | 4135 | * <ul> |
| 4136 | * <li>{@code boolean} |
| 4137 | * <li>{@code int} |
| 4138 | * <li>{@code String} or {@code String[]} |
| 4139 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4140 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4141 | * <p> |
| 4142 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 4143 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4144 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4145 | * <p> |
| 4146 | * The application restrictions are only made visible to the target application via |
| 4147 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 4148 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4149 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4150 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4151 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4152 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4153 | * @param packageName The name of the package to update restricted settings for. |
| 4154 | * @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] | 4155 | * set of active restrictions. |
| 4156 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4157 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4158 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4159 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4160 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4161 | Bundle settings) { |
| 4162 | if (mService != null) { |
| 4163 | try { |
| 4164 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 4165 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4166 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | } |
| 4170 | |
| 4171 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4172 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 4173 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 4174 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4175 | * {@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] | 4176 | * <p> |
| 4177 | * The calling device admin must have requested |
| 4178 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4179 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4180 | * <p> |
| 4181 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4182 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 4183 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4184 | * |
| 4185 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4186 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4187 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 4188 | * strictly disabled according to the state of the |
| 4189 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4190 | * <p> |
| 4191 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 4192 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 4193 | * device admins. |
| 4194 | * <p> |
| 4195 | * Consult documentation for the specific TrustAgent to determine legal options |
| 4196 | * parameters. |
| 4197 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4198 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4199 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4200 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4201 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4202 | if (mService != null) { |
| 4203 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4204 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4205 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4206 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4207 | } |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4212 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4213 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4214 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4215 | * <p> |
| 4216 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4217 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 4218 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4219 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4220 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4221 | * this function returns a list of configurations for all admins that declare |
| 4222 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4223 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4224 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4225 | * 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] | 4226 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4227 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4228 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4229 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4230 | @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4231 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4235 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 4236 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4237 | if (mService != null) { |
| 4238 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4239 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 4240 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4241 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4242 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4243 | } |
| 4244 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4245 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4249 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 4250 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4251 | * <p> |
| 4252 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4253 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4254 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4255 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4256 | * @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] | 4257 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4258 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4259 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4260 | if (mService != null) { |
| 4261 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4262 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4263 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4264 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4265 | } |
| 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4270 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4271 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4272 | * <p> |
| 4273 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4274 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4275 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4276 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
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. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4278 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4279 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4280 | if (mService != null) { |
| 4281 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4282 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4283 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4284 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4285 | } |
| 4286 | } |
| 4287 | return false; |
| 4288 | } |
| 4289 | |
| 4290 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4291 | * Determine whether or not caller-Id information has been disabled. |
| 4292 | * |
| 4293 | * @param userHandle The user for whom to check the caller-id permission |
| 4294 | * @hide |
| 4295 | */ |
| 4296 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4297 | if (mService != null) { |
| 4298 | try { |
| 4299 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4300 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4301 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4302 | } |
| 4303 | } |
| 4304 | return false; |
| 4305 | } |
| 4306 | |
| 4307 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4308 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 4309 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4310 | * <p> |
| 4311 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4312 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4313 | * |
| 4314 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4315 | * @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] | 4316 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4317 | */ |
| 4318 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4319 | boolean disabled) { |
| 4320 | if (mService != null) { |
| 4321 | try { |
| 4322 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 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 | } |
| 4328 | |
| 4329 | /** |
| 4330 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4331 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4332 | * <p> |
| 4333 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4334 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4335 | * |
| 4336 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4337 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4338 | */ |
| 4339 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
| 4340 | if (mService != null) { |
| 4341 | try { |
| 4342 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4343 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4344 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4345 | } |
| 4346 | } |
| 4347 | return false; |
| 4348 | } |
| 4349 | |
| 4350 | |
| 4351 | /** |
| 4352 | * Determine whether or not contacts search has been disabled. |
| 4353 | * |
| 4354 | * @param userHandle The user for whom to check the contacts search permission |
| 4355 | * @hide |
| 4356 | */ |
| 4357 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4358 | if (mService != null) { |
| 4359 | try { |
| 4360 | return mService |
| 4361 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4362 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4363 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4364 | } |
| 4365 | } |
| 4366 | return false; |
| 4367 | } |
| 4368 | |
| 4369 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4370 | * 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] | 4371 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4372 | * @hide |
| 4373 | */ |
| 4374 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4375 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4376 | if (mService != null) { |
| 4377 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4378 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 4379 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4380 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4381 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4382 | } |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4387 | * 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] | 4388 | * @hide |
| 4389 | */ |
| 4390 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4391 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4392 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4393 | originalIntent); |
| 4394 | } |
| 4395 | |
| 4396 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4397 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 4398 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4399 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4400 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4401 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4402 | * <p> |
| 4403 | * This API works on managed profile only. |
| 4404 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4405 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4406 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 4407 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4408 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4409 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4410 | if (mService != null) { |
| 4411 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4412 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4413 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4414 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4415 | } |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4420 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 4421 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4422 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4423 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4424 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4425 | * <p> |
| 4426 | * This API works on managed profile only. |
| 4427 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4428 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4429 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4430 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4431 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4432 | if (mService != null) { |
| 4433 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4434 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4435 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4436 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4437 | } |
| 4438 | } |
| 4439 | return true; |
| 4440 | } |
| 4441 | |
| 4442 | /** |
| 4443 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4444 | * <p> |
| 4445 | * This API works on managed profile UserHandle only. |
| 4446 | * |
| 4447 | * @param userHandle The user for whom to check the caller-id permission |
| 4448 | * @hide |
| 4449 | */ |
| 4450 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4451 | if (mService != null) { |
| 4452 | try { |
| 4453 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4454 | .getIdentifier()); |
| 4455 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4456 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4457 | } |
| 4458 | } |
| 4459 | return true; |
| 4460 | } |
| 4461 | |
| 4462 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4463 | * 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] | 4464 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 4465 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4466 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4467 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4468 | * @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] | 4469 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4470 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4471 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 4472 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4473 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4474 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4475 | if (mService != null) { |
| 4476 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4477 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4478 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4479 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | } |
| 4483 | |
| 4484 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4485 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4486 | * 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] | 4487 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4488 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4489 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4490 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4491 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4492 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4493 | if (mService != null) { |
| 4494 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4495 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4496 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4497 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4498 | } |
| 4499 | } |
| 4500 | } |
| 4501 | |
| 4502 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4503 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 4504 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4505 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 4506 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 4507 | * the list and not part of the system can not be enabled by the user. |
| 4508 | * <p> |
| 4509 | * Calling with a null value for the list disables the restriction so that all services can be |
| 4510 | * used, calling with an empty list only allows the builtin system's services. |
| 4511 | * <p> |
| 4512 | * 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] | 4513 | * |
| 4514 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4515 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4516 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 4517 | * accessibility services enabled, that are not in the list. |
| 4518 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4519 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4520 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4521 | List<String> packageNames) { |
| 4522 | if (mService != null) { |
| 4523 | try { |
| 4524 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4525 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4526 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4527 | } |
| 4528 | } |
| 4529 | return false; |
| 4530 | } |
| 4531 | |
| 4532 | /** |
| 4533 | * 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] | 4534 | * <p> |
| 4535 | * An empty list means no accessibility services except system services are allowed. Null means |
| 4536 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4537 | * |
| 4538 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4539 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4540 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4541 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4542 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4543 | if (mService != null) { |
| 4544 | try { |
| 4545 | return mService.getPermittedAccessibilityServices(admin); |
| 4546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4547 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4548 | } |
| 4549 | } |
| 4550 | return null; |
| 4551 | } |
| 4552 | |
| 4553 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4554 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 4555 | * |
| 4556 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4557 | * @param packageName Accessibility service package name that needs to be checked. |
| 4558 | * @param userHandle user id the admin is running as. |
| 4559 | * @return true if the accessibility service is permitted, otherwise false. |
| 4560 | * |
| 4561 | * @hide |
| 4562 | */ |
| 4563 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 4564 | @NonNull String packageName, int userHandle) { |
| 4565 | if (mService != null) { |
| 4566 | try { |
| 4567 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 4568 | userHandle); |
| 4569 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4570 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4571 | } |
| 4572 | } |
| 4573 | return false; |
| 4574 | } |
| 4575 | |
| 4576 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4577 | * Returns the list of accessibility services permitted by the device or profiles |
| 4578 | * owners of this user. |
| 4579 | * |
| 4580 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 4581 | * it will contain the intersection of the permitted lists for any device or profile |
| 4582 | * owners that apply to this user. It will also include any system accessibility services. |
| 4583 | * |
| 4584 | * @param userId which user to check for. |
| 4585 | * @return List of accessiblity service package names. |
| 4586 | * @hide |
| 4587 | */ |
| 4588 | @SystemApi |
| 4589 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 4590 | if (mService != null) { |
| 4591 | try { |
| 4592 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 4593 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4594 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | return null; |
| 4598 | } |
| 4599 | |
| 4600 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4601 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 4602 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4603 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 4604 | * When zero or more packages have been added, input method that are not in the list and not |
| 4605 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 4606 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 4607 | * <p> |
| 4608 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 4609 | * be used, calling with an empty list disables all but the system's own input methods. |
| 4610 | * <p> |
| 4611 | * 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] | 4612 | * |
| 4613 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4614 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4615 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 4616 | * non-system input methods currently enabled that are not in the packageNames list. |
| 4617 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4618 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4619 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4620 | if (mService != null) { |
| 4621 | try { |
| 4622 | return mService.setPermittedInputMethods(admin, packageNames); |
| 4623 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4624 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4625 | } |
| 4626 | } |
| 4627 | return false; |
| 4628 | } |
| 4629 | |
| 4630 | |
| 4631 | /** |
| 4632 | * 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] | 4633 | * <p> |
| 4634 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 4635 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4636 | * |
| 4637 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4638 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4639 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4640 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4641 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4642 | if (mService != null) { |
| 4643 | try { |
| 4644 | return mService.getPermittedInputMethods(admin); |
| 4645 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4646 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4647 | } |
| 4648 | } |
| 4649 | return null; |
| 4650 | } |
| 4651 | |
| 4652 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4653 | * Called by the system to check if a specific input method is disabled by admin. |
| 4654 | * |
| 4655 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4656 | * @param packageName Input method package name that needs to be checked. |
| 4657 | * @param userHandle user id the admin is running as. |
| 4658 | * @return true if the input method is permitted, otherwise false. |
| 4659 | * |
| 4660 | * @hide |
| 4661 | */ |
| 4662 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 4663 | @NonNull String packageName, int userHandle) { |
| 4664 | if (mService != null) { |
| 4665 | try { |
| 4666 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 4667 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4668 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 4669 | } |
| 4670 | } |
| 4671 | return false; |
| 4672 | } |
| 4673 | |
| 4674 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4675 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4676 | * 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] | 4677 | * |
| 4678 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 4679 | * it will contain the intersection of the permitted lists for any device or profile |
| 4680 | * owners that apply to this user. It will also include any system input methods. |
| 4681 | * |
| 4682 | * @return List of input method package names. |
| 4683 | * @hide |
| 4684 | */ |
| 4685 | @SystemApi |
| 4686 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 4687 | if (mService != null) { |
| 4688 | try { |
| 4689 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 4690 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4691 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4692 | } |
| 4693 | } |
| 4694 | return null; |
| 4695 | } |
| 4696 | |
| 4697 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4698 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 4699 | * currently installed it. |
| 4700 | * |
| 4701 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4702 | * |
| 4703 | * @return List of package names to keep cached. |
| 4704 | * @hide |
| 4705 | */ |
| 4706 | public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
| 4707 | if (mService != null) { |
| 4708 | try { |
| 4709 | return mService.getKeepUninstalledPackages(admin); |
| 4710 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4711 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4712 | } |
| 4713 | } |
| 4714 | return null; |
| 4715 | } |
| 4716 | |
| 4717 | /** |
| 4718 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 4719 | * currently installed it. |
| 4720 | * |
| 4721 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 4722 | * automatically pre-cached.</p> |
| 4723 | * |
| 4724 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4725 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4726 | * @throws SecurityException if {@code admin} is not a device owner. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4727 | * @hide |
| 4728 | */ |
| 4729 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 4730 | @NonNull List<String> packageNames) { |
| 4731 | if (mService != null) { |
| 4732 | try { |
| 4733 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 4734 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4735 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 4736 | } |
| 4737 | } |
| 4738 | } |
| 4739 | |
| 4740 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4741 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4742 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4743 | * created. If you need to persist an identifier for this user, use |
| 4744 | * {@link UserManager#getSerialNumberForUser}. |
| 4745 | * |
| 4746 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4747 | * @param name the user's name |
| 4748 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4749 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4750 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4751 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4752 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4753 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4754 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4755 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4756 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4757 | return null; |
| 4758 | } |
| 4759 | |
| 4760 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4761 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 4762 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 4763 | * created. If you need to persist an identifier for this user, use |
| 4764 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 4765 | * immediately. |
| 4766 | * |
| 4767 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 4768 | * as registered as an active admin on the new user. The profile owner package will be |
| 4769 | * installed on the new user if it already is installed on the device. |
| 4770 | * |
| 4771 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 4772 | * profileOwnerComponent when onEnable is called. |
| 4773 | * |
| 4774 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4775 | * @param name the user's name |
| 4776 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4777 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 4778 | * the user. |
| 4779 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 4780 | * on the new user. |
| 4781 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4782 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4783 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4784 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 4785 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 4786 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4787 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 4788 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4789 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 4790 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 4791 | return null; |
| 4792 | } |
| 4793 | |
| 4794 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4795 | * 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] | 4796 | */ |
| 4797 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 4798 | |
| 4799 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 4800 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 4801 | * ephemeral. |
| 4802 | * @hide |
| 4803 | */ |
| 4804 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 4805 | |
| 4806 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4807 | * Called by a device owner to create a user with the specified name and a given component of |
| 4808 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 4809 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 4810 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 4811 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4812 | * <p> |
| 4813 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 4814 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 4815 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 4816 | * on the new user. |
| 4817 | * <p> |
| 4818 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 4819 | * 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] | 4820 | * |
| 4821 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4822 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4823 | * @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] | 4824 | * same package as admin, otherwise no user is created and an |
| 4825 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4826 | * @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] | 4827 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4828 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4829 | * @see UserHandle |
| 4830 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 4831 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4832 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4833 | */ |
| 4834 | public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4835 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 4836 | int flags) { |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4837 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 4838 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4839 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4840 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4841 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4845 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 4846 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4847 | * |
| 4848 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4849 | * @param userHandle the user to remove. |
| 4850 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4851 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4852 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4853 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4854 | try { |
| 4855 | return mService.removeUser(admin, userHandle); |
| 4856 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4857 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 4858 | } |
| 4859 | } |
| 4860 | |
| 4861 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4862 | * Called by a device owner to switch the specified user to the foreground. |
| 4863 | * |
| 4864 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4865 | * @param userHandle the user to switch to; null will switch to primary. |
| 4866 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4867 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4868 | * @see Intent#ACTION_USER_FOREGROUND |
| 4869 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4870 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4871 | try { |
| 4872 | return mService.switchUser(admin, userHandle); |
| 4873 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4874 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 4875 | } |
| 4876 | } |
| 4877 | |
| 4878 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4879 | * Retrieves the application restrictions for a given target application running in the calling |
| 4880 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4881 | * <p> |
| 4882 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4883 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4884 | * security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4885 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4886 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4887 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4888 | * @param packageName The name of the package to fetch restricted settings of. |
| 4889 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4890 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 4891 | * {@link Bundle} if no restrictions have been set. |
| 4892 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4893 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4894 | */ |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4895 | public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4896 | if (mService != null) { |
| 4897 | try { |
| 4898 | return mService.getApplicationRestrictions(admin, packageName); |
| 4899 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4900 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4901 | } |
| 4902 | } |
| 4903 | return null; |
| 4904 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4905 | |
| 4906 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4907 | * 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] | 4908 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4909 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 4910 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4911 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4912 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4913 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 4914 | * for the list of keys. |
| 4915 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4916 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4917 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4918 | if (mService != null) { |
| 4919 | try { |
| 4920 | mService.setUserRestriction(admin, key, true); |
| 4921 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4922 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4923 | } |
| 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4928 | * 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] | 4929 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4930 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 4931 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 4932 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4933 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4934 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 4935 | * for the list of keys. |
| 4936 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4937 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4938 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4939 | if (mService != null) { |
| 4940 | try { |
| 4941 | mService.setUserRestriction(admin, key, false); |
| 4942 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4943 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 4944 | } |
| 4945 | } |
| 4946 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 4947 | |
| 4948 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4949 | * Called by a profile or device owner to get user restrictions set with |
| 4950 | * {@link #addUserRestriction(ComponentName, String)}. |
| 4951 | * <p> |
| 4952 | * 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] | 4953 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4954 | * {@link UserManager#getUserRestrictions()}. |
| 4955 | * |
| 4956 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4957 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4958 | */ |
| 4959 | public Bundle getUserRestrictions(@NonNull ComponentName admin) { |
| 4960 | Bundle ret = null; |
| 4961 | if (mService != null) { |
| 4962 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 4963 | ret = mService.getUserRestrictions(admin); |
| 4964 | } catch (RemoteException e) { |
| 4965 | throw e.rethrowFromSystemServer(); |
| 4966 | } |
| 4967 | } |
| 4968 | return ret == null ? new Bundle() : ret; |
| 4969 | } |
| 4970 | |
| 4971 | /** |
| 4972 | * Called by the system to get the user restrictions for a user. |
| 4973 | * |
| 4974 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4975 | * @param userHandle user id the admin is running as. |
| 4976 | * |
| 4977 | * @hide |
| 4978 | */ |
| 4979 | public Bundle getUserRestrictionsForUser(@NonNull ComponentName admin, int userHandle) { |
| 4980 | Bundle ret = null; |
| 4981 | if (mService != null) { |
| 4982 | try { |
| 4983 | ret = mService.getUserRestrictionsForUser(admin, userHandle); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4984 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4985 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 4986 | } |
| 4987 | } |
| 4988 | return ret == null ? new Bundle() : ret; |
| 4989 | } |
| 4990 | |
| 4991 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4992 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it is |
| 4993 | * unavailable for use, but the data and actual package file remain. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 4994 | * |
| 4995 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4996 | * @param packageName The name of the package to hide or unhide. |
| 4997 | * @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] | 4998 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4999 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5000 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5001 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5002 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5003 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5004 | if (mService != null) { |
| 5005 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5006 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5007 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5008 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5009 | } |
| 5010 | } |
| 5011 | return false; |
| 5012 | } |
| 5013 | |
| 5014 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5015 | * 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] | 5016 | * |
| 5017 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5018 | * @param packageName The name of the package to retrieve the hidden status of. |
| 5019 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5020 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5021 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5022 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5023 | if (mService != null) { |
| 5024 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5025 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5026 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5027 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5028 | } |
| 5029 | } |
| 5030 | return false; |
| 5031 | } |
| 5032 | |
| 5033 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5034 | * 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] | 5035 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5036 | * |
| 5037 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5038 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5039 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5040 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5041 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5042 | if (mService != null) { |
| 5043 | try { |
| 5044 | mService.enableSystemApp(admin, packageName); |
| 5045 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5046 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5047 | } |
| 5048 | } |
| 5049 | } |
| 5050 | |
| 5051 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5052 | * Called by profile or device owners to re-enable system apps by intent that were disabled by |
| 5053 | * default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5054 | * |
| 5055 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5056 | * @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] | 5057 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5058 | * @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] | 5059 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5060 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5061 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5062 | if (mService != null) { |
| 5063 | try { |
| 5064 | return mService.enableSystemAppWithIntent(admin, intent); |
| 5065 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5066 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | return 0; |
| 5070 | } |
| 5071 | |
| 5072 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 5073 | * Called by a device owner or profile owner to disable account management for a specific type |
| 5074 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5075 | * <p> |
| 5076 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 5077 | * exception will be thrown. |
| 5078 | * <p> |
| 5079 | * When account management is disabled for an account type, adding or removing an account of |
| 5080 | * that type will not be possible. |
| 5081 | * <p> |
| 5082 | * 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] | 5083 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 5084 | * management for a specific type is disabled. |
| 5085 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5086 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5087 | * @param accountType For which account management is disabled or enabled. |
| 5088 | * @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] | 5089 | * enabled (false). |
| 5090 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5091 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5092 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5093 | boolean disabled) { |
| 5094 | if (mService != null) { |
| 5095 | try { |
| 5096 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 5097 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5098 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5099 | } |
| 5100 | } |
| 5101 | } |
| 5102 | |
| 5103 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5104 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 5105 | * |
| 5106 | * <p> Account management can be disabled/enabled by calling |
| 5107 | * {@link #setAccountManagementDisabled}. |
| 5108 | * |
| 5109 | * @return a list of account types for which account management has been disabled. |
| 5110 | * |
| 5111 | * @see #setAccountManagementDisabled |
| 5112 | */ |
| 5113 | public String[] getAccountTypesWithManagementDisabled() { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5114 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | /** |
| 5118 | * @see #getAccountTypesWithManagementDisabled() |
| 5119 | * @hide |
| 5120 | */ |
| 5121 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5122 | if (mService != null) { |
| 5123 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5124 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5125 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5126 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | return null; |
| 5131 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5132 | |
| 5133 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5134 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5135 | * <p> |
| 5136 | * Any packages that shares uid with an allowed package will also be allowed to activate lock |
| 5137 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
| 5138 | * package list results in locked tasks belonging to those packages to be finished. This |
| 5139 | * function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5140 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5141 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5142 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5143 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5144 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 5145 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 5146 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 5147 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5148 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5149 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5150 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5151 | if (mService != null) { |
| 5152 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5153 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5154 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5155 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5156 | } |
| 5157 | } |
| 5158 | } |
| 5159 | |
| 5160 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5161 | * 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] | 5162 | * |
| 5163 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5164 | * @hide |
| 5165 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5166 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5167 | if (mService != null) { |
| 5168 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5169 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5170 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5171 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5172 | } |
| 5173 | } |
| 5174 | return null; |
| 5175 | } |
| 5176 | |
| 5177 | /** |
| 5178 | * This function lets the caller know whether the given component is allowed to start the |
| 5179 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5180 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5181 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5182 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5183 | if (mService != null) { |
| 5184 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5185 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5186 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5187 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5188 | } |
| 5189 | } |
| 5190 | return false; |
| 5191 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5192 | |
| 5193 | /** |
| 5194 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 5195 | * 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] | 5196 | * <p> |
| 5197 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5198 | * <ul> |
| 5199 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 5200 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 5201 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5202 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5203 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5204 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5205 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 5206 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 5207 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 5208 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 5209 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5210 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5211 | * <p> |
| 5212 | * 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] | 5213 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5214 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 5215 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5216 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5217 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5218 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 5219 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5220 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5221 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 5222 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5223 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5224 | * |
| 5225 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5226 | * @param setting The name of the setting to update. |
| 5227 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5228 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5229 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5230 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5231 | if (mService != null) { |
| 5232 | try { |
| 5233 | mService.setGlobalSetting(admin, setting, value); |
| 5234 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5235 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5236 | } |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | /** |
| 5241 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5242 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5243 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5244 | * <p> |
| 5245 | * 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] | 5246 | * <ul> |
| 5247 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5248 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5249 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5250 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5251 | * <p> |
| 5252 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5253 | * <ul> |
| 5254 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5255 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5256 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5257 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5258 | * @param setting The name of the setting to update. |
| 5259 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5260 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5261 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5262 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5263 | if (mService != null) { |
| 5264 | try { |
| 5265 | mService.setSecureSetting(admin, setting, value); |
| 5266 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5267 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5268 | } |
| 5269 | } |
| 5270 | } |
| 5271 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5272 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5273 | * Designates a specific service component as the provider for making permission requests of a |
| 5274 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5275 | * <p/> |
| 5276 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5277 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5278 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5279 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5280 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 5281 | * provider previously assigned. |
| 5282 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5283 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5284 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5285 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5286 | if (mService != null) { |
| 5287 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5288 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5289 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5290 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5291 | } |
| 5292 | } |
| 5293 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5294 | |
| 5295 | /** |
| 5296 | * Called by profile or device owners to set the master volume mute on or off. |
| 5297 | * |
| 5298 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5299 | * @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] | 5300 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5301 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5302 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5303 | if (mService != null) { |
| 5304 | try { |
| 5305 | mService.setMasterVolumeMuted(admin, on); |
| 5306 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5307 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5308 | } |
| 5309 | } |
| 5310 | } |
| 5311 | |
| 5312 | /** |
| 5313 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5314 | * |
| 5315 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5316 | * @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] | 5317 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5318 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5319 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5320 | if (mService != null) { |
| 5321 | try { |
| 5322 | return mService.isMasterVolumeMuted(admin); |
| 5323 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5324 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5325 | } |
| 5326 | } |
| 5327 | return false; |
| 5328 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5329 | |
| 5330 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5331 | * 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] | 5332 | * |
| 5333 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5334 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5335 | * @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] | 5336 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5337 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5338 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5339 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5340 | if (mService != null) { |
| 5341 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5342 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5343 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5344 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5345 | } |
| 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5350 | * 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] | 5351 | * 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] | 5352 | * <p> |
| 5353 | * <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] | 5354 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 5355 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 5356 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5357 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5358 | * @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] | 5359 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5360 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5361 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5362 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5363 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5364 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5365 | if (mService != null) { |
| 5366 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 5367 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5368 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5369 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5370 | } |
| 5371 | } |
| 5372 | return false; |
| 5373 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5374 | |
| 5375 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5376 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 5377 | * package to be available in the parent profile. As a result the user will be able to add |
| 5378 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 5379 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 5380 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5381 | * <p> |
| 5382 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5383 | * |
| 5384 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5385 | * @param packageName The package from which widget providers are white-listed. |
| 5386 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5387 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5388 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5389 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5390 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5391 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5392 | if (mService != null) { |
| 5393 | try { |
| 5394 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 5395 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5396 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5397 | } |
| 5398 | } |
| 5399 | return false; |
| 5400 | } |
| 5401 | |
| 5402 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5403 | * 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] | 5404 | * package to be available in the parent profile. For this method to take effect the package |
| 5405 | * should have been added via |
| 5406 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5407 | * <p> |
| 5408 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5409 | * |
| 5410 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5411 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5412 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5413 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5414 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5415 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5416 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5417 | public boolean removeCrossProfileWidgetProvider( |
| 5418 | @NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5419 | if (mService != null) { |
| 5420 | try { |
| 5421 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5422 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5423 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5424 | } |
| 5425 | } |
| 5426 | return false; |
| 5427 | } |
| 5428 | |
| 5429 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5430 | * 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] | 5431 | * available in the parent profile. |
| 5432 | * |
| 5433 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5434 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5435 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5436 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5437 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5438 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5439 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5440 | if (mService != null) { |
| 5441 | try { |
| 5442 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5443 | if (providers != null) { |
| 5444 | return providers; |
| 5445 | } |
| 5446 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5447 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5448 | } |
| 5449 | } |
| 5450 | return Collections.emptyList(); |
| 5451 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5452 | |
| 5453 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5454 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5455 | * |
| 5456 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5457 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5458 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5459 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5460 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5461 | try { |
| 5462 | mService.setUserIcon(admin, icon); |
| 5463 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5464 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5465 | } |
| 5466 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5467 | |
| 5468 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5469 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5470 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5471 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5472 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5473 | * components in the device owner package can set system update policies and the most |
| 5474 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5475 | * @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] | 5476 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5477 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5478 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5479 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5480 | if (mService != null) { |
| 5481 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5482 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5483 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5484 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5485 | } |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5490 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5491 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5492 | * @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] | 5493 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5494 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5495 | if (mService != null) { |
| 5496 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5497 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5498 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5499 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5500 | } |
| 5501 | } |
| 5502 | return null; |
| 5503 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5504 | |
| 5505 | /** |
| 5506 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5507 | * <p> |
| 5508 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 5509 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 5510 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 5511 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5512 | * |
| 5513 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5514 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5515 | * @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] | 5516 | * place. {@code true} otherwise. |
| 5517 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5518 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5519 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5520 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5521 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5522 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5523 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5524 | } |
| 5525 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5526 | |
| 5527 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5528 | * 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] | 5529 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 5530 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5531 | * |
| 5532 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5533 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5534 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 5535 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5536 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5537 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5538 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5539 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5540 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5541 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5542 | } |
| 5543 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5544 | |
| 5545 | /** |
| 5546 | * Callable by the system update service to notify device owners about pending updates. |
| 5547 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 5548 | * permission. |
| 5549 | * |
| 5550 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 5551 | * when the current pending update was first available. -1 if no update is available. |
| 5552 | * @hide |
| 5553 | */ |
| 5554 | @SystemApi |
| 5555 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 5556 | if (mService != null) { |
| 5557 | try { |
| 5558 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 5559 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5560 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 5561 | } |
| 5562 | } |
| 5563 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 5564 | |
| 5565 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5566 | * 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] | 5567 | * requests by applications. The policy can allow for normal operation which prompts the user to |
| 5568 | * grant a permission, or can allow automatic granting or denying of runtime permission requests |
| 5569 | * by an application. This also applies to new permissions declared by app updates. When a |
| 5570 | * permission is denied or granted this way, the effect is equivalent to setting the permission |
| 5571 | * grant state via {@link #setPermissionGrantState}. |
| 5572 | * <p/> |
| 5573 | * 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] | 5574 | * 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] | 5575 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5576 | * @param admin Which profile or device owner this request is associated with. |
| 5577 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5578 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 5579 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 5580 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5581 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5582 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5583 | try { |
| 5584 | mService.setPermissionPolicy(admin, policy); |
| 5585 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5586 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5587 | } |
| 5588 | } |
| 5589 | |
| 5590 | /** |
| 5591 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 5592 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 5593 | * @param admin Which profile or device owner this request is associated with. |
| 5594 | * @return the current policy for future permission requests. |
| 5595 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 5596 | public int getPermissionPolicy(ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5597 | try { |
| 5598 | return mService.getPermissionPolicy(admin); |
| 5599 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5600 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5605 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 5606 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 5607 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 5608 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 5609 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 5610 | * 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] | 5611 | * by a profile or device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5612 | * <p/> |
| 5613 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 5614 | * the permission. It retains the previous grant, if any. |
| 5615 | * <p/> |
| 5616 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5617 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 5618 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5619 | * @param admin Which profile or device owner this request is associated with. |
| 5620 | * @param packageName The application to grant or revoke a permission to. |
| 5621 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5622 | * @param grantState The permission grant state which is one of |
| 5623 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 5624 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5625 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5626 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5627 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 5628 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 5629 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5630 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5631 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5632 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5633 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 5634 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5635 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5636 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 5637 | } |
| 5638 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5639 | |
| 5640 | /** |
| 5641 | * Returns the current grant state of a runtime permission for a specific application. |
| 5642 | * |
| 5643 | * @param admin Which profile or device owner this request is associated with. |
| 5644 | * @param packageName The application to check the grant state for. |
| 5645 | * @param permission The permission to check for. |
| 5646 | * @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] | 5647 | * has not set a grant state, the return value is |
| 5648 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 5649 | * permission is currently granted for the package. |
| 5650 | * <p/> |
| 5651 | * If a grant state was set by the profile or device owner, then the return value will |
| 5652 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 5653 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 5654 | * currently denied or granted. |
| 5655 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5656 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 5657 | * @see PackageManager#checkPermission(String, String) |
| 5658 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5659 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5660 | String permission) { |
| 5661 | try { |
| 5662 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 5663 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5664 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 5665 | } |
| 5666 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5667 | |
| 5668 | /** |
| 5669 | * Returns if provisioning a managed profile or device is possible or not. |
| 5670 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 5671 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5672 | * @return if provisioning a managed profile or device is possible or not. |
| 5673 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 5674 | */ |
| 5675 | public boolean isProvisioningAllowed(String action) { |
| 5676 | try { |
| 5677 | return mService.isProvisioningAllowed(action); |
| 5678 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5679 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 5680 | } |
| 5681 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5682 | |
| 5683 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5684 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 5685 | * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed |
Kenny Guy | ffa3840 | 2016-03-31 16:40:57 +0100 | [diff] [blame] | 5686 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5687 | * @param admin Which profile owner this request is associated with. |
| 5688 | * @return if this user is a managed profile of another user. |
| 5689 | */ |
| 5690 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
| 5691 | try { |
| 5692 | return mService.isManagedProfile(admin); |
| 5693 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5694 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5695 | } |
| 5696 | } |
| 5697 | |
| 5698 | /** |
| 5699 | * @hide |
| 5700 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 5701 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 5702 | * @param admin Which device owner this request is associated with. |
| 5703 | * @return if this user is a system-only user. |
| 5704 | */ |
| 5705 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 5706 | try { |
| 5707 | return mService.isSystemOnlyUser(admin); |
| 5708 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5709 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 5710 | } |
| 5711 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5712 | |
| 5713 | /** |
| 5714 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 5715 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5716 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5717 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 5718 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 5719 | * <p> |
| 5720 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 5721 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5722 | */ |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5723 | public String getWifiMacAddress(@NonNull ComponentName admin) { |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5724 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 5725 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5726 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5727 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 5728 | } |
| 5729 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5730 | |
| 5731 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5732 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 5733 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5734 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5735 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5736 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 5737 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5738 | */ |
| 5739 | public void reboot(@NonNull ComponentName admin) { |
| 5740 | try { |
| 5741 | mService.reboot(admin); |
| 5742 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5743 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 5744 | } |
| 5745 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5746 | |
| 5747 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5748 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 5749 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 5750 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 5751 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 5752 | * truncated. |
| 5753 | * <p> |
| 5754 | * 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] | 5755 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5756 | * and set a new version of this string accordingly. |
| 5757 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5758 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5759 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5760 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 5761 | * existing message. |
| 5762 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5763 | */ |
| 5764 | public void setShortSupportMessage(@NonNull ComponentName admin, |
| 5765 | @Nullable String message) { |
| 5766 | if (mService != null) { |
| 5767 | try { |
| 5768 | mService.setShortSupportMessage(admin, message); |
| 5769 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5770 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5771 | } |
| 5772 | } |
| 5773 | } |
| 5774 | |
| 5775 | /** |
| 5776 | * Called by a device admin to get the short support message. |
| 5777 | * |
| 5778 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5779 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} or null if |
| 5780 | * no message has been set. |
| 5781 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5782 | */ |
| 5783 | public String getShortSupportMessage(@NonNull ComponentName admin) { |
| 5784 | if (mService != null) { |
| 5785 | try { |
| 5786 | return mService.getShortSupportMessage(admin); |
| 5787 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5788 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5789 | } |
| 5790 | } |
| 5791 | return null; |
| 5792 | } |
| 5793 | |
| 5794 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5795 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 5796 | * in the device administators settings screen. |
| 5797 | * <p> |
| 5798 | * 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] | 5799 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 5800 | * and set a new version of this string accordingly. |
| 5801 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5802 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5803 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5804 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 5805 | * existing message. |
| 5806 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5807 | */ |
| 5808 | public void setLongSupportMessage(@NonNull ComponentName admin, |
| 5809 | @Nullable String message) { |
| 5810 | if (mService != null) { |
| 5811 | try { |
| 5812 | mService.setLongSupportMessage(admin, message); |
| 5813 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5814 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5815 | } |
| 5816 | } |
| 5817 | } |
| 5818 | |
| 5819 | /** |
| 5820 | * Called by a device admin to get the long support message. |
| 5821 | * |
| 5822 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5823 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} or null if |
| 5824 | * no message has been set. |
| 5825 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5826 | */ |
| 5827 | public String getLongSupportMessage(@NonNull ComponentName admin) { |
| 5828 | if (mService != null) { |
| 5829 | try { |
| 5830 | return mService.getLongSupportMessage(admin); |
| 5831 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5832 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5833 | } |
| 5834 | } |
| 5835 | return null; |
| 5836 | } |
| 5837 | |
| 5838 | /** |
| 5839 | * Called by the system to get the short support message. |
| 5840 | * |
| 5841 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5842 | * @param userHandle user id the admin is running as. |
| 5843 | * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} |
| 5844 | * |
| 5845 | * @hide |
| 5846 | */ |
| 5847 | public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5848 | if (mService != null) { |
| 5849 | try { |
| 5850 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 5851 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5852 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5853 | } |
| 5854 | } |
| 5855 | return null; |
| 5856 | } |
| 5857 | |
| 5858 | |
| 5859 | /** |
| 5860 | * Called by the system to get the long support message. |
| 5861 | * |
| 5862 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5863 | * @param userHandle user id the admin is running as. |
| 5864 | * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} |
| 5865 | * |
| 5866 | * @hide |
| 5867 | */ |
| 5868 | public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) { |
| 5869 | if (mService != null) { |
| 5870 | try { |
| 5871 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 5872 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5873 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 5874 | } |
| 5875 | } |
| 5876 | return null; |
| 5877 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5878 | |
| 5879 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5880 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 5881 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 5882 | * |
| 5883 | * <p>The following methods are supported for the parent instance, all other methods will |
| 5884 | * throw a SecurityException when called on the parent instance: |
| 5885 | * <ul> |
| 5886 | * <li>{@link #getPasswordQuality}</li> |
| 5887 | * <li>{@link #setPasswordQuality}</li> |
| 5888 | * <li>{@link #getPasswordMinimumLength}</li> |
| 5889 | * <li>{@link #setPasswordMinimumLength}</li> |
| 5890 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 5891 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 5892 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 5893 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 5894 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 5895 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 5896 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 5897 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 5898 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 5899 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 5900 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 5901 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 5902 | * <li>{@link #getPasswordHistoryLength}</li> |
| 5903 | * <li>{@link #setPasswordHistoryLength}</li> |
| 5904 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 5905 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 5906 | * <li>{@link #getPasswordExpiration}</li> |
| 5907 | * <li>{@link #isActivePasswordSufficient}</li> |
| 5908 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 5909 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 5910 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 5911 | * <li>{@link #getMaximumTimeToLock}</li> |
| 5912 | * <li>{@link #setMaximumTimeToLock}</li> |
| 5913 | * <li>{@link #lockNow}</li> |
| 5914 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 5915 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 5916 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 5917 | * <li>{@link #setTrustAgentConfiguration}</li> |
| 5918 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5919 | * |
| 5920 | * @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] | 5921 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5922 | */ |
| 5923 | public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
| 5924 | try { |
| 5925 | if (!mService.isManagedProfile(admin)) { |
| 5926 | throw new SecurityException("The current user does not have a parent profile."); |
| 5927 | } |
| 5928 | return new DevicePolicyManager(mContext, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5929 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5930 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5935 | * Called by device owner to control the security logging feature. Logging can only be |
| 5936 | * enabled on single user devices where the sole user is managed by the device owner. |
| 5937 | * |
| 5938 | * <p> Security logs contain various information intended for security auditing purposes. |
| 5939 | * See {@link SecurityEvent} for details. |
| 5940 | * |
| 5941 | * <p>There must be only one user on the device, managed by the device owner. |
| 5942 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5943 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5944 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5945 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5946 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5947 | * @see #retrieveSecurityLogs |
| 5948 | */ |
| 5949 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 5950 | try { |
| 5951 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 5952 | } catch (RemoteException re) { |
| 5953 | throw re.rethrowFromSystemServer(); |
| 5954 | } |
| 5955 | } |
| 5956 | |
| 5957 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5958 | * Return whether security logging is enabled or not by the device owner. |
| 5959 | * |
| 5960 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 5961 | * thrown. |
| 5962 | * |
| 5963 | * @param admin Which device owner this request is associated with. |
| 5964 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 5965 | * @throws SecurityException if {@code admin} is not a device owner. |
| 5966 | */ |
| 5967 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5968 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5969 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5970 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5971 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5976 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 5977 | * this API after device boots. |
| 5978 | * |
| 5979 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 5980 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 5981 | * |
| 5982 | * <p>There must be only one user on the device, managed by the device owner. |
| 5983 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 5984 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5985 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5986 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 5987 | * 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] | 5988 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5989 | */ |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5990 | public List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5991 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 5992 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 5993 | if (list != null) { |
| 5994 | return list.getList(); |
| 5995 | } else { |
| 5996 | // Rate limit exceeded. |
| 5997 | return null; |
| 5998 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 5999 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6000 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6001 | } |
| 6002 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6003 | |
| 6004 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6005 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 6006 | * profile. |
| 6007 | * |
| 6008 | * @hide |
| 6009 | */ |
| 6010 | public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
| 6011 | mContext.checkSelfPermission( |
| 6012 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 6013 | if (!uInfo.isManagedProfile()) { |
| 6014 | throw new SecurityException("The user " + uInfo.id |
| 6015 | + " does not have a parent profile."); |
| 6016 | } |
| 6017 | return new DevicePolicyManager(mContext, true); |
| 6018 | } |
| 6019 | |
| 6020 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6021 | * 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] | 6022 | * <p> |
| 6023 | * <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] | 6024 | * corruption-free during power cycles, due to hardware variations and limitations. As a result, |
Michal Karpinski | e0e10098 | 2016-03-30 15:02:26 +0100 | [diff] [blame] | 6025 | * this API is provided as best-effort and the returned logs may be empty or contain corrupted |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6026 | * data. </strong> |
| 6027 | * <p> |
| 6028 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 6029 | * {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6030 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6031 | * @param admin Which device owner this request is associated with. |
| 6032 | * @return Device logs from before the latest reboot of the system. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6033 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6034 | */ |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6035 | public List<SecurityEvent> retrievePreRebootSecurityLogs(@NonNull ComponentName admin) { |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6036 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6037 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6038 | return list.getList(); |
| 6039 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6040 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6041 | } |
| 6042 | } |
| 6043 | |
| 6044 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6045 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 6046 | * color is used as background color of the confirm credentials screen for that user. The |
Clara Bayarri | 8d0bd7fa | 2016-03-30 14:59:58 +0100 | [diff] [blame] | 6047 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6048 | * <p> |
| 6049 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6050 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 6051 | * |
| 6052 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6053 | * @param color The 32bit representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6054 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6055 | */ |
| 6056 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
| 6057 | try { |
| 6058 | mService.setOrganizationColor(admin, color); |
| 6059 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6060 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6065 | * @hide |
| 6066 | * |
| 6067 | * Sets the color used for customization. |
| 6068 | * |
| 6069 | * @param color The 32bit representation of the color to be used. |
| 6070 | * @param userId which user to set the color to. |
| 6071 | * @RequiresPermission(allOf = { |
| 6072 | * Manifest.permission.MANAGE_USERS, |
| 6073 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 6074 | */ |
| 6075 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 6076 | try { |
| 6077 | mService.setOrganizationColorForUser(color, userId); |
| 6078 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6079 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6080 | } |
| 6081 | } |
| 6082 | |
| 6083 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6084 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 6085 | * This color is used as background color of the confirm credentials screen for that user. |
| 6086 | * |
| 6087 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6088 | * @return The 32bit representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6089 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6090 | */ |
| 6091 | public int getOrganizationColor(@NonNull ComponentName admin) { |
| 6092 | try { |
| 6093 | return mService.getOrganizationColor(admin); |
| 6094 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6095 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6096 | } |
| 6097 | } |
| 6098 | |
| 6099 | /** |
| 6100 | * @hide |
| 6101 | * Retrieve the customization color for a given user. |
| 6102 | * |
| 6103 | * @param userHandle The user id of the user we're interested in. |
| 6104 | * @return The 32bit representation of the color to be used. |
| 6105 | */ |
| 6106 | public int getOrganizationColorForUser(int userHandle) { |
| 6107 | try { |
| 6108 | return mService.getOrganizationColorForUser(userHandle); |
| 6109 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6110 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6111 | } |
| 6112 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6113 | |
| 6114 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6115 | * Called by a profile owner of a managed profile to set the name of the organization under |
| 6116 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6117 | * <p> |
| 6118 | * 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] | 6119 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6120 | * and set a new version of this string accordingly. |
| 6121 | * |
| 6122 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6123 | * @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] | 6124 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6125 | */ |
| 6126 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) { |
| 6127 | try { |
| 6128 | mService.setOrganizationName(admin, title); |
| 6129 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6130 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6135 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 6136 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6137 | * |
| 6138 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6139 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6140 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6141 | */ |
| 6142 | public String getOrganizationName(@NonNull ComponentName admin) { |
| 6143 | try { |
| 6144 | return mService.getOrganizationName(admin); |
| 6145 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6146 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6147 | } |
| 6148 | } |
| 6149 | |
| 6150 | /** |
| 6151 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 6152 | * |
| 6153 | * @param userHandle The user id of the user we're interested in. |
| 6154 | * @return The organization name or {@code null} if none is set. |
| 6155 | * |
| 6156 | * @hide |
| 6157 | */ |
| 6158 | public String getOrganizationNameForUser(int userHandle) { |
| 6159 | try { |
| 6160 | return mService.getOrganizationNameForUser(userHandle); |
| 6161 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6162 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6167 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 6168 | * return {@link #STATE_USER_UNMANAGED} |
| 6169 | * @hide |
| 6170 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 6171 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6172 | @UserProvisioningState |
| 6173 | public int getUserProvisioningState() { |
| 6174 | if (mService != null) { |
| 6175 | try { |
| 6176 | return mService.getUserProvisioningState(); |
| 6177 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6178 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6179 | } |
| 6180 | } |
| 6181 | return STATE_USER_UNMANAGED; |
| 6182 | } |
| 6183 | |
| 6184 | /** |
| 6185 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 6186 | * |
| 6187 | * @param state to store |
| 6188 | * @param userHandle for user |
| 6189 | * @hide |
| 6190 | */ |
| 6191 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 6192 | if (mService != null) { |
| 6193 | try { |
| 6194 | mService.setUserProvisioningState(state, userHandle); |
| 6195 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6196 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6197 | } |
| 6198 | } |
| 6199 | } |
| 6200 | |
| 6201 | /** |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6202 | * @hide |
| 6203 | * Indicates the entity that controls the device or profile owner. A user/profile is considered |
| 6204 | * affiliated if it is managed by the same entity as the device. |
| 6205 | * |
| 6206 | * <p> By definition, the user that the device owner runs on is always affiliated. Any other |
| 6207 | * user/profile is considered affiliated if the following conditions are both met: |
| 6208 | * <ul> |
| 6209 | * <li>The device owner and the user's/profile's profile owner have called this method, |
| 6210 | * specifying a set of opaque affiliation ids each. If the sets specified by the device owner |
| 6211 | * and a profile owner intersect, they must have come from the same source, which means that |
| 6212 | * the device owner and profile owner are controlled by the same entity.</li> |
| 6213 | * <li>The device owner's and profile owner's package names are the same.</li> |
| 6214 | * </ul> |
| 6215 | * |
| 6216 | * @param admin Which profile or device owner this request is associated with. |
| 6217 | * @param ids A set of opaque affiliation ids. |
| 6218 | */ |
| 6219 | public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) { |
| 6220 | try { |
| 6221 | mService.setAffiliationIds(admin, new ArrayList<String>(ids)); |
| 6222 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6223 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | /** |
| 6228 | * @hide |
| 6229 | * Returns whether this user/profile is affiliated with the device. See |
| 6230 | * {@link #setAffiliationIds} for the definition of affiliation. |
| 6231 | * |
| 6232 | * @return whether this user/profile is affiliated with the device. |
| 6233 | */ |
| 6234 | public boolean isAffiliatedUser() { |
| 6235 | try { |
| 6236 | return mService != null && mService.isAffiliatedUser(); |
| 6237 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6238 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6239 | } |
| 6240 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6241 | |
| 6242 | /** |
| 6243 | * @hide |
| 6244 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 6245 | * to be started |
| 6246 | * @param packageName the package to check for |
| 6247 | * @return whether the uninstall intent for {@code packageName} is pending |
| 6248 | */ |
| 6249 | public boolean isUninstallInQueue(String packageName) { |
| 6250 | try { |
| 6251 | return mService.isUninstallInQueue(packageName); |
| 6252 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6253 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | /** |
| 6258 | * @hide |
| 6259 | * @param packageName the package containing active DAs to be uninstalled |
| 6260 | */ |
| 6261 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 6262 | try { |
| 6263 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 6264 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6265 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6266 | } |
| 6267 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 6268 | } |