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; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 26 | import android.annotation.TestApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 27 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 28 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 29 | import android.app.Activity; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 30 | import android.app.IServiceConnection; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 31 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 32 | import android.content.ComponentName; |
| 33 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 34 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 35 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 36 | import android.content.ServiceConnection; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 38 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 39 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 40 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 41 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 42 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 43 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 44 | import android.os.Bundle; |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 45 | import android.os.Parcelable; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 46 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 47 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 48 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 51 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 52 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 53 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 54 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 55 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 56 | import android.telephony.TelephonyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 57 | import android.util.Log; |
| 58 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 59 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 60 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 61 | |
| 62 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 63 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 64 | import java.lang.annotation.Retention; |
| 65 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 66 | import java.net.InetSocketAddress; |
| 67 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 68 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 69 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 70 | import java.security.PrivateKey; |
| 71 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 72 | import java.security.cert.CertificateException; |
| 73 | import java.security.cert.CertificateFactory; |
| 74 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 75 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 76 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 77 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 78 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 79 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 80 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 83 | * 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] | 84 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 85 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 86 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 87 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 88 | * application calling an api may only pass as an argument a device administrator component it |
| 89 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 90 | * <div class="special reference"> |
| 91 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 92 | * <p> |
| 93 | * For more information about managing policies for device administration, read the <a href= |
| 94 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 95 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 96 | */ |
| 97 | public class DevicePolicyManager { |
| 98 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 99 | |
| 100 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 101 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 102 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 103 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 104 | /** @hide */ |
| 105 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 106 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 109 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 110 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 111 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 112 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 113 | mContext = context; |
| 114 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 115 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | /** @hide test will override it. */ |
| 119 | @VisibleForTesting |
| 120 | protected int myUserId() { |
| 121 | return UserHandle.myUserId(); |
| 122 | } |
| 123 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 124 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 125 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 126 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 127 | * <p>A managed profile allows data separation for example for the usage of a |
| 128 | * device as a personal and corporate device. The user which provisioning is started from and |
| 129 | * the managed profile share a launcher. |
| 130 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 131 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 132 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 133 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 134 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 135 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 136 | * {@link #isProvisioningAllowed(String)}. |
| 137 | * |
| 138 | * <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] | 139 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 140 | * 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] | 141 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 142 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 143 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 144 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 145 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 146 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 147 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 148 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 149 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 150 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 152 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 153 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 154 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 155 | * </ul> |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 156 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 157 | * <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] | 158 | * in the provisioning intent. The |
| 159 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 160 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 161 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 162 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 163 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has |
| 164 | * completed, along with the above broadcast, activity intent |
| 165 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in |
| 166 | * the provisioning intent. |
| 167 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 168 | * <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] | 169 | * previous state. |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 170 | * |
| 171 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 172 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 173 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 174 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 175 | * 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] | 176 | */ |
| 177 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 178 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 179 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 180 | |
| 181 | /** |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 182 | * Activity action: Starts the provisioning flow which sets up a managed user. |
| 183 | * |
| 184 | * <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] | 185 | * 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] | 186 | * owner who has full control over the user. Provisioning can only happen before user setup has |
| 187 | * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is |
| 188 | * allowed. |
| 189 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 190 | * <p>The intent contains the following extras: |
| 191 | * <ul> |
| 192 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 193 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 194 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 195 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 196 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
| 197 | * </ul> |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 198 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 199 | * <p>If provisioning fails, the device returns to its previous state. |
Mahaver Chopra | 7830daa | 2015-11-10 18:12:43 +0000 | [diff] [blame] | 200 | * |
| 201 | * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a |
| 202 | * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of |
| 203 | * the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 204 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 205 | * 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] | 206 | * |
| 207 | * @hide |
Mahaver Chopra | 5e73256 | 2015-11-05 11:55:12 +0000 | [diff] [blame] | 208 | */ |
| 209 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 210 | public static final String ACTION_PROVISION_MANAGED_USER |
| 211 | = "android.app.action.PROVISION_MANAGED_USER"; |
| 212 | |
| 213 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 214 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 215 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 216 | * |
| 217 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 218 | * A device owner has full control over the device. The device owner can not be modified by the |
| 219 | * user. |
| 220 | * |
| 221 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 222 | * employee or client. |
| 223 | * |
| 224 | * <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] | 225 | * It is possible to check if provisioning is allowed or not by querying the method |
| 226 | * {@link #isProvisioningAllowed(String)}. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 227 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 228 | * <p>The intent contains the following extras: |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 229 | * <ul> |
| 230 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 231 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 232 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 233 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 234 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 235 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 236 | * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 237 | * </ul> |
| 238 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 239 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 240 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 241 | * device owner. |
| 242 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 243 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 244 | * completed, along with the above broadcast, activity intent |
| 245 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 246 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 247 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 248 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 249 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 250 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 251 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 252 | * 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] | 253 | */ |
| 254 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 255 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 256 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 257 | |
| 258 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 259 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 260 | * |
| 261 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 262 | * the device. A device owner has full control over the device. The device owner can not be |
| 263 | * modified by the user and the only way of resetting the device is via factory reset. |
| 264 | * |
| 265 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 266 | * employee or client. |
| 267 | * |
| 268 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 269 | * |
| 270 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 271 | * by a privileged app with the permission |
| 272 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 273 | * |
| 274 | * <p>The provisioning intent contains the following properties: |
| 275 | * <ul> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 279 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 280 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li> |
| 281 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 282 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 283 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 284 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 285 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 286 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 287 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 288 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 289 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 290 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 291 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 292 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 293 | * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li> |
| 294 | * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li> |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 295 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 296 | * |
| 297 | * @hide |
| 298 | */ |
| 299 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 300 | @SystemApi |
| 301 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 302 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 303 | |
| 304 | /** |
| 305 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 306 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 307 | * |
| 308 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 309 | * management state that is distinct from that reached by |
| 310 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 311 | * user, and only has control over device-wide policies, not individual users and their data. |
| 312 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 313 | * this form of device management. |
| 314 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 315 | * <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] | 316 | * A device owner has full control over the device. The device owner can not be modified by the |
| 317 | * user. |
| 318 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 319 | * <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] | 320 | * employee or client. |
| 321 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 322 | * <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] | 323 | * It is possible to check if provisioning is allowed or not by querying the method |
| 324 | * {@link #isProvisioningAllowed(String)}. |
| 325 | * |
| 326 | * <p>The intent contains the following extras: |
| 327 | * <ul> |
| 328 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 329 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 330 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 331 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 332 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 333 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 334 | * </ul> |
| 335 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 336 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 337 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 338 | * device owner. |
| 339 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 340 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 341 | * completed, along with the above broadcast, activity intent |
| 342 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 343 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 344 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 345 | * |
| 346 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 347 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 348 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 349 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 350 | * |
| 351 | * @hide |
| 352 | */ |
| 353 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 354 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 355 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 356 | |
| 357 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 358 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 359 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 360 | * <ul> |
| 361 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 362 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 363 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 364 | * </ul> |
| 365 | * |
| 366 | * @hide |
| 367 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 368 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 369 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 370 | public static final String ACTION_PROVISION_FINALIZATION |
| 371 | = "android.app.action.PROVISION_FINALIZATION"; |
| 372 | |
| 373 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 374 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 375 | * |
| 376 | * @hide |
| 377 | */ |
| 378 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 379 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 380 | |
| 381 | /** |
| 382 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 383 | * |
| 384 | * @hide |
| 385 | */ |
| 386 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 387 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 388 | |
| 389 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 390 | * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}. |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 391 | * |
| 392 | * @hide |
| 393 | */ |
| 394 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 395 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 396 | |
| 397 | /** |
| 398 | * Extra for shared bugreport's SHA-256 hash. |
| 399 | * |
| 400 | * @hide |
| 401 | */ |
| 402 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 403 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 404 | |
| 405 | /** |
| 406 | * Extra for remote bugreport notification shown type. |
| 407 | * |
| 408 | * @hide |
| 409 | */ |
| 410 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 411 | "android.app.extra.bugreport_notification_type"; |
| 412 | |
| 413 | /** |
| 414 | * Notification type for a started remote bugreport flow. |
| 415 | * |
| 416 | * @hide |
| 417 | */ |
| 418 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 419 | |
| 420 | /** |
| 421 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 422 | * being taken. |
| 423 | * |
| 424 | * @hide |
| 425 | */ |
| 426 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 427 | |
| 428 | /** |
| 429 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 430 | * |
| 431 | * @hide |
| 432 | */ |
| 433 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 434 | |
| 435 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 436 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 437 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 438 | * |
| 439 | * @hide |
| 440 | */ |
| 441 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 442 | |
| 443 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 444 | * 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] | 445 | * allows a mobile device management application or NFC programmer application which starts |
| 446 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 447 | * <p> |
| 448 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 449 | * sends the intent to pass data to itself on the newly created profile. |
| 450 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 451 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 452 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 453 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 454 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 455 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 456 | * management application after provisioning. |
| 457 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 458 | * <p> |
| 459 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 460 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 461 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 462 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 463 | */ |
| 464 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 465 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 466 | |
| 467 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 468 | * A String extra holding the package name of the mobile device management application that |
| 469 | * will be set as the profile owner or device owner. |
| 470 | * |
| 471 | * <p>If an application starts provisioning directly via an intent with action |
| 472 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 473 | * application that started provisioning. The package will be set as profile owner in that case. |
| 474 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 475 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 476 | * 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] | 477 | * |
| 478 | * <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] | 479 | * 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] | 480 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 481 | * @see DeviceAdminReceiver |
| 482 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a8 | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 483 | * supported, but only if there is only one device admin receiver in the package that requires |
| 484 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 485 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 486 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 487 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 488 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 489 | |
| 490 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 491 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 492 | * application that will be set as the profile owner or device owner and active admin. |
| 493 | * |
| 494 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 495 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 496 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 497 | * 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] | 498 | * |
| 499 | * <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] | 500 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 501 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 502 | * {@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] | 503 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 504 | * |
| 505 | * @see DeviceAdminReceiver |
| 506 | */ |
| 507 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 508 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 509 | |
| 510 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 511 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 512 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 513 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 514 | * |
| 515 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 516 | */ |
| 517 | |
| 518 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 519 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 520 | |
| 521 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 522 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 523 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 524 | * the account will not be removed from the primary user after it is migrated to the newly |
| 525 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 526 | * |
| 527 | * <p> Defaults to {@code false} |
| 528 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 529 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 530 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 531 | */ |
| 532 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 533 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 534 | |
| 535 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 536 | * A String extra that, holds the email address of the account which a managed profile is |
| 537 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 538 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 539 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 540 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 541 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 542 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 543 | * contains this extra, it is forwarded in the |
| 544 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 545 | * device management application that was set as the profile owner during provisioning. |
| 546 | * 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] | 547 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 548 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 549 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 550 | |
| 551 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 552 | * A integer extra indicating the predominant color to show during the provisioning. |
| 553 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 554 | * |
| 555 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 556 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 557 | */ |
| 558 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 559 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 560 | |
| 561 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 562 | * 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] | 563 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 564 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 565 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 566 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 567 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 568 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 569 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 570 | |
| 571 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 572 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 573 | * will be set to. |
| 574 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 575 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 576 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 577 | */ |
| 578 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 579 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 580 | |
| 581 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 582 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 583 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 584 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 585 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 586 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 587 | */ |
| 588 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 589 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 590 | |
| 591 | /** |
| 592 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 593 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 594 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 595 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 596 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 597 | */ |
| 598 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 599 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 600 | |
| 601 | /** |
| 602 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 603 | * owner provisioning for downloading the mobile device management application. |
| 604 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 605 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 606 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 607 | */ |
| 608 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 609 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 610 | |
| 611 | /** |
| 612 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 613 | * is hidden or not. |
| 614 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 615 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 616 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 617 | */ |
| 618 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 619 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 620 | |
| 621 | /** |
| 622 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 623 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 624 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 625 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 626 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 627 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 628 | */ |
| 629 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 630 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 631 | |
| 632 | /** |
| 633 | * A String extra holding the password of the wifi network in |
| 634 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 635 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 636 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 637 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 638 | */ |
| 639 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 640 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 641 | |
| 642 | /** |
| 643 | * A String extra holding the proxy host for the wifi network in |
| 644 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 645 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 646 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 647 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 648 | */ |
| 649 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 650 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 651 | |
| 652 | /** |
| 653 | * An int extra holding the proxy port for the wifi network in |
| 654 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 655 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 656 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 657 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 658 | */ |
| 659 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 660 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 661 | |
| 662 | /** |
| 663 | * A String extra holding the proxy bypass for the wifi network in |
| 664 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 665 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 666 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 667 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 668 | */ |
| 669 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 670 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 671 | |
| 672 | /** |
| 673 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 674 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 675 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 676 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 677 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 678 | */ |
| 679 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 680 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 681 | |
| 682 | /** |
| 683 | * A String extra holding a url that specifies the download location of the device admin |
| 684 | * package. When not provided it is assumed that the device admin package is already installed. |
| 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. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 688 | */ |
| 689 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 690 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 691 | |
| 692 | /** |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 693 | * A String extra holding the localized name of the organization under management. |
| 694 | * |
| 695 | * The name is displayed only during provisioning. |
| 696 | * |
| 697 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 698 | * |
| 699 | * @hide |
| 700 | */ |
| 701 | @SystemApi |
| 702 | public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME = |
| 703 | "android.app.extra.PROVISIONING_ORGANIZATION_NAME"; |
| 704 | |
| 705 | /** |
| 706 | * A String extra holding a url to the website of the device's provider. The website can be |
| 707 | * opened in a browser during provisioning. |
| 708 | * |
| 709 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 710 | * |
| 711 | * @hide |
| 712 | */ |
| 713 | @SystemApi |
| 714 | public static final String EXTRA_PROVISIONING_SUPPORT_URL = |
| 715 | "android.app.extra.PROVISIONING_SUPPORT_URL"; |
| 716 | |
| 717 | /** |
| 718 | * A String extra holding the localized name of the device admin package. It should be the same |
| 719 | * as the app label of the package. |
| 720 | * |
| 721 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 722 | * |
| 723 | * @hide |
| 724 | */ |
| 725 | @SystemApi |
| 726 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL = |
| 727 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL"; |
| 728 | |
| 729 | /** |
| 730 | * A {@link Uri} extra pointing to the app icon of device admin package. This image will be |
| 731 | * shown during the provisioning. |
| 732 | * <h5>The following URI schemes are accepted:</h5> |
| 733 | * <ul> |
| 734 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 735 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 736 | * </ul> |
| 737 | * |
| 738 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
| 739 | * pixel density for the device. |
| 740 | * |
| 741 | * <p> If a content: URI is passed, the intent should have the flag |
| 742 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 743 | * {@link android.content.ClipData} of the intent too. |
| 744 | * |
| 745 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} |
| 746 | * |
| 747 | * @hide |
| 748 | */ |
| 749 | @SystemApi |
| 750 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI = |
| 751 | "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI"; |
| 752 | |
| 753 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 754 | * An int extra holding a minimum required version code for the device admin package. If the |
| 755 | * device admin is already installed on the device, it will only be re-downloaded from |
| 756 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 757 | * installed package is less than this version code. |
| 758 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 759 | * <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] | 760 | * provisioning via an NFC bump. |
| 761 | */ |
| 762 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 763 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 764 | |
| 765 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 766 | * A String extra holding a http cookie header which should be used in the http request to the |
| 767 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 768 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 769 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 770 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 771 | */ |
| 772 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 773 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 774 | |
| 775 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 776 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 777 | * the file at download location specified in |
| 778 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 779 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 780 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 781 | * 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] | 782 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 783 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 784 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 785 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 786 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 787 | * |
| 788 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 789 | * 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] | 790 | * 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] | 791 | * 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] | 792 | */ |
| 793 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 794 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 795 | |
| 796 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 797 | * 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] | 798 | * android package archive at the download location specified in {@link |
| 799 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 800 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 801 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 802 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 803 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 804 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 805 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 806 | * 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] | 807 | * the download location. If the checksum does not match an error will be shown to the user and |
| 808 | * the user will be asked to factory reset the device. |
| 809 | * |
| 810 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 811 | * provisioning via an NFC bump. |
| 812 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 813 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 814 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 815 | |
| 816 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 817 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 818 | * has completed successfully. |
| 819 | * |
| 820 | * <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] | 821 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 822 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 823 | * <p>This intent will contain the following extras |
| 824 | * <ul> |
| 825 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 826 | * profile.</li> |
| 827 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 828 | * be migrated at provisioning time, if any.</li> |
| 829 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 830 | */ |
| 831 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 832 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 833 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 834 | |
| 835 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 836 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 837 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 838 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 839 | * delivered faster as it's an activity intent. |
| 840 | * |
| 841 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 842 | * the device owner case the profile is the primary user. |
| 843 | * |
| 844 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 845 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 846 | */ |
| 847 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 848 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 849 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 850 | |
| 851 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 852 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 853 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 854 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 855 | * <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] | 856 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 857 | * |
| 858 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 859 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 860 | */ |
| 861 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 862 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 863 | |
| 864 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 865 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 866 | * provisioning. If this extra is not passed, a default image will be shown. |
| 867 | * <h5>The following URI schemes are accepted:</h5> |
| 868 | * <ul> |
| 869 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 870 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 871 | * </ul> |
| 872 | * |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 873 | * <p> It is the responsibility of the caller to provide an image with a reasonable |
Victor Chang | 38cfd9c | 2017-01-04 17:41:11 +0000 | [diff] [blame] | 874 | * pixel density for the device. |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 875 | * |
| 876 | * <p> If a content: URI is passed, the intent should have the flag |
| 877 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 878 | * {@link android.content.ClipData} of the intent too. |
| 879 | * |
| 880 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 881 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 882 | */ |
| 883 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 884 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 885 | |
| 886 | /** |
Victor Chang | c10f669 | 2016-12-09 15:24:00 +0000 | [diff] [blame] | 887 | * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents. |
| 888 | * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER} |
| 889 | * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer |
| 890 | * content. |
| 891 | * |
| 892 | * <p> The extra typically contains one disclaimer from the company of mobile device |
| 893 | * management application (MDM), and one disclaimer from the organization. |
| 894 | * |
| 895 | * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[] |
| 896 | * |
| 897 | * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored. |
| 898 | * |
| 899 | * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 900 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 901 | */ |
| 902 | public static final String EXTRA_PROVISIONING_DISCLAIMERS = |
| 903 | "android.app.extra.PROVISIONING_DISCLAIMERS"; |
| 904 | |
| 905 | /** |
| 906 | * A String extra of localized disclaimer header. |
| 907 | * |
| 908 | * <p> The extra is typically the company name of mobile device management application (MDM) |
| 909 | * or the organization name. |
| 910 | * |
| 911 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
| 912 | */ |
| 913 | public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER = |
| 914 | "android.app.extra.PROVISIONING_DISCLAIMER_HEADER"; |
| 915 | |
| 916 | /** |
| 917 | * A {@link Uri} extra pointing to disclaimer content. |
| 918 | * |
| 919 | * <h5>The following URI schemes are accepted:</h5> |
| 920 | * <ul> |
| 921 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 922 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 923 | * </ul> |
| 924 | * |
| 925 | * <p> Styled text is supported in the disclaimer content. The content is parsed by |
| 926 | * {@link android.text.Html#fromHtml(String)} and displayed in a |
| 927 | * {@link android.widget.TextView}. |
| 928 | * |
| 929 | * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag |
| 930 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 931 | * {@link android.content.ClipData} of the intent too. |
| 932 | * |
| 933 | * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS} |
| 934 | */ |
| 935 | public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT = |
| 936 | "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT"; |
| 937 | |
| 938 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 939 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 940 | * during setup-wizard. |
| 941 | * |
| 942 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 943 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 944 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 945 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 946 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 947 | * |
| 948 | * @hide |
| 949 | */ |
| 950 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 951 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 952 | |
| 953 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 954 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 955 | * skipped. If unspecified, defaults to {@code false}. |
| 956 | * |
| 957 | * It can only be used by an existing device owner trying to create a managed profile via |
| 958 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 959 | */ |
| 960 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 961 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 962 | |
| 963 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 964 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 965 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 966 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 967 | * A device owner has full control over the device. The device owner can not be modified by the |
| 968 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 969 | * reset. |
| 970 | * |
| 971 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 972 | * employee or client. |
| 973 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 974 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 975 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 976 | * <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] | 977 | * contains the following properties: |
| 978 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 979 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 980 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 981 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 982 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 983 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 984 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 985 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 986 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 987 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 988 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 989 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 990 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 991 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 992 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 993 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 994 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 995 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 996 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 997 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 998 | * 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] | 999 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 1000 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 1001 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 1002 | */ |
| 1003 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 1004 | = "application/com.android.managedprovisioning"; |
| 1005 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 1006 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1007 | * Activity action: ask the user to add a new device administrator to the system. |
| 1008 | * The desired policy is the ComponentName of the policy in the |
| 1009 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 1010 | * bring the user through adding the device administrator to the system (or |
| 1011 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1012 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1013 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1014 | * field to provide the user with additional explanation (in addition |
| 1015 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1016 | * |
| 1017 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 1018 | * user intervention). However, if your administrator has been updated and is requesting |
| 1019 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 1020 | * 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] | 1021 | */ |
| 1022 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1023 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 1024 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1025 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1026 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1027 | * @hide |
| 1028 | * 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] | 1029 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1030 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1031 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 1032 | * 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] | 1033 | * to remotely control restrictions on the user. |
| 1034 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 1035 | * <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] | 1036 | * result of whether or not the user approved the action. If approved, the result will |
| 1037 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 1038 | * as a profile owner. |
| 1039 | * |
| 1040 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 1041 | * field to provide the user with additional explanation (in addition |
| 1042 | * to your component's description) about what is being added. |
| 1043 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 1044 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 1045 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1046 | */ |
| 1047 | @SystemApi |
| 1048 | public static final String ACTION_SET_PROFILE_OWNER |
| 1049 | = "android.app.action.SET_PROFILE_OWNER"; |
| 1050 | |
| 1051 | /** |
| 1052 | * @hide |
| 1053 | * Name of the profile owner admin that controls the user. |
| 1054 | */ |
| 1055 | @SystemApi |
| 1056 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 1057 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 1058 | |
| 1059 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1060 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1061 | * 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] | 1062 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1063 | * @hide |
| 1064 | */ |
| 1065 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 1066 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 1067 | |
| 1068 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 1069 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 1070 | * |
| 1071 | * This broadcast is sent only to the primary user. |
| 1072 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 1073 | */ |
| 1074 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1075 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 1076 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 1077 | |
| 1078 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1079 | * The ComponentName of the administrator component. |
| 1080 | * |
| 1081 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1082 | */ |
| 1083 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1084 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1085 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1086 | * An optional CharSequence providing additional explanation for why the |
| 1087 | * admin is being added. |
| 1088 | * |
| 1089 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 1090 | */ |
| 1091 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1092 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1093 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1094 | * Activity action: have the user enter a new password. This activity should |
| 1095 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 1096 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 1097 | * enter a new password that meets the current requirements. You can use |
| 1098 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 1099 | * have the user select a new password in order to meet the current |
| 1100 | * constraints. Upon being resumed from this activity, you can check the new |
| 1101 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1102 | * |
| 1103 | * If the intent is launched from within a managed profile with a profile |
| 1104 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 1105 | * this will trigger entering a new password for the parent of the profile. |
| 1106 | * For all other cases it will trigger entering a new password for the user |
| 1107 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1108 | * |
| 1109 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1110 | */ |
| 1111 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1112 | public static final String ACTION_SET_NEW_PASSWORD |
| 1113 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 1114 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1115 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 1116 | * Activity action: have the user enter a new password for the parent profile. |
| 1117 | * If the intent is launched from within a managed profile, this will trigger |
| 1118 | * entering a new password for the parent of the profile. In all other cases |
| 1119 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1120 | */ |
| 1121 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1122 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1123 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1124 | |
| 1125 | /** |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 1126 | * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when |
| 1127 | * Network logging was enabled and the user tapped the notification. |
| 1128 | * <p class="note">This is a protected intent that can only be sent by the system.</p> |
| 1129 | * @hide |
| 1130 | */ |
| 1131 | public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG |
| 1132 | = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG"; |
| 1133 | |
| 1134 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1135 | * Broadcast Action: Sent after application delegation scopes are changed. The new list of |
| 1136 | * delegation scopes will be sent in an extra identified by the {@link #EXTRA_DELEGATION_SCOPES} |
| 1137 | * key. |
| 1138 | * |
| 1139 | * <p class=”note”> Note: This is a protected intent that can only be sent by the system.</p> |
| 1140 | */ |
| 1141 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1142 | public static final String ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED = |
| 1143 | "android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED"; |
| 1144 | |
| 1145 | /** |
| 1146 | * A list of Strings corresponding to the delegation scopes given to an app in the |
| 1147 | * {@link #ACTION_APPLICATION_DELEGATION_SCOPES_CHANGED} broadcast. |
| 1148 | */ |
| 1149 | public static final String EXTRA_DELEGATION_SCOPES = "android.app.extra.DELEGATION_SCOPES"; |
| 1150 | |
| 1151 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1152 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1153 | * the parent profile to access intents sent from the managed profile. |
| 1154 | * That is, when an app in the managed profile calls |
| 1155 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1156 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1157 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1158 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1159 | |
| 1160 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1161 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1162 | * the managed profile to access intents sent from the parent profile. |
| 1163 | * That is, when an app in the parent profile calls |
| 1164 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1165 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1166 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1167 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1168 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1169 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1170 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1171 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1172 | */ |
| 1173 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1174 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1175 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1176 | |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1177 | /** |
| 1178 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1179 | * Already granted or denied permissions are not affected by this. |
| 1180 | */ |
| 1181 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1182 | |
| 1183 | /** |
| 1184 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1185 | * Already granted or denied permissions are not affected by this. |
| 1186 | */ |
| 1187 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1188 | |
| 1189 | /** |
| 1190 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1191 | * Already granted or denied permissions are not affected by this. |
| 1192 | */ |
| 1193 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1194 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1195 | /** |
| 1196 | * Runtime permission state: The user can manage the permission |
| 1197 | * through the UI. |
| 1198 | */ |
| 1199 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1200 | |
| 1201 | /** |
| 1202 | * Runtime permission state: The permission is granted to the app |
| 1203 | * and the user cannot manage the permission through the UI. |
| 1204 | */ |
| 1205 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1206 | |
| 1207 | /** |
| 1208 | * Runtime permission state: The permission is denied to the app |
| 1209 | * and the user cannot manage the permission through the UI. |
| 1210 | */ |
| 1211 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1212 | |
| 1213 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 1214 | * Delegation of certificate installation and management. This scope grants access to the |
| 1215 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
| 1216 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair} APIs. |
| 1217 | */ |
| 1218 | public static final String DELEGATION_CERT_INSTALL = "delegation-cert-install"; |
| 1219 | |
| 1220 | /** |
| 1221 | * Delegation of application restrictions management. This scope grants access to the |
| 1222 | * {@link #setApplicationRestrictions} and {@link #getApplicationRestrictions} APIs. |
| 1223 | */ |
| 1224 | public static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions"; |
| 1225 | |
| 1226 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 1227 | * Delegation of application uninstall block. This scope grants access to the |
| 1228 | * {@link #setUninstallBlocked} API. |
| 1229 | */ |
| 1230 | public static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall"; |
| 1231 | |
| 1232 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 1233 | * Delegation of permission policy and permission grant state. This scope grants access to the |
| 1234 | * {@link #setPermissionPolicy}, {@link #getPermissionGrantState}, |
| 1235 | * and {@link #setPermissionGrantState} APIs. |
| 1236 | */ |
| 1237 | public static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant"; |
| 1238 | |
| 1239 | /** |
| 1240 | * Delegation of package access state. This scope grants access to the |
| 1241 | * {@link #isApplicationHidden}, {@link #setApplicationHidden}, {@link #isPackageSuspended}, and |
| 1242 | * {@link #setPackagesSuspended} APIs. |
| 1243 | */ |
| 1244 | public static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access"; |
| 1245 | |
| 1246 | /** |
| 1247 | * Delegation for enabling system apps. This scope grants access to the {@link #enableSystemApp} |
| 1248 | * API. |
| 1249 | */ |
| 1250 | public static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app"; |
| 1251 | |
| 1252 | /** |
| 1253 | * Delegation of management of uninstalled packages. This scope grants access to the |
| 1254 | * {@code #setKeepUninstalledPackages} and {@code #getKeepUninstalledPackages} APIs. |
| 1255 | * @hide |
| 1256 | */ |
| 1257 | public static final String DELEGATION_KEEP_UNINSTALLED_PACKAGES = |
| 1258 | "delegation-keep-uninstalled-packages"; |
| 1259 | |
| 1260 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1261 | * No management for current user in-effect. This is the default. |
| 1262 | * @hide |
| 1263 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1264 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1265 | public static final int STATE_USER_UNMANAGED = 0; |
| 1266 | |
| 1267 | /** |
| 1268 | * Management partially setup, user setup needs to be completed. |
| 1269 | * @hide |
| 1270 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1271 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1272 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1273 | |
| 1274 | /** |
| 1275 | * Management partially setup, user setup completed. |
| 1276 | * @hide |
| 1277 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1278 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1279 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1280 | |
| 1281 | /** |
| 1282 | * Management setup and active on current user. |
| 1283 | * @hide |
| 1284 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1285 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1286 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1287 | |
| 1288 | /** |
| 1289 | * Management partially setup on a managed profile. |
| 1290 | * @hide |
| 1291 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1292 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1293 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1294 | |
| 1295 | /** |
| 1296 | * @hide |
| 1297 | */ |
| 1298 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1299 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1300 | @Retention(RetentionPolicy.SOURCE) |
| 1301 | public @interface UserProvisioningState {} |
| 1302 | |
| 1303 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1304 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1305 | * |
| 1306 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1307 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1308 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1309 | * |
| 1310 | * @hide |
| 1311 | */ |
| 1312 | public static final int CODE_OK = 0; |
| 1313 | |
| 1314 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1315 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1316 | * |
| 1317 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1318 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1319 | * owner. |
| 1320 | * |
| 1321 | * @hide |
| 1322 | */ |
| 1323 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1324 | |
| 1325 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1326 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1327 | * |
| 1328 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1329 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1330 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1331 | * |
| 1332 | * @hide |
| 1333 | */ |
| 1334 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1335 | |
| 1336 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1337 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1338 | * |
| 1339 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1340 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1341 | * |
| 1342 | * @hide |
| 1343 | */ |
| 1344 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1345 | |
| 1346 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1347 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1348 | * |
| 1349 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1350 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1351 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1352 | * |
| 1353 | * @hide |
| 1354 | */ |
| 1355 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1356 | |
| 1357 | /** |
| 1358 | * Code used to indicate that the device also has a user other than the system user. |
| 1359 | * |
| 1360 | * @hide |
| 1361 | */ |
| 1362 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1363 | |
| 1364 | /** |
| 1365 | * Code used to indicate that device has an account that prevents provisioning. |
| 1366 | * |
| 1367 | * @hide |
| 1368 | */ |
| 1369 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1370 | |
| 1371 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1372 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1373 | * |
| 1374 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1375 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1376 | * |
| 1377 | * @hide |
| 1378 | */ |
| 1379 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1380 | |
| 1381 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1382 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1383 | * |
| 1384 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1385 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1386 | * when the device is a watch and is already paired. |
| 1387 | * |
| 1388 | * @hide |
| 1389 | */ |
| 1390 | public static final int CODE_HAS_PAIRED = 8; |
| 1391 | |
| 1392 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1393 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1394 | * |
| 1395 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1396 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1397 | * |
| 1398 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1399 | * @hide |
| 1400 | */ |
| 1401 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1402 | |
| 1403 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1404 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1405 | * |
| 1406 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1407 | * |
| 1408 | * @hide |
| 1409 | */ |
| 1410 | public static final int CODE_SYSTEM_USER = 10; |
| 1411 | |
| 1412 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1413 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1414 | * |
| 1415 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1416 | * managed profiles. |
| 1417 | * |
| 1418 | * @hide |
| 1419 | */ |
| 1420 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1421 | |
| 1422 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1423 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1424 | * |
| 1425 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1426 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1427 | * user. |
| 1428 | * |
| 1429 | * @hide |
| 1430 | */ |
| 1431 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1432 | |
| 1433 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1434 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1435 | * |
| 1436 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1437 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1438 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1439 | * admins. |
| 1440 | * |
| 1441 | * @hide |
| 1442 | */ |
| 1443 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1444 | |
| 1445 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1446 | * Result code for {@link #checkProvisioningPreCondition}. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1447 | * |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 1448 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a |
| 1449 | * system user on a split system user device. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1450 | * |
| 1451 | * @hide |
| 1452 | */ |
| 1453 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1454 | |
| 1455 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1456 | * Result code for {@link #checkProvisioningPreCondition}. |
| 1457 | * |
| 1458 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is |
| 1459 | * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}. |
| 1460 | * |
| 1461 | * @hide |
| 1462 | */ |
| 1463 | public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15; |
| 1464 | |
| 1465 | /** |
| 1466 | * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1467 | * conditions. |
| 1468 | * |
| 1469 | * @hide |
| 1470 | */ |
| 1471 | @Retention(RetentionPolicy.SOURCE) |
| 1472 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1473 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1474 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1475 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 1476 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED}) |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1477 | public @interface ProvisioningPreCondition {} |
| 1478 | |
| 1479 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1480 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1481 | * |
| 1482 | * @param admin The administrator component to check for. |
| 1483 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1484 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1485 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1486 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1487 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1488 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /** |
| 1492 | * @see #isAdminActive(ComponentName) |
| 1493 | * @hide |
| 1494 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1495 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1496 | if (mService != null) { |
| 1497 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1498 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1499 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1500 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | return false; |
| 1504 | } |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 1505 | |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1506 | /** |
| 1507 | * Return true if the given administrator component is currently being removed |
| 1508 | * for the user. |
| 1509 | * @hide |
| 1510 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1511 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1512 | if (mService != null) { |
| 1513 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1514 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1515 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1516 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | return false; |
| 1520 | } |
| 1521 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1522 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1523 | * Return a list of all currently active device administrators' component |
| 1524 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1525 | * returned. |
| 1526 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1527 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1528 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1529 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | /** |
| 1533 | * @see #getActiveAdmins() |
| 1534 | * @hide |
| 1535 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1536 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1537 | if (mService != null) { |
| 1538 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1539 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1540 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1541 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | return null; |
| 1545 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1546 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1547 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1548 | * Used by package administration code to determine if a package can be stopped |
| 1549 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1550 | * @hide |
| 1551 | */ |
David Ouyang | 3a83a33 | 2017-01-11 16:36:40 -0800 | [diff] [blame] | 1552 | @SystemApi |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1553 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1554 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * Used by package administration code to determine if a package can be stopped |
| 1559 | * or uninstalled. |
| 1560 | * @hide |
| 1561 | */ |
| 1562 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1563 | if (mService != null) { |
| 1564 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1565 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1566 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1567 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1568 | } |
| 1569 | } |
| 1570 | return false; |
| 1571 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1572 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1573 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1574 | * Remove a current administration component. This can only be called |
| 1575 | * by the application that owns the administration component; if you |
| 1576 | * try to remove someone else's component, a security exception will be |
| 1577 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1578 | * |
| 1579 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1580 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1581 | * |
| 1582 | * @param admin The administration compononent to remove. |
| 1583 | * @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] | 1584 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1585 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1586 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1587 | if (mService != null) { |
| 1588 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1589 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1590 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1591 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1595 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1596 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1597 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1598 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1599 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1600 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1601 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1602 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1603 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1604 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1605 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1606 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1607 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1608 | if (mService != null) { |
| 1609 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1610 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1611 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1612 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | return false; |
| 1616 | } |
| 1617 | |
| 1618 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1619 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1620 | * |
| 1621 | * @hide |
| 1622 | */ |
| 1623 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1624 | if (mService != null) { |
| 1625 | try { |
| 1626 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1627 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1628 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | return false; |
| 1632 | } |
| 1633 | |
| 1634 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1635 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1636 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1637 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1638 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1639 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1640 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1641 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1642 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1643 | * recognition technology. This implies technologies that can recognize the identity of |
| 1644 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1645 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1646 | */ |
| 1647 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1648 | |
| 1649 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1650 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1651 | * 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] | 1652 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1653 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1654 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1655 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1656 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1657 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1658 | * password containing at least numeric characters. Note that quality |
| 1659 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1660 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1661 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1662 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1663 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1664 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1665 | * password containing at least numeric characters with no repeating (4444) |
| 1666 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1667 | * constants are ordered so that higher values are more restrictive. |
| 1668 | */ |
| 1669 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1670 | |
| 1671 | /** |
| 1672 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1673 | * password containing at least alphabetic (or other symbol) characters. |
| 1674 | * Note that quality constants are ordered so that higher values are more |
| 1675 | * restrictive. |
| 1676 | */ |
| 1677 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1678 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1679 | /** |
| 1680 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1681 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1682 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1683 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1684 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1685 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1686 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1687 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1688 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1689 | * password containing at least a letter, a numerical digit and a special |
| 1690 | * symbol, by default. With this password quality, passwords can be |
| 1691 | * restricted to contain various sets of characters, like at least an |
| 1692 | * uppercase letter, etc. These are specified using various methods, |
| 1693 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1694 | * that quality constants are ordered so that higher values are more |
| 1695 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1696 | */ |
| 1697 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1698 | |
| 1699 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1700 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1701 | * modify password. In case this password quality is set, the password is |
| 1702 | * managed by a profile owner. The profile owner can set any password, |
| 1703 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1704 | * that quality constants are ordered so that higher values are more |
| 1705 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1706 | * the highest. |
| 1707 | * @hide |
| 1708 | */ |
| 1709 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1710 | |
| 1711 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1712 | * @hide |
| 1713 | * |
| 1714 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1715 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1716 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1717 | * used by authenticator to exempt their accounts from this: |
| 1718 | * |
| 1719 | * <ul> |
| 1720 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1721 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1722 | * <application> tag in the manifest. |
| 1723 | * |
| 1724 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1725 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1726 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1727 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1728 | * if any of the accounts have it. |
| 1729 | * </ul> |
| 1730 | */ |
| 1731 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1732 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1733 | |
| 1734 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
| 1735 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1736 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1737 | |
| 1738 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1739 | * Called by an application that is administering the device to set the password restrictions it |
| 1740 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1741 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1742 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1743 | * 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] | 1744 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1745 | * <p> |
| 1746 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1747 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1748 | * considerations) is the one that is in effect. |
| 1749 | * <p> |
| 1750 | * The calling device admin must have requested |
| 1751 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1752 | * not, a security exception will be thrown. |
| 1753 | * <p> |
| 1754 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1755 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1756 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1757 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1758 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1759 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1760 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1761 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1762 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1763 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1764 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1765 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1766 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1767 | if (mService != null) { |
| 1768 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1769 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1770 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1771 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1775 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1776 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1777 | * Retrieve the current minimum password quality for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1778 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1779 | * a separate challenge are not taken into account. |
| 1780 | * |
| 1781 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1782 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1783 | * restrictions on the parent profile. |
| 1784 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1785 | * @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] | 1786 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1787 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1788 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1789 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1793 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1794 | if (mService != null) { |
| 1795 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1796 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1797 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1798 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1799 | } |
| 1800 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1801 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1802 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1803 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1804 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1805 | * Called by an application that is administering the device to set the minimum allowed password |
| 1806 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1807 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1808 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1809 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1810 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1811 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1812 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1813 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1814 | * {@link #setPasswordQuality}. |
| 1815 | * <p> |
| 1816 | * The calling device admin must have requested |
| 1817 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1818 | * not, a security exception will be thrown. |
| 1819 | * <p> |
| 1820 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1821 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1822 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1823 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1824 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1825 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1826 | * restriction. |
| 1827 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1828 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1829 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1830 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1831 | if (mService != null) { |
| 1832 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1833 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1834 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1835 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1839 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1840 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1841 | * Retrieve the current minimum password length for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1842 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1843 | * a separate challenge are not taken into account. |
| 1844 | * |
| 1845 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1846 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1847 | * restrictions on the parent profile. |
| 1848 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1849 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1850 | * @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] | 1851 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1852 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1853 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1854 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1858 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1859 | if (mService != null) { |
| 1860 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1861 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1862 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1863 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | return 0; |
| 1867 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1868 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1869 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1870 | * Called by an application that is administering the device to set the minimum number of upper |
| 1871 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1872 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1873 | * current password will remain until the user has set a new one, so the change does not take |
| 1874 | * place immediately. To prompt the user for a new password, use |
| 1875 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1876 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1877 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1878 | * <p> |
| 1879 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1880 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1881 | * not, a security exception will be thrown. |
| 1882 | * <p> |
| 1883 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1884 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1885 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1886 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1887 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1888 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1889 | * A value of 0 means there is no restriction. |
| 1890 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1891 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1892 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1893 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1894 | if (mService != null) { |
| 1895 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1896 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1897 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1898 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1904 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1905 | * for a particular admin or all admins that set restrictions on this user and |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1906 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1907 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1908 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1909 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1910 | * and only applies when the password quality is |
| 1911 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1912 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1913 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1914 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1915 | * restrictions on the parent profile. |
| 1916 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1917 | * @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] | 1918 | * aggregate all admins. |
| 1919 | * @return The minimum number of upper case letters required in the |
| 1920 | * password. |
| 1921 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1922 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1923 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1927 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1928 | if (mService != null) { |
| 1929 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1930 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1931 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1932 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
| 1938 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1939 | * Called by an application that is administering the device to set the minimum number of lower |
| 1940 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1941 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1942 | * current password will remain until the user has set a new one, so the change does not take |
| 1943 | * place immediately. To prompt the user for a new password, use |
| 1944 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1945 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1946 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1947 | * <p> |
| 1948 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1949 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1950 | * not, a security exception will be thrown. |
| 1951 | * <p> |
| 1952 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1953 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1954 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1955 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1956 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1957 | * @param length The new desired minimum number of lower case letters required in the password. |
| 1958 | * A value of 0 means there is no restriction. |
| 1959 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1960 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1961 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1962 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1963 | if (mService != null) { |
| 1964 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1965 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1966 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1967 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1973 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1974 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1975 | * and its participating profiles. Restrictions on profiles that have |
| 1976 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1977 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1978 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1979 | * and only applies when the password quality is |
| 1980 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1981 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1982 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1983 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1984 | * restrictions on the parent profile. |
| 1985 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1986 | * @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] | 1987 | * aggregate all admins. |
| 1988 | * @return The minimum number of lower case letters required in the |
| 1989 | * password. |
| 1990 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1991 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1992 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1996 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1997 | if (mService != null) { |
| 1998 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1999 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2000 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2001 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | return 0; |
| 2005 | } |
| 2006 | |
| 2007 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2008 | * Called by an application that is administering the device to set the minimum number of |
| 2009 | * letters required in the password. After setting this, the user will not be able to enter a |
| 2010 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2011 | * password will remain until the user has set a new one, so the change does not take place |
| 2012 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2013 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2014 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2015 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2016 | * <p> |
| 2017 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2018 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2019 | * not, a security exception will be thrown. |
| 2020 | * <p> |
| 2021 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2022 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2023 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2024 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2025 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2026 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2027 | * 0 means there is no restriction. |
| 2028 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2029 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2030 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2031 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2032 | if (mService != null) { |
| 2033 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2034 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2035 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2036 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2042 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2043 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2044 | * and its participating profiles. Restrictions on profiles that have |
| 2045 | * a separate challenge are not taken into account. |
| 2046 | * This is the same value as set by |
| 2047 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2048 | * and only applies when the password quality is |
| 2049 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2050 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2051 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2052 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2053 | * restrictions on the parent profile. |
| 2054 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2055 | * @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] | 2056 | * aggregate all admins. |
| 2057 | * @return The minimum number of letters required in the password. |
| 2058 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2059 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2060 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2064 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2065 | if (mService != null) { |
| 2066 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2067 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2068 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2069 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | return 0; |
| 2073 | } |
| 2074 | |
| 2075 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2076 | * Called by an application that is administering the device to set the minimum number of |
| 2077 | * numerical digits required in the password. After setting this, the user will not be able to |
| 2078 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 2079 | * current password will remain until the user has set a new one, so the change does not take |
| 2080 | * place immediately. To prompt the user for a new password, use |
| 2081 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2082 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2083 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2084 | * <p> |
| 2085 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2086 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2087 | * not, a security exception will be thrown. |
| 2088 | * <p> |
| 2089 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2090 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2091 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2092 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2093 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2094 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 2095 | * value of 0 means there is no restriction. |
| 2096 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2097 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2098 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2099 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2100 | if (mService != null) { |
| 2101 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2102 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2103 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2104 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2111 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2112 | * and its participating profiles. Restrictions on profiles that have |
| 2113 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2114 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2115 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2116 | * and only applies when the password quality is |
| 2117 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2118 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2119 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2120 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2121 | * restrictions on the parent profile. |
| 2122 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2123 | * @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] | 2124 | * aggregate all admins. |
| 2125 | * @return The minimum number of numerical digits required in the password. |
| 2126 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2127 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2128 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2132 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2133 | if (mService != null) { |
| 2134 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2135 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2136 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2137 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | return 0; |
| 2141 | } |
| 2142 | |
| 2143 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2144 | * Called by an application that is administering the device to set the minimum number of |
| 2145 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 2146 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 2147 | * password will remain until the user has set a new one, so the change does not take place |
| 2148 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2149 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2150 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 2151 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2152 | * <p> |
| 2153 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2154 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2155 | * not, a security exception will be thrown. |
| 2156 | * <p> |
| 2157 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2158 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2159 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2160 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2161 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2162 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 2163 | * 0 means there is no restriction. |
| 2164 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2165 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2166 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2167 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2168 | if (mService != null) { |
| 2169 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2170 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2171 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2172 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2178 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2179 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2180 | * and its participating profiles. Restrictions on profiles that have |
| 2181 | * a separate challenge are not taken into account. This is the same value as |
| 2182 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2183 | * and only applies when the password quality is |
| 2184 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2185 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2186 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2187 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2188 | * restrictions on the parent profile. |
| 2189 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2190 | * @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] | 2191 | * aggregate all admins. |
| 2192 | * @return The minimum number of symbols required in the password. |
| 2193 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2194 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2195 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2199 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2200 | if (mService != null) { |
| 2201 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2202 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2203 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2204 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | return 0; |
| 2208 | } |
| 2209 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2210 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2211 | * Called by an application that is administering the device to set the minimum number of |
| 2212 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2213 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2214 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2215 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2216 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2217 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2218 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2219 | * <p> |
| 2220 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2221 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2222 | * not, a security exception will be thrown. |
| 2223 | * <p> |
| 2224 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2225 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2226 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2227 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2228 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2229 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2230 | * 0 means there is no restriction. |
| 2231 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2232 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2233 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2234 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2235 | if (mService != null) { |
| 2236 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2237 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2238 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2239 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2245 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2246 | * for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2247 | * and its participating profiles. Restrictions on profiles that have |
| 2248 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2249 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2250 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2251 | * and only applies when the password quality is |
| 2252 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2253 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2254 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2255 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2256 | * restrictions on the parent profile. |
| 2257 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2258 | * @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] | 2259 | * aggregate all admins. |
| 2260 | * @return The minimum number of letters required in the password. |
| 2261 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2262 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2263 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2267 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2268 | if (mService != null) { |
| 2269 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2270 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2271 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2272 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | return 0; |
| 2276 | } |
| 2277 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2278 | /** |
| 2279 | * Called by an application that is administering the device to set the length of the password |
| 2280 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2281 | * same as any password in the history. Note that the current password will remain until the |
| 2282 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2283 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2284 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2285 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2286 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2287 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2288 | * <p> |
| 2289 | * The calling device admin must have requested |
| 2290 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2291 | * not, a security exception will be thrown. |
| 2292 | * <p> |
| 2293 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2294 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2295 | * profile. |
| 2296 | * |
| 2297 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2298 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2299 | * restriction. |
| 2300 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2301 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2302 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2303 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2304 | if (mService != null) { |
| 2305 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2306 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2307 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2308 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2309 | } |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2314 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2315 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2316 | * device password (for all admins). |
| 2317 | * <p> |
| 2318 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2319 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2320 | * 432000000 ms for timeout. |
| 2321 | * <p> |
| 2322 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2323 | * <p> |
| 2324 | * The calling device admin must have requested |
| 2325 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2326 | * not, a security exception will be thrown. |
| 2327 | * <p> |
| 2328 | * Note that setting the password will automatically reset the expiration time for all active |
| 2329 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2330 | * <p> |
| 2331 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2332 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2333 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2334 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2335 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2336 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2337 | * there is no restriction (unlimited). |
| 2338 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2339 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2340 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2341 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2342 | if (mService != null) { |
| 2343 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2344 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2345 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2346 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2347 | } |
| 2348 | } |
| 2349 | } |
| 2350 | |
| 2351 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2352 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2353 | * recurring expiration timeout provided in the call to |
| 2354 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2355 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2356 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2357 | * |
| 2358 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2359 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2360 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2361 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2362 | * @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] | 2363 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2364 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2365 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2366 | if (mService != null) { |
| 2367 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2368 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2369 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2370 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | return 0; |
| 2374 | } |
| 2375 | |
| 2376 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2377 | * Get the current password expiration time for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2378 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2379 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2380 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2381 | * |
| 2382 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2383 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2384 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2385 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2386 | * @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] | 2387 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2388 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2389 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2390 | if (mService != null) { |
| 2391 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2392 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2393 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2394 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2395 | } |
| 2396 | } |
| 2397 | return 0; |
| 2398 | } |
| 2399 | |
| 2400 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2401 | * Retrieve the current password history length for a particular admin or all admins that |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2402 | * set restrictions on this user and its participating profiles. Restrictions on profiles that |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2403 | * have a separate challenge are not taken into account. |
| 2404 | * |
| 2405 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2406 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2407 | * restrictions on the parent profile. |
| 2408 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2409 | * @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] | 2410 | * all admins. |
| 2411 | * @return The length of the password history |
| 2412 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2413 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2414 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2418 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2419 | if (mService != null) { |
| 2420 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2421 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2422 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2423 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | return 0; |
| 2427 | } |
| 2428 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2429 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2430 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2431 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2432 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2433 | * @return Returns the maximum length that the user can enter. |
| 2434 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2435 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2436 | // Kind-of arbitrary. |
| 2437 | return 16; |
| 2438 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2439 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2440 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2441 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2442 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2443 | * user and its participating profiles. Restrictions on profiles that have a separate challenge |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2444 | * are not taken into account. The user must be unlocked in order to perform the check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2445 | * <p> |
| 2446 | * The calling device admin must have requested |
| 2447 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2448 | * not, a security exception will be thrown. |
| 2449 | * <p> |
| 2450 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2451 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2452 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2453 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2454 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2455 | * @throws SecurityException if the calling application does not own an active administrator |
| 2456 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 2457 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2458 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2459 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2460 | if (mService != null) { |
| 2461 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2462 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2463 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2464 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2465 | } |
| 2466 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2467 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2468 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2469 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2470 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2471 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2472 | * 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] | 2473 | * requested by the admins of the parent user and its profiles. |
| 2474 | * |
| 2475 | * @param userHandle the userId of the profile to check the password for. |
| 2476 | * @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] | 2477 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2478 | * @hide |
| 2479 | */ |
| 2480 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2481 | if (mService != null) { |
| 2482 | try { |
| 2483 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2484 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2485 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2486 | } |
| 2487 | } |
| 2488 | return false; |
| 2489 | } |
| 2490 | |
| 2491 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2492 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2493 | * successful password entry. |
| 2494 | * <p> |
| 2495 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2496 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2497 | * password attemts for the parent user. |
| 2498 | * <p> |
| 2499 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2500 | * 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] | 2501 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2502 | * @return The number of times user has entered an incorrect password since the last correct |
| 2503 | * password entry. |
| 2504 | * @throws SecurityException if the calling application does not own an active administrator |
| 2505 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2506 | */ |
| 2507 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2508 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2509 | } |
| 2510 | |
| 2511 | /** |
| 2512 | * Retrieve the number of times the given user has failed at entering a |
| 2513 | * password since that last successful password entry. |
| 2514 | * |
| 2515 | * <p>The calling device admin must have requested |
| 2516 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2517 | * not and it is not the system uid, a security exception will be thrown. |
| 2518 | * |
| 2519 | * @hide |
| 2520 | */ |
| 2521 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2522 | if (mService != null) { |
| 2523 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2524 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2525 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2526 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2527 | } |
| 2528 | } |
| 2529 | return -1; |
| 2530 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2531 | |
| 2532 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2533 | * 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] | 2534 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2535 | * @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] | 2536 | * @hide |
| 2537 | */ |
| 2538 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2539 | if (mService != null) { |
| 2540 | try { |
| 2541 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2542 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2543 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2544 | } |
| 2545 | } |
| 2546 | return false; |
| 2547 | } |
| 2548 | |
| 2549 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2550 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2551 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2552 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2553 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2554 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2555 | * <p> |
| 2556 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2557 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2558 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2559 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2560 | * immediately, and your callback will not be invoked. |
| 2561 | * <p> |
| 2562 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2563 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2564 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2565 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2566 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2567 | * @param num The number of failed password attempts at which point the device or profile will |
| 2568 | * be wiped. |
| 2569 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2570 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2571 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2572 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2573 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2574 | if (mService != null) { |
| 2575 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2576 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2577 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2578 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2582 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2583 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2584 | * Retrieve the current maximum number of login attempts that are allowed before the device |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2585 | * or profile is wiped, for a particular admin or all admins that set restrictions on this user |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2586 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2587 | * not taken into account. |
| 2588 | * |
| 2589 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2590 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2591 | * the value for the parent profile. |
| 2592 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2593 | * @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] | 2594 | * all admins. |
| 2595 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2596 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2597 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2601 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2602 | if (mService != null) { |
| 2603 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2604 | return mService.getMaximumFailedPasswordsForWipe( |
| 2605 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2606 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2607 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | return 0; |
| 2611 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2612 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2613 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2614 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2615 | * for the given user. So for primary user, it might return the primary or |
| 2616 | * a managed profile. For a secondary user, it would be the same as the |
| 2617 | * user passed in. |
| 2618 | * @hide Used only by Keyguard |
| 2619 | */ |
| 2620 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2621 | if (mService != null) { |
| 2622 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2623 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2624 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2625 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2626 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | return UserHandle.USER_NULL; |
| 2630 | } |
| 2631 | |
| 2632 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2633 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2634 | * the password again until the user has entered it. |
| 2635 | */ |
| 2636 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2637 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2638 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2639 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2640 | * If the flag is set, the device can be booted without asking for user password. |
| 2641 | * The absence of this flag does not change the current boot requirements. This flag |
| 2642 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2643 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2644 | * device to factory defaults. |
| 2645 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2646 | 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] | 2647 | |
| 2648 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2649 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2650 | * individual accounts) on the user. This takes effect immediately. |
| 2651 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2652 | * <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] | 2653 | * device admins that are not device owner and not profile owner. |
| 2654 | * The password can now only be changed if there is currently no password set. Device owner |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2655 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2656 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2657 | * <p> |
| 2658 | * The given password must be sufficient for the current password quality and length constraints |
| 2659 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2660 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2661 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2662 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2663 | * case the currently active quality will be increased to match. |
| 2664 | * <p> |
| 2665 | * 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] | 2666 | * current password constraints allow it. <em>Note: This will not work in |
| 2667 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2668 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2669 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2670 | * <p> |
| 2671 | * The calling device admin must have requested |
| 2672 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2673 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2674 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2675 | * @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] | 2676 | * @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] | 2677 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2678 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2679 | * current constraints or if the user has not been decrypted yet. |
| 2680 | * @throws SecurityException if the calling application does not own an active administrator |
| 2681 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2682 | * @throws IllegalStateException if the calling user is locked or has a managed profile. |
Andrew Scull | 3f81f4e | 2016-07-29 16:29:58 +0100 | [diff] [blame] | 2683 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2684 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2685 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2686 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2687 | if (mService != null) { |
| 2688 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2689 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2690 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2691 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2692 | } |
| 2693 | } |
| 2694 | return false; |
| 2695 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2696 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2697 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2698 | * Called by an application that is administering the device to set the maximum time for user |
| 2699 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2700 | * effect immediately. |
| 2701 | * <p> |
| 2702 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2703 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2704 | * <p> |
| 2705 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2706 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2707 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2708 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2709 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2710 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2711 | * is no restriction. |
| 2712 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2713 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2714 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2715 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2716 | if (mService != null) { |
| 2717 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2718 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2719 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2720 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2721 | } |
| 2722 | } |
| 2723 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2724 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2725 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2726 | * Retrieve the current maximum time to unlock for a particular admin or all admins that set |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2727 | * restrictions on this user and its participating profiles. Restrictions on profiles that have |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2728 | * a separate challenge are not taken into account. |
| 2729 | * |
| 2730 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2731 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2732 | * restrictions on the parent profile. |
| 2733 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2734 | * @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] | 2735 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2736 | * @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] | 2737 | * 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] | 2738 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2739 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2740 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2744 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2745 | if (mService != null) { |
| 2746 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2747 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2748 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2749 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | return 0; |
| 2753 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2754 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2755 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2756 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2757 | * do not have a separate timeout to lock for work challenge only. |
| 2758 | * |
| 2759 | * @hide |
| 2760 | */ |
| 2761 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2762 | if (mService != null) { |
| 2763 | try { |
| 2764 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2765 | } catch (RemoteException e) { |
| 2766 | throw e.rethrowFromSystemServer(); |
| 2767 | } |
| 2768 | } |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2773 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2774 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2775 | * authentication method like password, pin or pattern. |
| 2776 | * |
| 2777 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2778 | * specified timeout each time it has been successfully used. |
| 2779 | * |
| 2780 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2781 | * |
| 2782 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2783 | * |
| 2784 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2785 | * a {@link SecurityException} will be thrown. |
| 2786 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2787 | * <p>The calling device admin can verify the value it has set by calling |
| 2788 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2789 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2790 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2791 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2792 | * profile. |
| 2793 | * |
| 2794 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2795 | * @param timeoutMs The new timeout, after which the user will have to unlock with strong |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2796 | * authentication method. A value of 0 means the admin is not participating in |
| 2797 | * controlling the timeout. |
| 2798 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2799 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2800 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2801 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2802 | * |
| 2803 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2804 | */ |
| 2805 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2806 | long timeoutMs) { |
| 2807 | if (mService != null) { |
| 2808 | try { |
| 2809 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2810 | } catch (RemoteException e) { |
| 2811 | throw e.rethrowFromSystemServer(); |
| 2812 | } |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | /** |
| 2817 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 2818 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 2819 | * After the returned timeout the user is required to use strong authentication method. |
| 2820 | * |
| 2821 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2822 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2823 | * restrictions on the parent profile. |
| 2824 | * |
| 2825 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 2826 | * accross all participating admins. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2827 | * @return The timeout or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2828 | */ |
| 2829 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 2830 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 2831 | } |
| 2832 | |
| 2833 | /** @hide per-user version */ |
| 2834 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 2835 | if (mService != null) { |
| 2836 | try { |
| 2837 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 2838 | } catch (RemoteException e) { |
| 2839 | throw e.rethrowFromSystemServer(); |
| 2840 | } |
| 2841 | } |
| 2842 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 2843 | } |
| 2844 | |
| 2845 | /** |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2846 | * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the |
| 2847 | * keyring. The user's credential will need to be entered again in order to derive the |
| 2848 | * credential encryption key that will be stored back in the keyring for future use. |
| 2849 | * <p> |
| 2850 | * This flag can only be used by a profile owner when locking a managed profile on an FBE |
| 2851 | * device. |
| 2852 | * <p> |
| 2853 | * In order to secure user data, the user will be stopped and restarted so apps should wait |
| 2854 | * until they are next run to perform further actions. |
| 2855 | */ |
| 2856 | public static final int FLAG_EVICT_CE_KEY = 1; |
| 2857 | |
| 2858 | /** @hide */ |
| 2859 | @Retention(RetentionPolicy.SOURCE) |
| 2860 | @IntDef(flag=true, value={FLAG_EVICT_CE_KEY}) |
| 2861 | public @interface LockNowFlag {} |
| 2862 | |
| 2863 | /** |
| 2864 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2865 | * this call. |
| 2866 | * <p> |
| 2867 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2868 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2869 | * <p> |
| 2870 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2871 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
| 2872 | * <p> |
| 2873 | * Equivalent to calling {@link #lockNow(int)} with no flags. |
| 2874 | * |
| 2875 | * @throws SecurityException if the calling application does not own an active administrator |
| 2876 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2877 | */ |
| 2878 | public void lockNow() { |
| 2879 | lockNow(0); |
| 2880 | } |
| 2881 | |
| 2882 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2883 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2884 | * this call. |
| 2885 | * <p> |
| 2886 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2887 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2888 | * <p> |
| 2889 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2890 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2891 | * |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2892 | * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2893 | * @throws SecurityException if the calling application does not own an active administrator |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2894 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the |
| 2895 | * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile |
| 2896 | * owner of a managed profile. |
| 2897 | * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when |
| 2898 | * locking the parent profile. |
| 2899 | * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a |
| 2900 | * non-FBE device. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2901 | */ |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2902 | public void lockNow(@LockNowFlag int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2903 | if (mService != null) { |
| 2904 | try { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 2905 | mService.lockNow(flags, mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2906 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2907 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2908 | } |
| 2909 | } |
| 2910 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2911 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2912 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2913 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2914 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2915 | */ |
| 2916 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2917 | |
| 2918 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2919 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2920 | * data. |
| 2921 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2922 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2923 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2924 | */ |
| 2925 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2926 | |
| 2927 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 2928 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 2929 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 2930 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 2931 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2932 | * <p> |
| 2933 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2934 | * 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] | 2935 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2936 | * @param flags Bit mask of additional options: currently supported flags are |
| 2937 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2938 | * @throws SecurityException if the calling application does not own an active administrator |
| 2939 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2940 | */ |
| 2941 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2942 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2943 | if (mService != null) { |
| 2944 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2945 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2946 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2947 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2951 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2952 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2953 | * Called by an application that is administering the device to set the |
| 2954 | * global proxy and exclusion list. |
| 2955 | * <p> |
| 2956 | * The calling device admin must have requested |
| 2957 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2958 | * this method; if it has not, a security exception will be thrown. |
| 2959 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2960 | * 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] | 2961 | * 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] | 2962 | * be returned. |
| 2963 | * The method can be called repeatedly by the device admin alrady setting the |
| 2964 | * proxy to update the proxy and exclusion list. |
| 2965 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2966 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2967 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2968 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2969 | * @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] | 2970 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2971 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2972 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2973 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2974 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2975 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2976 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2977 | if (proxySpec == null) { |
| 2978 | throw new NullPointerException(); |
| 2979 | } |
| 2980 | if (mService != null) { |
| 2981 | try { |
| 2982 | String hostSpec; |
| 2983 | String exclSpec; |
| 2984 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2985 | hostSpec = null; |
| 2986 | exclSpec = null; |
| 2987 | } else { |
| 2988 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2989 | throw new IllegalArgumentException(); |
| 2990 | } |
| 2991 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2992 | String hostName = sa.getHostName(); |
| 2993 | int port = sa.getPort(); |
| 2994 | StringBuilder hostBuilder = new StringBuilder(); |
| 2995 | hostSpec = hostBuilder.append(hostName) |
| 2996 | .append(":").append(Integer.toString(port)).toString(); |
| 2997 | if (exclusionList == null) { |
| 2998 | exclSpec = ""; |
| 2999 | } else { |
| 3000 | StringBuilder listBuilder = new StringBuilder(); |
| 3001 | boolean firstDomain = true; |
| 3002 | for (String exclDomain : exclusionList) { |
| 3003 | if (!firstDomain) { |
| 3004 | listBuilder = listBuilder.append(","); |
| 3005 | } else { |
| 3006 | firstDomain = false; |
| 3007 | } |
| 3008 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 3009 | } |
| 3010 | exclSpec = listBuilder.toString(); |
| 3011 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 3012 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 3013 | != android.net.Proxy.PROXY_VALID) |
| 3014 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3015 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3016 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3017 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3018 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3019 | } |
| 3020 | } |
| 3021 | return null; |
| 3022 | } |
| 3023 | |
| 3024 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3025 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 3026 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 3027 | * unusual like general internal filtering this may be useful. On a private network where the |
| 3028 | * proxy is not accessible, you may break HTTP using this. |
| 3029 | * <p> |
| 3030 | * This method requires the caller to be the device owner. |
| 3031 | * <p> |
| 3032 | * 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] | 3033 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3034 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3035 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3036 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 3037 | * {@code null} value will clear the global HTTP proxy. |
| 3038 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3039 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3040 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 3041 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3042 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3043 | if (mService != null) { |
| 3044 | try { |
| 3045 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 3046 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3047 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3053 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3054 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 3055 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 3056 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3057 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3058 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3059 | if (mService != null) { |
| 3060 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3061 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3062 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3063 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 3064 | } |
| 3065 | } |
| 3066 | return null; |
| 3067 | } |
| 3068 | |
| 3069 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3070 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3071 | * indicating that encryption is not supported. |
| 3072 | */ |
| 3073 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 3074 | |
| 3075 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3076 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3077 | * indicating that encryption is supported, but is not currently active. |
| 3078 | */ |
| 3079 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 3080 | |
| 3081 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3082 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3083 | * indicating that encryption is not currently active, but is currently |
| 3084 | * being activated. This is only reported by devices that support |
| 3085 | * encryption of data and only when the storage is currently |
| 3086 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 3087 | * to become encrypted will never return this value. |
| 3088 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3089 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3090 | |
| 3091 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3092 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3093 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3094 | * <p> |
| 3095 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3096 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3097 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3098 | |
| 3099 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3100 | * Result code for {@link #getStorageEncryptionStatus}: |
| 3101 | * indicating that encryption is active, but an encryption key has not |
| 3102 | * been set by the user. |
| 3103 | */ |
| 3104 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 3105 | |
| 3106 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3107 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3108 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 3109 | * <p> |
| 3110 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 3111 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 3112 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3113 | */ |
| 3114 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 3115 | |
| 3116 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3117 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 3118 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 3119 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 3120 | * to check encryption status. However, on some devices this activity may never return, as |
| 3121 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 3122 | */ |
| 3123 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 3124 | public static final String ACTION_START_ENCRYPTION |
| 3125 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3126 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3127 | * Widgets are enabled in keyguard |
| 3128 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3129 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3130 | |
| 3131 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3132 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3133 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3134 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 3135 | |
| 3136 | /** |
| 3137 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3138 | */ |
| 3139 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 3140 | |
| 3141 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3142 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3143 | */ |
| 3144 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 3145 | |
| 3146 | /** |
| 3147 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 3148 | */ |
| 3149 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 3150 | |
| 3151 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 3152 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 3153 | * (e.g. PIN/Pattern/Password). |
| 3154 | */ |
| 3155 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 3156 | |
| 3157 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 3158 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 3159 | */ |
| 3160 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 3161 | |
| 3162 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 3163 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 3164 | */ |
| 3165 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 3166 | |
| 3167 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3168 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3169 | */ |
| 3170 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3171 | |
| 3172 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3173 | * Called by an application that is administering the device to request that the storage system |
| 3174 | * be encrypted. |
| 3175 | * <p> |
| 3176 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 3177 | * supported setting will always be used. If any device administrator requests device |
| 3178 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 3179 | * 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] | 3180 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3181 | * <p> |
| 3182 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 3183 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 3184 | * control the encryption of any other storage areas. There is one exception: If |
| 3185 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 3186 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 3187 | * written to disk within the encrypted storage area. |
| 3188 | * <p> |
| 3189 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 3190 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 3191 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 3192 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3193 | * |
| 3194 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3195 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3196 | * @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] | 3197 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 3198 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 3199 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 3200 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3201 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3202 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3203 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3204 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3205 | if (mService != null) { |
| 3206 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3207 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3208 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3209 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3213 | } |
| 3214 | |
| 3215 | /** |
| 3216 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3217 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3218 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3219 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3220 | * this will return the requested encryption setting as an aggregate of all active |
| 3221 | * administrators. |
| 3222 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3223 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3224 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3225 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3226 | if (mService != null) { |
| 3227 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3228 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3229 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3230 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3231 | } |
| 3232 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3233 | return false; |
| 3234 | } |
| 3235 | |
| 3236 | /** |
| 3237 | * Called by an application that is administering the device to |
| 3238 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3239 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3240 | * Depending on the returned status code, the caller may proceed in different |
| 3241 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 3242 | * storage system does not support encryption. If the |
| 3243 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 3244 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3245 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3246 | * storage system has enabled encryption but no password is set so further action |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3247 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3248 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3249 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3250 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3251 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3252 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3253 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3254 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3255 | */ |
| 3256 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3257 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3258 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | /** @hide per-user version */ |
| 3262 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3263 | if (mService != null) { |
| 3264 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3265 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3266 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3267 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3268 | } |
| 3269 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3270 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3271 | } |
| 3272 | |
| 3273 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3274 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3275 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3276 | * keep the certificate on the device. |
| 3277 | * |
| 3278 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3279 | * this certificate. |
| 3280 | * |
| 3281 | * @hide |
| 3282 | */ |
| 3283 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3284 | if (mService != null) { |
| 3285 | try { |
| 3286 | return mService.approveCaCert(alias, userHandle, approval); |
| 3287 | } catch (RemoteException e) { |
| 3288 | throw e.rethrowFromSystemServer(); |
| 3289 | } |
| 3290 | } |
| 3291 | return false; |
| 3292 | } |
| 3293 | |
| 3294 | /** |
| 3295 | * Check whether a CA certificate has been approved by the device user. |
| 3296 | * |
| 3297 | * @hide |
| 3298 | */ |
| 3299 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3300 | if (mService != null) { |
| 3301 | try { |
| 3302 | return mService.isCaCertApproved(alias, userHandle); |
| 3303 | } catch (RemoteException e) { |
| 3304 | throw e.rethrowFromSystemServer(); |
| 3305 | } |
| 3306 | } |
| 3307 | return false; |
| 3308 | } |
| 3309 | |
| 3310 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3311 | * Installs the given certificate as a user CA. |
| 3312 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3313 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3314 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3315 | * security exception will be thrown. |
| 3316 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3317 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3318 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3319 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3320 | * |
| 3321 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3322 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3323 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3324 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3325 | * @see #setDelegatedScopes |
| 3326 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3327 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3328 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3329 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3330 | if (mService != null) { |
| 3331 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3332 | return mService.installCaCert(admin, mContext.getPackageName(), certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3333 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3334 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3335 | } |
| 3336 | } |
| 3337 | return false; |
| 3338 | } |
| 3339 | |
| 3340 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3341 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3342 | * |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3343 | * The caller must be a profile or device owner on that user, or a delegate package given the |
| 3344 | * {@link #DELEGATION_CERT_INSTALL} scope via {@link #setDelegatedScopes}; otherwise a |
| 3345 | * security exception will be thrown. |
| 3346 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3347 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3348 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3349 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3350 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3351 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3352 | * @see #setDelegatedScopes |
| 3353 | * @see #DELEGATION_CERT_INSTALL |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3354 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3355 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3356 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3357 | if (mService != null) { |
| 3358 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3359 | final String alias = getCaCertAlias(certBuffer); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3360 | mService.uninstallCaCerts(admin, mContext.getPackageName(), new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3361 | } catch (CertificateException e) { |
| 3362 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3363 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3364 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3365 | } |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3370 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3371 | * If a user has installed any certificates by other means than device policy these will be |
| 3372 | * included too. |
| 3373 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3374 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3375 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3376 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3377 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3378 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3379 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3380 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3381 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3382 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3383 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3384 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3385 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3386 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3387 | for (String alias : certStore.userAliases()) { |
| 3388 | try { |
| 3389 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3390 | } catch (CertificateException ce) { |
| 3391 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3392 | } |
| 3393 | } |
| 3394 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3395 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3396 | } |
| 3397 | } |
| 3398 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3402 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3403 | * means other than device policy will also be removed, except for system CA certificates. |
| 3404 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3405 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3406 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3407 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3408 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3409 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3410 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3411 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3412 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3413 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3414 | mService.uninstallCaCerts(admin, mContext.getPackageName(), |
| 3415 | new TrustedCertificateStore().userAliases() .toArray(new String[0])); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3416 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3417 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3418 | } |
| 3419 | } |
| 3420 | } |
| 3421 | |
| 3422 | /** |
| 3423 | * Returns whether this certificate is installed as a trusted CA. |
| 3424 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3425 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3426 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3427 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3428 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3429 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3430 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3431 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3432 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3433 | if (mService != null) { |
| 3434 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3435 | mService.enforceCanManageCaCerts(admin, mContext.getPackageName()); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3436 | return getCaCertAlias(certBuffer) != null; |
| 3437 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3438 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3439 | } catch (CertificateException ce) { |
| 3440 | Log.w(TAG, "Could not parse certificate", ce); |
| 3441 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3442 | } |
| 3443 | return false; |
| 3444 | } |
| 3445 | |
| 3446 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3447 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3448 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3449 | * the certificate and use the private key, given direct user approval. |
| 3450 | * |
| 3451 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3452 | * direct user approval. This is for security - should a certificate installer become |
| 3453 | * compromised, certificates it had already installed will be protected. |
| 3454 | * |
| 3455 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3456 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3457 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3458 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3459 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3460 | * @param privKey The private key to install. |
| 3461 | * @param cert The certificate to install. |
| 3462 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3463 | * with that alias already exists, it will be overwritten. |
| 3464 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3465 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3466 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3467 | * @see #setDelegatedScopes |
| 3468 | * @see #DELEGATION_CERT_INSTALL |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3469 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3470 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3471 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3472 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | /** |
| 3476 | * 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] | 3477 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3478 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3479 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3480 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3481 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3482 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3483 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3484 | * |
| 3485 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3486 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3487 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3488 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3489 | * certificate and include the chain of trust in order. This will be returned by |
| 3490 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3491 | * @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] | 3492 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3493 | * @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] | 3494 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3495 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3496 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3497 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3498 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3499 | * @see android.security.KeyChain#getCertificateChain |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3500 | * @see #setDelegatedScopes |
| 3501 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3502 | */ |
| 3503 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3504 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3505 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3506 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3507 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3508 | byte[] pemChain = null; |
| 3509 | if (certs.length > 1) { |
| 3510 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3511 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3512 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3513 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3514 | return mService.installKeyPair(admin, mContext.getPackageName(), pkcs8Key, pemCert, |
| 3515 | pemChain, alias, requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3516 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3517 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3518 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3519 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3520 | } catch (CertificateException | IOException e) { |
| 3521 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3522 | } |
| 3523 | return false; |
| 3524 | } |
| 3525 | |
| 3526 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3527 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3528 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3529 | * |
| 3530 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3531 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3532 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3533 | * @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] | 3534 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3535 | * owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3536 | * @see #setDelegatedScopes |
| 3537 | * @see #DELEGATION_CERT_INSTALL |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3538 | */ |
| 3539 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3540 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3541 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3542 | return mService.removeKeyPair(admin, mContext.getPackageName(), alias); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3543 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3544 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3545 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3549 | * @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] | 3550 | * doesn't exist. |
| 3551 | */ |
| 3552 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3553 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3554 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3555 | new ByteArrayInputStream(certBuffer)); |
| 3556 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3557 | } |
| 3558 | |
| 3559 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3560 | * 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] | 3561 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3562 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3563 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3564 | * <p> |
| 3565 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3566 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3567 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3568 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3569 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3570 | * 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] | 3571 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3572 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3573 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3574 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3575 | * @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] | 3576 | * access. If {@code null} is given the current package will be cleared. |
| 3577 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3578 | * |
| 3579 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 3580 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3581 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3582 | @Deprecated |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3583 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3584 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3585 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3586 | if (mService != null) { |
| 3587 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3588 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3589 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3590 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3591 | } |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3596 | * Called by a profile owner or device owner to retrieve the certificate installer for the user, |
| 3597 | * or {@code null} if none is set. If there are multiple delegates this function will return one |
| 3598 | * of them. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3599 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3600 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3601 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3602 | * none is set. |
| 3603 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3604 | * |
| 3605 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 3606 | * with the {@link #DELEGATION_CERT_INSTALL} scope instead. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3607 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3608 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3609 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3610 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3611 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3612 | if (mService != null) { |
| 3613 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3614 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3615 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3616 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | return null; |
| 3620 | } |
| 3621 | |
| 3622 | /** |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 3623 | * Called by a profile owner or device owner to grant access to privileged APIs to another app. |
| 3624 | * Granted APIs are determined by {@code scopes}, which is a list of the {@code DELEGATION_*} |
| 3625 | * constants. |
| 3626 | * <p> |
| 3627 | * Delegated scopes are a per-user state. The delegated access is persistent until it is later |
| 3628 | * cleared by calling this method with an empty {@code scopes} list or uninstalling the |
| 3629 | * {@code delegatePackage}. |
| 3630 | * |
| 3631 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3632 | * @param delegatePackage The package name of the app which will be given access. |
| 3633 | * @param scopes The groups of privileged APIs whose access should be granted to |
| 3634 | * {@code delegatedPackage}. |
| 3635 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3636 | */ |
| 3637 | public void setDelegatedScopes(@NonNull ComponentName admin, @NonNull String delegatePackage, |
| 3638 | @NonNull List<String> scopes) { |
| 3639 | throwIfParentInstance("setDelegatedScopes"); |
| 3640 | if (mService != null) { |
| 3641 | try { |
| 3642 | mService.setDelegatedScopes(admin, delegatePackage, scopes); |
| 3643 | } catch (RemoteException e) { |
| 3644 | throw e.rethrowFromSystemServer(); |
| 3645 | } |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Called by a profile owner or device owner to retrieve a list of the scopes given to a |
| 3651 | * delegate package. Other apps can use this method to retrieve their own delegated scopes by |
| 3652 | * passing {@code null} for {@code admin} and their own package name as |
| 3653 | * {@code delegatedPackage}. |
| 3654 | * |
| 3655 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3656 | * {@code null} if the caller is {@code delegatedPackage}. |
| 3657 | * @param delegatedPackage The package name of the app whose scopes should be retrieved. |
| 3658 | * @return A list containing the scopes given to {@code delegatedPackage}. |
| 3659 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3660 | */ |
| 3661 | @NonNull |
| 3662 | public List<String> getDelegatedScopes(@NonNull ComponentName admin, |
| 3663 | @NonNull String delegatedPackage) { |
| 3664 | throwIfParentInstance("getDelegatedScopes"); |
| 3665 | if (mService != null) { |
| 3666 | try { |
| 3667 | return mService.getDelegatedScopes(admin, delegatedPackage); |
| 3668 | } catch (RemoteException e) { |
| 3669 | throw e.rethrowFromSystemServer(); |
| 3670 | } |
| 3671 | } |
| 3672 | return null; |
| 3673 | } |
| 3674 | |
| 3675 | /** |
| 3676 | * Called by a profile owner or device owner to retrieve a list of delegate packages that were |
| 3677 | * granted a delegation scope. |
| 3678 | * |
| 3679 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3680 | * @param delegationScope The scope whose delegates should be retrieved. |
| 3681 | * @return A list of package names of the current delegated packages for |
| 3682 | {@code delegationScope}. |
| 3683 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
| 3684 | */ |
| 3685 | @Nullable |
| 3686 | public List<String> getDelegatePackages(@NonNull ComponentName admin, |
| 3687 | @NonNull String delegationScope) { |
| 3688 | throwIfParentInstance("getDelegatePackages"); |
| 3689 | if (mService != null) { |
| 3690 | try { |
| 3691 | return mService.getDelegatePackages(admin, delegationScope); |
| 3692 | } catch (RemoteException e) { |
| 3693 | throw e.rethrowFromSystemServer(); |
| 3694 | } |
| 3695 | } |
| 3696 | return null; |
| 3697 | } |
| 3698 | |
| 3699 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3700 | * Called by a device or profile owner to configure an always-on VPN connection through a |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3701 | * specific application for the current user. |
| 3702 | * |
| 3703 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3704 | * TODO: delete once there are no longer any live references. |
| 3705 | * @hide |
| 3706 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3707 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3708 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3709 | throws NameNotFoundException, UnsupportedOperationException { |
| 3710 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3711 | } |
| 3712 | |
| 3713 | /** |
| 3714 | * 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] | 3715 | * specific application for the current user. This connection is automatically granted and |
| 3716 | * persisted after a reboot. |
| 3717 | * <p> |
| 3718 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3719 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3720 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3721 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3722 | * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3723 | * remove an existing always-on VPN configuration. |
| 3724 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3725 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3726 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3727 | * @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] | 3728 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3729 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3730 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3731 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3732 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3733 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3734 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3735 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3736 | if (mService != null) { |
| 3737 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3738 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3739 | throw new NameNotFoundException(vpnPackage); |
| 3740 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3741 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3742 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3743 | } |
| 3744 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | /** |
| 3748 | * 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] | 3749 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3750 | * 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] | 3751 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3752 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3753 | * is set. |
| 3754 | * @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] | 3755 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3756 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3757 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3758 | if (mService != null) { |
| 3759 | try { |
| 3760 | return mService.getAlwaysOnVpnPackage(admin); |
| 3761 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3762 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3763 | } |
| 3764 | } |
| 3765 | return null; |
| 3766 | } |
| 3767 | |
| 3768 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3769 | * Called by an application that is administering the device to disable all cameras on the |
| 3770 | * device, for this user. After setting this, no applications running as this user will be able |
| 3771 | * to access any cameras on the device. |
| 3772 | * <p> |
| 3773 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3774 | * <p> |
| 3775 | * The calling device admin must have requested |
| 3776 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3777 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3778 | * |
| 3779 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3780 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3781 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3782 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3783 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3784 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3785 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3786 | if (mService != null) { |
| 3787 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3788 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3789 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3790 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3791 | } |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3796 | * 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] | 3797 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3798 | * @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] | 3799 | * have disabled the camera |
| 3800 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3801 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3802 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3803 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3807 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3808 | if (mService != null) { |
| 3809 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3810 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3811 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3812 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3813 | } |
| 3814 | } |
| 3815 | return false; |
| 3816 | } |
| 3817 | |
| 3818 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3819 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3820 | * <p> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 3821 | * If the device contains secondary users or profiles, they must be affiliated with the device |
| 3822 | * owner user. Otherwise a {@link SecurityException} will be thrown. See |
| 3823 | * {@link #setAffiliationIds}. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3824 | * |
| 3825 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3826 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3827 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3828 | * bugreport is still running or waiting for the user to share or decline) |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 3829 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 3830 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3831 | */ |
| 3832 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3833 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3834 | if (mService != null) { |
| 3835 | try { |
| 3836 | return mService.requestBugreport(admin); |
| 3837 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3838 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3839 | } |
| 3840 | } |
| 3841 | return false; |
| 3842 | } |
| 3843 | |
| 3844 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3845 | * Determine whether or not creating a guest user has been disabled for the device |
| 3846 | * |
| 3847 | * @hide |
| 3848 | */ |
| 3849 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3850 | // Currently guest users can always be created if multi-user is enabled |
| 3851 | // TODO introduce a policy for guest user creation |
| 3852 | return false; |
| 3853 | } |
| 3854 | |
| 3855 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3856 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3857 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3858 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3859 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3860 | * <p> |
| 3861 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3862 | * exception will be thrown. |
| 3863 | * <p> |
| 3864 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3865 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3866 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3867 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3868 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3869 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3870 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3871 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3872 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3873 | if (mService != null) { |
| 3874 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3875 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3876 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3877 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3878 | } |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3883 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3884 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3885 | * @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] | 3886 | * have disabled screen capture. |
| 3887 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3888 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3889 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3890 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3894 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3895 | if (mService != null) { |
| 3896 | try { |
| 3897 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3898 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3899 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3900 | } |
| 3901 | } |
| 3902 | return false; |
| 3903 | } |
| 3904 | |
| 3905 | /** |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 3906 | * Called by a device or profile owner to set whether auto time is required. If auto time is |
| 3907 | * required, no user will be able set the date and time and network date and time will be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3908 | * <p> |
| 3909 | * Note: if auto time is required the user can still manually set the time zone. |
| 3910 | * <p> |
Jason Parks | 841cb0a | 2017-01-17 15:25:17 -0600 | [diff] [blame] | 3911 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3912 | * exception will be thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3913 | * |
| 3914 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3915 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3916 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3917 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3918 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3919 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3920 | if (mService != null) { |
| 3921 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3922 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3923 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3924 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3925 | } |
| 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | /** |
| 3930 | * @return true if auto time is required. |
| 3931 | */ |
| 3932 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3933 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3934 | if (mService != null) { |
| 3935 | try { |
| 3936 | return mService.getAutoTimeRequired(); |
| 3937 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3938 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3939 | } |
| 3940 | } |
| 3941 | return false; |
| 3942 | } |
| 3943 | |
| 3944 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3945 | * 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] | 3946 | * <p> |
| 3947 | * The system user is exempt from this policy - it is never ephemeral. |
| 3948 | * <p> |
| 3949 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 3950 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3951 | * |
| 3952 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3953 | * @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] | 3954 | * subsequently created users will be ephemeral. |
| 3955 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3956 | * @hide |
| 3957 | */ |
| 3958 | public void setForceEphemeralUsers( |
| 3959 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3960 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3961 | if (mService != null) { |
| 3962 | try { |
| 3963 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3964 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3965 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3966 | } |
| 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | /** |
| 3971 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3972 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3973 | * @hide |
| 3974 | */ |
| 3975 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3976 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3977 | if (mService != null) { |
| 3978 | try { |
| 3979 | return mService.getForceEphemeralUsers(admin); |
| 3980 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3981 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3982 | } |
| 3983 | } |
| 3984 | return false; |
| 3985 | } |
| 3986 | |
| 3987 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3988 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3989 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3990 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3991 | * <p> |
| 3992 | * The calling device admin must have requested |
| 3993 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 3994 | * if it has not, a security exception will be thrown. |
| 3995 | * <p> |
| 3996 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 3997 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 3998 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3999 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4000 | * <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] | 4001 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4002 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4003 | * there is one, or the parent user otherwise. |
| 4004 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 4005 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4006 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4007 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 4008 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4009 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 4010 | * profile. |
| 4011 | * <p> |
| 4012 | * Requests to disable other features on a managed profile will be ignored. |
| 4013 | * <p> |
| 4014 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 4015 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 4016 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4017 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4018 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4019 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 4020 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 4021 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 4022 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 4023 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 4024 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 4025 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4026 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4027 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4028 | if (mService != null) { |
| 4029 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4030 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4031 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4032 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4033 | } |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4038 | * Determine whether or not features have been disabled in keyguard either by the calling |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 4039 | * admin, if specified, or all admins that set restrictions on this user and its participating |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 4040 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 4041 | * |
| 4042 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 4043 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 4044 | * restrictions on the parent profile. |
| 4045 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4046 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 4047 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 4048 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 4049 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4050 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4051 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4052 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4056 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4057 | if (mService != null) { |
| 4058 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 4059 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4060 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4061 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4062 | } |
| 4063 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 4064 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4068 | * @hide |
| 4069 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4070 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 4071 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4072 | if (mService != null) { |
| 4073 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4074 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4075 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4076 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4077 | } |
| 4078 | } |
| 4079 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4080 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4081 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4082 | * @hide |
| 4083 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4084 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4085 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4089 | * @hide |
| 4090 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4091 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4092 | if (mService != null) { |
| 4093 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4094 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4095 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4096 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 4097 | } |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | /** |
| 4102 | * @hide |
| 4103 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4104 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4105 | if (mService != null) { |
| 4106 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 4107 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4108 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4109 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4113 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4114 | /** |
| 4115 | * @hide |
| 4116 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame] | 4117 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 4118 | if (mService != null) { |
| 4119 | try { |
| 4120 | mService.reportPasswordChanged(userId); |
| 4121 | } catch (RemoteException e) { |
| 4122 | throw e.rethrowFromSystemServer(); |
| 4123 | } |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | /** |
| 4128 | * @hide |
| 4129 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4130 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4131 | if (mService != null) { |
| 4132 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4133 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4134 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4135 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4136 | } |
| 4137 | } |
| 4138 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 4139 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4140 | /** |
| 4141 | * @hide |
| 4142 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4143 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4144 | if (mService != null) { |
| 4145 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 4146 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4147 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4148 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4149 | } |
| 4150 | } |
| 4151 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4152 | |
| 4153 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4154 | * @hide |
| 4155 | */ |
| 4156 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 4157 | if (mService != null) { |
| 4158 | try { |
| 4159 | mService.reportFailedFingerprintAttempt(userHandle); |
| 4160 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4161 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | /** |
| 4167 | * @hide |
| 4168 | */ |
| 4169 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 4170 | if (mService != null) { |
| 4171 | try { |
| 4172 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 4173 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4174 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4175 | } |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4180 | * Should be called when keyguard has been dismissed. |
| 4181 | * @hide |
| 4182 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4183 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4184 | if (mService != null) { |
| 4185 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4186 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4187 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4188 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | } |
| 4192 | |
| 4193 | /** |
| 4194 | * Should be called when keyguard view has been shown to the user. |
| 4195 | * @hide |
| 4196 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4197 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4198 | if (mService != null) { |
| 4199 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 4200 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4201 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4202 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4208 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4209 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4210 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 4211 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4212 | * @return whether the package was successfully registered as the device owner. |
| 4213 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4214 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4215 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4216 | public boolean setDeviceOwner(ComponentName who) { |
| 4217 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | /** |
| 4221 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4222 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4223 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 4224 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | /** |
| 4228 | * @hide |
| 4229 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4230 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 4231 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | /** |
| 4235 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4236 | * Sets the given package as the device owner. The package must already be installed. There |
| 4237 | * must not already be a device owner. |
| 4238 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4239 | * this method. |
| 4240 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 4241 | * 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] | 4242 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4243 | * @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] | 4244 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4245 | * @return whether the package was successfully registered as the device owner. |
| 4246 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4247 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4248 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4249 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4250 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4251 | if (mService != null) { |
| 4252 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4253 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4254 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4255 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4256 | } |
| 4257 | } |
| 4258 | return false; |
| 4259 | } |
| 4260 | |
| 4261 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4262 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 4263 | * 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] | 4264 | * 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] | 4265 | * package is currently registered as the device owner app, pass in the package name from |
| 4266 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4267 | * 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] | 4268 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 4269 | * the setup process. |
| 4270 | * @param packageName the package name of the app, to compare with the registered device owner |
| 4271 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4272 | * @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] | 4273 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4274 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4275 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4276 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 4277 | } |
| 4278 | |
| 4279 | /** |
| 4280 | * @return true if a package is registered as device owner, only when it's running on the |
| 4281 | * calling user. |
| 4282 | * |
| 4283 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 4284 | * @hide |
| 4285 | */ |
| 4286 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 4287 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * @return true if a package is registered as device owner, even if it's running on a different |
| 4292 | * user. |
| 4293 | * |
| 4294 | * <p>Requires the MANAGE_USERS permission. |
| 4295 | * |
| 4296 | * @hide |
| 4297 | */ |
| 4298 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 4299 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 4300 | } |
| 4301 | |
| 4302 | /** |
| 4303 | * @return device owner component name, only when it's running on the calling user. |
| 4304 | * |
| 4305 | * @hide |
| 4306 | */ |
| 4307 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 4308 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 4309 | } |
| 4310 | |
| 4311 | /** |
| 4312 | * @return device owner component name, even if it's running on a different user. |
| 4313 | * |
| 4314 | * <p>Requires the MANAGE_USERS permission. |
| 4315 | * |
| 4316 | * @hide |
| 4317 | */ |
Polina Bondarenko | 23561db | 2016-12-16 11:47:28 +0100 | [diff] [blame] | 4318 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4319 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 4320 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 4321 | } |
| 4322 | |
| 4323 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4324 | if (packageName == null) { |
| 4325 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4326 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4327 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 4328 | if (deviceOwner == null) { |
| 4329 | return false; |
| 4330 | } |
| 4331 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4334 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 4335 | if (mService != null) { |
| 4336 | try { |
| 4337 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 4338 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4339 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 4343 | } |
| 4344 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4345 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4346 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 4347 | * no device owner. |
| 4348 | * |
| 4349 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4350 | * |
| 4351 | * @hide |
| 4352 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4353 | public int getDeviceOwnerUserId() { |
| 4354 | if (mService != null) { |
| 4355 | try { |
| 4356 | return mService.getDeviceOwnerUserId(); |
| 4357 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4358 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4359 | } |
| 4360 | } |
| 4361 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4365 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4366 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 4367 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4368 | * |
| 4369 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4370 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4371 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4372 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4373 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4374 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4375 | if (mService != null) { |
| 4376 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4377 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4378 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4379 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | } |
| 4383 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4384 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4385 | * Returns the device owner package name, only if it's running on the calling user. |
| 4386 | * |
| 4387 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4388 | * |
| 4389 | * @hide |
| 4390 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4391 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4392 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4393 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4394 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4395 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4399 | * Called by the system to find out whether the device is managed by a Device Owner. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4400 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4401 | * @return whether the device is managed by a Device Owner. |
| 4402 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4403 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4404 | * |
| 4405 | * @hide |
| 4406 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4407 | @SystemApi |
| 4408 | @TestApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4409 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4410 | try { |
| 4411 | return mService.hasDeviceOwner(); |
| 4412 | } catch (RemoteException re) { |
| 4413 | throw re.rethrowFromSystemServer(); |
| 4414 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | /** |
| 4418 | * Returns the device owner name. Note this method *will* return the device owner |
| 4419 | * name when it's running on a different user. |
| 4420 | * |
| 4421 | * <p>Requires the MANAGE_USERS permission. |
| 4422 | * |
| 4423 | * @hide |
| 4424 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4425 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4426 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4427 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4428 | if (mService != null) { |
| 4429 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4430 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4431 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4432 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4433 | } |
| 4434 | } |
| 4435 | return null; |
| 4436 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4437 | |
| 4438 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4439 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4440 | * @deprecated Do not use |
| 4441 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4442 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4443 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4444 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4445 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4446 | return null; |
| 4447 | } |
| 4448 | |
| 4449 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4450 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4451 | * @deprecated Do not use |
| 4452 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4453 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4454 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4455 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4456 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4457 | return null; |
| 4458 | } |
| 4459 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4460 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4461 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4462 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4463 | * Sets the given component as an active admin and registers the package as the profile |
| 4464 | * owner for this user. The package must already be installed and there shouldn't be |
| 4465 | * an existing profile owner registered for this user. Also, this method must be called |
| 4466 | * before the user setup has been completed. |
| 4467 | * <p> |
| 4468 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4469 | * MANAGE_DEVICE_ADMINS permission. |
| 4470 | * @param admin The component to register as an active admin and profile owner. |
| 4471 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4472 | * @return whether the admin was successfully registered as the profile owner. |
| 4473 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4474 | * the user has already been set up. |
| 4475 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4476 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4477 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4478 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4479 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4480 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4481 | if (mService != null) { |
| 4482 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4483 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4484 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4485 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4486 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4487 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4488 | } |
| 4489 | } |
| 4490 | return false; |
| 4491 | } |
| 4492 | |
| 4493 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4494 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 4495 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 4496 | * will be thrown. |
| 4497 | * <p> |
| 4498 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4499 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4500 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4501 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4502 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4503 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4504 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4505 | if (mService != null) { |
| 4506 | try { |
| 4507 | mService.clearProfileOwner(admin); |
| 4508 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4509 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4510 | } |
| 4511 | } |
| 4512 | } |
| 4513 | |
| 4514 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4515 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4516 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4517 | */ |
| 4518 | public boolean hasUserSetupCompleted() { |
| 4519 | if (mService != null) { |
| 4520 | try { |
| 4521 | return mService.hasUserSetupCompleted(); |
| 4522 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4523 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4524 | } |
| 4525 | } |
| 4526 | return true; |
| 4527 | } |
| 4528 | |
| 4529 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4530 | * @hide |
| 4531 | * 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] | 4532 | * already be installed. There must not already be a profile owner for this user. |
| 4533 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4534 | * this method. |
| 4535 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4536 | * - the caller is SYSTEM_UID. |
| 4537 | * - 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] | 4538 | * @param admin the component name to be registered as profile owner. |
| 4539 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4540 | * @param userHandle the userId to set the profile owner for. |
| 4541 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4542 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4543 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4544 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4545 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4546 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4547 | if (mService != null) { |
| 4548 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4549 | if (ownerName == null) { |
| 4550 | ownerName = ""; |
| 4551 | } |
| 4552 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4553 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4554 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4555 | } |
| 4556 | } |
| 4557 | return false; |
| 4558 | } |
| 4559 | |
| 4560 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4561 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4562 | * <p> |
| 4563 | * 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] | 4564 | * 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] | 4565 | * <p> |
| 4566 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4567 | * will be blank and the user will not be allowed to change it. |
| 4568 | * <p> |
| 4569 | * 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] | 4570 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4571 | * and set a new version of this string accordingly. |
| 4572 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4573 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4574 | * @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] | 4575 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4576 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4577 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4578 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4579 | if (mService != null) { |
| 4580 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4581 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4582 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4583 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4584 | } |
| 4585 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | /** |
| 4589 | * @return The device owner information. If it is not set returns {@code null}. |
| 4590 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4591 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4592 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4593 | if (mService != null) { |
| 4594 | try { |
| 4595 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4596 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4597 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | return null; |
| 4601 | } |
| 4602 | |
| 4603 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4604 | * Called by device or profile owners to suspend packages for this user. This function can be |
| 4605 | * called by a device owner, profile owner, or by a delegate given the |
| 4606 | * {@link #DELEGATION_PACKAGE_ACCESS} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4607 | * <p> |
| 4608 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4609 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4610 | * device. |
| 4611 | * <p> |
| 4612 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4613 | * 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] | 4614 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4615 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4616 | * @param admin The name of the admin component to check, or {@code null} if the caller is a |
| 4617 | * package access delegate. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4618 | * @param packageNames The package names to suspend or unsuspend. |
| 4619 | * @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] | 4620 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4621 | * @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] | 4622 | * this method. |
| 4623 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4624 | * @see #setDelegatedScopes |
| 4625 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4626 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4627 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4628 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4629 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4630 | if (mService != null) { |
| 4631 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4632 | return mService.setPackagesSuspended(admin, mContext.getPackageName(), packageNames, |
| 4633 | suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4634 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4635 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4636 | } |
| 4637 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4638 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4642 | * Determine if a package is suspended. This function can be called by a device owner, profile |
| 4643 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 4644 | * {@link #setDelegatedScopes}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4645 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4646 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 4647 | * {@code null} if the caller is a package access delegate. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4648 | * @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] | 4649 | * @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] | 4650 | * suspended, could not be found or an error occurred. |
| 4651 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4652 | * @throws NameNotFoundException if the package could not be found. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4653 | * @see #setDelegatedScopes |
| 4654 | * @see #DELEGATION_PACKAGE_ACCESS |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4655 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4656 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4657 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4658 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4659 | if (mService != null) { |
| 4660 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 4661 | return mService.isPackageSuspended(admin, mContext.getPackageName(), packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4662 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4663 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4664 | } catch (IllegalArgumentException ex) { |
| 4665 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | return false; |
| 4669 | } |
| 4670 | |
| 4671 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4672 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4673 | * be used. Only the profile owner can call this. |
| 4674 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4675 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4676 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4677 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4678 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4679 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4680 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4681 | if (mService != null) { |
| 4682 | try { |
| 4683 | mService.setProfileEnabled(admin); |
| 4684 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4685 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4686 | } |
| 4687 | } |
| 4688 | } |
| 4689 | |
| 4690 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4691 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4692 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4693 | * 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] | 4694 | * |
| 4695 | * @see #isProfileOwnerApp |
| 4696 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4697 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4698 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4699 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4700 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4701 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4702 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4703 | if (mService != null) { |
| 4704 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4705 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4706 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4707 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4708 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4709 | } |
| 4710 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4711 | |
| 4712 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4713 | * 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] | 4714 | * 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] | 4715 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4716 | * |
| 4717 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4718 | * @return Whether or not the package is registered as the profile owner. |
| 4719 | */ |
| 4720 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4721 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4722 | if (mService != null) { |
| 4723 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4724 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4725 | return profileOwner != null |
| 4726 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4727 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4728 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4729 | } |
| 4730 | } |
| 4731 | return false; |
| 4732 | } |
| 4733 | |
| 4734 | /** |
| 4735 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4736 | * @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] | 4737 | * owner has been set for that user. |
| 4738 | * @throws IllegalArgumentException if the userId is invalid. |
| 4739 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4740 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4741 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4742 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4743 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4744 | } |
| 4745 | |
| 4746 | /** |
| 4747 | * @see #getProfileOwner() |
| 4748 | * @hide |
| 4749 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4750 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4751 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4752 | if (mService != null) { |
| 4753 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4754 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4755 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4756 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4757 | } |
| 4758 | } |
| 4759 | return null; |
| 4760 | } |
| 4761 | |
| 4762 | /** |
| 4763 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4764 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4765 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4766 | * @throws IllegalArgumentException if the userId is invalid. |
| 4767 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4768 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4769 | if (mService != null) { |
| 4770 | try { |
| 4771 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4772 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4773 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4774 | } |
| 4775 | } |
| 4776 | return null; |
| 4777 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4778 | |
| 4779 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4780 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4781 | * @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] | 4782 | * @return the human readable name of the organisation associated with this profile owner or |
| 4783 | * null if one is not set. |
| 4784 | * @throws IllegalArgumentException if the userId is invalid. |
| 4785 | */ |
| 4786 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4787 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4788 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4789 | if (mService != null) { |
| 4790 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 4791 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4792 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4793 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4794 | } |
| 4795 | } |
| 4796 | return null; |
| 4797 | } |
| 4798 | |
| 4799 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4800 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 4801 | * 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] | 4802 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 4803 | * intent preferences are reset. |
| 4804 | * <p> |
| 4805 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 4806 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 4807 | * the filter. |
| 4808 | * <p> |
| 4809 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 4810 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4811 | * |
| 4812 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4813 | * @param filter The IntentFilter for which a default handler is added. |
| 4814 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4815 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4816 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4817 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 4818 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4819 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4820 | if (mService != null) { |
| 4821 | try { |
| 4822 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4823 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4824 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | } |
| 4828 | |
| 4829 | /** |
| 4830 | * 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] | 4831 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4832 | * <p> |
| 4833 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4834 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4835 | * |
| 4836 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4837 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4838 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4839 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4840 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4841 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4842 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4843 | if (mService != null) { |
| 4844 | try { |
| 4845 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4846 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4847 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4848 | } |
| 4849 | } |
| 4850 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4851 | |
| 4852 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4853 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4854 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4855 | * {@link #getApplicationRestrictions}. |
| 4856 | * <p> |
| 4857 | * This permission is persistent until it is later cleared by calling this method with a |
| 4858 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4859 | * <p> |
| 4860 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4861 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4862 | * |
| 4863 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4864 | * @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] | 4865 | * APIs. If {@code null} is given the current package will be cleared. |
| 4866 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4867 | * @throws NameNotFoundException if {@code packageName} is not found |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4868 | * |
| 4869 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #setDelegatedScopes} |
| 4870 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4871 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4872 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4873 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4874 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4875 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4876 | if (mService != null) { |
| 4877 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4878 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4879 | throw new NameNotFoundException(packageName); |
| 4880 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4881 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4882 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4883 | } |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | /** |
| 4888 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4889 | * package for the current user, or {@code null} if none is set. If there are multiple |
| 4890 | * delegates this function will return one of them. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4891 | * |
| 4892 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4893 | * @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] | 4894 | * {@code null} if none is set. |
| 4895 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4896 | * |
| 4897 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatePackages} |
| 4898 | * with the {@link #DELEGATION_APP_RESTRICTIONS} scope instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4899 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4900 | @Deprecated |
| 4901 | @Nullable |
| 4902 | public String getApplicationRestrictionsManagingPackage( |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4903 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4904 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4905 | if (mService != null) { |
| 4906 | try { |
| 4907 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4908 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4909 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4910 | } |
| 4911 | } |
| 4912 | return null; |
| 4913 | } |
| 4914 | |
| 4915 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4916 | * Called by any application to find out whether it has been granted permission via |
| 4917 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4918 | * for the calling user. |
| 4919 | * |
| 4920 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4921 | * that method. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4922 | * |
| 4923 | * @deprecated From {@link android.os.Build.VERSION_CODES#O}. Use {@link #getDelegatedScopes} |
| 4924 | * instead. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4925 | */ |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4926 | @Deprecated |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4927 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4928 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4929 | if (mService != null) { |
| 4930 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4931 | return mService.isCallerApplicationRestrictionsManagingPackage( |
| 4932 | mContext.getPackageName()); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4933 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4934 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4935 | } |
| 4936 | } |
| 4937 | return false; |
| 4938 | } |
| 4939 | |
| 4940 | /** |
| 4941 | * 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] | 4942 | * <p> |
| 4943 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4944 | * application restrictions via {@link #setDelegatedScopes} with the |
| 4945 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4946 | * <p> |
| 4947 | * 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] | 4948 | * <ul> |
| 4949 | * <li>{@code boolean} |
| 4950 | * <li>{@code int} |
| 4951 | * <li>{@code String} or {@code String[]} |
| 4952 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4953 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4954 | * <p> |
| 4955 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 4956 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4957 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4958 | * <p> |
| 4959 | * The application restrictions are only made visible to the target application via |
| 4960 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 4961 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4962 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4963 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4964 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 4965 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4966 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4967 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4968 | * @param packageName The name of the package to update restricted settings for. |
| 4969 | * @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] | 4970 | * set of active restrictions. |
| 4971 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4972 | * @see #setDelegatedScopes |
| 4973 | * @see #DELEGATION_APP_RESTRICTIONS |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4974 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4975 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4976 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4977 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4978 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4979 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4980 | if (mService != null) { |
| 4981 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 4982 | mService.setApplicationRestrictions(admin, mContext.getPackageName(), packageName, |
| 4983 | settings); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4984 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4985 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4986 | } |
| 4987 | } |
| 4988 | } |
| 4989 | |
| 4990 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4991 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 4992 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 4993 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4994 | * {@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] | 4995 | * <p> |
| 4996 | * The calling device admin must have requested |
| 4997 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4998 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4999 | * <p> |
| 5000 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5001 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 5002 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5003 | * |
| 5004 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5005 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5006 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 5007 | * strictly disabled according to the state of the |
| 5008 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 5009 | * <p> |
| 5010 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 5011 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 5012 | * device admins. |
| 5013 | * <p> |
| 5014 | * Consult documentation for the specific TrustAgent to determine legal options |
| 5015 | * parameters. |
| 5016 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 5017 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5018 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5019 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 5020 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5021 | if (mService != null) { |
| 5022 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5023 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5024 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5025 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | } |
| 5029 | |
| 5030 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5031 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 5032 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 5033 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5034 | * <p> |
| 5035 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 5036 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 5037 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5038 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 5039 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 5040 | * this function returns a list of configurations for all admins that declare |
| 5041 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 5042 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 5043 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 5044 | * 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] | 5045 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5046 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5047 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5048 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5049 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5050 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5054 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 5055 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5056 | if (mService != null) { |
| 5057 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 5058 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 5059 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5060 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5061 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5062 | } |
| 5063 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 5064 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 5065 | } |
| 5066 | |
| 5067 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5068 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 5069 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5070 | * <p> |
| 5071 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5072 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5073 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5074 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5075 | * @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] | 5076 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5077 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5078 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5079 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5080 | if (mService != null) { |
| 5081 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5082 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5083 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5084 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5085 | } |
| 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5090 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 5091 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5092 | * <p> |
| 5093 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5094 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5095 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5096 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5097 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5098 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5099 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5100 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5101 | if (mService != null) { |
| 5102 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5103 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5104 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5105 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 5106 | } |
| 5107 | } |
| 5108 | return false; |
| 5109 | } |
| 5110 | |
| 5111 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5112 | * Determine whether or not caller-Id information has been disabled. |
| 5113 | * |
| 5114 | * @param userHandle The user for whom to check the caller-id permission |
| 5115 | * @hide |
| 5116 | */ |
| 5117 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 5118 | if (mService != null) { |
| 5119 | try { |
| 5120 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 5121 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5122 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 5123 | } |
| 5124 | } |
| 5125 | return false; |
| 5126 | } |
| 5127 | |
| 5128 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5129 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 5130 | * managed profile will be shown in the parent profile, for incoming calls. |
| 5131 | * <p> |
| 5132 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5133 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5134 | * |
| 5135 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5136 | * @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] | 5137 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5138 | */ |
| 5139 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 5140 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5141 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5142 | if (mService != null) { |
| 5143 | try { |
| 5144 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 5145 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5146 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5147 | } |
| 5148 | } |
| 5149 | } |
| 5150 | |
| 5151 | /** |
| 5152 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 5153 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5154 | * <p> |
| 5155 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5156 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5157 | * |
| 5158 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5159 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5160 | */ |
| 5161 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5162 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5163 | if (mService != null) { |
| 5164 | try { |
| 5165 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 5166 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5167 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5168 | } |
| 5169 | } |
| 5170 | return false; |
| 5171 | } |
| 5172 | |
| 5173 | |
| 5174 | /** |
| 5175 | * Determine whether or not contacts search has been disabled. |
| 5176 | * |
| 5177 | * @param userHandle The user for whom to check the contacts search permission |
| 5178 | * @hide |
| 5179 | */ |
| 5180 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 5181 | if (mService != null) { |
| 5182 | try { |
| 5183 | return mService |
| 5184 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 5185 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5186 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 5187 | } |
| 5188 | } |
| 5189 | return false; |
| 5190 | } |
| 5191 | |
| 5192 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5193 | * 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] | 5194 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5195 | * @hide |
| 5196 | */ |
| 5197 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5198 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5199 | if (mService != null) { |
| 5200 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5201 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 5202 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5203 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5204 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 5205 | } |
| 5206 | } |
| 5207 | } |
| 5208 | |
| 5209 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5210 | * 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] | 5211 | * @hide |
| 5212 | */ |
| 5213 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 5214 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 5215 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 5216 | originalIntent); |
| 5217 | } |
| 5218 | |
| 5219 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5220 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 5221 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5222 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5223 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5224 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5225 | * <p> |
| 5226 | * This API works on managed profile only. |
| 5227 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5228 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5229 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 5230 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5231 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5232 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5233 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5234 | if (mService != null) { |
| 5235 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5236 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5237 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5238 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5239 | } |
| 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5244 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 5245 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5246 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5247 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 5248 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5249 | * <p> |
| 5250 | * This API works on managed profile only. |
| 5251 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5252 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5253 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5254 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5255 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5256 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5257 | if (mService != null) { |
| 5258 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5259 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5260 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5261 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5262 | } |
| 5263 | } |
| 5264 | return true; |
| 5265 | } |
| 5266 | |
| 5267 | /** |
| 5268 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 5269 | * <p> |
| 5270 | * This API works on managed profile UserHandle only. |
| 5271 | * |
| 5272 | * @param userHandle The user for whom to check the caller-id permission |
| 5273 | * @hide |
| 5274 | */ |
| 5275 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 5276 | if (mService != null) { |
| 5277 | try { |
| 5278 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 5279 | .getIdentifier()); |
| 5280 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5281 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 5282 | } |
| 5283 | } |
| 5284 | return true; |
| 5285 | } |
| 5286 | |
| 5287 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5288 | * 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] | 5289 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 5290 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 5291 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5292 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5293 | * @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] | 5294 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 5295 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5296 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 5297 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5298 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5299 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5300 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5301 | if (mService != null) { |
| 5302 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5303 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5304 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5305 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5311 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 5312 | * 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] | 5313 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5314 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5315 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5316 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5317 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5318 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5319 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5320 | if (mService != null) { |
| 5321 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 5322 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5323 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5324 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 5325 | } |
| 5326 | } |
| 5327 | } |
| 5328 | |
| 5329 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5330 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 5331 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5332 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 5333 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 5334 | * the list and not part of the system can not be enabled by the user. |
| 5335 | * <p> |
| 5336 | * Calling with a null value for the list disables the restriction so that all services can be |
| 5337 | * used, calling with an empty list only allows the builtin system's services. |
| 5338 | * <p> |
| 5339 | * 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] | 5340 | * |
| 5341 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5342 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5343 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 5344 | * accessibility services enabled, that are not in the list. |
| 5345 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5346 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5347 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5348 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5349 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5350 | if (mService != null) { |
| 5351 | try { |
| 5352 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 5353 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5354 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5355 | } |
| 5356 | } |
| 5357 | return false; |
| 5358 | } |
| 5359 | |
| 5360 | /** |
| 5361 | * 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] | 5362 | * <p> |
| 5363 | * An empty list means no accessibility services except system services are allowed. Null means |
| 5364 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5365 | * |
| 5366 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5367 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5368 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5369 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5370 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5371 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5372 | if (mService != null) { |
| 5373 | try { |
| 5374 | return mService.getPermittedAccessibilityServices(admin); |
| 5375 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5376 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5377 | } |
| 5378 | } |
| 5379 | return null; |
| 5380 | } |
| 5381 | |
| 5382 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5383 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5384 | * |
| 5385 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5386 | * @param packageName Accessibility service package name that needs to be checked. |
| 5387 | * @param userHandle user id the admin is running as. |
| 5388 | * @return true if the accessibility service is permitted, otherwise false. |
| 5389 | * |
| 5390 | * @hide |
| 5391 | */ |
| 5392 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5393 | @NonNull String packageName, int userHandle) { |
| 5394 | if (mService != null) { |
| 5395 | try { |
| 5396 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5397 | userHandle); |
| 5398 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5399 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5400 | } |
| 5401 | } |
| 5402 | return false; |
| 5403 | } |
| 5404 | |
| 5405 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5406 | * Returns the list of accessibility services permitted by the device or profiles |
| 5407 | * owners of this user. |
| 5408 | * |
| 5409 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5410 | * it will contain the intersection of the permitted lists for any device or profile |
| 5411 | * owners that apply to this user. It will also include any system accessibility services. |
| 5412 | * |
| 5413 | * @param userId which user to check for. |
| 5414 | * @return List of accessiblity service package names. |
| 5415 | * @hide |
| 5416 | */ |
| 5417 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5418 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5419 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5420 | if (mService != null) { |
| 5421 | try { |
| 5422 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5423 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5424 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | return null; |
| 5428 | } |
| 5429 | |
| 5430 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5431 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5432 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5433 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5434 | * When zero or more packages have been added, input method that are not in the list and not |
| 5435 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5436 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5437 | * <p> |
| 5438 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5439 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5440 | * <p> |
| 5441 | * 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] | 5442 | * |
| 5443 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5444 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5445 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5446 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5447 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5448 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5449 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5450 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5451 | if (mService != null) { |
| 5452 | try { |
| 5453 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5454 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5455 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5456 | } |
| 5457 | } |
| 5458 | return false; |
| 5459 | } |
| 5460 | |
| 5461 | |
| 5462 | /** |
| 5463 | * 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] | 5464 | * <p> |
| 5465 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5466 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5467 | * |
| 5468 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5469 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5470 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5471 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5472 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5473 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5474 | if (mService != null) { |
| 5475 | try { |
| 5476 | return mService.getPermittedInputMethods(admin); |
| 5477 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5478 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5479 | } |
| 5480 | } |
| 5481 | return null; |
| 5482 | } |
| 5483 | |
| 5484 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5485 | * Called by the system to check if a specific input method is disabled by admin. |
| 5486 | * |
| 5487 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5488 | * @param packageName Input method package name that needs to be checked. |
| 5489 | * @param userHandle user id the admin is running as. |
| 5490 | * @return true if the input method is permitted, otherwise false. |
| 5491 | * |
| 5492 | * @hide |
| 5493 | */ |
| 5494 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5495 | @NonNull String packageName, int userHandle) { |
| 5496 | if (mService != null) { |
| 5497 | try { |
| 5498 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5499 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5500 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5501 | } |
| 5502 | } |
| 5503 | return false; |
| 5504 | } |
| 5505 | |
| 5506 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5507 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5508 | * 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] | 5509 | * |
| 5510 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5511 | * it will contain the intersection of the permitted lists for any device or profile |
| 5512 | * owners that apply to this user. It will also include any system input methods. |
| 5513 | * |
| 5514 | * @return List of input method package names. |
| 5515 | * @hide |
| 5516 | */ |
| 5517 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5518 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5519 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5520 | if (mService != null) { |
| 5521 | try { |
| 5522 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5523 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5524 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5525 | } |
| 5526 | } |
| 5527 | return null; |
| 5528 | } |
| 5529 | |
| 5530 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5531 | * Get the list of apps to keep around as APKs even if no user has currently installed it. This |
| 5532 | * function can be called by a device owner or by a delegate given the |
| 5533 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
| 5534 | * <p> |
| 5535 | * Please note that packages returned in this method are not automatically pre-cached. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5536 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5537 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5538 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5539 | * @return List of package names to keep cached. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5540 | * @see #setDelegatedScopes |
| 5541 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5542 | * @hide |
| 5543 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5544 | public @Nullable List<String> getKeepUninstalledPackages(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5545 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5546 | if (mService != null) { |
| 5547 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5548 | return mService.getKeepUninstalledPackages(admin, mContext.getPackageName()); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5549 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5550 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5551 | } |
| 5552 | } |
| 5553 | return null; |
| 5554 | } |
| 5555 | |
| 5556 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5557 | * Set a list of apps to keep around as APKs even if no user has currently installed it. This |
| 5558 | * function can be called by a device owner or by a delegate given the |
| 5559 | * {@link #DELEGATION_KEEP_UNINSTALLED_PACKAGES} scope via {@link #setDelegatedScopes}. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5560 | * |
| 5561 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5562 | * automatically pre-cached.</p> |
| 5563 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5564 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5565 | * {@code null} if the caller is a keep uninstalled packages delegate. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5566 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5567 | * @throws SecurityException if {@code admin} is not a device owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5568 | * @see #setDelegatedScopes |
| 5569 | * @see #DELEGATION_KEEP_UNINSTALLED_PACKAGES |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5570 | * @hide |
| 5571 | */ |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5572 | public void setKeepUninstalledPackages(@Nullable ComponentName admin, |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5573 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5574 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5575 | if (mService != null) { |
| 5576 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5577 | mService.setKeepUninstalledPackages(admin, mContext.getPackageName(), packageNames); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5578 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5579 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5580 | } |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5585 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5586 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5587 | * created. If you need to persist an identifier for this user, use |
| 5588 | * {@link UserManager#getSerialNumberForUser}. |
| 5589 | * |
| 5590 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5591 | * @param name the user's name |
| 5592 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5593 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5594 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5595 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5596 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5597 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5598 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5599 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5600 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5601 | return null; |
| 5602 | } |
| 5603 | |
| 5604 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5605 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5606 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5607 | * created. If you need to persist an identifier for this user, use |
| 5608 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5609 | * immediately. |
| 5610 | * |
| 5611 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5612 | * as registered as an active admin on the new user. The profile owner package will be |
| 5613 | * installed on the new user if it already is installed on the device. |
| 5614 | * |
| 5615 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5616 | * profileOwnerComponent when onEnable is called. |
| 5617 | * |
| 5618 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5619 | * @param name the user's name |
| 5620 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5621 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5622 | * the user. |
| 5623 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5624 | * on the new user. |
| 5625 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5626 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5627 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5628 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5629 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5630 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5631 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5632 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5633 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5634 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5635 | return null; |
| 5636 | } |
| 5637 | |
| 5638 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5639 | * 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] | 5640 | */ |
| 5641 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5642 | |
| 5643 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5644 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5645 | * ephemeral. |
| 5646 | * @hide |
| 5647 | */ |
| 5648 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5649 | |
| 5650 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5651 | * Called by a device owner to create a user with the specified name and a given component of |
| 5652 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5653 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5654 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5655 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5656 | * <p> |
| 5657 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5658 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5659 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5660 | * on the new user. |
| 5661 | * <p> |
| 5662 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5663 | * 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] | 5664 | * |
| 5665 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5666 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5667 | * @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] | 5668 | * same package as admin, otherwise no user is created and an |
| 5669 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5670 | * @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] | 5671 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5672 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5673 | * @see UserHandle |
| 5674 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5675 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5676 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5677 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5678 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5679 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5680 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5681 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5682 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5683 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5684 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5685 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5686 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5687 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5691 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5692 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5693 | * |
| 5694 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5695 | * @param userHandle the user to remove. |
| 5696 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5697 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5698 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5699 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5700 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5701 | try { |
| 5702 | return mService.removeUser(admin, userHandle); |
| 5703 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5704 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5705 | } |
| 5706 | } |
| 5707 | |
| 5708 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5709 | * Called by a device owner to switch the specified user to the foreground. |
| 5710 | * |
| 5711 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5712 | * @param userHandle the user to switch to; null will switch to primary. |
| 5713 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5714 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5715 | * @see Intent#ACTION_USER_FOREGROUND |
| 5716 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5717 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5718 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5719 | try { |
| 5720 | return mService.switchUser(admin, userHandle); |
| 5721 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5722 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5723 | } |
| 5724 | } |
| 5725 | |
| 5726 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5727 | * Retrieves the application restrictions for a given target application running in the calling |
| 5728 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5729 | * <p> |
| 5730 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5731 | * application restrictions via {@link #setDelegatedScopes} with the |
| 5732 | * {@link #DELEGATION_APP_RESTRICTIONS} scope; otherwise a security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5733 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5734 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5735 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5736 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5737 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5738 | * @param packageName The name of the package to fetch restricted settings of. |
| 5739 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5740 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 5741 | * {@link Bundle} if no restrictions have been set. |
| 5742 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5743 | * @see #setDelegatedScopes |
| 5744 | * @see #DELEGATION_APP_RESTRICTIONS |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5745 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5746 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5747 | public @NonNull Bundle getApplicationRestrictions( |
| 5748 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5749 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5750 | if (mService != null) { |
| 5751 | try { |
Edman Anjos | f994677 | 2016-11-28 16:35:15 +0100 | [diff] [blame] | 5752 | return mService.getApplicationRestrictions(admin, mContext.getPackageName(), |
| 5753 | packageName); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5754 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5755 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | return null; |
| 5759 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5760 | |
| 5761 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5762 | * 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] | 5763 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5764 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5765 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5766 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5767 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5768 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5769 | * for the list of keys. |
| 5770 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5771 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5772 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5773 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5774 | if (mService != null) { |
| 5775 | try { |
| 5776 | mService.setUserRestriction(admin, key, true); |
| 5777 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5778 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5779 | } |
| 5780 | } |
| 5781 | } |
| 5782 | |
| 5783 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5784 | * 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] | 5785 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5786 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5787 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5788 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5789 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5790 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5791 | * for the list of keys. |
| 5792 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5793 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5794 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5795 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5796 | if (mService != null) { |
| 5797 | try { |
| 5798 | mService.setUserRestriction(admin, key, false); |
| 5799 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5800 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5801 | } |
| 5802 | } |
| 5803 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 5804 | |
| 5805 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5806 | * Called by a profile or device owner to get user restrictions set with |
| 5807 | * {@link #addUserRestriction(ComponentName, String)}. |
| 5808 | * <p> |
| 5809 | * 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] | 5810 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5811 | * {@link UserManager#getUserRestrictions()}. |
| 5812 | * |
| 5813 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5814 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5815 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5816 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5817 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5818 | Bundle ret = null; |
| 5819 | if (mService != null) { |
| 5820 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 5821 | ret = mService.getUserRestrictions(admin); |
| 5822 | } catch (RemoteException e) { |
| 5823 | throw e.rethrowFromSystemServer(); |
| 5824 | } |
| 5825 | } |
| 5826 | return ret == null ? new Bundle() : ret; |
| 5827 | } |
| 5828 | |
| 5829 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5830 | * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and |
| 5831 | * actual package file remain. This function can be called by a device owner, profile owner, or |
| 5832 | * by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 5833 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5834 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5835 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5836 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5837 | * @param packageName The name of the package to hide or unhide. |
| 5838 | * @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] | 5839 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5840 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5841 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5842 | * @see #setDelegatedScopes |
| 5843 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5844 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5845 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5846 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5847 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5848 | if (mService != null) { |
| 5849 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5850 | return mService.setApplicationHidden(admin, mContext.getPackageName(), packageName, |
| 5851 | hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5852 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5853 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5854 | } |
| 5855 | } |
| 5856 | return false; |
| 5857 | } |
| 5858 | |
| 5859 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5860 | * Determine if a package is hidden. This function can be called by a device owner, profile |
| 5861 | * owner, or by a delegate given the {@link #DELEGATION_PACKAGE_ACCESS} scope via |
| 5862 | * {@link #setDelegatedScopes}. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5863 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5864 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5865 | * {@code null} if the caller is a package access delegate. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5866 | * @param packageName The name of the package to retrieve the hidden status of. |
| 5867 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5868 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5869 | * @see #setDelegatedScopes |
| 5870 | * @see #DELEGATION_PACKAGE_ACCESS |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5871 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5872 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5873 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5874 | if (mService != null) { |
| 5875 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5876 | return mService.isApplicationHidden(admin, mContext.getPackageName(), packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5877 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5878 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5879 | } |
| 5880 | } |
| 5881 | return false; |
| 5882 | } |
| 5883 | |
| 5884 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5885 | * Re-enable a system app that was disabled by default when the user was initialized. This |
| 5886 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 5887 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5888 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5889 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5890 | * {@code null} if the caller is an enable system app delegate. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5891 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5892 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5893 | * @see #setDelegatedScopes |
| 5894 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5895 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5896 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5897 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5898 | if (mService != null) { |
| 5899 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5900 | mService.enableSystemApp(admin, mContext.getPackageName(), packageName); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5901 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5902 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5903 | } |
| 5904 | } |
| 5905 | } |
| 5906 | |
| 5907 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5908 | * Re-enable system apps by intent that were disabled by default when the user was initialized. |
| 5909 | * This function can be called by a device owner, profile owner, or by a delegate given the |
| 5910 | * {@link #DELEGATION_ENABLE_SYSTEM_APP} scope via {@link #setDelegatedScopes}. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5911 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5912 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 5913 | * {@code null} if the caller is an enable system app delegate. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5914 | * @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] | 5915 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5916 | * @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] | 5917 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5918 | * @see #setDelegatedScopes |
| 5919 | * @see #DELEGATION_PACKAGE_ACCESS |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5920 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5921 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5922 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5923 | if (mService != null) { |
| 5924 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 5925 | return mService.enableSystemAppWithIntent(admin, mContext.getPackageName(), intent); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5926 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5927 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5928 | } |
| 5929 | } |
| 5930 | return 0; |
| 5931 | } |
| 5932 | |
| 5933 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 5934 | * Called by a device owner or profile owner to disable account management for a specific type |
| 5935 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5936 | * <p> |
| 5937 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 5938 | * exception will be thrown. |
| 5939 | * <p> |
| 5940 | * When account management is disabled for an account type, adding or removing an account of |
| 5941 | * that type will not be possible. |
| 5942 | * <p> |
| 5943 | * 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] | 5944 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 5945 | * management for a specific type is disabled. |
| 5946 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5947 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5948 | * @param accountType For which account management is disabled or enabled. |
| 5949 | * @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] | 5950 | * enabled (false). |
| 5951 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5952 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5953 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5954 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5955 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5956 | if (mService != null) { |
| 5957 | try { |
| 5958 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 5959 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5960 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5961 | } |
| 5962 | } |
| 5963 | } |
| 5964 | |
| 5965 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5966 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 5967 | * |
| 5968 | * <p> Account management can be disabled/enabled by calling |
| 5969 | * {@link #setAccountManagementDisabled}. |
| 5970 | * |
| 5971 | * @return a list of account types for which account management has been disabled. |
| 5972 | * |
| 5973 | * @see #setAccountManagementDisabled |
| 5974 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5975 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5976 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5977 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | /** |
| 5981 | * @see #getAccountTypesWithManagementDisabled() |
| 5982 | * @hide |
| 5983 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5984 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5985 | if (mService != null) { |
| 5986 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5987 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5988 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5989 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5990 | } |
| 5991 | } |
| 5992 | |
| 5993 | return null; |
| 5994 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5995 | |
| 5996 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5997 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5998 | * <p> |
| 5999 | * Any packages that shares uid with an allowed package will also be allowed to activate lock |
| 6000 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
| 6001 | * package list results in locked tasks belonging to those packages to be finished. This |
| 6002 | * function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6003 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6004 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6005 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6006 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6007 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 6008 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 6009 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 6010 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6011 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6012 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6013 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6014 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6015 | if (mService != null) { |
| 6016 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6017 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6018 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6019 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6020 | } |
| 6021 | } |
| 6022 | } |
| 6023 | |
| 6024 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6025 | * 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] | 6026 | * |
| 6027 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6028 | * @hide |
| 6029 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6030 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6031 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6032 | if (mService != null) { |
| 6033 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 6034 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6035 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6036 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6037 | } |
| 6038 | } |
| 6039 | return null; |
| 6040 | } |
| 6041 | |
| 6042 | /** |
| 6043 | * This function lets the caller know whether the given component is allowed to start the |
| 6044 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6045 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6046 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6047 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6048 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6049 | if (mService != null) { |
| 6050 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 6051 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6052 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6053 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 6054 | } |
| 6055 | } |
| 6056 | return false; |
| 6057 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6058 | |
| 6059 | /** |
| 6060 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 6061 | * 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] | 6062 | * <p> |
| 6063 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6064 | * <ul> |
| 6065 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 6066 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 6067 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6068 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6069 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6070 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6071 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 6072 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 6073 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 6074 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 6075 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6076 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6077 | * <p> |
| 6078 | * 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] | 6079 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6080 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 6081 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 6082 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6083 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6084 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 6085 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6086 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6087 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 6088 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 6089 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6090 | * |
| 6091 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6092 | * @param setting The name of the setting to update. |
| 6093 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6094 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6095 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6096 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6097 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6098 | if (mService != null) { |
| 6099 | try { |
| 6100 | mService.setGlobalSetting(admin, setting, value); |
| 6101 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6102 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | } |
| 6106 | |
| 6107 | /** |
| 6108 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 6109 | * that the value of the setting is in the correct form for the setting type should be performed |
| 6110 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6111 | * <p> |
| 6112 | * 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] | 6113 | * <ul> |
| 6114 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 6115 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 6116 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 6117 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6118 | * <p> |
| 6119 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 6120 | * <ul> |
| 6121 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 6122 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6123 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6124 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6125 | * @param setting The name of the setting to update. |
| 6126 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6127 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6128 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6129 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6130 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6131 | if (mService != null) { |
| 6132 | try { |
| 6133 | mService.setSecureSetting(admin, setting, value); |
| 6134 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6135 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 6136 | } |
| 6137 | } |
| 6138 | } |
| 6139 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6140 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6141 | * Designates a specific service component as the provider for making permission requests of a |
| 6142 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6143 | * <p/> |
| 6144 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6145 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6146 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6147 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6148 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 6149 | * provider previously assigned. |
| 6150 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6151 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6152 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 6153 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6154 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6155 | if (mService != null) { |
| 6156 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 6157 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6158 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6159 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 6160 | } |
| 6161 | } |
| 6162 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6163 | |
| 6164 | /** |
| 6165 | * Called by profile or device owners to set the master volume mute on or off. |
Nicolas Prevot | aef3ce2 | 2016-09-22 12:00:25 +0100 | [diff] [blame] | 6166 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6167 | * |
| 6168 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6169 | * @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] | 6170 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6171 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6172 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6173 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6174 | if (mService != null) { |
| 6175 | try { |
| 6176 | mService.setMasterVolumeMuted(admin, on); |
| 6177 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6178 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6179 | } |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | /** |
| 6184 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 6185 | * |
| 6186 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6187 | * @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] | 6188 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6189 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6190 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6191 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6192 | if (mService != null) { |
| 6193 | try { |
| 6194 | return mService.isMasterVolumeMuted(admin); |
| 6195 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6196 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 6197 | } |
| 6198 | } |
| 6199 | return false; |
| 6200 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6201 | |
| 6202 | /** |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6203 | * Change whether a user can uninstall a package. This function can be called by a device owner, |
| 6204 | * profile owner, or by a delegate given the {@link #DELEGATION_BLOCK_UNINSTALL} scope via |
| 6205 | * {@link #setDelegatedScopes}. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6206 | * |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6207 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 6208 | * {@code null} if the caller is a block uninstall delegate. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6209 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6210 | * @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] | 6211 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6212 | * @see #setDelegatedScopes |
| 6213 | * @see #DELEGATION_BLOCK_UNINSTALL |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6214 | */ |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6215 | public void setUninstallBlocked(@Nullable ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 6216 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6217 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6218 | if (mService != null) { |
| 6219 | try { |
Edman Anjos | a5f2fb1 | 2016-12-19 11:25:54 -0800 | [diff] [blame] | 6220 | mService.setUninstallBlocked(admin, mContext.getPackageName(), packageName, |
| 6221 | uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6222 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6223 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6224 | } |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6229 | * 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] | 6230 | * 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] | 6231 | * <p> |
| 6232 | * <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] | 6233 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 6234 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 6235 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6236 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6237 | * @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] | 6238 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6239 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 6240 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6241 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6242 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6243 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6244 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6245 | if (mService != null) { |
| 6246 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 6247 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6248 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6249 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 6250 | } |
| 6251 | } |
| 6252 | return false; |
| 6253 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6254 | |
| 6255 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6256 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 6257 | * package to be available in the parent profile. As a result the user will be able to add |
| 6258 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 6259 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 6260 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6261 | * <p> |
| 6262 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6263 | * |
| 6264 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6265 | * @param packageName The package from which widget providers are white-listed. |
| 6266 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6267 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6268 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6269 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6270 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6271 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6272 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6273 | if (mService != null) { |
| 6274 | try { |
| 6275 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 6276 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6277 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6278 | } |
| 6279 | } |
| 6280 | return false; |
| 6281 | } |
| 6282 | |
| 6283 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6284 | * 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] | 6285 | * package to be available in the parent profile. For this method to take effect the package |
| 6286 | * should have been added via |
| 6287 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6288 | * <p> |
| 6289 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6290 | * |
| 6291 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6292 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6293 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6294 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6295 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6296 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 6297 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6298 | public boolean removeCrossProfileWidgetProvider( |
| 6299 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6300 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6301 | if (mService != null) { |
| 6302 | try { |
| 6303 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 6304 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6305 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6306 | } |
| 6307 | } |
| 6308 | return false; |
| 6309 | } |
| 6310 | |
| 6311 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 6312 | * 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] | 6313 | * available in the parent profile. |
| 6314 | * |
| 6315 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6316 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6317 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 6318 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6319 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6320 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6321 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6322 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6323 | if (mService != null) { |
| 6324 | try { |
| 6325 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 6326 | if (providers != null) { |
| 6327 | return providers; |
| 6328 | } |
| 6329 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6330 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 6331 | } |
| 6332 | } |
| 6333 | return Collections.emptyList(); |
| 6334 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6335 | |
| 6336 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 6337 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6338 | * |
| 6339 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6340 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6341 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6342 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6343 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6344 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6345 | try { |
| 6346 | mService.setUserIcon(admin, icon); |
| 6347 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6348 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 6349 | } |
| 6350 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 6351 | |
| 6352 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6353 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 6354 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6355 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6356 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6357 | * components in the device owner package can set system update policies and the most |
| 6358 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6359 | * @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] | 6360 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6361 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6362 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6363 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6364 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6365 | if (mService != null) { |
| 6366 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6367 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6368 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6369 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6370 | } |
| 6371 | } |
| 6372 | } |
| 6373 | |
| 6374 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 6375 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6376 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6377 | * @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] | 6378 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6379 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6380 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6381 | if (mService != null) { |
| 6382 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 6383 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6384 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6385 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 6386 | } |
| 6387 | } |
| 6388 | return null; |
| 6389 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6390 | |
| 6391 | /** |
| 6392 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6393 | * <p> |
| 6394 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 6395 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 6396 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 6397 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6398 | * |
| 6399 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6400 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6401 | * @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] | 6402 | * place. {@code true} otherwise. |
| 6403 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6404 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6405 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6406 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6407 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6408 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6409 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6410 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 6411 | } |
| 6412 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6413 | |
| 6414 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6415 | * 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] | 6416 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6417 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6418 | * |
| 6419 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6420 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6421 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6422 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6423 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6424 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6425 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6426 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6427 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6428 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6429 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6430 | } |
| 6431 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6432 | |
| 6433 | /** |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6434 | * Called by the system update service to notify device and profile owners of pending system |
| 6435 | * updates. |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6436 | * |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6437 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6438 | * permission. This method should only be used when it is unknown whether the pending system |
| 6439 | * update is a security patch. Otherwise, use |
| 6440 | * {@link #notifyPendingSystemUpdate(long, boolean)}. |
| 6441 | * |
| 6442 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6443 | * indicating when the current pending update was first available. {@code -1} if no |
| 6444 | * update is available. |
| 6445 | * @see #notifyPendingSystemUpdate(long, boolean) |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6446 | * @hide |
| 6447 | */ |
| 6448 | @SystemApi |
| 6449 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6450 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6451 | if (mService != null) { |
| 6452 | try { |
Charles He | dea0c3b | 2017-01-13 10:04:12 +0000 | [diff] [blame] | 6453 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime)); |
| 6454 | } catch (RemoteException re) { |
| 6455 | throw re.rethrowFromSystemServer(); |
| 6456 | } |
| 6457 | } |
| 6458 | } |
| 6459 | |
| 6460 | /** |
| 6461 | * Called by the system update service to notify device and profile owners of pending system |
| 6462 | * updates. |
| 6463 | * |
| 6464 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6465 | * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)} |
| 6466 | * when it is known whether the pending system update is a security patch. |
| 6467 | * |
| 6468 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} |
| 6469 | * indicating when the current pending update was first available. {@code -1} if no |
| 6470 | * update is available. |
| 6471 | * @param isSecurityPatch {@code true} if this system update is purely a security patch; |
| 6472 | * {@code false} if not. |
| 6473 | * @see #notifyPendingSystemUpdate(long) |
| 6474 | * @hide |
| 6475 | */ |
| 6476 | @SystemApi |
| 6477 | public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) { |
| 6478 | throwIfParentInstance("notifyPendingSystemUpdate"); |
| 6479 | if (mService != null) { |
| 6480 | try { |
| 6481 | mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime, |
| 6482 | isSecurityPatch)); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6483 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6484 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6485 | } |
| 6486 | } |
| 6487 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6488 | |
| 6489 | /** |
Pavel Grafov | d65799e | 2016-12-02 11:21:45 +0000 | [diff] [blame] | 6490 | * Called by device or profile owners to get information about a pending system update. |
| 6491 | * |
| 6492 | * @param admin Which profile or device owner this request is associated with. |
| 6493 | * @return Information about a pending system update or {@code null} if no update pending. |
| 6494 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
| 6495 | * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long) |
| 6496 | */ |
| 6497 | public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) { |
| 6498 | throwIfParentInstance("getPendingSystemUpdate"); |
| 6499 | try { |
| 6500 | return mService.getPendingSystemUpdate(admin); |
| 6501 | } catch (RemoteException re) { |
| 6502 | throw re.rethrowFromSystemServer(); |
| 6503 | } |
| 6504 | } |
| 6505 | |
| 6506 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6507 | * Set the default response for future runtime permission requests by applications. This |
| 6508 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6509 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
| 6510 | * The policy can allow for normal operation which prompts the user to grant a permission, or |
| 6511 | * can allow automatic granting or denying of runtime permission requests by an application. |
| 6512 | * This also applies to new permissions declared by app updates. When a permission is denied or |
| 6513 | * granted this way, the effect is equivalent to setting the permission * grant state via |
| 6514 | * {@link #setPermissionGrantState}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6515 | * <p/> |
| 6516 | * 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] | 6517 | * 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] | 6518 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6519 | * @param admin Which profile or device owner this request is associated with. |
| 6520 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6521 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6522 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6523 | * @see #setPermissionGrantState |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6524 | * @see #setDelegatedScopes |
| 6525 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6526 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6527 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6528 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6529 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6530 | mService.setPermissionPolicy(admin, mContext.getPackageName(), policy); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6531 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6532 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | /** |
| 6537 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6538 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6539 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6540 | * @param admin Which profile or device owner this request is associated with. |
| 6541 | * @return the current policy for future permission requests. |
| 6542 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6543 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6544 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6545 | try { |
| 6546 | return mService.getPermissionPolicy(admin); |
| 6547 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6548 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6549 | } |
| 6550 | } |
| 6551 | |
| 6552 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6553 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6554 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6555 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6556 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6557 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6558 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6559 | * by a profile owner, device owner, or a delegate given the |
| 6560 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6561 | * <p/> |
| 6562 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6563 | * the permission. It retains the previous grant, if any. |
| 6564 | * <p/> |
| 6565 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6566 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6567 | * |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6568 | * @param admin Which profile or device owner this request is associated with. |
| 6569 | * @param packageName The application to grant or revoke a permission to. |
| 6570 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6571 | * @param grantState The permission grant state which is one of |
| 6572 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6573 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6574 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6575 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6576 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6577 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6578 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6579 | * @see #setDelegatedScopes |
| 6580 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6581 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6582 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6583 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6584 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6585 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6586 | return mService.setPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6587 | permission, grantState); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6588 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6589 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b3 | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6590 | } |
| 6591 | } |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6592 | |
| 6593 | /** |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6594 | * Returns the current grant state of a runtime permission for a specific application. This |
| 6595 | * function can be called by a device owner, profile owner, or by a delegate given the |
| 6596 | * {@link #DELEGATION_PERMISSION_GRANT} scope via {@link #setDelegatedScopes}. |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6597 | * |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6598 | * @param admin Which profile or device owner this request is associated with, or {@code null} |
| 6599 | * if the caller is a permission grant delegate. |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6600 | * @param packageName The application to check the grant state for. |
| 6601 | * @param permission The permission to check for. |
| 6602 | * @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] | 6603 | * has not set a grant state, the return value is |
| 6604 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6605 | * permission is currently granted for the package. |
| 6606 | * <p/> |
| 6607 | * If a grant state was set by the profile or device owner, then the return value will |
| 6608 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6609 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6610 | * currently denied or granted. |
| 6611 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6612 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6613 | * @see PackageManager#checkPermission(String, String) |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6614 | * @see #setDelegatedScopes |
| 6615 | * @see #DELEGATION_PERMISSION_GRANT |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6616 | */ |
Bartosz Fabianowski | 4b0624f | 2017-01-16 11:47:28 +0100 | [diff] [blame] | 6617 | public int getPermissionGrantState(@Nullable ComponentName admin, String packageName, |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6618 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6619 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6620 | try { |
Edman Anjos | 52088e4 | 2017-01-13 22:26:17 +0100 | [diff] [blame^] | 6621 | return mService.getPermissionGrantState(admin, mContext.getPackageName(), packageName, |
| 6622 | permission); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6623 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6624 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b3753 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6625 | } |
| 6626 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6627 | |
| 6628 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6629 | * Returns whether it is possible for the caller to initiate provisioning of a managed profile |
| 6630 | * or device, setting itself as the device or profile owner. |
| 6631 | * |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6632 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6633 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6634 | * @return whether provisioning a managed profile or device is possible. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6635 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 6636 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6637 | public boolean isProvisioningAllowed(@NonNull String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6638 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6639 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6640 | return mService.isProvisioningAllowed(action, mContext.getPackageName()); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6641 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6642 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6643 | } |
| 6644 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6645 | |
| 6646 | /** |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6647 | * Checks whether it is possible to initiate provisioning a managed device, |
| 6648 | * profile or user, setting the given package as owner. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6649 | * |
| 6650 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6651 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 6652 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 6653 | * {@link #ACTION_PROVISION_MANAGED_USER} |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6654 | * @param packageName The package of the component that would be set as device, user, or profile |
| 6655 | * owner. |
| 6656 | * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed. |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6657 | * @hide |
| 6658 | */ |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6659 | public @ProvisioningPreCondition int checkProvisioningPreCondition( |
| 6660 | String action, @NonNull String packageName) { |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6661 | try { |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 6662 | return mService.checkProvisioningPreCondition(action, packageName); |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6663 | } catch (RemoteException re) { |
| 6664 | throw re.rethrowFromSystemServer(); |
| 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6669 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 6670 | * 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] | 6671 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6672 | * @param admin Which profile owner this request is associated with. |
| 6673 | * @return if this user is a managed profile of another user. |
| 6674 | */ |
| 6675 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6676 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6677 | try { |
| 6678 | return mService.isManagedProfile(admin); |
| 6679 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6680 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | /** |
| 6685 | * @hide |
| 6686 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 6687 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 6688 | * @param admin Which device owner this request is associated with. |
| 6689 | * @return if this user is a system-only user. |
| 6690 | */ |
| 6691 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 6692 | try { |
| 6693 | return mService.isSystemOnlyUser(admin); |
| 6694 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6695 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6696 | } |
| 6697 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6698 | |
| 6699 | /** |
| 6700 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 6701 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6702 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6703 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 6704 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 6705 | * <p> |
| 6706 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 6707 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6708 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6709 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6710 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6711 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6712 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6713 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6714 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6715 | } |
| 6716 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6717 | |
| 6718 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6719 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 6720 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6721 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6722 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6723 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6724 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6725 | */ |
| 6726 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6727 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6728 | try { |
| 6729 | mService.reboot(admin); |
| 6730 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6731 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6732 | } |
| 6733 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6734 | |
| 6735 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6736 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 6737 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 6738 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 6739 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 6740 | * truncated. |
| 6741 | * <p> |
| 6742 | * 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] | 6743 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6744 | * and set a new version of this string accordingly. |
| 6745 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6746 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6747 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6748 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 6749 | * existing message. |
| 6750 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6751 | */ |
| 6752 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6753 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6754 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6755 | if (mService != null) { |
| 6756 | try { |
| 6757 | mService.setShortSupportMessage(admin, message); |
| 6758 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6759 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6760 | } |
| 6761 | } |
| 6762 | } |
| 6763 | |
| 6764 | /** |
| 6765 | * Called by a device admin to get the short support message. |
| 6766 | * |
| 6767 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6768 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 6769 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6770 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6771 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6772 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6773 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6774 | if (mService != null) { |
| 6775 | try { |
| 6776 | return mService.getShortSupportMessage(admin); |
| 6777 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6778 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6779 | } |
| 6780 | } |
| 6781 | return null; |
| 6782 | } |
| 6783 | |
| 6784 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6785 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 6786 | * in the device administators settings screen. |
| 6787 | * <p> |
| 6788 | * 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] | 6789 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6790 | * and set a new version of this string accordingly. |
| 6791 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6792 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6793 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6794 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 6795 | * existing message. |
| 6796 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6797 | */ |
| 6798 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6799 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6800 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6801 | if (mService != null) { |
| 6802 | try { |
| 6803 | mService.setLongSupportMessage(admin, message); |
| 6804 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6805 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6806 | } |
| 6807 | } |
| 6808 | } |
| 6809 | |
| 6810 | /** |
| 6811 | * Called by a device admin to get the long support message. |
| 6812 | * |
| 6813 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6814 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 6815 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6816 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6817 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6818 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6819 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6820 | if (mService != null) { |
| 6821 | try { |
| 6822 | return mService.getLongSupportMessage(admin); |
| 6823 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6824 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6825 | } |
| 6826 | } |
| 6827 | return null; |
| 6828 | } |
| 6829 | |
| 6830 | /** |
| 6831 | * Called by the system to get the short support message. |
| 6832 | * |
| 6833 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6834 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6835 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6836 | * |
| 6837 | * @hide |
| 6838 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6839 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6840 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6841 | if (mService != null) { |
| 6842 | try { |
| 6843 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 6844 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6845 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6846 | } |
| 6847 | } |
| 6848 | return null; |
| 6849 | } |
| 6850 | |
| 6851 | |
| 6852 | /** |
| 6853 | * Called by the system to get the long support message. |
| 6854 | * |
| 6855 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6856 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6857 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6858 | * |
| 6859 | * @hide |
| 6860 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6861 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 6862 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6863 | if (mService != null) { |
| 6864 | try { |
| 6865 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 6866 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6867 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6868 | } |
| 6869 | } |
| 6870 | return null; |
| 6871 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6872 | |
| 6873 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6874 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 6875 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6876 | * |
| 6877 | * <p>The following methods are supported for the parent instance, all other methods will |
| 6878 | * throw a SecurityException when called on the parent instance: |
| 6879 | * <ul> |
| 6880 | * <li>{@link #getPasswordQuality}</li> |
| 6881 | * <li>{@link #setPasswordQuality}</li> |
| 6882 | * <li>{@link #getPasswordMinimumLength}</li> |
| 6883 | * <li>{@link #setPasswordMinimumLength}</li> |
| 6884 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 6885 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 6886 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 6887 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 6888 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 6889 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 6890 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 6891 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 6892 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 6893 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 6894 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 6895 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 6896 | * <li>{@link #getPasswordHistoryLength}</li> |
| 6897 | * <li>{@link #setPasswordHistoryLength}</li> |
| 6898 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 6899 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 6900 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 6901 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6902 | * <li>{@link #isActivePasswordSufficient}</li> |
| 6903 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 6904 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 6905 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 6906 | * <li>{@link #getMaximumTimeToLock}</li> |
| 6907 | * <li>{@link #setMaximumTimeToLock}</li> |
| 6908 | * <li>{@link #lockNow}</li> |
| 6909 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 6910 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 6911 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 6912 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 6913 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 6914 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6915 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6916 | * |
| 6917 | * @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] | 6918 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6919 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6920 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6921 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6922 | try { |
| 6923 | if (!mService.isManagedProfile(admin)) { |
| 6924 | throw new SecurityException("The current user does not have a parent profile."); |
| 6925 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6926 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6927 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6928 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6929 | } |
| 6930 | } |
| 6931 | |
| 6932 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 6933 | * Called by device owner to control the security logging feature. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6934 | * |
| 6935 | * <p> Security logs contain various information intended for security auditing purposes. |
| 6936 | * See {@link SecurityEvent} for details. |
| 6937 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 6938 | * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there |
| 6939 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 6940 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 6941 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 6942 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6943 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6944 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6945 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6946 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6947 | * @see #retrieveSecurityLogs |
| 6948 | */ |
| 6949 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6950 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6951 | try { |
| 6952 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 6953 | } catch (RemoteException re) { |
| 6954 | throw re.rethrowFromSystemServer(); |
| 6955 | } |
| 6956 | } |
| 6957 | |
| 6958 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6959 | * Return whether security logging is enabled or not by the device owner. |
| 6960 | * |
| 6961 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 6962 | * thrown. |
| 6963 | * |
| 6964 | * @param admin Which device owner this request is associated with. |
| 6965 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 6966 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6967 | */ |
| 6968 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6969 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6970 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6971 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6972 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6973 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6974 | } |
| 6975 | } |
| 6976 | |
| 6977 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6978 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 6979 | * this API after device boots. |
| 6980 | * |
| 6981 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 6982 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 6983 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 6984 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 6985 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 6986 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6987 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6988 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6989 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 6990 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 6991 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 6992 | * profile or secondary user that is not affiliated with the device owner user. |
| 6993 | * @see DeviceAdminReceiver#onSecurityLogsAvailable |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6994 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6995 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6996 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6997 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6998 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6999 | if (list != null) { |
| 7000 | return list.getList(); |
| 7001 | } else { |
| 7002 | // Rate limit exceeded. |
| 7003 | return null; |
| 7004 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7005 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7006 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 7007 | } |
| 7008 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7009 | |
| 7010 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7011 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 7012 | * profile. |
| 7013 | * |
| 7014 | * @hide |
| 7015 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7016 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7017 | mContext.checkSelfPermission( |
| 7018 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 7019 | if (!uInfo.isManagedProfile()) { |
| 7020 | throw new SecurityException("The user " + uInfo.id |
| 7021 | + " does not have a parent profile."); |
| 7022 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 7023 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 7024 | } |
| 7025 | |
| 7026 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7027 | * 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] | 7028 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7029 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 7030 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 7031 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 7032 | * about data corruption when parsing. </strong> |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7033 | * |
| 7034 | * <p>If there is any other user or profile on the device, it must be affiliated with the |
| 7035 | * device owner. Otherwise a {@link SecurityException} will be thrown. See |
| 7036 | * {@link #setAffiliationIds} |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 7037 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7038 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7039 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 7040 | * is not supported on the device. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7041 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7042 | * profile or secondary user that is not affiliated with the device owner user. |
| 7043 | * @see #retrieveSecurityLogs |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7044 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7045 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 7046 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7047 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7048 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 7049 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 7050 | if (list != null) { |
| 7051 | return list.getList(); |
| 7052 | } else { |
| 7053 | return null; |
| 7054 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7055 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7056 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7061 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 7062 | * 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] | 7063 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7064 | * <p> |
| 7065 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7066 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 7067 | * |
| 7068 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7069 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7070 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7071 | */ |
| 7072 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7073 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7074 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7075 | // always enforce alpha channel to have 100% opacity |
| 7076 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7077 | mService.setOrganizationColor(admin, color); |
| 7078 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7079 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7080 | } |
| 7081 | } |
| 7082 | |
| 7083 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7084 | * @hide |
| 7085 | * |
| 7086 | * Sets the color used for customization. |
| 7087 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7088 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7089 | * @param userId which user to set the color to. |
| 7090 | * @RequiresPermission(allOf = { |
| 7091 | * Manifest.permission.MANAGE_USERS, |
| 7092 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 7093 | */ |
| 7094 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 7095 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7096 | // always enforce alpha channel to have 100% opacity |
| 7097 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7098 | mService.setOrganizationColorForUser(color, userId); |
| 7099 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7100 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 7101 | } |
| 7102 | } |
| 7103 | |
| 7104 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7105 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 7106 | * This color is used as background color of the confirm credentials screen for that user. |
| 7107 | * |
| 7108 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7109 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7110 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7111 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7112 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7113 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7114 | try { |
| 7115 | return mService.getOrganizationColor(admin); |
| 7116 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7117 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7118 | } |
| 7119 | } |
| 7120 | |
| 7121 | /** |
| 7122 | * @hide |
| 7123 | * Retrieve the customization color for a given user. |
| 7124 | * |
| 7125 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7126 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7127 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7128 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7129 | try { |
| 7130 | return mService.getOrganizationColorForUser(userHandle); |
| 7131 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7132 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 7133 | } |
| 7134 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7135 | |
| 7136 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7137 | * Called by the device owner or profile owner to set the name of the organization under |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7138 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7139 | * <p> |
| 7140 | * 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] | 7141 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 7142 | * and set a new version of this string accordingly. |
| 7143 | * |
| 7144 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7145 | * @param title The organization name or {@code null} to clear a previously set name. |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7146 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7147 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 7148 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7149 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7150 | try { |
| 7151 | mService.setOrganizationName(admin, title); |
| 7152 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7153 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7154 | } |
| 7155 | } |
| 7156 | |
| 7157 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7158 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 7159 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7160 | * |
| 7161 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7162 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 7163 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7164 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7165 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7166 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7167 | try { |
| 7168 | return mService.getOrganizationName(admin); |
| 7169 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7170 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7171 | } |
| 7172 | } |
| 7173 | |
| 7174 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 7175 | * Called by the system to retrieve the name of the organization managing the device. |
| 7176 | * |
| 7177 | * @return The organization name or {@code null} if none is set. |
| 7178 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7179 | * MANAGE_USERS permission and is not the system. |
| 7180 | * |
| 7181 | * @hide |
| 7182 | */ |
| 7183 | @SystemApi |
| 7184 | @TestApi |
| 7185 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 7186 | try { |
| 7187 | return mService.getDeviceOwnerOrganizationName(); |
| 7188 | } catch (RemoteException re) { |
| 7189 | throw re.rethrowFromSystemServer(); |
| 7190 | } |
| 7191 | } |
| 7192 | |
| 7193 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7194 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 7195 | * |
| 7196 | * @param userHandle The user id of the user we're interested in. |
| 7197 | * @return The organization name or {@code null} if none is set. |
| 7198 | * |
| 7199 | * @hide |
| 7200 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 7201 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7202 | try { |
| 7203 | return mService.getOrganizationNameForUser(userHandle); |
| 7204 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7205 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7210 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 7211 | * return {@link #STATE_USER_UNMANAGED} |
| 7212 | * @hide |
| 7213 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 7214 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7215 | @UserProvisioningState |
| 7216 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7217 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7218 | if (mService != null) { |
| 7219 | try { |
| 7220 | return mService.getUserProvisioningState(); |
| 7221 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7222 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7223 | } |
| 7224 | } |
| 7225 | return STATE_USER_UNMANAGED; |
| 7226 | } |
| 7227 | |
| 7228 | /** |
| 7229 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 7230 | * |
| 7231 | * @param state to store |
| 7232 | * @param userHandle for user |
| 7233 | * @hide |
| 7234 | */ |
| 7235 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 7236 | if (mService != null) { |
| 7237 | try { |
| 7238 | mService.setUserProvisioningState(state, userHandle); |
| 7239 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7240 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 7241 | } |
| 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7246 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 7247 | * affiliated if the set of ids set by their device or profile owners intersect. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7248 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7249 | * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging |
| 7250 | * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile |
| 7251 | * is created, until it becomes affiliated. Therefore it is recommended that the appropriate |
| 7252 | * affiliation ids are set by its profile owner as soon as possible after the user/profile is |
| 7253 | * created. |
| 7254 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7255 | * @param admin Which profile or device owner this request is associated with. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7256 | * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored. |
| 7257 | * |
| 7258 | * @throws NullPointerException if {@code ids} is null or contains null elements. |
| 7259 | * @throws IllegalArgumentException if {@code ids} contains an empty string. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7260 | */ |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7261 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7262 | throwIfParentInstance("setAffiliationIds"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7263 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7264 | mService.setAffiliationIds(admin, ids); |
| 7265 | } catch (RemoteException e) { |
| 7266 | throw e.rethrowFromSystemServer(); |
| 7267 | } |
| 7268 | } |
| 7269 | |
| 7270 | /** |
| 7271 | * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 7272 | * empty list if none have been set. |
| 7273 | */ |
| 7274 | public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) { |
| 7275 | throwIfParentInstance("getAffiliationIds"); |
| 7276 | try { |
| 7277 | return mService.getAffiliationIds(admin); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7278 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7279 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7280 | } |
| 7281 | } |
| 7282 | |
| 7283 | /** |
| 7284 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7285 | * Returns whether this user/profile is affiliated with the device. |
| 7286 | * <p> |
| 7287 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 7288 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 7289 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7290 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7291 | */ |
| 7292 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7293 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7294 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 7295 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7296 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7297 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 7298 | } |
| 7299 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7300 | |
| 7301 | /** |
| 7302 | * @hide |
| 7303 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 7304 | * to be started |
| 7305 | * @param packageName the package to check for |
| 7306 | * @return whether the uninstall intent for {@code packageName} is pending |
| 7307 | */ |
| 7308 | public boolean isUninstallInQueue(String packageName) { |
| 7309 | try { |
| 7310 | return mService.isUninstallInQueue(packageName); |
| 7311 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7312 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7313 | } |
| 7314 | } |
| 7315 | |
| 7316 | /** |
| 7317 | * @hide |
| 7318 | * @param packageName the package containing active DAs to be uninstalled |
| 7319 | */ |
| 7320 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 7321 | try { |
| 7322 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 7323 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 7324 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 7325 | } |
| 7326 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7327 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 7328 | /** |
| 7329 | * @hide |
| 7330 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 7331 | * If the admin is a profile owner or device owner it will still be removed. |
| 7332 | * |
| 7333 | * @param userHandle user id to remove the admin for. |
| 7334 | * @param admin The administration compononent to remove. |
| 7335 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 7336 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 7337 | */ |
| 7338 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 7339 | try { |
| 7340 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 7341 | } catch (RemoteException re) { |
| 7342 | throw re.rethrowFromSystemServer(); |
| 7343 | } |
| 7344 | } |
| 7345 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7346 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7347 | * Returns whether the device has been provisioned. |
| 7348 | * |
| 7349 | * <p>Not for use by third-party applications. |
| 7350 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7351 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7352 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7353 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 7354 | public boolean isDeviceProvisioned() { |
| 7355 | try { |
| 7356 | return mService.isDeviceProvisioned(); |
| 7357 | } catch (RemoteException re) { |
| 7358 | throw re.rethrowFromSystemServer(); |
| 7359 | } |
| 7360 | } |
| 7361 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7362 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7363 | * Writes that the provisioning configuration has been applied. |
| 7364 | * |
| 7365 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 7366 | * permission. |
| 7367 | * |
| 7368 | * <p>Not for use by third-party applications. |
| 7369 | * |
| 7370 | * @hide |
| 7371 | */ |
| 7372 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7373 | public void setDeviceProvisioningConfigApplied() { |
| 7374 | try { |
| 7375 | mService.setDeviceProvisioningConfigApplied(); |
| 7376 | } catch (RemoteException re) { |
| 7377 | throw re.rethrowFromSystemServer(); |
| 7378 | } |
| 7379 | } |
| 7380 | |
| 7381 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7382 | * Returns whether the provisioning configuration has been applied. |
| 7383 | * |
| 7384 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 7385 | * |
| 7386 | * <p>Not for use by third-party applications. |
| 7387 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7388 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7389 | * |
| 7390 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7391 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 7392 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 7393 | public boolean isDeviceProvisioningConfigApplied() { |
| 7394 | try { |
| 7395 | return mService.isDeviceProvisioningConfigApplied(); |
| 7396 | } catch (RemoteException re) { |
| 7397 | throw re.rethrowFromSystemServer(); |
| 7398 | } |
| 7399 | } |
| 7400 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7401 | /** |
| 7402 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 7403 | * Force update user setup completed status. This API has no effect on user build. |
| 7404 | * @throws {@link SecurityException} if the caller has no |
Esteban Talavera | 0157686 | 2016-12-15 11:16:44 +0000 | [diff] [blame] | 7405 | * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 7406 | * not {@link UserHandle#SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 7407 | */ |
| 7408 | public void forceUpdateUserSetupComplete() { |
| 7409 | try { |
| 7410 | mService.forceUpdateUserSetupComplete(); |
| 7411 | } catch (RemoteException re) { |
| 7412 | throw re.rethrowFromSystemServer(); |
| 7413 | } |
| 7414 | } |
| 7415 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 7416 | private void throwIfParentInstance(String functionName) { |
| 7417 | if (mParentInstance) { |
| 7418 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 7419 | } |
| 7420 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7421 | |
| 7422 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7423 | * Allows the device owner to enable or disable the backup service. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7424 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7425 | * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to |
| 7426 | * false will prevent data from being backed up or restored. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7427 | * |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7428 | * <p> Backup service is off by default when device owner is present. |
| 7429 | * |
| 7430 | * @throws SecurityException if {@code admin} is not a device owner. |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7431 | */ |
| 7432 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7433 | try { |
| 7434 | mService.setBackupServiceEnabled(admin, enabled); |
| 7435 | } catch (RemoteException re) { |
| 7436 | throw re.rethrowFromSystemServer(); |
| 7437 | } |
| 7438 | } |
| 7439 | |
| 7440 | /** |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7441 | * Return whether the backup service is enabled by the device owner. |
| 7442 | * |
| 7443 | * <p> Backup service manages all backup and restore mechanisms on the device. |
| 7444 | * |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7445 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
Michal Karpinski | b71fedc | 2017-01-05 15:21:38 +0000 | [diff] [blame] | 7446 | * @see #setBackupServiceEnabled |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 7447 | */ |
| 7448 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
| 7449 | try { |
| 7450 | return mService.isBackupServiceEnabled(admin); |
| 7451 | } catch (RemoteException re) { |
| 7452 | throw re.rethrowFromSystemServer(); |
| 7453 | } |
| 7454 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7455 | |
| 7456 | /** |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7457 | * Called by a device owner to control the network logging feature. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7458 | * |
| 7459 | * <p> Network logs contain DNS lookup and connect() library call events. |
| 7460 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7461 | * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there |
| 7462 | * are unaffiliated secondary users or profiles on the device, regardless of whether the |
| 7463 | * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for |
| 7464 | * all users to become affiliated. Therefore it's recommended that affiliation ids are set for |
| 7465 | * new users as soon as possible after provisioning via {@link #setAffiliationIds}. |
| 7466 | * |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7467 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7468 | * @param enabled whether network logging should be enabled or not. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7469 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7470 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7471 | */ |
| 7472 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 7473 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 7474 | try { |
| 7475 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 7476 | } catch (RemoteException re) { |
| 7477 | throw re.rethrowFromSystemServer(); |
| 7478 | } |
| 7479 | } |
| 7480 | |
| 7481 | /** |
| 7482 | * Return whether network logging is enabled by a device owner. |
| 7483 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7484 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 7485 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7486 | * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7487 | * @throws SecurityException if {@code admin} is not a device owner and caller has |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7488 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7489 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 7490 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 7491 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 7492 | try { |
| 7493 | return mService.isNetworkLoggingEnabled(admin); |
| 7494 | } catch (RemoteException re) { |
| 7495 | throw re.rethrowFromSystemServer(); |
| 7496 | } |
| 7497 | } |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7498 | |
| 7499 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7500 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 7501 | * A device owner has to provide a batchToken provided as part of |
| 7502 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 7503 | * token of the most recent available batch of logs, {@code null} will be returned. |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7504 | * |
| 7505 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 7506 | * |
| 7507 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 7508 | * |
| 7509 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7510 | * after the device device owner has been notified via |
| 7511 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7512 | * |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7513 | * <p>If a secondary user or profile is created, calling this method will throw a |
| 7514 | * {@link SecurityException} until all users become affiliated again. It will also no longer be |
| 7515 | * possible to retrieve the network logs batch with the most recent batchToken provided |
| 7516 | * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See |
| 7517 | * {@link DevicePolicyManager#setAffiliationIds}. |
| 7518 | * |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7519 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7520 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7521 | * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7522 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7523 | * logging is disabled. |
Esteban Talavera | d36dd15 | 2016-12-15 08:51:45 +0000 | [diff] [blame] | 7524 | * @throws SecurityException if {@code admin} is not a device owner, or there is at least one |
| 7525 | * profile or secondary user that is not affiliated with the device owner user. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7526 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7527 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7528 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7529 | long batchToken) { |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7530 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7531 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7532 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f1 | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7533 | } catch (RemoteException re) { |
| 7534 | throw re.rethrowFromSystemServer(); |
| 7535 | } |
| 7536 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7537 | |
| 7538 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7539 | * Called by a device owner to bind to a service from a profile owner of a managed profile or |
| 7540 | * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
| 7541 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7542 | * <p> |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7543 | * The service must be unexported. Note that the {@link Context} used to obtain this |
| 7544 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7545 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7546 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7547 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7548 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7549 | * explicit component name or a package name to match an |
| 7550 | * {@link IntentFilter} published by a service. |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7551 | * @param conn Receives information as the service is started and stopped in main thread. This |
| 7552 | * must be a valid {@link ServiceConnection} object; it must not be {@code null}. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7553 | * @param flags Operation options for the binding operation. See |
| 7554 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7555 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7556 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7557 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7558 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7559 | * {@code false} is returned if the connection is not made and you will not |
| 7560 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7561 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7562 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7563 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7564 | */ |
| 7565 | public boolean bindDeviceAdminServiceAsUser( |
| 7566 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7567 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7568 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7569 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7570 | try { |
Tony Mak | bf9928d | 2016-12-22 11:02:45 +0000 | [diff] [blame] | 7571 | final IServiceConnection sd = mContext.getServiceDispatcher( |
| 7572 | conn, mContext.getMainThreadHandler(), flags); |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7573 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7574 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7575 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7576 | sd, flags, targetUser.getIdentifier()); |
| 7577 | } catch (RemoteException re) { |
| 7578 | throw re.rethrowFromSystemServer(); |
| 7579 | } |
| 7580 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7581 | |
| 7582 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7583 | * Returns the list of target users that the calling device or profile owner can use when |
| 7584 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 7585 | * <p> |
| 7586 | * A device owner can bind to a service from a profile owner of a managed profile and |
| 7587 | * vice versa, provided that: |
| 7588 | * <ul> |
| 7589 | * <li>Both belong to the same package name. |
| 7590 | * <li>The managed profile is a profile of the user where the device owner is set. |
| 7591 | * See {@link UserManager#getUserProfiles()} |
| 7592 | * <li>Both users are affiliated. |
Nicolas Prevot | d5b0360 | 2016-12-06 13:32:22 +0000 | [diff] [blame] | 7593 | * See {@link #setAffiliationIds}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7594 | * </ul> |
| 7595 | */ |
| 7596 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 7597 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 7598 | try { |
| 7599 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 7600 | } catch (RemoteException re) { |
| 7601 | throw re.rethrowFromSystemServer(); |
| 7602 | } |
| 7603 | } |
| 7604 | |
| 7605 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7606 | * Called by the system to get the time at which the device owner last retrieved security |
| 7607 | * logging entries. |
| 7608 | * |
| 7609 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 7610 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7611 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7612 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7613 | * |
| 7614 | * @hide |
| 7615 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7616 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7617 | public long getLastSecurityLogRetrievalTime() { |
| 7618 | try { |
| 7619 | return mService.getLastSecurityLogRetrievalTime(); |
| 7620 | } catch (RemoteException re) { |
| 7621 | throw re.rethrowFromSystemServer(); |
| 7622 | } |
| 7623 | } |
| 7624 | |
| 7625 | /** |
| 7626 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 7627 | * |
| 7628 | * @return the time at which the device owner most recently requested a bug report, in |
| 7629 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7630 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7631 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7632 | * |
| 7633 | * @hide |
| 7634 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7635 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7636 | public long getLastBugReportRequestTime() { |
| 7637 | try { |
| 7638 | return mService.getLastBugReportRequestTime(); |
| 7639 | } catch (RemoteException re) { |
| 7640 | throw re.rethrowFromSystemServer(); |
| 7641 | } |
| 7642 | } |
| 7643 | |
| 7644 | /** |
| 7645 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 7646 | * events. |
| 7647 | * |
| 7648 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 7649 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7650 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7651 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7652 | * |
| 7653 | * @hide |
| 7654 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7655 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7656 | public long getLastNetworkLogRetrievalTime() { |
| 7657 | try { |
| 7658 | return mService.getLastNetworkLogRetrievalTime(); |
| 7659 | } catch (RemoteException re) { |
| 7660 | throw re.rethrowFromSystemServer(); |
| 7661 | } |
| 7662 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 7663 | } |