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; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
| 25 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 26 | import android.annotation.SystemApi; |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 27 | import android.annotation.TestApi; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 28 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 29 | import android.annotation.WorkerThread; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 30 | import android.app.Activity; |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 31 | import android.app.admin.PasswordMetrics; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 32 | import android.app.IServiceConnection; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 33 | import android.app.admin.SecurityLog.SecurityEvent; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 34 | import android.content.ComponentName; |
| 35 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 36 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 37 | import android.content.IntentFilter; |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 38 | import android.content.ServiceConnection; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 40 | import android.content.pm.PackageManager.NameNotFoundException; |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 41 | import android.content.pm.ParceledListSlice; |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 42 | import android.content.pm.UserInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 43 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 44 | import android.net.ProxyInfo; |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 45 | import android.net.Uri; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 46 | import android.os.Bundle; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 47 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 48 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 49 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 50 | import android.os.RemoteException; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 51 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 52 | import android.os.UserManager; |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 53 | import android.provider.ContactsContract.Directory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 54 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 55 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 56 | import android.service.restrictions.RestrictionsReceiver; |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 57 | import android.telephony.TelephonyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 58 | import android.util.Log; |
| 59 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 60 | import com.android.internal.annotations.VisibleForTesting; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 61 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 62 | |
| 63 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 64 | import java.io.IOException; |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 65 | import java.lang.annotation.Retention; |
| 66 | import java.lang.annotation.RetentionPolicy; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 67 | import java.net.InetSocketAddress; |
| 68 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 69 | import java.security.KeyFactory; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 70 | import java.security.NoSuchAlgorithmException; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 71 | import java.security.PrivateKey; |
| 72 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 73 | import java.security.cert.CertificateException; |
| 74 | import java.security.cert.CertificateFactory; |
| 75 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 76 | import java.security.spec.InvalidKeySpecException; |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 77 | import java.security.spec.PKCS8EncodedKeySpec; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 78 | import java.util.ArrayList; |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 79 | import java.util.Arrays; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 80 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 81 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 82 | |
| 83 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 84 | * 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] | 85 | * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device |
| 86 | * administrator</a>. Additionally, a device administrator may be registered as either a profile or |
| 87 | * device owner. A given method is accessible to all device administrators unless the documentation |
| 88 | * for that method specifies that it is restricted to either device or profile owners. Any |
| 89 | * application calling an api may only pass as an argument a device administrator component it |
| 90 | * owns. Otherwise, a {@link SecurityException} will be thrown. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 91 | * <div class="special reference"> |
| 92 | * <h3>Developer Guides</h3> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 93 | * <p> |
| 94 | * For more information about managing policies for device administration, read the <a href= |
| 95 | * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer |
| 96 | * guide. </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 97 | */ |
| 98 | public class DevicePolicyManager { |
| 99 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 100 | |
| 101 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 102 | private final IDevicePolicyManager mService; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 103 | private final boolean mParentInstance; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 104 | |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 105 | /** @hide */ |
| 106 | public DevicePolicyManager(Context context, IDevicePolicyManager service) { |
| 107 | this(context, service, false); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 110 | /** @hide */ |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 111 | @VisibleForTesting |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 112 | protected DevicePolicyManager(Context context, IDevicePolicyManager service, |
| 113 | boolean parentInstance) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 114 | mContext = context; |
| 115 | mService = service; |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 116 | mParentInstance = parentInstance; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 119 | /** @hide test will override it. */ |
| 120 | @VisibleForTesting |
| 121 | protected int myUserId() { |
| 122 | return UserHandle.myUserId(); |
| 123 | } |
| 124 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 125 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 126 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 127 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 128 | * <p>A managed profile allows data separation for example for the usage of a |
| 129 | * device as a personal and corporate device. The user which provisioning is started from and |
| 130 | * the managed profile share a launcher. |
| 131 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 132 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 133 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 134 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 135 | * |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 136 | * <p>It is possible to check if provisioning is allowed or not by querying the method |
| 137 | * {@link #isProvisioningAllowed(String)}. |
| 138 | * |
| 139 | * <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] | 140 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 141 | * 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] | 142 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 143 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 144 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 145 | * <p>The intent may also contain the following extras: |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 146 | * <ul> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 147 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li> |
| 148 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from |
| 149 | * {@link android.os.Build.VERSION_CODES#N}</li> |
| 150 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 152 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 153 | * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li> |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 154 | * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, 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> |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 236 | * </ul> |
| 237 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 238 | * <p>When device owner provisioning has completed, an intent of the type |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 239 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 240 | * device owner. |
| 241 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 242 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 243 | * completed, along with the above broadcast, activity intent |
| 244 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 245 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 246 | * <p>If provisioning fails, the device is factory reset. |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 247 | * |
Alan Treadway | 4582f81 | 2015-07-28 11:49:35 +0100 | [diff] [blame] | 248 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 249 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 250 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 251 | * 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] | 252 | */ |
| 253 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 254 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 255 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 256 | |
| 257 | /** |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 258 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Steven Ng | 980a1b6 | 2016-02-02 17:43:18 +0000 | [diff] [blame] | 259 | * |
| 260 | * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of |
| 261 | * the device. A device owner has full control over the device. The device owner can not be |
| 262 | * modified by the user and the only way of resetting the device is via factory reset. |
| 263 | * |
| 264 | * <p>A typical use case would be a device that is owned by a company, but used by either an |
| 265 | * employee or client. |
| 266 | * |
| 267 | * <p>The provisioning message should be sent to an unprovisioned device. |
| 268 | * |
| 269 | * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent |
| 270 | * by a privileged app with the permission |
| 271 | * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}. |
| 272 | * |
| 273 | * <p>The provisioning intent contains the following properties: |
| 274 | * <ul> |
| 275 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 276 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 277 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 278 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
| 279 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 280 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 281 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 282 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 283 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 284 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 285 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 286 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 287 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 288 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 289 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 290 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul> |
| 291 | * |
| 292 | * @hide |
| 293 | */ |
| 294 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 295 | @SystemApi |
| 296 | public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE = |
| 297 | "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE"; |
| 298 | |
| 299 | /** |
| 300 | * Activity action: Starts the provisioning flow which sets up a managed device. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 301 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 302 | * |
| 303 | * <p>NOTE: This is only supported on split system user devices, and puts the device into a |
| 304 | * management state that is distinct from that reached by |
| 305 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system |
| 306 | * user, and only has control over device-wide policies, not individual users and their data. |
| 307 | * The primary benefit is that multiple non-system users are supported when provisioning using |
| 308 | * this form of device management. |
| 309 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 310 | * <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] | 311 | * A device owner has full control over the device. The device owner can not be modified by the |
| 312 | * user. |
| 313 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 314 | * <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] | 315 | * employee or client. |
| 316 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 317 | * <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] | 318 | * It is possible to check if provisioning is allowed or not by querying the method |
| 319 | * {@link #isProvisioningAllowed(String)}. |
| 320 | * |
| 321 | * <p>The intent contains the following extras: |
| 322 | * <ul> |
| 323 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 324 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 325 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 326 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li> |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 327 | * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li> |
| 328 | * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li> |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 329 | * </ul> |
| 330 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 331 | * <p>When device owner provisioning has completed, an intent of the type |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 332 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 333 | * device owner. |
| 334 | * |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 335 | * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has |
| 336 | * completed, along with the above broadcast, activity intent |
| 337 | * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner. |
| 338 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 339 | * <p>If provisioning fails, the device is factory reset. |
Alan Treadway | 46dd449 | 2015-11-09 13:57:19 +0000 | [diff] [blame] | 340 | * |
| 341 | * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part |
| 342 | * of the provisioning flow was successful, although this doesn't guarantee the full flow will |
| 343 | * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies |
| 344 | * that the user backed-out of provisioning, or some precondition for provisioning wasn't met. |
| 345 | * |
| 346 | * @hide |
| 347 | */ |
| 348 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 349 | public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE |
| 350 | = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE"; |
| 351 | |
| 352 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 353 | * Activity action: Finalizes management provisioning, should be used after user-setup |
| 354 | * has been completed and {@link #getUserProvisioningState()} returns one of: |
| 355 | * <ul> |
| 356 | * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li> |
| 357 | * <li>{@link #STATE_USER_SETUP_COMPLETE}</li> |
| 358 | * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li> |
| 359 | * </ul> |
| 360 | * |
| 361 | * @hide |
| 362 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 363 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 364 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 365 | public static final String ACTION_PROVISION_FINALIZATION |
| 366 | = "android.app.action.PROVISION_FINALIZATION"; |
| 367 | |
| 368 | /** |
Michal Karpinski | ba24409 | 2016-02-25 17:28:24 +0000 | [diff] [blame] | 369 | * Action: Bugreport sharing with device owner has been accepted by the user. |
| 370 | * |
| 371 | * @hide |
| 372 | */ |
| 373 | public static final String ACTION_BUGREPORT_SHARING_ACCEPTED = |
| 374 | "com.android.server.action.BUGREPORT_SHARING_ACCEPTED"; |
| 375 | |
| 376 | /** |
| 377 | * Action: Bugreport sharing with device owner has been declined by the user. |
| 378 | * |
| 379 | * @hide |
| 380 | */ |
| 381 | public static final String ACTION_BUGREPORT_SHARING_DECLINED = |
| 382 | "com.android.server.action.BUGREPORT_SHARING_DECLINED"; |
| 383 | |
| 384 | /** |
| 385 | * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}. |
| 386 | * |
| 387 | * @hide |
| 388 | */ |
| 389 | public static final String ACTION_REMOTE_BUGREPORT_DISPATCH = |
| 390 | "android.intent.action.REMOTE_BUGREPORT_DISPATCH"; |
| 391 | |
| 392 | /** |
| 393 | * Extra for shared bugreport's SHA-256 hash. |
| 394 | * |
| 395 | * @hide |
| 396 | */ |
| 397 | public static final String EXTRA_REMOTE_BUGREPORT_HASH = |
| 398 | "android.intent.extra.REMOTE_BUGREPORT_HASH"; |
| 399 | |
| 400 | /** |
| 401 | * Extra for remote bugreport notification shown type. |
| 402 | * |
| 403 | * @hide |
| 404 | */ |
| 405 | public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE = |
| 406 | "android.app.extra.bugreport_notification_type"; |
| 407 | |
| 408 | /** |
| 409 | * Notification type for a started remote bugreport flow. |
| 410 | * |
| 411 | * @hide |
| 412 | */ |
| 413 | public static final int NOTIFICATION_BUGREPORT_STARTED = 1; |
| 414 | |
| 415 | /** |
| 416 | * Notification type for a bugreport that has already been accepted to be shared, but is still |
| 417 | * being taken. |
| 418 | * |
| 419 | * @hide |
| 420 | */ |
| 421 | public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2; |
| 422 | |
| 423 | /** |
| 424 | * Notification type for a bugreport that has been taken and can be shared or declined. |
| 425 | * |
| 426 | * @hide |
| 427 | */ |
| 428 | public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3; |
| 429 | |
| 430 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 431 | * Default and maximum timeout in milliseconds after which unlocking with weak auth times out, |
| 432 | * i.e. the user has to use a strong authentication method like password, PIN or pattern. |
| 433 | * |
| 434 | * @hide |
| 435 | */ |
| 436 | public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h |
| 437 | |
| 438 | /** |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 439 | * 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] | 440 | * allows a mobile device management application or NFC programmer application which starts |
| 441 | * managed provisioning to pass data to the management application instance after provisioning. |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 442 | * <p> |
| 443 | * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that |
| 444 | * sends the intent to pass data to itself on the newly created profile. |
| 445 | * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same |
| 446 | * instance of the app on the primary user. |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 447 | * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with |
| 448 | * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC |
| 449 | * message should contain a stringified {@link java.util.Properties} instance, whose string |
| 450 | * properties will be converted into a {@link android.os.PersistableBundle} and passed to the |
| 451 | * management application after provisioning. |
| 452 | * |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 453 | * <p> |
| 454 | * In both cases the application receives the data in |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 455 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 456 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
Rubin Xu | a4f9dc1 | 2015-06-12 13:27:59 +0100 | [diff] [blame] | 457 | * during the managed provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 458 | */ |
| 459 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 460 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 461 | |
| 462 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 463 | * A String extra holding the package name of the mobile device management application that |
| 464 | * will be set as the profile owner or device owner. |
| 465 | * |
| 466 | * <p>If an application starts provisioning directly via an intent with action |
| 467 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 468 | * application that started provisioning. The package will be set as profile owner in that case. |
| 469 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 470 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 471 | * 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] | 472 | * |
| 473 | * <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] | 474 | * 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] | 475 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 476 | * @see DeviceAdminReceiver |
| 477 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
Nicolas Prevot | 8f78d6a | 2015-08-21 11:06:31 +0100 | [diff] [blame] | 478 | * supported, but only if there is only one device admin receiver in the package that requires |
| 479 | * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 480 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 481 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 482 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 483 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 484 | |
| 485 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 486 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 487 | * application that will be set as the profile owner or device owner and active admin. |
| 488 | * |
| 489 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 490 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 491 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 492 | * 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] | 493 | * |
| 494 | * <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] | 495 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 496 | * message containing an NFC record with MIME type |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 497 | * {@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] | 498 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 499 | * |
| 500 | * @see DeviceAdminReceiver |
| 501 | */ |
| 502 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 503 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 504 | |
| 505 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 506 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 507 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 508 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 509 | * |
| 510 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 511 | */ |
| 512 | |
| 513 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 514 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 515 | |
| 516 | /** |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 517 | * Boolean extra to indicate that the migrated account should be kept. This is used in |
| 518 | * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true}, |
| 519 | * the account will not be removed from the primary user after it is migrated to the newly |
| 520 | * created user or profile. |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 521 | * |
| 522 | * <p> Defaults to {@code false} |
| 523 | * |
Victor Chang | aa9cbc0 | 2016-12-05 20:50:57 +0000 | [diff] [blame] | 524 | * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 525 | * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} |
Victor Chang | 89ee279 | 2016-11-23 12:10:55 +0000 | [diff] [blame] | 526 | */ |
| 527 | public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION |
| 528 | = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION"; |
| 529 | |
| 530 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 531 | * A String extra that, holds the email address of the account which a managed profile is |
| 532 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 533 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 534 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 535 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 536 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 537 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 538 | * contains this extra, it is forwarded in the |
| 539 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 540 | * device management application that was set as the profile owner during provisioning. |
| 541 | * 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] | 542 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 543 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 544 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 545 | |
| 546 | /** |
Nicolas Prevot | cd2d859 | 2015-11-23 13:27:21 +0000 | [diff] [blame] | 547 | * A integer extra indicating the predominant color to show during the provisioning. |
| 548 | * Refer to {@link android.graphics.Color} for how the color is represented. |
Nicolas Prevot | caf11cd | 2015-11-19 10:58:35 +0000 | [diff] [blame] | 549 | * |
| 550 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 551 | * {@link #ACTION_PROVISION_MANAGED_DEVICE}. |
| 552 | */ |
| 553 | public static final String EXTRA_PROVISIONING_MAIN_COLOR = |
| 554 | "android.app.extra.PROVISIONING_MAIN_COLOR"; |
| 555 | |
| 556 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 557 | * 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] | 558 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 559 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 560 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 561 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 562 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 563 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 564 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 565 | |
| 566 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 567 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 568 | * will be set to. |
| 569 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 570 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 571 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 572 | */ |
| 573 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 574 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 575 | |
| 576 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 577 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 578 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 579 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 580 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 581 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 582 | */ |
| 583 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 584 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 585 | |
| 586 | /** |
| 587 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 588 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 589 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 590 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 591 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 592 | */ |
| 593 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 594 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 595 | |
| 596 | /** |
| 597 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 598 | * owner provisioning for downloading the mobile device management application. |
| 599 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 600 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 601 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 602 | */ |
| 603 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 604 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 605 | |
| 606 | /** |
| 607 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 608 | * is hidden or not. |
| 609 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 610 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 611 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 612 | */ |
| 613 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 614 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 615 | |
| 616 | /** |
| 617 | * A String extra indicating the security type of the wifi network in |
Mahaver Chopra | 76b08a9 | 2015-10-08 17:58:45 +0100 | [diff] [blame] | 618 | * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or |
| 619 | * {@code WEP}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 620 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 621 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 622 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 623 | */ |
| 624 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 625 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 626 | |
| 627 | /** |
| 628 | * A String extra holding the password of the wifi network in |
| 629 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 630 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 631 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 632 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 633 | */ |
| 634 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 635 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 636 | |
| 637 | /** |
| 638 | * A String extra holding the proxy host for the wifi network in |
| 639 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 640 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 641 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 642 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 643 | */ |
| 644 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 645 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 646 | |
| 647 | /** |
| 648 | * An int extra holding the proxy port for the wifi network in |
| 649 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 650 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 651 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 652 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 653 | */ |
| 654 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 655 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 656 | |
| 657 | /** |
| 658 | * A String extra holding the proxy bypass for the wifi network in |
| 659 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 660 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 661 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 662 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 663 | */ |
| 664 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 665 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 666 | |
| 667 | /** |
| 668 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 669 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 670 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 671 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 672 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 673 | */ |
| 674 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 675 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 676 | |
| 677 | /** |
| 678 | * A String extra holding a url that specifies the download location of the device admin |
| 679 | * package. When not provided it is assumed that the device admin package is already installed. |
| 680 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 681 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 682 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 683 | */ |
| 684 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 685 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 686 | |
| 687 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 688 | * An int extra holding a minimum required version code for the device admin package. If the |
| 689 | * device admin is already installed on the device, it will only be re-downloaded from |
| 690 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 691 | * installed package is less than this version code. |
| 692 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 693 | * <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] | 694 | * provisioning via an NFC bump. |
| 695 | */ |
| 696 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 697 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 698 | |
| 699 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 700 | * A String extra holding a http cookie header which should be used in the http request to the |
| 701 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 702 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 703 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 704 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 705 | */ |
| 706 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 707 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 708 | |
| 709 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 710 | * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of |
| 711 | * the file at download location specified in |
| 712 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 713 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 714 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be |
| 715 | * 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] | 716 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 717 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 718 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 719 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 720 | * provisioning via an NFC bump. |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 721 | * |
| 722 | * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP} |
| 723 | * 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] | 724 | * 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] | 725 | * 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] | 726 | */ |
| 727 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 728 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 729 | |
| 730 | /** |
Rubin Xu | d92e757 | 2015-05-18 17:01:13 +0100 | [diff] [blame] | 731 | * 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] | 732 | * android package archive at the download location specified in {@link |
| 733 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 734 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 735 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 736 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 737 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 738 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 739 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be |
| 740 | * 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] | 741 | * the download location. If the checksum does not match an error will be shown to the user and |
| 742 | * the user will be asked to factory reset the device. |
| 743 | * |
| 744 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 745 | * provisioning via an NFC bump. |
| 746 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame] | 747 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 748 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 749 | |
| 750 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 751 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 752 | * has completed successfully. |
| 753 | * |
| 754 | * <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] | 755 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 756 | * |
Mahaver | 7074caf | 2016-11-29 20:52:18 +0000 | [diff] [blame] | 757 | * <p>This intent will contain the following extras |
| 758 | * <ul> |
| 759 | * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed |
| 760 | * profile.</li> |
| 761 | * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to |
| 762 | * be migrated at provisioning time, if any.</li> |
| 763 | * </ul> |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 764 | */ |
| 765 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 766 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 767 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 768 | |
| 769 | /** |
Mahaver Chopra | 3c58cfe | 2016-11-01 21:25:59 +0000 | [diff] [blame] | 770 | * Activity action: This activity action is sent to indicate that provisioning of a managed |
| 771 | * profile or managed device has completed successfully. It'll be sent at the same time as |
| 772 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be |
| 773 | * delivered faster as it's an activity intent. |
| 774 | * |
| 775 | * <p>The intent is only sent to the application on the profile that requested provisioning. In |
| 776 | * the device owner case the profile is the primary user. |
| 777 | * |
| 778 | * @see #ACTION_PROVISION_MANAGED_PROFILE |
| 779 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 780 | */ |
| 781 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 782 | public static final String ACTION_PROVISIONING_SUCCESSFUL = |
| 783 | "android.app.action.PROVISIONING_SUCCESSFUL"; |
| 784 | |
| 785 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 786 | * A boolean extra indicating whether device encryption can be skipped as part of device owner |
| 787 | * or managed profile provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 788 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 789 | * <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] | 790 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 791 | * |
| 792 | * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an |
| 793 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 794 | */ |
| 795 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 796 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 797 | |
| 798 | /** |
Nicolas Prevot | 8b7991c | 2015-11-12 17:40:12 +0000 | [diff] [blame] | 799 | * A {@link Uri} extra pointing to a logo image. This image will be shown during the |
| 800 | * provisioning. If this extra is not passed, a default image will be shown. |
| 801 | * <h5>The following URI schemes are accepted:</h5> |
| 802 | * <ul> |
| 803 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 804 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 805 | * </ul> |
| 806 | * |
| 807 | * <p> It is the responsability of the caller to provide an image with a reasonable |
| 808 | * pixed density for the device. |
| 809 | * |
| 810 | * <p> If a content: URI is passed, the intent should have the flag |
| 811 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the |
| 812 | * {@link android.content.ClipData} of the intent too. |
| 813 | * |
| 814 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 815 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} |
| 816 | */ |
| 817 | public static final String EXTRA_PROVISIONING_LOGO_URI = |
| 818 | "android.app.extra.PROVISIONING_LOGO_URI"; |
| 819 | |
| 820 | /** |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 821 | * A boolean extra indicating if user setup should be skipped, for when provisioning is started |
| 822 | * during setup-wizard. |
| 823 | * |
| 824 | * <p>If unspecified, defaults to {@code true} to match the behavior in |
| 825 | * {@link android.os.Build.VERSION_CODES#M} and earlier. |
| 826 | * |
Alan Treadway | 1a538d0 | 2016-01-18 16:42:30 +0000 | [diff] [blame] | 827 | * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or |
| 828 | * {@link #ACTION_PROVISION_MANAGED_USER}. |
Alan Treadway | 94de8c8 | 2016-01-11 10:25:23 +0000 | [diff] [blame] | 829 | * |
| 830 | * @hide |
| 831 | */ |
| 832 | public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP = |
| 833 | "android.app.extra.PROVISIONING_SKIP_USER_SETUP"; |
| 834 | |
| 835 | /** |
Victor Chang | 51d84f9 | 2016-11-16 12:22:56 +0000 | [diff] [blame] | 836 | * A boolean extra indicating if the user consent steps from the provisioning flow should be |
| 837 | * skipped. If unspecified, defaults to {@code false}. |
| 838 | * |
| 839 | * It can only be used by an existing device owner trying to create a managed profile via |
| 840 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored. |
| 841 | */ |
| 842 | public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT = |
| 843 | "android.app.extra.PROVISIONING_SKIP_USER_CONSENT"; |
| 844 | |
| 845 | /** |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 846 | * This MIME type is used for starting the device owner provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 847 | * |
Craig Lafayette | 3cc72ba | 2015-06-26 11:51:04 -0400 | [diff] [blame] | 848 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 849 | * A device owner has full control over the device. The device owner can not be modified by the |
| 850 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 851 | * reset. |
| 852 | * |
| 853 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 854 | * employee or client. |
| 855 | * |
Benjamin Franz | ea95624 | 2016-03-21 15:45:56 +0000 | [diff] [blame] | 856 | * <p> The NFC message must be sent to an unprovisioned device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 857 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 858 | * <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] | 859 | * contains the following properties: |
| 860 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 861 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 862 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 863 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 864 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 865 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 866 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 867 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 868 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 869 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 870 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 871 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 872 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 873 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 874 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Rubin Xu | 41f2ccb9 | 2015-08-05 16:29:13 +0100 | [diff] [blame] | 875 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li> |
| 876 | * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from |
| 877 | * {@link android.os.Build.VERSION_CODES#M} </li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 878 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 879 | * <p> |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 880 | * 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] | 881 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 882 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 883 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 884 | */ |
| 885 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 886 | = "application/com.android.managedprovisioning"; |
| 887 | |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 888 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 889 | * Activity action: ask the user to add a new device administrator to the system. |
| 890 | * The desired policy is the ComponentName of the policy in the |
| 891 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 892 | * bring the user through adding the device administrator to the system (or |
| 893 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 894 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 895 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 896 | * field to provide the user with additional explanation (in addition |
| 897 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 898 | * |
| 899 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 900 | * user intervention). However, if your administrator has been updated and is requesting |
| 901 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 902 | * 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] | 903 | */ |
| 904 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 905 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 906 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 907 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 908 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 909 | * @hide |
| 910 | * 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] | 911 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 912 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 913 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 914 | * 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] | 915 | * to remotely control restrictions on the user. |
| 916 | * |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 917 | * <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] | 918 | * result of whether or not the user approved the action. If approved, the result will |
| 919 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 920 | * as a profile owner. |
| 921 | * |
| 922 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 923 | * field to provide the user with additional explanation (in addition |
| 924 | * to your component's description) about what is being added. |
| 925 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 926 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 927 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 928 | */ |
| 929 | @SystemApi |
| 930 | public static final String ACTION_SET_PROFILE_OWNER |
| 931 | = "android.app.action.SET_PROFILE_OWNER"; |
| 932 | |
| 933 | /** |
| 934 | * @hide |
| 935 | * Name of the profile owner admin that controls the user. |
| 936 | */ |
| 937 | @SystemApi |
| 938 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 939 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 940 | |
| 941 | /** |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 942 | * Broadcast action: send when any policy admin changes a policy. |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 943 | * 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] | 944 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 945 | * @hide |
| 946 | */ |
| 947 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 948 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 949 | |
| 950 | /** |
Tony Mak | 1970f97 | 2016-08-30 17:41:48 +0100 | [diff] [blame] | 951 | * Broadcast action: sent when the device owner is set, changed or cleared. |
Nicolas Prevot | 0079900 | 2015-07-27 18:15:20 +0100 | [diff] [blame] | 952 | * |
| 953 | * This broadcast is sent only to the primary user. |
| 954 | * @see #ACTION_PROVISION_MANAGED_DEVICE |
| 955 | */ |
| 956 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 957 | public static final String ACTION_DEVICE_OWNER_CHANGED |
| 958 | = "android.app.action.DEVICE_OWNER_CHANGED"; |
| 959 | |
| 960 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 961 | * The ComponentName of the administrator component. |
| 962 | * |
| 963 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 964 | */ |
| 965 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 966 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 967 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 968 | * An optional CharSequence providing additional explanation for why the |
| 969 | * admin is being added. |
| 970 | * |
| 971 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 972 | */ |
| 973 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 974 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 975 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 976 | * Activity action: have the user enter a new password. This activity should |
| 977 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 978 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 979 | * enter a new password that meets the current requirements. You can use |
| 980 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 981 | * have the user select a new password in order to meet the current |
| 982 | * constraints. Upon being resumed from this activity, you can check the new |
| 983 | * password characteristics to see if they are sufficient. |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 984 | * |
| 985 | * If the intent is launched from within a managed profile with a profile |
| 986 | * owner built against {@link android.os.Build.VERSION_CODES#M} or before, |
| 987 | * this will trigger entering a new password for the parent of the profile. |
| 988 | * For all other cases it will trigger entering a new password for the user |
| 989 | * or profile it is launched from. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 990 | * |
| 991 | * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 992 | */ |
| 993 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 994 | public static final String ACTION_SET_NEW_PASSWORD |
| 995 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 996 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 997 | /** |
Benjamin Franz | c992109 | 2016-01-08 17:17:44 +0000 | [diff] [blame] | 998 | * Activity action: have the user enter a new password for the parent profile. |
| 999 | * If the intent is launched from within a managed profile, this will trigger |
| 1000 | * entering a new password for the parent of the profile. In all other cases |
| 1001 | * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}. |
| 1002 | */ |
| 1003 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1004 | public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD |
| 1005 | = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD"; |
| 1006 | |
| 1007 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1008 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1009 | * the parent profile to access intents sent from the managed profile. |
| 1010 | * That is, when an app in the managed profile calls |
| 1011 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1012 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1013 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1014 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1015 | |
| 1016 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 1017 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 1018 | * the managed profile to access intents sent from the parent profile. |
| 1019 | * That is, when an app in the parent profile calls |
| 1020 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 1021 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1022 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 1023 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1024 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1025 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1026 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 1027 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1028 | */ |
| 1029 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 1030 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 1031 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1032 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 1033 | /** |
| 1034 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 1035 | * Already granted or denied permissions are not affected by this. |
| 1036 | */ |
| 1037 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 1038 | |
| 1039 | /** |
| 1040 | * Permission policy to always grant new permission requests for runtime permissions. |
| 1041 | * Already granted or denied permissions are not affected by this. |
| 1042 | */ |
| 1043 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 1044 | |
| 1045 | /** |
| 1046 | * Permission policy to always deny new permission requests for runtime permissions. |
| 1047 | * Already granted or denied permissions are not affected by this. |
| 1048 | */ |
| 1049 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 1050 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 1051 | /** |
| 1052 | * Runtime permission state: The user can manage the permission |
| 1053 | * through the UI. |
| 1054 | */ |
| 1055 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 1056 | |
| 1057 | /** |
| 1058 | * Runtime permission state: The permission is granted to the app |
| 1059 | * and the user cannot manage the permission through the UI. |
| 1060 | */ |
| 1061 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 1062 | |
| 1063 | /** |
| 1064 | * Runtime permission state: The permission is denied to the app |
| 1065 | * and the user cannot manage the permission through the UI. |
| 1066 | */ |
| 1067 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 1068 | |
| 1069 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1070 | * No management for current user in-effect. This is the default. |
| 1071 | * @hide |
| 1072 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1073 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1074 | public static final int STATE_USER_UNMANAGED = 0; |
| 1075 | |
| 1076 | /** |
| 1077 | * Management partially setup, user setup needs to be completed. |
| 1078 | * @hide |
| 1079 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1080 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1081 | public static final int STATE_USER_SETUP_INCOMPLETE = 1; |
| 1082 | |
| 1083 | /** |
| 1084 | * Management partially setup, user setup completed. |
| 1085 | * @hide |
| 1086 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1087 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1088 | public static final int STATE_USER_SETUP_COMPLETE = 2; |
| 1089 | |
| 1090 | /** |
| 1091 | * Management setup and active on current user. |
| 1092 | * @hide |
| 1093 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1094 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1095 | public static final int STATE_USER_SETUP_FINALIZED = 3; |
| 1096 | |
| 1097 | /** |
| 1098 | * Management partially setup on a managed profile. |
| 1099 | * @hide |
| 1100 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 1101 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 1102 | public static final int STATE_USER_PROFILE_COMPLETE = 4; |
| 1103 | |
| 1104 | /** |
| 1105 | * @hide |
| 1106 | */ |
| 1107 | @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE, |
| 1108 | STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE}) |
| 1109 | @Retention(RetentionPolicy.SOURCE) |
| 1110 | public @interface UserProvisioningState {} |
| 1111 | |
| 1112 | /** |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 1113 | * Result code for {@link checkProvisioningPreCondition}. |
| 1114 | * |
| 1115 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1116 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1117 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed. |
| 1118 | * |
| 1119 | * @hide |
| 1120 | */ |
| 1121 | public static final int CODE_OK = 0; |
| 1122 | |
| 1123 | /** |
| 1124 | * Result code for {@link checkProvisioningPreCondition}. |
| 1125 | * |
| 1126 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1127 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device |
| 1128 | * owner. |
| 1129 | * |
| 1130 | * @hide |
| 1131 | */ |
| 1132 | public static final int CODE_HAS_DEVICE_OWNER = 1; |
| 1133 | |
| 1134 | /** |
| 1135 | * Result code for {@link checkProvisioningPreCondition}. |
| 1136 | * |
| 1137 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1138 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for |
| 1139 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set. |
| 1140 | * |
| 1141 | * @hide |
| 1142 | */ |
| 1143 | public static final int CODE_USER_HAS_PROFILE_OWNER = 2; |
| 1144 | |
| 1145 | /** |
| 1146 | * Result code for {@link checkProvisioningPreCondition}. |
| 1147 | * |
| 1148 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1149 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running. |
| 1150 | * |
| 1151 | * @hide |
| 1152 | */ |
| 1153 | public static final int CODE_USER_NOT_RUNNING = 3; |
| 1154 | |
| 1155 | /** |
| 1156 | * Result code for {@link checkProvisioningPreCondition}. |
| 1157 | * |
| 1158 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1159 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and |
| 1160 | * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup. |
| 1161 | * |
| 1162 | * @hide |
| 1163 | */ |
| 1164 | public static final int CODE_USER_SETUP_COMPLETED = 4; |
| 1165 | |
| 1166 | /** |
| 1167 | * Code used to indicate that the device also has a user other than the system user. |
| 1168 | * |
| 1169 | * @hide |
| 1170 | */ |
| 1171 | public static final int CODE_NONSYSTEM_USER_EXISTS = 5; |
| 1172 | |
| 1173 | /** |
| 1174 | * Code used to indicate that device has an account that prevents provisioning. |
| 1175 | * |
| 1176 | * @hide |
| 1177 | */ |
| 1178 | public static final int CODE_ACCOUNTS_NOT_EMPTY = 6; |
| 1179 | |
| 1180 | /** |
| 1181 | * Result code for {@link checkProvisioningPreCondition}. |
| 1182 | * |
| 1183 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and |
| 1184 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user. |
| 1185 | * |
| 1186 | * @hide |
| 1187 | */ |
| 1188 | public static final int CODE_NOT_SYSTEM_USER = 7; |
| 1189 | |
| 1190 | /** |
| 1191 | * Result code for {@link checkProvisioningPreCondition}. |
| 1192 | * |
| 1193 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1194 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER} |
| 1195 | * when the device is a watch and is already paired. |
| 1196 | * |
| 1197 | * @hide |
| 1198 | */ |
| 1199 | public static final int CODE_HAS_PAIRED = 8; |
| 1200 | |
| 1201 | /** |
| 1202 | * Result code for {@link checkProvisioningPreCondition}. |
| 1203 | * |
| 1204 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 1205 | * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users. |
| 1206 | * |
| 1207 | * @see {@link PackageManager#FEATURE_MANAGED_USERS} |
| 1208 | * @hide |
| 1209 | */ |
| 1210 | public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9; |
| 1211 | |
| 1212 | /** |
| 1213 | * Result code for {@link checkProvisioningPreCondition}. |
| 1214 | * |
| 1215 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user. |
| 1216 | * |
| 1217 | * @hide |
| 1218 | */ |
| 1219 | public static final int CODE_SYSTEM_USER = 10; |
| 1220 | |
| 1221 | /** |
| 1222 | * Result code for {@link checkProvisioningPreCondition}. |
| 1223 | * |
| 1224 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more |
| 1225 | * managed profiles. |
| 1226 | * |
| 1227 | * @hide |
| 1228 | */ |
| 1229 | public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11; |
| 1230 | |
| 1231 | /** |
| 1232 | * Result code for {@link checkProvisioningPreCondition}. |
| 1233 | * |
| 1234 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1235 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system |
| 1236 | * user. |
| 1237 | * |
| 1238 | * @hide |
| 1239 | */ |
| 1240 | public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12; |
| 1241 | |
| 1242 | /** |
| 1243 | * Result code for {@link checkProvisioningPreCondition}. |
| 1244 | * |
| 1245 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 1246 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and |
| 1247 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device |
| 1248 | * admins. |
| 1249 | * |
| 1250 | * @hide |
| 1251 | */ |
| 1252 | public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13; |
| 1253 | |
| 1254 | /** |
| 1255 | * Result code for {@link checkProvisioningPreCondition}. |
| 1256 | * |
| 1257 | * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device has a device owner |
| 1258 | * and the user is a system user on a split system user device. |
| 1259 | * |
| 1260 | * @hide |
| 1261 | */ |
| 1262 | public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14; |
| 1263 | |
| 1264 | /** |
| 1265 | * Result codes for {@link checkProvisioningPreCondition} indicating all the provisioning pre |
| 1266 | * conditions. |
| 1267 | * |
| 1268 | * @hide |
| 1269 | */ |
| 1270 | @Retention(RetentionPolicy.SOURCE) |
| 1271 | @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING, |
| 1272 | CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED, |
| 1273 | CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE, |
| 1274 | CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED, |
| 1275 | CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER}) |
| 1276 | public @interface ProvisioningPreCondition {} |
| 1277 | |
| 1278 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1279 | * Return true if the given administrator component is currently active (enabled) in the system. |
| 1280 | * |
| 1281 | * @param admin The administrator component to check for. |
| 1282 | * @return {@code true} if {@code admin} is currently enabled in the system, {@code false} |
| 1283 | * otherwise |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1284 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1285 | public boolean isAdminActive(@NonNull ComponentName admin) { |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 1286 | throwIfParentInstance("isAdminActive"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1287 | return isAdminActiveAsUser(admin, myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /** |
| 1291 | * @see #isAdminActive(ComponentName) |
| 1292 | * @hide |
| 1293 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1294 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1295 | if (mService != null) { |
| 1296 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1297 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1298 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1299 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | return false; |
| 1303 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1304 | /** |
| 1305 | * Return true if the given administrator component is currently being removed |
| 1306 | * for the user. |
| 1307 | * @hide |
| 1308 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1309 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1310 | if (mService != null) { |
| 1311 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1312 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1313 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1314 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1320 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1321 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1322 | * Return a list of all currently active device administrators' component |
| 1323 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1324 | * returned. |
| 1325 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1326 | public @Nullable List<ComponentName> getActiveAdmins() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1327 | throwIfParentInstance("getActiveAdmins"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1328 | return getActiveAdminsAsUser(myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * @see #getActiveAdmins() |
| 1333 | * @hide |
| 1334 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 1335 | public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1336 | if (mService != null) { |
| 1337 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 1338 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1339 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1340 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | return null; |
| 1344 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1345 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1346 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1347 | * Used by package administration code to determine if a package can be stopped |
| 1348 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1349 | * @hide |
| 1350 | */ |
| 1351 | public boolean packageHasActiveAdmins(String packageName) { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1352 | return packageHasActiveAdmins(packageName, myUserId()); |
| 1353 | } |
| 1354 | |
| 1355 | /** |
| 1356 | * Used by package administration code to determine if a package can be stopped |
| 1357 | * or uninstalled. |
| 1358 | * @hide |
| 1359 | */ |
| 1360 | public boolean packageHasActiveAdmins(String packageName, int userId) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1361 | if (mService != null) { |
| 1362 | try { |
Amith Yamasani | ca5d6d2 | 2016-02-16 13:58:46 -0800 | [diff] [blame] | 1363 | return mService.packageHasActiveAdmins(packageName, userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1364 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1365 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | return false; |
| 1369 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1370 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1371 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1372 | * Remove a current administration component. This can only be called |
| 1373 | * by the application that owns the administration component; if you |
| 1374 | * try to remove someone else's component, a security exception will be |
| 1375 | * thrown. |
Esteban Talavera | 552a561 | 2016-02-19 17:02:24 +0000 | [diff] [blame] | 1376 | * |
| 1377 | * <p>Note that the operation is not synchronous and the admin might still be active (as |
| 1378 | * indicated by {@link #getActiveAdmins()}) by the time this method returns. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1379 | * |
| 1380 | * @param admin The administration compononent to remove. |
| 1381 | * @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] | 1382 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1383 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1384 | throwIfParentInstance("removeActiveAdmin"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1385 | if (mService != null) { |
| 1386 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1387 | mService.removeActiveAdmin(admin, myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1388 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1389 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1393 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1394 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1395 | * Returns true if an administrator has been granted a particular device policy. This can be |
| 1396 | * used to check whether the administrator was activated under an earlier set of policies, but |
| 1397 | * requires additional policies after an upgrade. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1398 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1399 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an |
| 1400 | * active administrator, or an exception will be thrown. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1401 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1402 | * @throws SecurityException if {@code admin} is not an active administrator. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1403 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1404 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 1405 | throwIfParentInstance("hasGrantedPolicy"); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1406 | if (mService != null) { |
| 1407 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1408 | return mService.hasGrantedPolicy(admin, usesPolicy, myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1409 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1410 | throw e.rethrowFromSystemServer(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1411 | } |
| 1412 | } |
| 1413 | return false; |
| 1414 | } |
| 1415 | |
| 1416 | /** |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1417 | * Returns true if the Profile Challenge is available to use for the given profile user. |
| 1418 | * |
| 1419 | * @hide |
| 1420 | */ |
| 1421 | public boolean isSeparateProfileChallengeAllowed(int userHandle) { |
| 1422 | if (mService != null) { |
| 1423 | try { |
| 1424 | return mService.isSeparateProfileChallengeAllowed(userHandle); |
| 1425 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1426 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | return false; |
| 1430 | } |
| 1431 | |
| 1432 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1433 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 1434 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1435 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1436 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1437 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1438 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1439 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 1440 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 1441 | * recognition technology. This implies technologies that can recognize the identity of |
| 1442 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 1443 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 1444 | */ |
| 1445 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 1446 | |
| 1447 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1448 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
Benjamin Franz | c6a9653 | 2015-06-16 11:23:38 +0100 | [diff] [blame] | 1449 | * 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] | 1450 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1451 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1452 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1453 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1454 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1455 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 1456 | * password containing at least numeric characters. Note that quality |
| 1457 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1458 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1459 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1460 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1461 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1462 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1463 | * password containing at least numeric characters with no repeating (4444) |
| 1464 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 1465 | * constants are ordered so that higher values are more restrictive. |
| 1466 | */ |
| 1467 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 1468 | |
| 1469 | /** |
| 1470 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1471 | * password containing at least alphabetic (or other symbol) characters. |
| 1472 | * Note that quality constants are ordered so that higher values are more |
| 1473 | * restrictive. |
| 1474 | */ |
| 1475 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1476 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1477 | /** |
| 1478 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1479 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1480 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1481 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1482 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1483 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1484 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1485 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1486 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1487 | * password containing at least a letter, a numerical digit and a special |
| 1488 | * symbol, by default. With this password quality, passwords can be |
| 1489 | * restricted to contain various sets of characters, like at least an |
| 1490 | * uppercase letter, etc. These are specified using various methods, |
| 1491 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 1492 | * that quality constants are ordered so that higher values are more |
| 1493 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1494 | */ |
| 1495 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 1496 | |
| 1497 | /** |
Oleksandr Peletskyi | 0fdcd3d | 2016-01-13 16:49:56 +0100 | [diff] [blame] | 1498 | * Constant for {@link #setPasswordQuality}: the user is not allowed to |
| 1499 | * modify password. In case this password quality is set, the password is |
| 1500 | * managed by a profile owner. The profile owner can set any password, |
| 1501 | * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note |
| 1502 | * that quality constants are ordered so that higher values are more |
| 1503 | * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is |
| 1504 | * the highest. |
| 1505 | * @hide |
| 1506 | */ |
| 1507 | public static final int PASSWORD_QUALITY_MANAGED = 0x80000; |
| 1508 | |
| 1509 | /** |
Makoto Onuki | 5e7e0670 | 2016-09-01 18:02:01 -0700 | [diff] [blame] | 1510 | * @hide |
| 1511 | * |
| 1512 | * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to |
| 1513 | * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} |
| 1514 | * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features |
| 1515 | * used by authenticator to exempt their accounts from this: |
| 1516 | * |
| 1517 | * <ul> |
| 1518 | * <li>Non-test-only DO/PO still can't be installed when there are accounts. |
| 1519 | * <p>In order to make an apk test-only, add android:testOnly="true" to the |
| 1520 | * <application> tag in the manifest. |
| 1521 | * |
| 1522 | * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the |
| 1523 | * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature. |
| 1524 | * Some authenticators claim to have any features, so to detect it, we also check |
| 1525 | * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing |
| 1526 | * if any of the accounts have it. |
| 1527 | * </ul> |
| 1528 | */ |
| 1529 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = |
| 1530 | "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED"; |
| 1531 | |
| 1532 | /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */ |
| 1533 | public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = |
| 1534 | "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED"; |
| 1535 | |
| 1536 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1537 | * Called by an application that is administering the device to set the password restrictions it |
| 1538 | * is imposing. After setting this, the user will not be able to enter a new password that is |
| 1539 | * not at least as restrictive as what has been set. Note that the current password will remain |
| 1540 | * until the user has set a new one, so the change does not take place immediately. To prompt |
| 1541 | * 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] | 1542 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1543 | * <p> |
| 1544 | * Quality constants are ordered so that higher values are more restrictive; thus the highest |
| 1545 | * requested quality constant (between the policy set here, the user's preference, and any other |
| 1546 | * considerations) is the one that is in effect. |
| 1547 | * <p> |
| 1548 | * The calling device admin must have requested |
| 1549 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1550 | * not, a security exception will be thrown. |
| 1551 | * <p> |
| 1552 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1553 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1554 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1555 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1556 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1557 | * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED}, |
| 1558 | * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC}, |
| 1559 | * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1560 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1561 | * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin} |
| 1562 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1563 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1564 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1565 | if (mService != null) { |
| 1566 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1567 | mService.setPasswordQuality(admin, quality, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1568 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1569 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1573 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1574 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1575 | * 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] | 1576 | * 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] | 1577 | * a separate challenge are not taken into account. |
| 1578 | * |
| 1579 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1580 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1581 | * restrictions on the parent profile. |
| 1582 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1583 | * @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] | 1584 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1585 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1586 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1587 | return getPasswordQuality(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1591 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1592 | if (mService != null) { |
| 1593 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 1594 | return mService.getPasswordQuality(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1595 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1596 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1597 | } |
| 1598 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1599 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1600 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1601 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1602 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1603 | * Called by an application that is administering the device to set the minimum allowed password |
| 1604 | * length. After setting this, the user will not be able to enter a new password that is not at |
| 1605 | * least as restrictive as what has been set. Note that the current password will remain until |
| 1606 | * the user has set a new one, so the change does not take place immediately. To prompt the user |
| 1607 | * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1608 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1609 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 1610 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC}, |
| 1611 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1612 | * {@link #setPasswordQuality}. |
| 1613 | * <p> |
| 1614 | * The calling device admin must have requested |
| 1615 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1616 | * not, a security exception will be thrown. |
| 1617 | * <p> |
| 1618 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1619 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1620 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1621 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1622 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1623 | * @param length The new desired minimum password length. A value of 0 means there is no |
| 1624 | * restriction. |
| 1625 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1626 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1627 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1628 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1629 | if (mService != null) { |
| 1630 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1631 | mService.setPasswordMinimumLength(admin, length, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1632 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1633 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1637 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1638 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1639 | * 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] | 1640 | * 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] | 1641 | * a separate challenge are not taken into account. |
| 1642 | * |
| 1643 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1644 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1645 | * restrictions on the parent profile. |
| 1646 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1647 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1648 | * @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] | 1649 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1650 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1651 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1652 | return getPasswordMinimumLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1656 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1657 | if (mService != null) { |
| 1658 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1659 | return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1660 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1661 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | return 0; |
| 1665 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1666 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1667 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1668 | * Called by an application that is administering the device to set the minimum number of upper |
| 1669 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1670 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1671 | * current password will remain until the user has set a new one, so the change does not take |
| 1672 | * place immediately. To prompt the user for a new password, use |
| 1673 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1674 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1675 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1676 | * <p> |
| 1677 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1678 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1679 | * not, a security exception will be thrown. |
| 1680 | * <p> |
| 1681 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1682 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1683 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1684 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1685 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1686 | * @param length The new desired minimum number of upper case letters required in the password. |
| 1687 | * A value of 0 means there is no restriction. |
| 1688 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1689 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1690 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1691 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1692 | if (mService != null) { |
| 1693 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1694 | mService.setPasswordMinimumUpperCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1695 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1696 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1702 | * Retrieve the current number of upper case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1703 | * 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] | 1704 | * its participating profiles. Restrictions on profiles that have a separate challenge |
| 1705 | * are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1706 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1707 | * {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1708 | * and only applies when the password quality is |
| 1709 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1710 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1711 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1712 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1713 | * restrictions on the parent profile. |
| 1714 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1715 | * @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] | 1716 | * aggregate all admins. |
| 1717 | * @return The minimum number of upper case letters required in the |
| 1718 | * password. |
| 1719 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1720 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1721 | return getPasswordMinimumUpperCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1725 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1726 | if (mService != null) { |
| 1727 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1728 | return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1729 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1730 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
| 1736 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1737 | * Called by an application that is administering the device to set the minimum number of lower |
| 1738 | * case letters required in the password. After setting this, the user will not be able to enter |
| 1739 | * a new password that is not at least as restrictive as what has been set. Note that the |
| 1740 | * current password will remain until the user has set a new one, so the change does not take |
| 1741 | * place immediately. To prompt the user for a new password, use |
| 1742 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1743 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1744 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1745 | * <p> |
| 1746 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1747 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1748 | * not, a security exception will be thrown. |
| 1749 | * <p> |
| 1750 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1751 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1752 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1753 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1754 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1755 | * @param length The new desired minimum number of lower case letters required in the password. |
| 1756 | * A value of 0 means there is no restriction. |
| 1757 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1758 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1759 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1760 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1761 | if (mService != null) { |
| 1762 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1763 | mService.setPasswordMinimumLowerCase(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1764 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1765 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1771 | * Retrieve the current number of lower case letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1772 | * 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] | 1773 | * and its participating profiles. Restrictions on profiles that have |
| 1774 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1775 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1776 | * {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1777 | * and only applies when the password quality is |
| 1778 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1779 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1780 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1781 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1782 | * restrictions on the parent profile. |
| 1783 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1784 | * @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] | 1785 | * aggregate all admins. |
| 1786 | * @return The minimum number of lower case letters required in the |
| 1787 | * password. |
| 1788 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1789 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1790 | return getPasswordMinimumLowerCase(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1794 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1795 | if (mService != null) { |
| 1796 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1797 | return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1798 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1799 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1800 | } |
| 1801 | } |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
| 1805 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1806 | * Called by an application that is administering the device to set the minimum number of |
| 1807 | * letters required in the password. After setting this, the user will not be able to enter a |
| 1808 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1809 | * password will remain until the user has set a new one, so the change does not take place |
| 1810 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1811 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1812 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1813 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1814 | * <p> |
| 1815 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1816 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1817 | * not, a security exception will be thrown. |
| 1818 | * <p> |
| 1819 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1820 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1821 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1822 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1823 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1824 | * @param length The new desired minimum number of letters required in the password. A value of |
| 1825 | * 0 means there is no restriction. |
| 1826 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1827 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1828 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1829 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1830 | if (mService != null) { |
| 1831 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1832 | mService.setPasswordMinimumLetters(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1833 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1834 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1835 | } |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1840 | * Retrieve the current number of letters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1841 | * 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] | 1842 | * and its participating profiles. Restrictions on profiles that have |
| 1843 | * a separate challenge are not taken into account. |
| 1844 | * This is the same value as set by |
| 1845 | * {@link #setPasswordMinimumLetters(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1846 | * and only applies when the password quality is |
| 1847 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1848 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1849 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1850 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1851 | * restrictions on the parent profile. |
| 1852 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1853 | * @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] | 1854 | * aggregate all admins. |
| 1855 | * @return The minimum number of letters required in the password. |
| 1856 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1857 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1858 | return getPasswordMinimumLetters(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1862 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1863 | if (mService != null) { |
| 1864 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1865 | return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1866 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1867 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | return 0; |
| 1871 | } |
| 1872 | |
| 1873 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1874 | * Called by an application that is administering the device to set the minimum number of |
| 1875 | * numerical digits required in the password. After setting this, the user will not be able to |
| 1876 | * enter a new password that is not at least as restrictive as what has been set. Note that the |
| 1877 | * current password will remain until the user has set a new one, so the change does not take |
| 1878 | * place immediately. To prompt the user for a new password, use |
| 1879 | * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 1880 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 1881 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1882 | * <p> |
| 1883 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1884 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1885 | * not, a security exception will be thrown. |
| 1886 | * <p> |
| 1887 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1888 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1889 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1890 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1891 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1892 | * @param length The new desired minimum number of numerical digits required in the password. A |
| 1893 | * value of 0 means there is no restriction. |
| 1894 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1895 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1896 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1897 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1898 | if (mService != null) { |
| 1899 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1900 | mService.setPasswordMinimumNumeric(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1901 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1902 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * Retrieve the current number of numerical digits required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1909 | * 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] | 1910 | * and its participating profiles. Restrictions on profiles that have |
| 1911 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1912 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1913 | * {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1914 | * and only applies when the password quality is |
| 1915 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1916 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1917 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1918 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1919 | * restrictions on the parent profile. |
| 1920 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1921 | * @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] | 1922 | * aggregate all admins. |
| 1923 | * @return The minimum number of numerical digits required in the password. |
| 1924 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1925 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1926 | return getPasswordMinimumNumeric(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1930 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1931 | if (mService != null) { |
| 1932 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1933 | return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1934 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1935 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | return 0; |
| 1939 | } |
| 1940 | |
| 1941 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1942 | * Called by an application that is administering the device to set the minimum number of |
| 1943 | * symbols required in the password. After setting this, the user will not be able to enter a |
| 1944 | * new password that is not at least as restrictive as what has been set. Note that the current |
| 1945 | * password will remain until the user has set a new one, so the change does not take place |
| 1946 | * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 1947 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 1948 | * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1949 | * {@link #setPasswordQuality}. The default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1950 | * <p> |
| 1951 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1952 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 1953 | * not, a security exception will be thrown. |
| 1954 | * <p> |
| 1955 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 1956 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 1957 | * profile. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1958 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 1959 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1960 | * @param length The new desired minimum number of symbols required in the password. A value of |
| 1961 | * 0 means there is no restriction. |
| 1962 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 1963 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1964 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1965 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1966 | if (mService != null) { |
| 1967 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 1968 | mService.setPasswordMinimumSymbols(admin, length, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1969 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 1970 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1971 | } |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1976 | * Retrieve the current number of symbols required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 1977 | * 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] | 1978 | * and its participating profiles. Restrictions on profiles that have |
| 1979 | * a separate challenge are not taken into account. This is the same value as |
| 1980 | * set by {@link #setPasswordMinimumSymbols(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1981 | * and only applies when the password quality is |
| 1982 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1983 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 1984 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 1985 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 1986 | * restrictions on the parent profile. |
| 1987 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1988 | * @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] | 1989 | * aggregate all admins. |
| 1990 | * @return The minimum number of symbols required in the password. |
| 1991 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1992 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 1993 | return getPasswordMinimumSymbols(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1997 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1998 | if (mService != null) { |
| 1999 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2000 | return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2001 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2002 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | return 0; |
| 2006 | } |
| 2007 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2008 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2009 | * Called by an application that is administering the device to set the minimum number of |
| 2010 | * non-letter characters (numerical digits or symbols) required in the password. After setting |
| 2011 | * this, the user will not be able to enter a new password that is not at least as restrictive |
| 2012 | * as what has been set. Note that the current password will remain until the user has set a new |
| 2013 | * one, so the change does not take place immediately. To prompt the user for a new password, |
| 2014 | * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after |
| 2015 | * setting this value. This constraint is only imposed if the administrator has also requested |
| 2016 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2017 | * <p> |
| 2018 | * The calling device admin must have requested |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2019 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2020 | * not, a security exception will be thrown. |
| 2021 | * <p> |
| 2022 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2023 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2024 | * profile. |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2025 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2026 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2027 | * @param length The new desired minimum number of letters required in the password. A value of |
| 2028 | * 0 means there is no restriction. |
| 2029 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2030 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2031 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2032 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2033 | if (mService != null) { |
| 2034 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2035 | mService.setPasswordMinimumNonLetter(admin, length, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2036 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2037 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2043 | * Retrieve the current number of non-letter characters required in the password |
Rubin Xu | d3609d4 | 2016-07-13 18:32:57 +0100 | [diff] [blame] | 2044 | * 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] | 2045 | * and its participating profiles. Restrictions on profiles that have |
| 2046 | * a separate challenge are not taken into account. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2047 | * This is the same value as set by |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2048 | * {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2049 | * and only applies when the password quality is |
| 2050 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 2051 | * |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2052 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2053 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2054 | * restrictions on the parent profile. |
| 2055 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2056 | * @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] | 2057 | * aggregate all admins. |
| 2058 | * @return The minimum number of letters required in the password. |
| 2059 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2060 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2061 | return getPasswordMinimumNonLetter(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2065 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2066 | if (mService != null) { |
| 2067 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2068 | return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2069 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2070 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 2071 | } |
| 2072 | } |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2076 | /** |
| 2077 | * Called by an application that is administering the device to set the length of the password |
| 2078 | * history. After setting this, the user will not be able to enter a new password that is the |
| 2079 | * same as any password in the history. Note that the current password will remain until the |
| 2080 | * user has set a new one, so the change does not take place immediately. To prompt the user for |
| 2081 | * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or |
| 2082 | * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is |
| 2083 | * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC} |
| 2084 | * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or |
| 2085 | * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}. |
| 2086 | * <p> |
| 2087 | * The calling device admin must have requested |
| 2088 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2089 | * not, a security exception will be thrown. |
| 2090 | * <p> |
| 2091 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2092 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2093 | * profile. |
| 2094 | * |
| 2095 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2096 | * @param length The new desired length of password history. A value of 0 means there is no |
| 2097 | * restriction. |
| 2098 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2099 | * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
| 2100 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2101 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2102 | if (mService != null) { |
| 2103 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2104 | mService.setPasswordHistoryLength(admin, length, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2105 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2106 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2107 | } |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2112 | * Called by a device admin to set the password expiration timeout. Calling this method will |
| 2113 | * restart the countdown for password expiration for the given admin, as will changing the |
| 2114 | * device password (for all admins). |
| 2115 | * <p> |
| 2116 | * The provided timeout is the time delta in ms and will be added to the current time. For |
| 2117 | * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = |
| 2118 | * 432000000 ms for timeout. |
| 2119 | * <p> |
| 2120 | * To disable password expiration, a value of 0 may be used for timeout. |
| 2121 | * <p> |
| 2122 | * The calling device admin must have requested |
| 2123 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has |
| 2124 | * not, a security exception will be thrown. |
| 2125 | * <p> |
| 2126 | * Note that setting the password will automatically reset the expiration time for all active |
| 2127 | * admins. Active admins do not need to explicitly call this method in that case. |
| 2128 | * <p> |
| 2129 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2130 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2131 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2132 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2133 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2134 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means |
| 2135 | * there is no restriction (unlimited). |
| 2136 | * @throws SecurityException if {@code admin} is not an active administrator or {@code admin} |
| 2137 | * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2138 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2139 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2140 | if (mService != null) { |
| 2141 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2142 | mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2143 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2144 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 2150 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 2151 | * recurring expiration timeout provided in the call to |
| 2152 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2153 | * aggregate of all participating policy administrators if {@code admin} is null. Admins that |
| 2154 | * have set restrictions on profiles that have a separate challenge are not taken into account. |
| 2155 | * |
| 2156 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2157 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2158 | * restrictions on the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2159 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2160 | * @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] | 2161 | * @return The timeout for the given admin or the minimum of all timeouts |
| 2162 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2163 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2164 | if (mService != null) { |
| 2165 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2166 | return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2167 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2168 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2169 | } |
| 2170 | } |
| 2171 | return 0; |
| 2172 | } |
| 2173 | |
| 2174 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2175 | * 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] | 2176 | * 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] | 2177 | * a separate challenge are not taken into account. If admin is {@code null}, then a composite |
| 2178 | * of all expiration times is returned - which will be the minimum of all of them. |
| 2179 | * |
| 2180 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2181 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2182 | * the password expiration for the parent profile. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2183 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2184 | * @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] | 2185 | * @return The password expiration time, in milliseconds since epoch. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2186 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2187 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2188 | if (mService != null) { |
| 2189 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2190 | return mService.getPasswordExpiration(admin, myUserId(), mParentInstance); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2191 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2192 | throw e.rethrowFromSystemServer(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2193 | } |
| 2194 | } |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
| 2198 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2199 | * 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] | 2200 | * 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] | 2201 | * have a separate challenge are not taken into account. |
| 2202 | * |
| 2203 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2204 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2205 | * restrictions on the parent profile. |
| 2206 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2207 | * @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] | 2208 | * all admins. |
| 2209 | * @return The length of the password history |
| 2210 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2211 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2212 | return getPasswordHistoryLength(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2216 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2217 | if (mService != null) { |
| 2218 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2219 | return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2220 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2221 | throw e.rethrowFromSystemServer(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | return 0; |
| 2225 | } |
| 2226 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2227 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2228 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2229 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 2230 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2231 | * @return Returns the maximum length that the user can enter. |
| 2232 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 2233 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2234 | // Kind-of arbitrary. |
| 2235 | return 16; |
| 2236 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2237 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2238 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2239 | * Determine whether the current password the user has set is sufficient to meet the policy |
| 2240 | * requirements (e.g. quality, minimum length) that have been requested by the admins of this |
| 2241 | * 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^] | 2242 | * 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] | 2243 | * <p> |
| 2244 | * The calling device admin must have requested |
| 2245 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has |
| 2246 | * not, a security exception will be thrown. |
| 2247 | * <p> |
| 2248 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2249 | * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on |
| 2250 | * the parent profile is sufficient. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2251 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 2252 | * @return Returns true if the password meets the current requirements, else false. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2253 | * @throws SecurityException if the calling application does not own an active administrator |
| 2254 | * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame^] | 2255 | * @throws InvalidStateException if the user is not unlocked. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2256 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2257 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2258 | if (mService != null) { |
| 2259 | try { |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 2260 | return mService.isActivePasswordSufficient(myUserId(), mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2261 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2262 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2263 | } |
| 2264 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2265 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2266 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2267 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2268 | /** |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2269 | * Determine whether the current profile password the user has set is sufficient |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2270 | * 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] | 2271 | * requested by the admins of the parent user and its profiles. |
| 2272 | * |
| 2273 | * @param userHandle the userId of the profile to check the password for. |
| 2274 | * @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] | 2275 | * @throws SecurityException if {@code userHandle} is not a managed profile. |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2276 | * @hide |
| 2277 | */ |
| 2278 | public boolean isProfileActivePasswordSufficientForParent(int userHandle) { |
| 2279 | if (mService != null) { |
| 2280 | try { |
| 2281 | return mService.isProfileActivePasswordSufficientForParent(userHandle); |
| 2282 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2283 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d769391 | 2016-01-22 17:26:31 +0000 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | return false; |
| 2287 | } |
| 2288 | |
| 2289 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2290 | * Retrieve the number of times the user has failed at entering a password since that last |
| 2291 | * successful password entry. |
| 2292 | * <p> |
| 2293 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2294 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed |
| 2295 | * password attemts for the parent user. |
| 2296 | * <p> |
| 2297 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
| 2298 | * 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] | 2299 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2300 | * @return The number of times user has entered an incorrect password since the last correct |
| 2301 | * password entry. |
| 2302 | * @throws SecurityException if the calling application does not own an active administrator |
| 2303 | * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2304 | */ |
| 2305 | public int getCurrentFailedPasswordAttempts() { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2306 | return getCurrentFailedPasswordAttempts(myUserId()); |
| 2307 | } |
| 2308 | |
| 2309 | /** |
| 2310 | * Retrieve the number of times the given user has failed at entering a |
| 2311 | * password since that last successful password entry. |
| 2312 | * |
| 2313 | * <p>The calling device admin must have requested |
| 2314 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has |
| 2315 | * not and it is not the system uid, a security exception will be thrown. |
| 2316 | * |
| 2317 | * @hide |
| 2318 | */ |
| 2319 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2320 | if (mService != null) { |
| 2321 | try { |
Clara Bayarri | 51e41ad | 2016-02-11 17:48:53 +0000 | [diff] [blame] | 2322 | return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2323 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2324 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | return -1; |
| 2328 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2329 | |
| 2330 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2331 | * 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] | 2332 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2333 | * @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] | 2334 | * @hide |
| 2335 | */ |
| 2336 | public boolean getDoNotAskCredentialsOnBoot() { |
| 2337 | if (mService != null) { |
| 2338 | try { |
| 2339 | return mService.getDoNotAskCredentialsOnBoot(); |
| 2340 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2341 | throw e.rethrowFromSystemServer(); |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | return false; |
| 2345 | } |
| 2346 | |
| 2347 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2348 | * Setting this to a value greater than zero enables a built-in policy that will perform a |
| 2349 | * device or profile wipe after too many incorrect device-unlock passwords have been entered. |
| 2350 | * This built-in policy combines watching for failed passwords and wiping the device, and |
| 2351 | * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2352 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2353 | * <p> |
| 2354 | * To implement any other policy (e.g. wiping data for a particular application only, erasing or |
| 2355 | * revoking credentials, or reporting the failure to a server), you should implement |
| 2356 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not |
| 2357 | * use this API, because if the maximum count is reached, the device or profile will be wiped |
| 2358 | * immediately, and your callback will not be invoked. |
| 2359 | * <p> |
| 2360 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2361 | * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent |
| 2362 | * profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2363 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2364 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2365 | * @param num The number of failed password attempts at which point the device or profile will |
| 2366 | * be wiped. |
| 2367 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2368 | * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
| 2369 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2370 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2371 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2372 | if (mService != null) { |
| 2373 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2374 | mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2375 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2376 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2377 | } |
| 2378 | } |
| 2379 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2380 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2381 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2382 | * 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] | 2383 | * 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] | 2384 | * and its participating profiles. Restrictions on profiles that have a separate challenge are |
| 2385 | * not taken into account. |
| 2386 | * |
| 2387 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2388 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2389 | * the value for the parent profile. |
| 2390 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2391 | * @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] | 2392 | * all admins. |
| 2393 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2394 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2395 | return getMaximumFailedPasswordsForWipe(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2399 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2400 | if (mService != null) { |
| 2401 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2402 | return mService.getMaximumFailedPasswordsForWipe( |
| 2403 | admin, userHandle, mParentInstance); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2404 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2405 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2406 | } |
| 2407 | } |
| 2408 | return 0; |
| 2409 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2410 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2411 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2412 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 2413 | * for the given user. So for primary user, it might return the primary or |
| 2414 | * a managed profile. For a secondary user, it would be the same as the |
| 2415 | * user passed in. |
| 2416 | * @hide Used only by Keyguard |
| 2417 | */ |
| 2418 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 2419 | if (mService != null) { |
| 2420 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2421 | return mService.getProfileWithMinimumFailedPasswordsForWipe( |
| 2422 | userHandle, mParentInstance); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2423 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2424 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 2425 | } |
| 2426 | } |
| 2427 | return UserHandle.USER_NULL; |
| 2428 | } |
| 2429 | |
| 2430 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2431 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 2432 | * the password again until the user has entered it. |
| 2433 | */ |
| 2434 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2435 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2436 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 2437 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 2438 | * If the flag is set, the device can be booted without asking for user password. |
| 2439 | * The absence of this flag does not change the current boot requirements. This flag |
| 2440 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 2441 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 2442 | * device to factory defaults. |
| 2443 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 2444 | 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] | 2445 | |
| 2446 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2447 | * Force a new device unlock password (the password needed to access the entire device, not for |
| 2448 | * individual accounts) on the user. This takes effect immediately. |
| 2449 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2450 | * <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] | 2451 | * device admins that are not device owner and not profile owner. |
| 2452 | * 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] | 2453 | * and profile owner can still do this when user is unlocked and does not have a managed |
| 2454 | * profile.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2455 | * <p> |
| 2456 | * The given password must be sufficient for the current password quality and length constraints |
| 2457 | * as returned by {@link #getPasswordQuality(ComponentName)} and |
| 2458 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then |
| 2459 | * it will be rejected and false returned. Note that the password may be a stronger quality |
| 2460 | * (containing alphanumeric characters when the requested quality is only numeric), in which |
| 2461 | * case the currently active quality will be increased to match. |
| 2462 | * <p> |
| 2463 | * 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] | 2464 | * current password constraints allow it. <em>Note: This will not work in |
| 2465 | * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins |
| 2466 | * that are not device owner or profile owner. Once set, the password cannot be changed to null |
| 2467 | * or empty except by these admins.</em> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2468 | * <p> |
| 2469 | * The calling device admin must have requested |
| 2470 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has |
| 2471 | * not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2472 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 2473 | * @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] | 2474 | * @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] | 2475 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
| 2476 | * @return Returns true if the password was applied, or false if it is not acceptable for the |
| 2477 | * current constraints or if the user has not been decrypted yet. |
| 2478 | * @throws SecurityException if the calling application does not own an active administrator |
| 2479 | * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} |
Ricky Wai | 977ade2 | 2016-05-24 15:02:41 +0100 | [diff] [blame] | 2480 | * @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] | 2481 | * @throws IllegalArgumentException if the password does not meet system requirements. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2482 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2483 | public boolean resetPassword(String password, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2484 | throwIfParentInstance("resetPassword"); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2485 | if (mService != null) { |
| 2486 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2487 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2488 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2489 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2490 | } |
| 2491 | } |
| 2492 | return false; |
| 2493 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2494 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2495 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2496 | * Called by an application that is administering the device to set the maximum time for user |
| 2497 | * activity until the device will lock. This limits the length that the user can set. It takes |
| 2498 | * effect immediately. |
| 2499 | * <p> |
| 2500 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2501 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2502 | * <p> |
| 2503 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2504 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2505 | * profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2506 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2507 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2508 | * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there |
| 2509 | * is no restriction. |
| 2510 | * @throws SecurityException if {@code admin} is not an active administrator or it does not use |
| 2511 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2512 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2513 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2514 | if (mService != null) { |
| 2515 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2516 | mService.setMaximumTimeToLock(admin, timeMs, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2517 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2518 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2522 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2523 | /** |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 2524 | * 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] | 2525 | * 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] | 2526 | * a separate challenge are not taken into account. |
| 2527 | * |
| 2528 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2529 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2530 | * restrictions on the parent profile. |
| 2531 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2532 | * @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] | 2533 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 2534 | * @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] | 2535 | * 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] | 2536 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2537 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2538 | return getMaximumTimeToLock(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2542 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2543 | if (mService != null) { |
| 2544 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2545 | return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2546 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2547 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | return 0; |
| 2551 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2552 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2553 | /** |
Ricky Wai | 035e924 | 2016-03-18 16:43:31 +0000 | [diff] [blame] | 2554 | * Returns maximum time to lock that applied by all profiles in this user. We do this because we |
| 2555 | * do not have a separate timeout to lock for work challenge only. |
| 2556 | * |
| 2557 | * @hide |
| 2558 | */ |
| 2559 | public long getMaximumTimeToLockForUserAndProfiles(int userHandle) { |
| 2560 | if (mService != null) { |
| 2561 | try { |
| 2562 | return mService.getMaximumTimeToLockForUserAndProfiles(userHandle); |
| 2563 | } catch (RemoteException e) { |
| 2564 | throw e.rethrowFromSystemServer(); |
| 2565 | } |
| 2566 | } |
| 2567 | return 0; |
| 2568 | } |
| 2569 | |
| 2570 | /** |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2571 | * Called by a device/profile owner to set the timeout after which unlocking with secondary, non |
| 2572 | * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong |
| 2573 | * authentication method like password, pin or pattern. |
| 2574 | * |
| 2575 | * <p>This timeout is used internally to reset the timer to require strong auth again after |
| 2576 | * specified timeout each time it has been successfully used. |
| 2577 | * |
| 2578 | * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}. |
| 2579 | * |
| 2580 | * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
| 2581 | * |
| 2582 | * <p>The calling device admin must be a device or profile owner. If it is not, |
| 2583 | * a {@link SecurityException} will be thrown. |
| 2584 | * |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2585 | * <p>The calling device admin can verify the value it has set by calling |
| 2586 | * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance. |
| 2587 | * |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2588 | * <p>This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2589 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 2590 | * profile. |
| 2591 | * |
| 2592 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2593 | * @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] | 2594 | * authentication method. A value of 0 means the admin is not participating in |
| 2595 | * controlling the timeout. |
| 2596 | * The minimum and maximum timeouts are platform-defined and are typically 1 hour and |
| 2597 | * 72 hours, respectively. Though discouraged, the admin may choose to require strong |
| 2598 | * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or |
| 2599 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2600 | * |
| 2601 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2602 | */ |
| 2603 | public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin, |
| 2604 | long timeoutMs) { |
| 2605 | if (mService != null) { |
| 2606 | try { |
| 2607 | mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance); |
| 2608 | } catch (RemoteException e) { |
| 2609 | throw e.rethrowFromSystemServer(); |
| 2610 | } |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | /** |
| 2615 | * Determine for how long the user will be able to use secondary, non strong auth for |
| 2616 | * authentication, since last strong method authentication (password, pin or pattern) was used. |
| 2617 | * After the returned timeout the user is required to use strong authentication method. |
| 2618 | * |
| 2619 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 2620 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 2621 | * restrictions on the parent profile. |
| 2622 | * |
| 2623 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
| 2624 | * accross all participating admins. |
Michal Karpinski | 943aabd | 2016-10-06 11:09:25 +0100 | [diff] [blame] | 2625 | * @return The timeout or 0 if not configured for the provided admin. |
Michal Karpinski | 8f010dd | 2016-06-21 15:05:53 +0100 | [diff] [blame] | 2626 | */ |
| 2627 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) { |
| 2628 | return getRequiredStrongAuthTimeout(admin, myUserId()); |
| 2629 | } |
| 2630 | |
| 2631 | /** @hide per-user version */ |
| 2632 | public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) { |
| 2633 | if (mService != null) { |
| 2634 | try { |
| 2635 | return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance); |
| 2636 | } catch (RemoteException e) { |
| 2637 | throw e.rethrowFromSystemServer(); |
| 2638 | } |
| 2639 | } |
| 2640 | return DEFAULT_STRONG_AUTH_TIMEOUT_MS; |
| 2641 | } |
| 2642 | |
| 2643 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2644 | * Make the device lock immediately, as if the lock screen timeout has expired at the point of |
| 2645 | * this call. |
| 2646 | * <p> |
| 2647 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
| 2648 | * to be able to call this method; if it has not, a security exception will be thrown. |
| 2649 | * <p> |
| 2650 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 2651 | * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2652 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2653 | * @throws SecurityException if the calling application does not own an active administrator |
| 2654 | * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2655 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2656 | public void lockNow() { |
| 2657 | if (mService != null) { |
| 2658 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 2659 | mService.lockNow(mParentInstance); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2660 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2661 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2662 | } |
| 2663 | } |
| 2664 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2665 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2666 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2667 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2668 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2669 | */ |
| 2670 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 2671 | |
| 2672 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2673 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 2674 | * data. |
| 2675 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 2676 | * <p>This flag may only be set by device owner admins; if it is set by |
| 2677 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 2678 | */ |
| 2679 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 2680 | |
| 2681 | /** |
Suprabh Shukla | 556b05a | 2016-08-10 15:49:24 -0700 | [diff] [blame] | 2682 | * Ask that all user data be wiped. If called as a secondary user, the user will be removed and |
| 2683 | * other users will remain unaffected. Calling from the primary user will cause the device to |
| 2684 | * reboot, erasing all device data - including all the secondary users and their data - while |
| 2685 | * booting up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2686 | * <p> |
| 2687 | * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to |
| 2688 | * 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] | 2689 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2690 | * @param flags Bit mask of additional options: currently supported flags are |
| 2691 | * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}. |
| 2692 | * @throws SecurityException if the calling application does not own an active administrator |
| 2693 | * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2694 | */ |
| 2695 | public void wipeData(int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2696 | throwIfParentInstance("wipeData"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2697 | if (mService != null) { |
| 2698 | try { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 2699 | mService.wipeData(flags); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2700 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2701 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2702 | } |
| 2703 | } |
| 2704 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2705 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2706 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2707 | * Called by an application that is administering the device to set the |
| 2708 | * global proxy and exclusion list. |
| 2709 | * <p> |
| 2710 | * The calling device admin must have requested |
| 2711 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 2712 | * this method; if it has not, a security exception will be thrown. |
| 2713 | * Only the first device admin can set the proxy. If a second admin attempts |
| 2714 | * 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] | 2715 | * 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] | 2716 | * be returned. |
| 2717 | * The method can be called repeatedly by the device admin alrady setting the |
| 2718 | * proxy to update the proxy and exclusion list. |
| 2719 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2720 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2721 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 2722 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 2723 | * @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] | 2724 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 2725 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2726 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2727 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2728 | public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2729 | List<String> exclusionList ) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2730 | throwIfParentInstance("setGlobalProxy"); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2731 | if (proxySpec == null) { |
| 2732 | throw new NullPointerException(); |
| 2733 | } |
| 2734 | if (mService != null) { |
| 2735 | try { |
| 2736 | String hostSpec; |
| 2737 | String exclSpec; |
| 2738 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 2739 | hostSpec = null; |
| 2740 | exclSpec = null; |
| 2741 | } else { |
| 2742 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 2743 | throw new IllegalArgumentException(); |
| 2744 | } |
| 2745 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 2746 | String hostName = sa.getHostName(); |
| 2747 | int port = sa.getPort(); |
| 2748 | StringBuilder hostBuilder = new StringBuilder(); |
| 2749 | hostSpec = hostBuilder.append(hostName) |
| 2750 | .append(":").append(Integer.toString(port)).toString(); |
| 2751 | if (exclusionList == null) { |
| 2752 | exclSpec = ""; |
| 2753 | } else { |
| 2754 | StringBuilder listBuilder = new StringBuilder(); |
| 2755 | boolean firstDomain = true; |
| 2756 | for (String exclDomain : exclusionList) { |
| 2757 | if (!firstDomain) { |
| 2758 | listBuilder = listBuilder.append(","); |
| 2759 | } else { |
| 2760 | firstDomain = false; |
| 2761 | } |
| 2762 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 2763 | } |
| 2764 | exclSpec = listBuilder.toString(); |
| 2765 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 2766 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 2767 | != android.net.Proxy.PROXY_VALID) |
| 2768 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2769 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2770 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2771 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2772 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | return null; |
| 2776 | } |
| 2777 | |
| 2778 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2779 | * Set a network-independent global HTTP proxy. This is not normally what you want for typical |
| 2780 | * HTTP proxies - they are generally network dependent. However if you're doing something |
| 2781 | * unusual like general internal filtering this may be useful. On a private network where the |
| 2782 | * proxy is not accessible, you may break HTTP using this. |
| 2783 | * <p> |
| 2784 | * This method requires the caller to be the device owner. |
| 2785 | * <p> |
| 2786 | * 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] | 2787 | * |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2788 | * @see ProxyInfo |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2789 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2790 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A |
| 2791 | * {@code null} value will clear the global HTTP proxy. |
| 2792 | * @throws SecurityException if {@code admin} is not the device owner. |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2793 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2794 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 2795 | proxyInfo) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2796 | throwIfParentInstance("setRecommendedGlobalProxy"); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2797 | if (mService != null) { |
| 2798 | try { |
| 2799 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 2800 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2801 | throw e.rethrowFromSystemServer(); |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 2802 | } |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2807 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2808 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 2809 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 2810 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2811 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 2812 | public @Nullable ComponentName getGlobalProxyAdmin() { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2813 | if (mService != null) { |
| 2814 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2815 | return mService.getGlobalProxyAdmin(myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2816 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2817 | throw e.rethrowFromSystemServer(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2818 | } |
| 2819 | } |
| 2820 | return null; |
| 2821 | } |
| 2822 | |
| 2823 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2824 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2825 | * indicating that encryption is not supported. |
| 2826 | */ |
| 2827 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 2828 | |
| 2829 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2830 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2831 | * indicating that encryption is supported, but is not currently active. |
| 2832 | */ |
| 2833 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 2834 | |
| 2835 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2836 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2837 | * indicating that encryption is not currently active, but is currently |
| 2838 | * being activated. This is only reported by devices that support |
| 2839 | * encryption of data and only when the storage is currently |
| 2840 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 2841 | * to become encrypted will never return this value. |
| 2842 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2843 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2844 | |
| 2845 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2846 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2847 | * indicating that encryption is active. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2848 | * <p> |
| 2849 | * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2850 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2851 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2852 | |
| 2853 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2854 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2855 | * indicating that encryption is active, but an encryption key has not |
| 2856 | * been set by the user. |
| 2857 | */ |
| 2858 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2859 | |
| 2860 | /** |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2861 | * Result code for {@link #getStorageEncryptionStatus}: |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2862 | * indicating that encryption is active and the encryption key is tied to the user or profile. |
| 2863 | * <p> |
| 2864 | * This value is only returned to apps targeting API level 24 and above. For apps targeting |
| 2865 | * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the |
| 2866 | * encryption key is specific to the user or profile. |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 2867 | */ |
| 2868 | public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5; |
| 2869 | |
| 2870 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2871 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2872 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2873 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2874 | * to check encryption status. However, on some devices this activity may never return, as |
| 2875 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2876 | */ |
| 2877 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2878 | public static final String ACTION_START_ENCRYPTION |
| 2879 | = "android.app.action.START_ENCRYPTION"; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2880 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2881 | * Widgets are enabled in keyguard |
| 2882 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2883 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2884 | |
| 2885 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2886 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2887 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2888 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2889 | |
| 2890 | /** |
| 2891 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2892 | */ |
| 2893 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2894 | |
| 2895 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2896 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2897 | */ |
| 2898 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2899 | |
| 2900 | /** |
| 2901 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2902 | */ |
| 2903 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2904 | |
| 2905 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2906 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2907 | * (e.g. PIN/Pattern/Password). |
| 2908 | */ |
| 2909 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2910 | |
| 2911 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2912 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2913 | */ |
| 2914 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2915 | |
| 2916 | /** |
Adrian Roos | 7f06eed | 2016-02-05 15:21:02 -0800 | [diff] [blame] | 2917 | * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password). |
| 2918 | */ |
| 2919 | public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6; |
| 2920 | |
| 2921 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2922 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2923 | */ |
| 2924 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2925 | |
| 2926 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2927 | * Called by an application that is administering the device to request that the storage system |
| 2928 | * be encrypted. |
| 2929 | * <p> |
| 2930 | * When multiple device administrators attempt to control device encryption, the most secure, |
| 2931 | * supported setting will always be used. If any device administrator requests device |
| 2932 | * encryption, it will be enabled; Conversely, if a device administrator attempts to disable |
| 2933 | * 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] | 2934 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 2935 | * <p> |
| 2936 | * This policy controls encryption of the secure (application data) storage area. Data written |
| 2937 | * to other storage areas may or may not be encrypted, and this policy does not require or |
| 2938 | * control the encryption of any other storage areas. There is one exception: If |
| 2939 | * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the |
| 2940 | * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be |
| 2941 | * written to disk within the encrypted storage area. |
| 2942 | * <p> |
| 2943 | * Important Note: On some devices, it is possible to encrypt storage without requiring the user |
| 2944 | * to create a device PIN or Password. In this case, the storage is encrypted, but the |
| 2945 | * encryption key may not be fully secured. For maximum security, the administrator should also |
| 2946 | * require (and check for) a pattern, PIN, or password. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2947 | * |
| 2948 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2949 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2950 | * @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] | 2951 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2952 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2953 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
| 2954 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 2955 | * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE} |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2956 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2957 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2958 | throwIfParentInstance("setStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2959 | if (mService != null) { |
| 2960 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2961 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2962 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2963 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2967 | } |
| 2968 | |
| 2969 | /** |
| 2970 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2971 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2972 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2973 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2974 | * this will return the requested encryption setting as an aggregate of all active |
| 2975 | * administrators. |
| 2976 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2977 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2978 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 2979 | throwIfParentInstance("getStorageEncryption"); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2980 | if (mService != null) { |
| 2981 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 2982 | return mService.getStorageEncryption(admin, myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2983 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 2984 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2985 | } |
| 2986 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2987 | return false; |
| 2988 | } |
| 2989 | |
| 2990 | /** |
| 2991 | * Called by an application that is administering the device to |
| 2992 | * determine the current encryption status of the device. |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 2993 | * <p> |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2994 | * Depending on the returned status code, the caller may proceed in different |
| 2995 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2996 | * storage system does not support encryption. If the |
| 2997 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2998 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2999 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 3000 | * 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] | 3001 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING}, |
| 3002 | * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}, |
| 3003 | * no further action is required. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3004 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3005 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3006 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 3007 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
Amith Yamasani | 75db125 | 2016-07-11 14:41:01 -0700 | [diff] [blame] | 3008 | * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3009 | */ |
| 3010 | public int getStorageEncryptionStatus() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3011 | throwIfParentInstance("getStorageEncryptionStatus"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3012 | return getStorageEncryptionStatus(myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | /** @hide per-user version */ |
| 3016 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3017 | if (mService != null) { |
| 3018 | try { |
Makoto Onuki | d4c9e54 | 2016-02-25 18:17:30 -0800 | [diff] [blame] | 3019 | return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3020 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3021 | throw e.rethrowFromSystemServer(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 3022 | } |
| 3023 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 3024 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 3025 | } |
| 3026 | |
| 3027 | /** |
Robin Lee | 2f7e1e4 | 2016-03-21 10:50:01 +0000 | [diff] [blame] | 3028 | * Mark a CA certificate as approved by the device user. This means that they have been notified |
| 3029 | * of the installation, were made aware of the risks, viewed the certificate and still wanted to |
| 3030 | * keep the certificate on the device. |
| 3031 | * |
| 3032 | * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to |
| 3033 | * this certificate. |
| 3034 | * |
| 3035 | * @hide |
| 3036 | */ |
| 3037 | public boolean approveCaCert(String alias, int userHandle, boolean approval) { |
| 3038 | if (mService != null) { |
| 3039 | try { |
| 3040 | return mService.approveCaCert(alias, userHandle, approval); |
| 3041 | } catch (RemoteException e) { |
| 3042 | throw e.rethrowFromSystemServer(); |
| 3043 | } |
| 3044 | } |
| 3045 | return false; |
| 3046 | } |
| 3047 | |
| 3048 | /** |
| 3049 | * Check whether a CA certificate has been approved by the device user. |
| 3050 | * |
| 3051 | * @hide |
| 3052 | */ |
| 3053 | public boolean isCaCertApproved(String alias, int userHandle) { |
| 3054 | if (mService != null) { |
| 3055 | try { |
| 3056 | return mService.isCaCertApproved(alias, userHandle); |
| 3057 | } catch (RemoteException e) { |
| 3058 | throw e.rethrowFromSystemServer(); |
| 3059 | } |
| 3060 | } |
| 3061 | return false; |
| 3062 | } |
| 3063 | |
| 3064 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3065 | * Installs the given certificate as a user CA. |
| 3066 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3067 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3068 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3069 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3070 | * |
| 3071 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3072 | * interrupted, true otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3073 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3074 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3075 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3076 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3077 | throwIfParentInstance("installCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3078 | if (mService != null) { |
| 3079 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3080 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3081 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3082 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | return false; |
| 3086 | } |
| 3087 | |
| 3088 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3089 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 3090 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3091 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3092 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3093 | * @param certBuffer encoded form of the certificate to remove. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3094 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3095 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3096 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3097 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3098 | throwIfParentInstance("uninstallCaCert"); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3099 | if (mService != null) { |
| 3100 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3101 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3102 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 3103 | } catch (CertificateException e) { |
| 3104 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3105 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3106 | throw e.rethrowFromSystemServer(); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3112 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 3113 | * If a user has installed any certificates by other means than device policy these will be |
| 3114 | * included too. |
| 3115 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3116 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3117 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3118 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3119 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3120 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3121 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3122 | public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
| 3123 | final List<byte[]> certs = new ArrayList<byte[]>(); |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3124 | throwIfParentInstance("getInstalledCaCerts"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3125 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3126 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3127 | mService.enforceCanManageCaCerts(admin); |
| 3128 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 3129 | for (String alias : certStore.userAliases()) { |
| 3130 | try { |
| 3131 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 3132 | } catch (CertificateException ce) { |
| 3133 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 3134 | } |
| 3135 | } |
| 3136 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3137 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3144 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 3145 | * means other than device policy will also be removed, except for system CA certificates. |
| 3146 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3147 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3148 | * {@code null} if calling from a delegated certificate installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3149 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3150 | * owner. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3151 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3152 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3153 | throwIfParentInstance("uninstallAllUserCaCerts"); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3154 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 3155 | try { |
| 3156 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 3157 | .toArray(new String[0])); |
| 3158 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3159 | throw re.rethrowFromSystemServer(); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3160 | } |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | /** |
| 3165 | * Returns whether this certificate is installed as a trusted CA. |
| 3166 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3167 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3168 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 3169 | * @param certBuffer encoded form of the certificate to look up. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3170 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3171 | * owner. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3172 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3173 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3174 | throwIfParentInstance("hasCaCertInstalled"); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3175 | if (mService != null) { |
| 3176 | try { |
| 3177 | mService.enforceCanManageCaCerts(admin); |
| 3178 | return getCaCertAlias(certBuffer) != null; |
| 3179 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3180 | throw re.rethrowFromSystemServer(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 3181 | } catch (CertificateException ce) { |
| 3182 | Log.w(TAG, "Could not parse certificate", ce); |
| 3183 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 3184 | } |
| 3185 | return false; |
| 3186 | } |
| 3187 | |
| 3188 | /** |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3189 | * Called by a device or profile owner, or delegated certificate installer, to install a |
| 3190 | * certificate and corresponding private key. All apps within the profile will be able to access |
| 3191 | * the certificate and use the private key, given direct user approval. |
| 3192 | * |
| 3193 | * <p>Access to the installed credentials will not be granted to the caller of this API without |
| 3194 | * direct user approval. This is for security - should a certificate installer become |
| 3195 | * compromised, certificates it had already installed will be protected. |
| 3196 | * |
| 3197 | * <p>If the installer must have access to the credentials, call |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3198 | * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3199 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3200 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 3201 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3202 | * @param privKey The private key to install. |
| 3203 | * @param cert The certificate to install. |
| 3204 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 3205 | * with that alias already exists, it will be overwritten. |
| 3206 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3207 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3208 | * owner. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3209 | */ |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3210 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
| 3211 | @NonNull Certificate cert, @NonNull String alias) { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3212 | return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false); |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | /** |
| 3216 | * 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] | 3217 | * certificate chain and corresponding private key for the leaf certificate. All apps within the |
| 3218 | * profile will be able to access the certificate chain and use the private key, given direct |
| 3219 | * user approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3220 | * |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3221 | * <p>The caller of this API may grant itself access to the certificate and private key |
| 3222 | * immediately, without user approval. It is a best practice not to request this unless strictly |
| 3223 | * necessary since it opens up additional security vulnerabilities. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3224 | * |
| 3225 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3226 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3227 | * @param privKey The private key to install. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3228 | * @param certs The certificate chain to install. The chain should start with the leaf |
| 3229 | * certificate and include the chain of trust in order. This will be returned by |
| 3230 | * {@link android.security.KeyChain#getCertificateChain}. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3231 | * @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] | 3232 | * with that alias already exists, it will be overwritten. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3233 | * @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] | 3234 | * credentials immediately. Otherwise, access to the credentials will be gated by user |
| 3235 | * approval. |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3236 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3237 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3238 | * owner. |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3239 | * @see android.security.KeyChain#getCertificateChain |
Robin Lee | ce3399f | 2016-02-24 12:08:32 +0000 | [diff] [blame] | 3240 | */ |
| 3241 | public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey, |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3242 | @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3243 | throwIfParentInstance("installKeyPair"); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3244 | try { |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3245 | final byte[] pemCert = Credentials.convertToPem(certs[0]); |
| 3246 | byte[] pemChain = null; |
| 3247 | if (certs.length > 1) { |
| 3248 | pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length)); |
| 3249 | } |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3250 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 3251 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Rubin Xu | b436591 | 2016-03-23 12:13:22 +0000 | [diff] [blame] | 3252 | return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias, |
| 3253 | requestAccess); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3254 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3255 | throw e.rethrowFromSystemServer(); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 3256 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 3257 | Log.w(TAG, "Failed to obtain private key material", e); |
| 3258 | } catch (CertificateException | IOException e) { |
| 3259 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 3260 | } |
| 3261 | return false; |
| 3262 | } |
| 3263 | |
| 3264 | /** |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3265 | * Called by a device or profile owner, or delegated certificate installer, to remove a |
| 3266 | * certificate and private key pair installed under a given alias. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3267 | * |
| 3268 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3269 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3270 | * @param alias The private key alias under which the certificate is installed. |
Robin Lee | a1b290e | 2016-03-09 14:38:36 +0000 | [diff] [blame] | 3271 | * @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] | 3272 | * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile |
| 3273 | * owner. |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3274 | */ |
| 3275 | public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3276 | throwIfParentInstance("removeKeyPair"); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3277 | try { |
| 3278 | return mService.removeKeyPair(admin, alias); |
| 3279 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3280 | throw e.rethrowFromSystemServer(); |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3281 | } |
Robin Lee | fbc6564 | 2015-08-03 16:21:22 +0100 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3285 | * @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] | 3286 | * doesn't exist. |
| 3287 | */ |
| 3288 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 3289 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 3290 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 3291 | new ByteArrayInputStream(certBuffer)); |
| 3292 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 3293 | } |
| 3294 | |
| 3295 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3296 | * 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] | 3297 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3298 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 3299 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3300 | * <p> |
| 3301 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 3302 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 3303 | * installer. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3304 | * <p> |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 3305 | * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller |
| 3306 | * 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] | 3307 | * supplied certificate installer package must be installed when calling this API, otherwise an |
| 3308 | * {@link IllegalArgumentException} will be thrown. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3309 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3310 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3311 | * @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] | 3312 | * access. If {@code null} is given the current package will be cleared. |
| 3313 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3314 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3315 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 3316 | installerPackage) throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3317 | throwIfParentInstance("setCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3318 | if (mService != null) { |
| 3319 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3320 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3321 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3322 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3328 | * Called by a profile owner or device owner to retrieve the certificate installer for the user. |
| 3329 | * null if none is set. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3330 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3331 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3332 | * @return The package name of the current delegated certificate installer, or {@code null} if |
| 3333 | * none is set. |
| 3334 | * @throws SecurityException if {@code admin} is not a device or a profile owner. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3335 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3336 | public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin) |
| 3337 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3338 | throwIfParentInstance("getCertInstallerPackage"); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3339 | if (mService != null) { |
| 3340 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3341 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3342 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3343 | throw e.rethrowFromSystemServer(); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 3344 | } |
| 3345 | } |
| 3346 | return null; |
| 3347 | } |
| 3348 | |
| 3349 | /** |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3350 | * 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] | 3351 | * specific application for the current user. |
| 3352 | * |
| 3353 | * @deprecated this version only exists for compability with previous developer preview builds. |
| 3354 | * TODO: delete once there are no longer any live references. |
| 3355 | * @hide |
| 3356 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 3357 | @Deprecated |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3358 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage) |
| 3359 | throws NameNotFoundException, UnsupportedOperationException { |
| 3360 | setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true); |
| 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * 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] | 3365 | * specific application for the current user. This connection is automatically granted and |
| 3366 | * persisted after a reboot. |
| 3367 | * <p> |
| 3368 | * The designated package should declare a {@link android.net.VpnService} in its manifest |
| 3369 | * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will |
| 3370 | * fail. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3371 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3372 | * @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] | 3373 | * remove an existing always-on VPN configuration. |
| 3374 | * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or |
| 3375 | * {@code false} otherwise. This carries the risk that any failure of the VPN provider |
| 3376 | * could break networking for all apps. This has no effect when clearing. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3377 | * @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] | 3378 | * @throws NameNotFoundException if {@code vpnPackage} is not installed. |
| 3379 | * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being |
| 3380 | * set as always-on, or if always-on VPN is not available. |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3381 | */ |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3382 | public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage, |
| 3383 | boolean lockdownEnabled) |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3384 | throws NameNotFoundException, UnsupportedOperationException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3385 | throwIfParentInstance("setAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3386 | if (mService != null) { |
| 3387 | try { |
Robin Lee | dc67971 | 2016-05-03 13:23:03 +0100 | [diff] [blame] | 3388 | if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) { |
Robin Lee | ee5eb93 | 2016-04-05 16:27:15 +0100 | [diff] [blame] | 3389 | throw new NameNotFoundException(vpnPackage); |
| 3390 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3391 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3392 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3393 | } |
| 3394 | } |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | /** |
| 3398 | * 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] | 3399 | * always-on VPN connection for the current user. If there is no such package, or the always-on |
| 3400 | * 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] | 3401 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3402 | * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none |
| 3403 | * is set. |
| 3404 | * @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] | 3405 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 3406 | public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3407 | throwIfParentInstance("getAlwaysOnVpnPackage"); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3408 | if (mService != null) { |
| 3409 | try { |
| 3410 | return mService.getAlwaysOnVpnPackage(admin); |
| 3411 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3412 | throw e.rethrowFromSystemServer(); |
Robin Lee | 244ce8e | 2016-01-05 18:03:46 +0000 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | return null; |
| 3416 | } |
| 3417 | |
| 3418 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3419 | * Called by an application that is administering the device to disable all cameras on the |
| 3420 | * device, for this user. After setting this, no applications running as this user will be able |
| 3421 | * to access any cameras on the device. |
| 3422 | * <p> |
| 3423 | * If the caller is device owner, then the restriction will be applied to all users. |
| 3424 | * <p> |
| 3425 | * The calling device admin must have requested |
| 3426 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has |
| 3427 | * not, a security exception will be thrown. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3428 | * |
| 3429 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3430 | * @param disabled Whether or not the camera should be disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3431 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 3432 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3433 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3434 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3435 | throwIfParentInstance("setCameraDisabled"); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3436 | if (mService != null) { |
| 3437 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3438 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3439 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3440 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3441 | } |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3446 | * 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] | 3447 | * either by the calling admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3448 | * @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] | 3449 | * have disabled the camera |
| 3450 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3451 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3452 | throwIfParentInstance("getCameraDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3453 | return getCameraDisabled(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3457 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3458 | if (mService != null) { |
| 3459 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3460 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3461 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3462 | throw e.rethrowFromSystemServer(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 3463 | } |
| 3464 | } |
| 3465 | return false; |
| 3466 | } |
| 3467 | |
| 3468 | /** |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3469 | * Called by a device owner to request a bugreport. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3470 | * <p> |
| 3471 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 3472 | * {@link SecurityException} will be thrown. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3473 | * |
| 3474 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3475 | * @return {@code true} if the bugreport collection started successfully, or {@code false} if it |
| 3476 | * wasn't triggered because a previous bugreport operation is still active (either the |
| 3477 | * bugreport is still running or waiting for the user to share or decline) |
| 3478 | * @throws SecurityException if {@code admin} is not a device owner, or if there are users other |
| 3479 | * than the one managed by the device owner. |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3480 | */ |
| 3481 | public boolean requestBugreport(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3482 | throwIfParentInstance("requestBugreport"); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3483 | if (mService != null) { |
| 3484 | try { |
| 3485 | return mService.requestBugreport(admin); |
| 3486 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3487 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 3fc437e | 2015-12-15 10:09:00 +0000 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | return false; |
| 3491 | } |
| 3492 | |
| 3493 | /** |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 3494 | * Determine whether or not creating a guest user has been disabled for the device |
| 3495 | * |
| 3496 | * @hide |
| 3497 | */ |
| 3498 | public boolean getGuestUserDisabled(@Nullable ComponentName admin) { |
| 3499 | // Currently guest users can always be created if multi-user is enabled |
| 3500 | // TODO introduce a policy for guest user creation |
| 3501 | return false; |
| 3502 | } |
| 3503 | |
| 3504 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 3505 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 3506 | * screen capture also prevents the content from being shown on display devices that do not have |
| 3507 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 3508 | * secure surfaces and secure displays. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3509 | * <p> |
| 3510 | * The calling device admin must be a device or profile owner. If it is not, a security |
| 3511 | * exception will be thrown. |
| 3512 | * <p> |
| 3513 | * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks |
| 3514 | * assist requests for all activities of the relevant user. |
Benjamin Franz | c200f44 | 2015-06-25 18:20:04 +0100 | [diff] [blame] | 3515 | * |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3516 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3517 | * @param disabled Whether screen capture is disabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3518 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3519 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3520 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3521 | throwIfParentInstance("setScreenCaptureDisabled"); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3522 | if (mService != null) { |
| 3523 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3524 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3525 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3526 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3527 | } |
| 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3532 | * Determine whether or not screen capture has been disabled by the calling |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3533 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3534 | * @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] | 3535 | * have disabled screen capture. |
| 3536 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3537 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3538 | throwIfParentInstance("getScreenCaptureDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3539 | return getScreenCaptureDisabled(admin, myUserId()); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3543 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3544 | if (mService != null) { |
| 3545 | try { |
| 3546 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 3547 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3548 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 3549 | } |
| 3550 | } |
| 3551 | return false; |
| 3552 | } |
| 3553 | |
| 3554 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3555 | * Called by a device owner to set whether auto time is required. If auto time is required the |
| 3556 | * user cannot set the date and time, but has to use network date and time. |
| 3557 | * <p> |
| 3558 | * Note: if auto time is required the user can still manually set the time zone. |
| 3559 | * <p> |
| 3560 | * The calling device admin must be a device owner. If it is not, a security exception will be |
| 3561 | * thrown. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3562 | * |
| 3563 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3564 | * @param required Whether auto time is set required or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3565 | * @throws SecurityException if {@code admin} is not a device owner. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3566 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3567 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3568 | throwIfParentInstance("setAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3569 | if (mService != null) { |
| 3570 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3571 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3572 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3573 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | /** |
| 3579 | * @return true if auto time is required. |
| 3580 | */ |
| 3581 | public boolean getAutoTimeRequired() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3582 | throwIfParentInstance("getAutoTimeRequired"); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3583 | if (mService != null) { |
| 3584 | try { |
| 3585 | return mService.getAutoTimeRequired(); |
| 3586 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3587 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 3588 | } |
| 3589 | } |
| 3590 | return false; |
| 3591 | } |
| 3592 | |
| 3593 | /** |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3594 | * 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] | 3595 | * <p> |
| 3596 | * The system user is exempt from this policy - it is never ephemeral. |
| 3597 | * <p> |
| 3598 | * The calling device admin must be the device owner. If it is not, a security exception will be |
| 3599 | * thrown. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3600 | * |
| 3601 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3602 | * @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] | 3603 | * subsequently created users will be ephemeral. |
| 3604 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3605 | * @hide |
| 3606 | */ |
| 3607 | public void setForceEphemeralUsers( |
| 3608 | @NonNull ComponentName admin, boolean forceEphemeralUsers) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3609 | throwIfParentInstance("setForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3610 | if (mService != null) { |
| 3611 | try { |
| 3612 | mService.setForceEphemeralUsers(admin, forceEphemeralUsers); |
| 3613 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3614 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3615 | } |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | /** |
| 3620 | * @return true if all users are created ephemeral. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3621 | * @throws SecurityException if {@code admin} is not a device owner. |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3622 | * @hide |
| 3623 | */ |
| 3624 | public boolean getForceEphemeralUsers(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3625 | throwIfParentInstance("getForceEphemeralUsers"); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3626 | if (mService != null) { |
| 3627 | try { |
| 3628 | return mService.getForceEphemeralUsers(admin); |
| 3629 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3630 | throw e.rethrowFromSystemServer(); |
Lenka Trochtova | f348e8e | 2016-01-07 17:20:34 +0100 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | return false; |
| 3634 | } |
| 3635 | |
| 3636 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3637 | * Called by an application that is administering the device to disable keyguard customizations, |
| 3638 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 3639 | * provided feature list. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3640 | * <p> |
| 3641 | * The calling device admin must have requested |
| 3642 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 3643 | * if it has not, a security exception will be thrown. |
| 3644 | * <p> |
| 3645 | * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M} |
| 3646 | * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the |
| 3647 | * profile owner of a managed profile can set: |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3648 | * <ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3649 | * <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] | 3650 | * is no separate challenge set on the managed profile. |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3651 | * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3652 | * there is one, or the parent user otherwise. |
| 3653 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated |
| 3654 | * by applications in the managed profile. |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3655 | * </ul> |
Esteban Talavera | c1c8359 | 2016-02-17 17:56:15 +0000 | [diff] [blame] | 3656 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be |
| 3657 | * set on the {@link DevicePolicyManager} instance returned by |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3658 | * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent |
| 3659 | * profile. |
| 3660 | * <p> |
| 3661 | * Requests to disable other features on a managed profile will be ignored. |
| 3662 | * <p> |
| 3663 | * The admin can check which features have been disabled by calling |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 3664 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 3665 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3666 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3667 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 3668 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
| 3669 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, |
| 3670 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 3671 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, |
| 3672 | * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
| 3673 | * @throws SecurityException if {@code admin} is not an active administrator or does not user |
| 3674 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3675 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3676 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3677 | if (mService != null) { |
| 3678 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3679 | mService.setKeyguardDisabledFeatures(admin, which, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3680 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3681 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3682 | } |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 3687 | * 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] | 3688 | * 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] | 3689 | * profiles. Restrictions on profiles that have a separate challenge are not taken into account. |
| 3690 | * |
| 3691 | * <p>This method can be called on the {@link DevicePolicyManager} instance |
| 3692 | * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve |
| 3693 | * restrictions on the parent profile. |
| 3694 | * |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3695 | * @param admin The name of the admin component to check, or {@code null} to check whether any |
| 3696 | * admins have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 3697 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 3698 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3699 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3700 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3701 | return getKeyguardDisabledFeatures(admin, myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3705 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3706 | if (mService != null) { |
| 3707 | try { |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 3708 | return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3709 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3710 | throw e.rethrowFromSystemServer(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3711 | } |
| 3712 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 3713 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3717 | * @hide |
| 3718 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3719 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 3720 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3721 | if (mService != null) { |
| 3722 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3723 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3724 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3725 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3726 | } |
| 3727 | } |
| 3728 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3729 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3730 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3731 | * @hide |
| 3732 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3733 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3734 | setActiveAdmin(policyReceiver, refreshing, myUserId()); |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3738 | * @hide |
| 3739 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3740 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3741 | if (mService != null) { |
| 3742 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 3743 | mService.getRemoveWarning(admin, result, myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3744 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3745 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 3746 | } |
| 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | /** |
| 3751 | * @hide |
| 3752 | */ |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 3753 | public void setActivePasswordState(PasswordMetrics metrics, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3754 | if (mService != null) { |
| 3755 | try { |
Andrew Scull | 5f9e6f3 | 2016-08-02 14:22:17 +0100 | [diff] [blame] | 3756 | mService.setActivePasswordState(metrics, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3757 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3758 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3762 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3763 | /** |
| 3764 | * @hide |
| 3765 | */ |
Andrew Scull | 5daf273 | 2016-11-14 15:02:45 +0000 | [diff] [blame^] | 3766 | public void reportPasswordChanged(@UserIdInt int userId) { |
| 3767 | if (mService != null) { |
| 3768 | try { |
| 3769 | mService.reportPasswordChanged(userId); |
| 3770 | } catch (RemoteException e) { |
| 3771 | throw e.rethrowFromSystemServer(); |
| 3772 | } |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | /** |
| 3777 | * @hide |
| 3778 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3779 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3780 | if (mService != null) { |
| 3781 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3782 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3783 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3784 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3785 | } |
| 3786 | } |
| 3787 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 3788 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3789 | /** |
| 3790 | * @hide |
| 3791 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3792 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3793 | if (mService != null) { |
| 3794 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 3795 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3796 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3797 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3798 | } |
| 3799 | } |
| 3800 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3801 | |
| 3802 | /** |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3803 | * @hide |
| 3804 | */ |
| 3805 | public void reportFailedFingerprintAttempt(int userHandle) { |
| 3806 | if (mService != null) { |
| 3807 | try { |
| 3808 | mService.reportFailedFingerprintAttempt(userHandle); |
| 3809 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3810 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3811 | } |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | /** |
| 3816 | * @hide |
| 3817 | */ |
| 3818 | public void reportSuccessfulFingerprintAttempt(int userHandle) { |
| 3819 | if (mService != null) { |
| 3820 | try { |
| 3821 | mService.reportSuccessfulFingerprintAttempt(userHandle); |
| 3822 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3823 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3824 | } |
| 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | /** |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3829 | * Should be called when keyguard has been dismissed. |
| 3830 | * @hide |
| 3831 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3832 | public void reportKeyguardDismissed(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3833 | if (mService != null) { |
| 3834 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3835 | mService.reportKeyguardDismissed(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3836 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3837 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3838 | } |
| 3839 | } |
| 3840 | } |
| 3841 | |
| 3842 | /** |
| 3843 | * Should be called when keyguard view has been shown to the user. |
| 3844 | * @hide |
| 3845 | */ |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3846 | public void reportKeyguardSecured(int userHandle) { |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3847 | if (mService != null) { |
| 3848 | try { |
Michal Karpinski | ed5c8f0 | 2016-02-09 15:43:41 +0000 | [diff] [blame] | 3849 | mService.reportKeyguardSecured(userHandle); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3850 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3851 | throw e.rethrowFromSystemServer(); |
Michal Karpinski | 31502d3 | 2016-01-25 16:43:07 +0000 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | } |
| 3855 | |
| 3856 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3857 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3858 | * Sets the given package as the device owner. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3859 | * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name. |
| 3860 | * @param who the component name to be registered as device owner. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3861 | * @return whether the package was successfully registered as the device owner. |
| 3862 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3863 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3864 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3865 | public boolean setDeviceOwner(ComponentName who) { |
| 3866 | return setDeviceOwner(who, null); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | /** |
| 3870 | * @hide |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3871 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3872 | public boolean setDeviceOwner(ComponentName who, int userId) { |
| 3873 | return setDeviceOwner(who, null, userId); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | /** |
| 3877 | * @hide |
| 3878 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3879 | public boolean setDeviceOwner(ComponentName who, String ownerName) { |
| 3880 | return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM); |
Makoto Onuki | 58b684f | 2015-09-04 10:48:16 -0700 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | /** |
| 3884 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3885 | * Sets the given package as the device owner. The package must already be installed. There |
| 3886 | * must not already be a device owner. |
| 3887 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 3888 | * this method. |
| 3889 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 3890 | * 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] | 3891 | * @param who the component name to be registered as device owner. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3892 | * @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] | 3893 | * @param userId ID of the user on which the device owner runs. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3894 | * @return whether the package was successfully registered as the device owner. |
| 3895 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 3896 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3897 | */ |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3898 | public boolean setDeviceOwner(ComponentName who, String ownerName, int userId) |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 3899 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3900 | if (mService != null) { |
| 3901 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3902 | return mService.setDeviceOwner(who, ownerName, userId); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3903 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3904 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | return false; |
| 3908 | } |
| 3909 | |
| 3910 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3911 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 3912 | * 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] | 3913 | * 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] | 3914 | * package is currently registered as the device owner app, pass in the package name from |
| 3915 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3916 | * 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] | 3917 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 3918 | * the setup process. |
| 3919 | * @param packageName the package name of the app, to compare with the registered device owner |
| 3920 | * app, if any. |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3921 | * @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] | 3922 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3923 | public boolean isDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 3924 | throwIfParentInstance("isDeviceOwnerApp"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3925 | return isDeviceOwnerAppOnCallingUser(packageName); |
| 3926 | } |
| 3927 | |
| 3928 | /** |
| 3929 | * @return true if a package is registered as device owner, only when it's running on the |
| 3930 | * calling user. |
| 3931 | * |
| 3932 | * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity. |
| 3933 | * @hide |
| 3934 | */ |
| 3935 | public boolean isDeviceOwnerAppOnCallingUser(String packageName) { |
| 3936 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true); |
| 3937 | } |
| 3938 | |
| 3939 | /** |
| 3940 | * @return true if a package is registered as device owner, even if it's running on a different |
| 3941 | * user. |
| 3942 | * |
| 3943 | * <p>Requires the MANAGE_USERS permission. |
| 3944 | * |
| 3945 | * @hide |
| 3946 | */ |
| 3947 | public boolean isDeviceOwnerAppOnAnyUser(String packageName) { |
| 3948 | return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false); |
| 3949 | } |
| 3950 | |
| 3951 | /** |
| 3952 | * @return device owner component name, only when it's running on the calling user. |
| 3953 | * |
| 3954 | * @hide |
| 3955 | */ |
| 3956 | public ComponentName getDeviceOwnerComponentOnCallingUser() { |
| 3957 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true); |
| 3958 | } |
| 3959 | |
| 3960 | /** |
| 3961 | * @return device owner component name, even if it's running on a different user. |
| 3962 | * |
| 3963 | * <p>Requires the MANAGE_USERS permission. |
| 3964 | * |
| 3965 | * @hide |
| 3966 | */ |
| 3967 | public ComponentName getDeviceOwnerComponentOnAnyUser() { |
| 3968 | return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false); |
| 3969 | } |
| 3970 | |
| 3971 | private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) { |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3972 | if (packageName == null) { |
| 3973 | return false; |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3974 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3975 | final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly); |
Makoto Onuki | 70f929e | 2015-11-11 12:40:15 -0800 | [diff] [blame] | 3976 | if (deviceOwner == null) { |
| 3977 | return false; |
| 3978 | } |
| 3979 | return packageName.equals(deviceOwner.getPackageName()); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3982 | private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) { |
| 3983 | if (mService != null) { |
| 3984 | try { |
| 3985 | return mService.getDeviceOwnerComponent(callingUserOnly); |
| 3986 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 3987 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | return null; |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 3993 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 3994 | * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's |
| 3995 | * no device owner. |
| 3996 | * |
| 3997 | * <p>Requires the MANAGE_USERS permission. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 3998 | * |
| 3999 | * @hide |
| 4000 | */ |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4001 | public int getDeviceOwnerUserId() { |
| 4002 | if (mService != null) { |
| 4003 | try { |
| 4004 | return mService.getDeviceOwnerUserId(); |
| 4005 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4006 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4007 | } |
| 4008 | } |
| 4009 | return UserHandle.USER_NULL; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4013 | * Clears the current device owner. The caller must be the device owner. This function should be |
| 4014 | * used cautiously as once it is called it cannot be undone. The device owner can only be set as |
| 4015 | * a part of device setup before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4016 | * |
| 4017 | * @param packageName The package name of the device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4018 | * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName} |
| 4019 | * does not own the current device owner component. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4020 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4021 | public void clearDeviceOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4022 | throwIfParentInstance("clearDeviceOwnerApp"); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4023 | if (mService != null) { |
| 4024 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 4025 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4026 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4027 | throw re.rethrowFromSystemServer(); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 4028 | } |
| 4029 | } |
| 4030 | } |
| 4031 | |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4032 | /** |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4033 | * Returns the device owner package name, only if it's running on the calling user. |
| 4034 | * |
| 4035 | * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4036 | * |
| 4037 | * @hide |
| 4038 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4039 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4040 | public @Nullable String getDeviceOwner() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4041 | throwIfParentInstance("getDeviceOwner"); |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4042 | final ComponentName name = getDeviceOwnerComponentOnCallingUser(); |
| 4043 | return name != null ? name.getPackageName() : null; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | /** |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4047 | * 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] | 4048 | * |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4049 | * @return whether the device is managed by a Device Owner. |
| 4050 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 4051 | * MANAGE_USERS permission and is not the system. |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4052 | * |
| 4053 | * @hide |
| 4054 | */ |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4055 | @SystemApi |
| 4056 | @TestApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4057 | public boolean isDeviceManaged() { |
Bartosz Fabianowski | dd7f8da | 2016-11-30 11:09:22 +0100 | [diff] [blame] | 4058 | try { |
| 4059 | return mService.hasDeviceOwner(); |
| 4060 | } catch (RemoteException re) { |
| 4061 | throw re.rethrowFromSystemServer(); |
| 4062 | } |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | /** |
| 4066 | * Returns the device owner name. Note this method *will* return the device owner |
| 4067 | * name when it's running on a different user. |
| 4068 | * |
| 4069 | * <p>Requires the MANAGE_USERS permission. |
| 4070 | * |
| 4071 | * @hide |
| 4072 | */ |
Makoto Onuki | a2b274b | 2016-01-19 13:26:02 -0800 | [diff] [blame] | 4073 | @SystemApi |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4074 | public String getDeviceOwnerNameOnAnyUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4075 | throwIfParentInstance("getDeviceOwnerNameOnAnyUser"); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4076 | if (mService != null) { |
| 4077 | try { |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 4078 | return mService.getDeviceOwnerName(); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 4079 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4080 | throw re.rethrowFromSystemServer(); |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 4081 | } |
| 4082 | } |
| 4083 | return null; |
| 4084 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4085 | |
| 4086 | /** |
Julia Reynolds | 94e7bf6 | 2015-06-10 14:44:56 -0400 | [diff] [blame] | 4087 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4088 | * @deprecated Do not use |
| 4089 | * @removed |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4090 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4091 | @Deprecated |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4092 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4093 | public @Nullable String getDeviceInitializerApp() { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4094 | return null; |
| 4095 | } |
| 4096 | |
| 4097 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4098 | * @hide |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4099 | * @deprecated Do not use |
| 4100 | * @removed |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4101 | */ |
Craig Lafayette | e7ee54e | 2015-09-21 13:48:53 -0400 | [diff] [blame] | 4102 | @Deprecated |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4103 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4104 | public @Nullable ComponentName getDeviceInitializerComponent() { |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 4105 | return null; |
| 4106 | } |
| 4107 | |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4108 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4109 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4110 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4111 | * Sets the given component as an active admin and registers the package as the profile |
| 4112 | * owner for this user. The package must already be installed and there shouldn't be |
| 4113 | * an existing profile owner registered for this user. Also, this method must be called |
| 4114 | * before the user setup has been completed. |
| 4115 | * <p> |
| 4116 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 4117 | * MANAGE_DEVICE_ADMINS permission. |
| 4118 | * @param admin The component to register as an active admin and profile owner. |
| 4119 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 4120 | * @return whether the admin was successfully registered as the profile owner. |
| 4121 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 4122 | * the user has already been set up. |
| 4123 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4124 | @Deprecated |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 4125 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4126 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4127 | throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4128 | throwIfParentInstance("setActiveProfileOwner"); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4129 | if (mService != null) { |
| 4130 | try { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4131 | final int myUserId = myUserId(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4132 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4133 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4134 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4135 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 4136 | } |
| 4137 | } |
| 4138 | return false; |
| 4139 | } |
| 4140 | |
| 4141 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4142 | * Clears the active profile owner and removes all user restrictions. The caller must be from |
| 4143 | * the same package as the active profile owner for this user, otherwise a SecurityException |
| 4144 | * will be thrown. |
| 4145 | * <p> |
| 4146 | * This doesn't work for managed profile owners. |
Makoto Onuki | 5bf6802 | 2016-01-27 13:49:19 -0800 | [diff] [blame] | 4147 | * |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4148 | * @param admin The component to remove as the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4149 | * @throws SecurityException if {@code admin} is not an active profile owner. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4150 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4151 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4152 | throwIfParentInstance("clearProfileOwner"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4153 | if (mService != null) { |
| 4154 | try { |
| 4155 | mService.clearProfileOwner(admin); |
| 4156 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4157 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 4163 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4164 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4165 | */ |
| 4166 | public boolean hasUserSetupCompleted() { |
| 4167 | if (mService != null) { |
| 4168 | try { |
| 4169 | return mService.hasUserSetupCompleted(); |
| 4170 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4171 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4172 | } |
| 4173 | } |
| 4174 | return true; |
| 4175 | } |
| 4176 | |
| 4177 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4178 | * @hide |
| 4179 | * 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] | 4180 | * already be installed. There must not already be a profile owner for this user. |
| 4181 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 4182 | * this method. |
| 4183 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 4184 | * - the caller is SYSTEM_UID. |
| 4185 | * - 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] | 4186 | * @param admin the component name to be registered as profile owner. |
| 4187 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 4188 | * @param userHandle the userId to set the profile owner for. |
| 4189 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 4190 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 4191 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4192 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4193 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 4194 | int userHandle) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4195 | if (mService != null) { |
| 4196 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 4197 | if (ownerName == null) { |
| 4198 | ownerName = ""; |
| 4199 | } |
| 4200 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4201 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4202 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | return false; |
| 4206 | } |
| 4207 | |
| 4208 | /** |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4209 | * Sets the device owner information to be shown on the lock screen. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4210 | * <p> |
| 4211 | * 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] | 4212 | * 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] | 4213 | * <p> |
| 4214 | * If the device owner information contains only whitespaces then the message on the lock screen |
| 4215 | * will be blank and the user will not be allowed to change it. |
| 4216 | * <p> |
| 4217 | * 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] | 4218 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 4219 | * and set a new version of this string accordingly. |
| 4220 | * |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4221 | * @param admin The name of the admin component to check. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4222 | * @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] | 4223 | * @throws SecurityException if {@code admin} is not a device owner. |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4224 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4225 | public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4226 | throwIfParentInstance("setDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4227 | if (mService != null) { |
| 4228 | try { |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4229 | mService.setDeviceOwnerLockScreenInfo(admin, info); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4230 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4231 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4232 | } |
| 4233 | } |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4234 | } |
| 4235 | |
| 4236 | /** |
| 4237 | * @return The device owner information. If it is not set returns {@code null}. |
| 4238 | */ |
Andrei Stingaceanu | 1618790 | 2016-03-21 15:44:45 +0000 | [diff] [blame] | 4239 | public CharSequence getDeviceOwnerLockScreenInfo() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4240 | throwIfParentInstance("getDeviceOwnerLockScreenInfo"); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4241 | if (mService != null) { |
| 4242 | try { |
| 4243 | return mService.getDeviceOwnerLockScreenInfo(); |
| 4244 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4245 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 6644cd9 | 2015-11-10 13:03:31 +0000 | [diff] [blame] | 4246 | } |
| 4247 | } |
| 4248 | return null; |
| 4249 | } |
| 4250 | |
| 4251 | /** |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4252 | * Called by device or profile owners to suspend packages for this user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4253 | * <p> |
| 4254 | * A suspended package will not be able to start activities. Its notifications will be hidden, |
| 4255 | * it will not show up in recents, will not be able to show toasts or dialogs or ring the |
| 4256 | * device. |
| 4257 | * <p> |
| 4258 | * The package must already be installed. If the package is uninstalled while suspended the |
| 4259 | * 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] | 4260 | * {@link #setUninstallBlocked}. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4261 | * |
| 4262 | * @param admin The name of the admin component to check. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4263 | * @param packageNames The package names to suspend or unsuspend. |
| 4264 | * @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] | 4265 | * {@code false} the packages will be unsuspended. |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4266 | * @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] | 4267 | * this method. |
| 4268 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4269 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4270 | public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin, |
| 4271 | @NonNull String[] packageNames, boolean suspended) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4272 | throwIfParentInstance("setPackagesSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4273 | if (mService != null) { |
| 4274 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4275 | return mService.setPackagesSuspended(admin, packageNames, suspended); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4276 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4277 | throw re.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4278 | } |
| 4279 | } |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 4280 | return packageNames; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4281 | } |
| 4282 | |
| 4283 | /** |
| 4284 | * Called by device or profile owners to determine if a package is suspended. |
| 4285 | * |
| 4286 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4287 | * @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] | 4288 | * @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] | 4289 | * suspended, could not be found or an error occurred. |
| 4290 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4291 | * @throws NameNotFoundException if the package could not be found. |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4292 | */ |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4293 | public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName) |
| 4294 | throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4295 | throwIfParentInstance("isPackageSuspended"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4296 | if (mService != null) { |
| 4297 | try { |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4298 | return mService.isPackageSuspended(admin, packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4299 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4300 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | efc4a34 | 2016-03-22 14:43:01 +0000 | [diff] [blame] | 4301 | } catch (IllegalArgumentException ex) { |
| 4302 | throw new NameNotFoundException(packageName); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4303 | } |
| 4304 | } |
| 4305 | return false; |
| 4306 | } |
| 4307 | |
| 4308 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4309 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 4310 | * be used. Only the profile owner can call this. |
| 4311 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 4312 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4313 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4314 | * @throws SecurityException if {@code admin} is not a profile owner. |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4315 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4316 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4317 | throwIfParentInstance("setProfileEnabled"); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4318 | if (mService != null) { |
| 4319 | try { |
| 4320 | mService.setProfileEnabled(admin); |
| 4321 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4322 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | } |
| 4326 | |
| 4327 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4328 | * Sets the name of the profile. In the device owner case it sets the name of the user which it |
| 4329 | * is called from. Only a profile owner or device owner can call this. If this is never called |
| 4330 | * 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] | 4331 | * |
| 4332 | * @see #isProfileOwnerApp |
| 4333 | * @see #isDeviceOwnerApp |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4334 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4335 | * @param profileName The name of the profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4336 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4337 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4338 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4339 | throwIfParentInstance("setProfileName"); |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4340 | if (mService != null) { |
| 4341 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4342 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4343 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4344 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 4345 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4346 | } |
| 4347 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 4348 | |
| 4349 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4350 | * 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] | 4351 | * 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] | 4352 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4353 | * |
| 4354 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 4355 | * @return Whether or not the package is registered as the profile owner. |
| 4356 | */ |
| 4357 | public boolean isProfileOwnerApp(String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4358 | throwIfParentInstance("isProfileOwnerApp"); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4359 | if (mService != null) { |
| 4360 | try { |
Makoto Onuki | 90b8965 | 2016-01-28 14:44:18 -0800 | [diff] [blame] | 4361 | ComponentName profileOwner = mService.getProfileOwner(myUserId()); |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 4362 | return profileOwner != null |
| 4363 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4364 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4365 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | return false; |
| 4369 | } |
| 4370 | |
| 4371 | /** |
| 4372 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4373 | * @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] | 4374 | * owner has been set for that user. |
| 4375 | * @throws IllegalArgumentException if the userId is invalid. |
| 4376 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 4377 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4378 | public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4379 | throwIfParentInstance("getProfileOwner"); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4380 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 4381 | } |
| 4382 | |
| 4383 | /** |
| 4384 | * @see #getProfileOwner() |
| 4385 | * @hide |
| 4386 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4387 | public @Nullable ComponentName getProfileOwnerAsUser(final int userId) |
| 4388 | throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4389 | if (mService != null) { |
| 4390 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 4391 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4392 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4393 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4394 | } |
| 4395 | } |
| 4396 | return null; |
| 4397 | } |
| 4398 | |
| 4399 | /** |
| 4400 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4401 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 4402 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4403 | * @throws IllegalArgumentException if the userId is invalid. |
| 4404 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4405 | public @Nullable String getProfileOwnerName() throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4406 | if (mService != null) { |
| 4407 | try { |
| 4408 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 4409 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4410 | throw re.rethrowFromSystemServer(); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 4411 | } |
| 4412 | } |
| 4413 | return null; |
| 4414 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4415 | |
| 4416 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4417 | * @hide |
Makoto Onuki | c8a5a55 | 2015-11-19 14:29:12 -0800 | [diff] [blame] | 4418 | * @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] | 4419 | * @return the human readable name of the organisation associated with this profile owner or |
| 4420 | * null if one is not set. |
| 4421 | * @throws IllegalArgumentException if the userId is invalid. |
| 4422 | */ |
| 4423 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4424 | public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4425 | throwIfParentInstance("getProfileOwnerNameAsUser"); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4426 | if (mService != null) { |
| 4427 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 4428 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4429 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4430 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 4431 | } |
| 4432 | } |
| 4433 | return null; |
| 4434 | } |
| 4435 | |
| 4436 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4437 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 4438 | * 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] | 4439 | * handler even if the set of potential event handlers for the intent filter changes and if the |
| 4440 | * intent preferences are reset. |
| 4441 | * <p> |
| 4442 | * The default disambiguation mechanism takes over if the activity is not installed (anymore). |
| 4443 | * When the activity is (re)installed, it is automatically reset as default intent handler for |
| 4444 | * the filter. |
| 4445 | * <p> |
| 4446 | * The calling device admin must be a profile owner or device owner. If it is not, a security |
| 4447 | * exception will be thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4448 | * |
| 4449 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4450 | * @param filter The IntentFilter for which a default handler is added. |
| 4451 | * @param activity The Activity that is added as default intent handler. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4452 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4453 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4454 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 4455 | @NonNull ComponentName activity) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4456 | throwIfParentInstance("addPersistentPreferredActivity"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4457 | if (mService != null) { |
| 4458 | try { |
| 4459 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 4460 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4461 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4462 | } |
| 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | /** |
| 4467 | * 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] | 4468 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4469 | * <p> |
| 4470 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4471 | * thrown. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4472 | * |
| 4473 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4474 | * @param packageName The name of the package for which preferences are removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4475 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4476 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4477 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4478 | String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4479 | throwIfParentInstance("clearPackagePersistentPreferredActivities"); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4480 | if (mService != null) { |
| 4481 | try { |
| 4482 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 4483 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4484 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 4485 | } |
| 4486 | } |
| 4487 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4488 | |
| 4489 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4490 | * Called by a profile owner or device owner to grant permission to a package to manage |
| 4491 | * application restrictions for the calling user via {@link #setApplicationRestrictions} and |
| 4492 | * {@link #getApplicationRestrictions}. |
| 4493 | * <p> |
| 4494 | * This permission is persistent until it is later cleared by calling this method with a |
| 4495 | * {@code null} value or uninstalling the managing package. |
Rubin Xu | f03d0a6 | 2016-02-10 14:54:15 +0000 | [diff] [blame] | 4496 | * <p> |
| 4497 | * The supplied application restriction managing package must be installed when calling this |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4498 | * API, otherwise an {@link NameNotFoundException} will be thrown. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4499 | * |
| 4500 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4501 | * @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] | 4502 | * APIs. If {@code null} is given the current package will be cleared. |
| 4503 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4504 | * @throws NameNotFoundException if {@code packageName} is not found |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4505 | */ |
| 4506 | public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin, |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4507 | @Nullable String packageName) throws NameNotFoundException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4508 | throwIfParentInstance("setApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4509 | if (mService != null) { |
| 4510 | try { |
Victor Chang | cd14c0a | 2016-03-16 19:10:15 +0000 | [diff] [blame] | 4511 | if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) { |
| 4512 | throw new NameNotFoundException(packageName); |
| 4513 | } |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4514 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4515 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4516 | } |
| 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | /** |
| 4521 | * Called by a profile owner or device owner to retrieve the application restrictions managing |
| 4522 | * package for the current user, or {@code null} if none is set. |
| 4523 | * |
| 4524 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4525 | * @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] | 4526 | * {@code null} if none is set. |
| 4527 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4528 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4529 | public @Nullable String getApplicationRestrictionsManagingPackage( |
| 4530 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4531 | throwIfParentInstance("getApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4532 | if (mService != null) { |
| 4533 | try { |
| 4534 | return mService.getApplicationRestrictionsManagingPackage(admin); |
| 4535 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4536 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | return null; |
| 4540 | } |
| 4541 | |
| 4542 | /** |
Esteban Talavera | 96895ca | 2016-03-16 12:00:40 +0000 | [diff] [blame] | 4543 | * Called by any application to find out whether it has been granted permission via |
| 4544 | * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions |
| 4545 | * for the calling user. |
| 4546 | * |
| 4547 | * <p>This is done by comparing the calling Linux uid with the uid of the package specified by |
| 4548 | * that method. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4549 | */ |
| 4550 | public boolean isCallerApplicationRestrictionsManagingPackage() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4551 | throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage"); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4552 | if (mService != null) { |
| 4553 | try { |
| 4554 | return mService.isCallerApplicationRestrictionsManagingPackage(); |
| 4555 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4556 | throw e.rethrowFromSystemServer(); |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | return false; |
| 4560 | } |
| 4561 | |
| 4562 | /** |
| 4563 | * 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] | 4564 | * <p> |
| 4565 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 4566 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 4567 | * security exception will be thrown. |
| 4568 | * <p> |
| 4569 | * 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] | 4570 | * <ul> |
| 4571 | * <li>{@code boolean} |
| 4572 | * <li>{@code int} |
| 4573 | * <li>{@code String} or {@code String[]} |
| 4574 | * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]} |
| 4575 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4576 | * <p> |
| 4577 | * If the restrictions are not available yet, but may be applied in the near future, the caller |
| 4578 | * can notify the target application of that by adding |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4579 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4580 | * <p> |
| 4581 | * The application restrictions are only made visible to the target application via |
| 4582 | * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device |
| 4583 | * owner, and the application restrictions managing package via |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4584 | * {@link #getApplicationRestrictions}. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4585 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4586 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 4587 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4588 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4589 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4590 | * @param packageName The name of the package to update restricted settings for. |
| 4591 | * @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] | 4592 | * set of active restrictions. |
| 4593 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4594 | * @see #setApplicationRestrictionsManagingPackage |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 4595 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4596 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 4597 | @WorkerThread |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 4598 | public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4599 | Bundle settings) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4600 | throwIfParentInstance("setApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4601 | if (mService != null) { |
| 4602 | try { |
| 4603 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 4604 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4605 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4611 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant to |
| 4612 | * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust |
| 4613 | * agents but those enabled by this function call. If flag |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4614 | * {@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] | 4615 | * <p> |
| 4616 | * The calling device admin must have requested |
| 4617 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method; |
| 4618 | * if not, a security exception will be thrown. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4619 | * <p> |
| 4620 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4621 | * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for |
| 4622 | * the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4623 | * |
| 4624 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4625 | * @param target Component name of the agent to be enabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4626 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be |
| 4627 | * strictly disabled according to the state of the |
| 4628 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 4629 | * <p> |
| 4630 | * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all |
| 4631 | * admins, then it's up to the TrustAgent itself to aggregate the values from all |
| 4632 | * device admins. |
| 4633 | * <p> |
| 4634 | * Consult documentation for the specific TrustAgent to determine legal options |
| 4635 | * parameters. |
| 4636 | * @throws SecurityException if {@code admin} is not an active administrator or does not use |
| 4637 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4638 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4639 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 4640 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4641 | if (mService != null) { |
| 4642 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4643 | mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4644 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4645 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4646 | } |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4651 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 4652 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 4653 | * all device admins. |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4654 | * <p> |
| 4655 | * This method can be called on the {@link DevicePolicyManager} instance returned by |
| 4656 | * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set |
| 4657 | * on the parent profile. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4658 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 4659 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 4660 | * this function returns a list of configurations for all admins that declare |
| 4661 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 4662 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 4663 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 4664 | * 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] | 4665 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4666 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4667 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4668 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 4669 | @Nullable ComponentName admin, @NonNull ComponentName agent) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 4670 | return getTrustAgentConfiguration(admin, agent, myUserId()); |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4671 | } |
| 4672 | |
| 4673 | /** @hide per-user version */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4674 | public @Nullable List<PersistableBundle> getTrustAgentConfiguration( |
| 4675 | @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4676 | if (mService != null) { |
| 4677 | try { |
Tony Mak | 089d840 | 2016-04-05 17:42:55 +0100 | [diff] [blame] | 4678 | return mService.getTrustAgentConfiguration(admin, agent, userHandle, |
| 4679 | mParentInstance); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4680 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4681 | throw e.rethrowFromSystemServer(); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4682 | } |
| 4683 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 4684 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4688 | * Called by a profile owner of a managed profile to set whether caller-Id information from the |
| 4689 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4690 | * <p> |
| 4691 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4692 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4693 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4694 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4695 | * @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] | 4696 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4697 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4698 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4699 | throwIfParentInstance("setCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4700 | if (mService != null) { |
| 4701 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4702 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4703 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4704 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4705 | } |
| 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4710 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 4711 | * information has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4712 | * <p> |
| 4713 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4714 | * thrown. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4715 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4716 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4717 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4718 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4719 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4720 | throwIfParentInstance("getCrossProfileCallerIdDisabled"); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4721 | if (mService != null) { |
| 4722 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4723 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4724 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4725 | throw e.rethrowFromSystemServer(); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 4726 | } |
| 4727 | } |
| 4728 | return false; |
| 4729 | } |
| 4730 | |
| 4731 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4732 | * Determine whether or not caller-Id information has been disabled. |
| 4733 | * |
| 4734 | * @param userHandle The user for whom to check the caller-id permission |
| 4735 | * @hide |
| 4736 | */ |
| 4737 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 4738 | if (mService != null) { |
| 4739 | try { |
| 4740 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 4741 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4742 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 4743 | } |
| 4744 | } |
| 4745 | return false; |
| 4746 | } |
| 4747 | |
| 4748 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4749 | * Called by a profile owner of a managed profile to set whether contacts search from the |
| 4750 | * managed profile will be shown in the parent profile, for incoming calls. |
| 4751 | * <p> |
| 4752 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4753 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4754 | * |
| 4755 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4756 | * @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] | 4757 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4758 | */ |
| 4759 | public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin, |
| 4760 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4761 | throwIfParentInstance("setCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4762 | if (mService != null) { |
| 4763 | try { |
| 4764 | mService.setCrossProfileContactsSearchDisabled(admin, disabled); |
| 4765 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4766 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | /** |
| 4772 | * Called by a profile owner of a managed profile to determine whether or not contacts search |
| 4773 | * has been disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4774 | * <p> |
| 4775 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4776 | * thrown. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4777 | * |
| 4778 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4779 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4780 | */ |
| 4781 | public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4782 | throwIfParentInstance("getCrossProfileContactsSearchDisabled"); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4783 | if (mService != null) { |
| 4784 | try { |
| 4785 | return mService.getCrossProfileContactsSearchDisabled(admin); |
| 4786 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4787 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4788 | } |
| 4789 | } |
| 4790 | return false; |
| 4791 | } |
| 4792 | |
| 4793 | |
| 4794 | /** |
| 4795 | * Determine whether or not contacts search has been disabled. |
| 4796 | * |
| 4797 | * @param userHandle The user for whom to check the contacts search permission |
| 4798 | * @hide |
| 4799 | */ |
| 4800 | public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) { |
| 4801 | if (mService != null) { |
| 4802 | try { |
| 4803 | return mService |
| 4804 | .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier()); |
| 4805 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4806 | throw e.rethrowFromSystemServer(); |
Victor Chang | 1060c618 | 2016-01-04 20:16:23 +0000 | [diff] [blame] | 4807 | } |
| 4808 | } |
| 4809 | return false; |
| 4810 | } |
| 4811 | |
| 4812 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4813 | * 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] | 4814 | * |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4815 | * @hide |
| 4816 | */ |
| 4817 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4818 | boolean isContactIdIgnored, long directoryId, Intent originalIntent) { |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4819 | if (mService != null) { |
| 4820 | try { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4821 | mService.startManagedQuickContact(actualLookupKey, actualContactId, |
| 4822 | isContactIdIgnored, directoryId, originalIntent); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4823 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4824 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | } |
| 4828 | |
| 4829 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 4830 | * 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] | 4831 | * @hide |
| 4832 | */ |
| 4833 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 4834 | Intent originalIntent) { |
Victor Chang | 97bdacc | 2016-01-21 22:24:11 +0000 | [diff] [blame] | 4835 | startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT, |
Ricky Wai | 494b95d | 2015-11-20 16:07:15 +0000 | [diff] [blame] | 4836 | originalIntent); |
| 4837 | } |
| 4838 | |
| 4839 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4840 | * Called by a profile owner of a managed profile to set whether bluetooth devices can access |
| 4841 | * enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4842 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4843 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4844 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4845 | * <p> |
| 4846 | * This API works on managed profile only. |
| 4847 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4848 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4849 | * @param disabled If true, bluetooth devices cannot access enterprise contacts. |
| 4850 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4851 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4852 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4853 | throwIfParentInstance("setBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4854 | if (mService != null) { |
| 4855 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4856 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4857 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4858 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4859 | } |
| 4860 | } |
| 4861 | } |
| 4862 | |
| 4863 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4864 | * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices |
| 4865 | * cannot access enterprise contacts. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4866 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4867 | * The calling device admin must be a profile owner. If it is not, a security exception will be |
| 4868 | * thrown. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4869 | * <p> |
| 4870 | * This API works on managed profile only. |
| 4871 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4872 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4873 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4874 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4875 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4876 | throwIfParentInstance("getBluetoothContactSharingDisabled"); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4877 | if (mService != null) { |
| 4878 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4879 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4880 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4881 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4882 | } |
| 4883 | } |
| 4884 | return true; |
| 4885 | } |
| 4886 | |
| 4887 | /** |
| 4888 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 4889 | * <p> |
| 4890 | * This API works on managed profile UserHandle only. |
| 4891 | * |
| 4892 | * @param userHandle The user for whom to check the caller-id permission |
| 4893 | * @hide |
| 4894 | */ |
| 4895 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 4896 | if (mService != null) { |
| 4897 | try { |
| 4898 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 4899 | .getIdentifier()); |
| 4900 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4901 | throw e.rethrowFromSystemServer(); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 4902 | } |
| 4903 | } |
| 4904 | return true; |
| 4905 | } |
| 4906 | |
| 4907 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4908 | * 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] | 4909 | * profile can also be resolved in the parent, or vice versa. Only activity intents are |
| 4910 | * supported. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 4911 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4912 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4913 | * @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] | 4914 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 4915 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4916 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
| 4917 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4918 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4919 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4920 | throwIfParentInstance("addCrossProfileIntentFilter"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4921 | if (mService != null) { |
| 4922 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4923 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4924 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4925 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4926 | } |
| 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4931 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 4932 | * 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] | 4933 | * Only removes those that have been set by the profile owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4934 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4935 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4936 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4937 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4938 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4939 | throwIfParentInstance("clearCrossProfileIntentFilters"); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4940 | if (mService != null) { |
| 4941 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 4942 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4943 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4944 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 4945 | } |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4950 | * Called by a profile or device owner to set the permitted accessibility services. When set by |
| 4951 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 4952 | * device owner or profile owner is an admin for. By default the user can use any accessiblity |
| 4953 | * service. When zero or more packages have been added, accessiblity services that are not in |
| 4954 | * the list and not part of the system can not be enabled by the user. |
| 4955 | * <p> |
| 4956 | * Calling with a null value for the list disables the restriction so that all services can be |
| 4957 | * used, calling with an empty list only allows the builtin system's services. |
| 4958 | * <p> |
| 4959 | * 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] | 4960 | * |
| 4961 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4962 | * @param packageNames List of accessibility service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4963 | * @return true if setting the restriction succeeded. It fail if there is one or more non-system |
| 4964 | * accessibility services enabled, that are not in the list. |
| 4965 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4966 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4967 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4968 | List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4969 | throwIfParentInstance("setPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4970 | if (mService != null) { |
| 4971 | try { |
| 4972 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 4973 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4974 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4975 | } |
| 4976 | } |
| 4977 | return false; |
| 4978 | } |
| 4979 | |
| 4980 | /** |
| 4981 | * 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] | 4982 | * <p> |
| 4983 | * An empty list means no accessibility services except system services are allowed. Null means |
| 4984 | * all accessibility services are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4985 | * |
| 4986 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4987 | * @return List of accessiblity service package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 4988 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4989 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 4990 | public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 4991 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4992 | if (mService != null) { |
| 4993 | try { |
| 4994 | return mService.getPermittedAccessibilityServices(admin); |
| 4995 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 4996 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 4997 | } |
| 4998 | } |
| 4999 | return null; |
| 5000 | } |
| 5001 | |
| 5002 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5003 | * Called by the system to check if a specific accessibility service is disabled by admin. |
| 5004 | * |
| 5005 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5006 | * @param packageName Accessibility service package name that needs to be checked. |
| 5007 | * @param userHandle user id the admin is running as. |
| 5008 | * @return true if the accessibility service is permitted, otherwise false. |
| 5009 | * |
| 5010 | * @hide |
| 5011 | */ |
| 5012 | public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin, |
| 5013 | @NonNull String packageName, int userHandle) { |
| 5014 | if (mService != null) { |
| 5015 | try { |
| 5016 | return mService.isAccessibilityServicePermittedByAdmin(admin, packageName, |
| 5017 | userHandle); |
| 5018 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5019 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | return false; |
| 5023 | } |
| 5024 | |
| 5025 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5026 | * Returns the list of accessibility services permitted by the device or profiles |
| 5027 | * owners of this user. |
| 5028 | * |
| 5029 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 5030 | * it will contain the intersection of the permitted lists for any device or profile |
| 5031 | * owners that apply to this user. It will also include any system accessibility services. |
| 5032 | * |
| 5033 | * @param userId which user to check for. |
| 5034 | * @return List of accessiblity service package names. |
| 5035 | * @hide |
| 5036 | */ |
| 5037 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5038 | public @Nullable List<String> getPermittedAccessibilityServices(int userId) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5039 | throwIfParentInstance("getPermittedAccessibilityServices"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5040 | if (mService != null) { |
| 5041 | try { |
| 5042 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 5043 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5044 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5045 | } |
| 5046 | } |
| 5047 | return null; |
| 5048 | } |
| 5049 | |
| 5050 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5051 | * Called by a profile or device owner to set the permitted input methods services. When set by |
| 5052 | * a device owner or profile owner the restriction applies to all profiles of the user the |
| 5053 | * device owner or profile owner is an admin for. By default the user can use any input method. |
| 5054 | * When zero or more packages have been added, input method that are not in the list and not |
| 5055 | * part of the system can not be enabled by the user. This method will fail if it is called for |
| 5056 | * a admin that is not for the foreground user or a profile of the foreground user. |
| 5057 | * <p> |
| 5058 | * Calling with a null value for the list disables the restriction so that all input methods can |
| 5059 | * be used, calling with an empty list disables all but the system's own input methods. |
| 5060 | * <p> |
| 5061 | * 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] | 5062 | * |
| 5063 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5064 | * @param packageNames List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5065 | * @return true if setting the restriction succeeded. It will fail if there are one or more |
| 5066 | * non-system input methods currently enabled that are not in the packageNames list. |
| 5067 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5068 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5069 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5070 | throwIfParentInstance("setPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5071 | if (mService != null) { |
| 5072 | try { |
| 5073 | return mService.setPermittedInputMethods(admin, packageNames); |
| 5074 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5075 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5076 | } |
| 5077 | } |
| 5078 | return false; |
| 5079 | } |
| 5080 | |
| 5081 | |
| 5082 | /** |
| 5083 | * 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] | 5084 | * <p> |
| 5085 | * An empty list means no input methods except system input methods are allowed. Null means all |
| 5086 | * input methods are allowed. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5087 | * |
| 5088 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5089 | * @return List of input method package names. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5090 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5091 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5092 | public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5093 | throwIfParentInstance("getPermittedInputMethods"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5094 | if (mService != null) { |
| 5095 | try { |
| 5096 | return mService.getPermittedInputMethods(admin); |
| 5097 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5098 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5099 | } |
| 5100 | } |
| 5101 | return null; |
| 5102 | } |
| 5103 | |
| 5104 | /** |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5105 | * Called by the system to check if a specific input method is disabled by admin. |
| 5106 | * |
| 5107 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5108 | * @param packageName Input method package name that needs to be checked. |
| 5109 | * @param userHandle user id the admin is running as. |
| 5110 | * @return true if the input method is permitted, otherwise false. |
| 5111 | * |
| 5112 | * @hide |
| 5113 | */ |
| 5114 | public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin, |
| 5115 | @NonNull String packageName, int userHandle) { |
| 5116 | if (mService != null) { |
| 5117 | try { |
| 5118 | return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle); |
| 5119 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5120 | throw e.rethrowFromSystemServer(); |
Sudheer Shanka | 5692586 | 2016-01-28 19:43:59 +0000 | [diff] [blame] | 5121 | } |
| 5122 | } |
| 5123 | return false; |
| 5124 | } |
| 5125 | |
| 5126 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5127 | * Returns the list of input methods permitted by the device or profiles |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5128 | * 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] | 5129 | * |
| 5130 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 5131 | * it will contain the intersection of the permitted lists for any device or profile |
| 5132 | * owners that apply to this user. It will also include any system input methods. |
| 5133 | * |
| 5134 | * @return List of input method package names. |
| 5135 | * @hide |
| 5136 | */ |
| 5137 | @SystemApi |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5138 | public @Nullable List<String> getPermittedInputMethodsForCurrentUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5139 | throwIfParentInstance("getPermittedInputMethodsForCurrentUser"); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5140 | if (mService != null) { |
| 5141 | try { |
| 5142 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 5143 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5144 | throw e.rethrowFromSystemServer(); |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 5145 | } |
| 5146 | } |
| 5147 | return null; |
| 5148 | } |
| 5149 | |
| 5150 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5151 | * Called by a device owner to get the list of apps to keep around as APKs even if no user has |
| 5152 | * currently installed it. |
| 5153 | * |
| 5154 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5155 | * |
| 5156 | * @return List of package names to keep cached. |
| 5157 | * @hide |
| 5158 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5159 | public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5160 | throwIfParentInstance("getKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5161 | if (mService != null) { |
| 5162 | try { |
| 5163 | return mService.getKeepUninstalledPackages(admin); |
| 5164 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5165 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5166 | } |
| 5167 | } |
| 5168 | return null; |
| 5169 | } |
| 5170 | |
| 5171 | /** |
| 5172 | * Called by a device owner to set a list of apps to keep around as APKs even if no user has |
| 5173 | * currently installed it. |
| 5174 | * |
| 5175 | * <p>Please note that setting this policy does not imply that specified apps will be |
| 5176 | * automatically pre-cached.</p> |
| 5177 | * |
| 5178 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5179 | * @param packageNames List of package names to keep cached. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5180 | * @throws SecurityException if {@code admin} is not a device owner. |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5181 | * @hide |
| 5182 | */ |
| 5183 | public void setKeepUninstalledPackages(@NonNull ComponentName admin, |
| 5184 | @NonNull List<String> packageNames) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5185 | throwIfParentInstance("setKeepUninstalledPackages"); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5186 | if (mService != null) { |
| 5187 | try { |
| 5188 | mService.setKeepUninstalledPackages(admin, packageNames); |
| 5189 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5190 | throw e.rethrowFromSystemServer(); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 5191 | } |
| 5192 | } |
| 5193 | } |
| 5194 | |
| 5195 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5196 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5197 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5198 | * created. If you need to persist an identifier for this user, use |
| 5199 | * {@link UserManager#getSerialNumberForUser}. |
| 5200 | * |
| 5201 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5202 | * @param name the user's name |
| 5203 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5204 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5205 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5206 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5207 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5208 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5209 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5210 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5211 | public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5212 | return null; |
| 5213 | } |
| 5214 | |
| 5215 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5216 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 5217 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 5218 | * created. If you need to persist an identifier for this user, use |
| 5219 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 5220 | * immediately. |
| 5221 | * |
| 5222 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 5223 | * as registered as an active admin on the new user. The profile owner package will be |
| 5224 | * installed on the new user if it already is installed on the device. |
| 5225 | * |
| 5226 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 5227 | * profileOwnerComponent when onEnable is called. |
| 5228 | * |
| 5229 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5230 | * @param name the user's name |
| 5231 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 5232 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 5233 | * the user. |
| 5234 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 5235 | * on the new user. |
| 5236 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5237 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5238 | * user could not be created. |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5239 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 5240 | * @deprecated From {@link android.os.Build.VERSION_CODES#M} |
phweiss | 27ee334 | 2016-02-08 16:40:45 +0100 | [diff] [blame] | 5241 | * @removed From {@link android.os.Build.VERSION_CODES#N} |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5242 | */ |
Kenny Guy | 14f48e5 | 2015-06-29 15:12:36 +0100 | [diff] [blame] | 5243 | @Deprecated |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5244 | public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5245 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 5246 | return null; |
| 5247 | } |
| 5248 | |
| 5249 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5250 | * 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] | 5251 | */ |
| 5252 | public static final int SKIP_SETUP_WIZARD = 0x0001; |
| 5253 | |
| 5254 | /** |
Lenka Trochtova | c8202c8 | 2016-01-26 15:11:09 +0100 | [diff] [blame] | 5255 | * Flag used by {@link #createAndManageUser} to specify that the user should be created |
| 5256 | * ephemeral. |
| 5257 | * @hide |
| 5258 | */ |
| 5259 | public static final int MAKE_USER_EPHEMERAL = 0x0002; |
| 5260 | |
| 5261 | /** |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5262 | * Called by a device owner to create a user with the specified name and a given component of |
| 5263 | * the calling package as profile owner. The UserHandle returned by this method should not be |
| 5264 | * persisted as user handles are recycled as users are removed and created. If you need to |
| 5265 | * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new |
| 5266 | * user will not be started in the background. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5267 | * <p> |
| 5268 | * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a |
| 5269 | * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will |
| 5270 | * be registered as an active admin on the new user. The profile owner package will be installed |
| 5271 | * on the new user. |
| 5272 | * <p> |
| 5273 | * If the adminExtras are not null, they will be stored on the device until the user is started |
| 5274 | * 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] | 5275 | * |
| 5276 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5277 | * @param name The user's name. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5278 | * @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] | 5279 | * same package as admin, otherwise no user is created and an |
| 5280 | * IllegalArgumentException is thrown. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5281 | * @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] | 5282 | * user. |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5283 | * @param flags {@link #SKIP_SETUP_WIZARD} is supported. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5284 | * @see UserHandle |
| 5285 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 5286 | * user could not be created. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5287 | * @throws SecurityException if {@code admin} is not a device owner. |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5288 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5289 | public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin, |
| 5290 | @NonNull String name, |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5291 | @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras, |
| 5292 | int flags) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5293 | throwIfParentInstance("createAndManageUser"); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5294 | try { |
phweiss | a92e121 | 2016-01-25 17:14:10 +0100 | [diff] [blame] | 5295 | return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5296 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5297 | throw re.rethrowFromSystemServer(); |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5298 | } |
phweiss | 343fb33 | 2016-01-25 14:48:59 +0100 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5302 | * Called by a device owner to remove a user and all associated data. The primary user can not |
| 5303 | * be removed. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5304 | * |
| 5305 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5306 | * @param userHandle the user to remove. |
| 5307 | * @return {@code true} if the user was removed, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5308 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5309 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5310 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5311 | throwIfParentInstance("removeUser"); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5312 | try { |
| 5313 | return mService.removeUser(admin, userHandle); |
| 5314 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5315 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | |
| 5319 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5320 | * Called by a device owner to switch the specified user to the foreground. |
| 5321 | * |
| 5322 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5323 | * @param userHandle the user to switch to; null will switch to primary. |
| 5324 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5325 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5326 | * @see Intent#ACTION_USER_FOREGROUND |
| 5327 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5328 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5329 | throwIfParentInstance("switchUser"); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5330 | try { |
| 5331 | return mService.switchUser(admin, userHandle); |
| 5332 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5333 | throw re.rethrowFromSystemServer(); |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 5334 | } |
| 5335 | } |
| 5336 | |
| 5337 | /** |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5338 | * Retrieves the application restrictions for a given target application running in the calling |
| 5339 | * user. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5340 | * <p> |
| 5341 | * The caller must be a profile or device owner on that user, or the package allowed to manage |
| 5342 | * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a |
| 5343 | * security exception will be thrown. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5344 | * |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5345 | * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread |
| 5346 | * |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5347 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5348 | * {@code null} if called by the application restrictions managing package. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5349 | * @param packageName The name of the package to fetch restricted settings of. |
| 5350 | * @return {@link Bundle} of settings corresponding to what was set last time |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5351 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty |
| 5352 | * {@link Bundle} if no restrictions have been set. |
| 5353 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Esteban Talavera | bf60f72 | 2015-12-10 16:26:44 +0000 | [diff] [blame] | 5354 | * @see {@link #setApplicationRestrictionsManagingPackage} |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5355 | */ |
Fyodor Kupolov | 4e9af06 | 2016-07-18 16:59:11 -0700 | [diff] [blame] | 5356 | @WorkerThread |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5357 | public @NonNull Bundle getApplicationRestrictions( |
| 5358 | @Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5359 | throwIfParentInstance("getApplicationRestrictions"); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5360 | if (mService != null) { |
| 5361 | try { |
| 5362 | return mService.getApplicationRestrictions(admin, packageName); |
| 5363 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5364 | throw e.rethrowFromSystemServer(); |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 5365 | } |
| 5366 | } |
| 5367 | return null; |
| 5368 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5369 | |
| 5370 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5371 | * 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] | 5372 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5373 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5374 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5375 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5376 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5377 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5378 | * for the list of keys. |
| 5379 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5380 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5381 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5382 | throwIfParentInstance("addUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5383 | if (mService != null) { |
| 5384 | try { |
| 5385 | mService.setUserRestriction(admin, key, true); |
| 5386 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5387 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5388 | } |
| 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5393 | * 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] | 5394 | * <p> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5395 | * The calling device admin must be a profile or device owner; if it is not, a security |
| 5396 | * exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 5397 | * |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5398 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5399 | * @param key The key of the restriction. See the constants in {@link android.os.UserManager} |
| 5400 | * for the list of keys. |
| 5401 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5402 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5403 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5404 | throwIfParentInstance("clearUserRestriction"); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5405 | if (mService != null) { |
| 5406 | try { |
| 5407 | mService.setUserRestriction(admin, key, false); |
| 5408 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5409 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 5410 | } |
| 5411 | } |
| 5412 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 5413 | |
| 5414 | /** |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5415 | * Called by a profile or device owner to get user restrictions set with |
| 5416 | * {@link #addUserRestriction(ComponentName, String)}. |
| 5417 | * <p> |
| 5418 | * 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] | 5419 | * owner. To get all the user restrictions currently set, use |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5420 | * {@link UserManager#getUserRestrictions()}. |
| 5421 | * |
| 5422 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5423 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5424 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5425 | public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5426 | throwIfParentInstance("getUserRestrictions"); |
Makoto Onuki | 3a3092f | 2015-10-30 11:07:51 -0700 | [diff] [blame] | 5427 | Bundle ret = null; |
| 5428 | if (mService != null) { |
| 5429 | try { |
Sudheer Shanka | 549b969 | 2016-03-30 17:12:07 -0700 | [diff] [blame] | 5430 | ret = mService.getUserRestrictions(admin); |
| 5431 | } catch (RemoteException e) { |
| 5432 | throw e.rethrowFromSystemServer(); |
| 5433 | } |
| 5434 | } |
| 5435 | return ret == null ? new Bundle() : ret; |
| 5436 | } |
| 5437 | |
| 5438 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5439 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it is |
| 5440 | * unavailable for use, but the data and actual package file remain. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5441 | * |
| 5442 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5443 | * @param packageName The name of the package to hide or unhide. |
| 5444 | * @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] | 5445 | * unhidden. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5446 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5447 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5448 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5449 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5450 | boolean hidden) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5451 | throwIfParentInstance("setApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5452 | if (mService != null) { |
| 5453 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5454 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5455 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5456 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5457 | } |
| 5458 | } |
| 5459 | return false; |
| 5460 | } |
| 5461 | |
| 5462 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5463 | * Called by profile or device owners to determine if a package is hidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5464 | * |
| 5465 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5466 | * @param packageName The name of the package to retrieve the hidden status of. |
| 5467 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5468 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5469 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5470 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5471 | throwIfParentInstance("isApplicationHidden"); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5472 | if (mService != null) { |
| 5473 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5474 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5475 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5476 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 5477 | } |
| 5478 | } |
| 5479 | return false; |
| 5480 | } |
| 5481 | |
| 5482 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 5483 | * Called by profile or device owners to re-enable a system app that was disabled by default |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5484 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5485 | * |
| 5486 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5487 | * @param packageName The package to be re-enabled in the calling profile. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5488 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5489 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5490 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5491 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5492 | if (mService != null) { |
| 5493 | try { |
| 5494 | mService.enableSystemApp(admin, packageName); |
| 5495 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5496 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5497 | } |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5502 | * Called by profile or device owners to re-enable system apps by intent that were disabled by |
| 5503 | * default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5504 | * |
| 5505 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5506 | * @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] | 5507 | * intent will be re-enabled in the calling profile. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5508 | * @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] | 5509 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5510 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5511 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5512 | throwIfParentInstance("enableSystemApp"); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5513 | if (mService != null) { |
| 5514 | try { |
| 5515 | return mService.enableSystemAppWithIntent(admin, intent); |
| 5516 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5517 | throw e.rethrowFromSystemServer(); |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 5518 | } |
| 5519 | } |
| 5520 | return 0; |
| 5521 | } |
| 5522 | |
| 5523 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 5524 | * Called by a device owner or profile owner to disable account management for a specific type |
| 5525 | * of account. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5526 | * <p> |
| 5527 | * The calling device admin must be a device owner or profile owner. If it is not, a security |
| 5528 | * exception will be thrown. |
| 5529 | * <p> |
| 5530 | * When account management is disabled for an account type, adding or removing an account of |
| 5531 | * that type will not be possible. |
| 5532 | * <p> |
| 5533 | * 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] | 5534 | * {@link android.accounts.AccountManager} APIs to add or remove accounts when account |
| 5535 | * management for a specific type is disabled. |
| 5536 | * |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5537 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5538 | * @param accountType For which account management is disabled or enabled. |
| 5539 | * @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] | 5540 | * enabled (false). |
| 5541 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5542 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5543 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5544 | boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5545 | throwIfParentInstance("setAccountManagementDisabled"); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5546 | if (mService != null) { |
| 5547 | try { |
| 5548 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 5549 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5550 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 5551 | } |
| 5552 | } |
| 5553 | } |
| 5554 | |
| 5555 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5556 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 5557 | * |
| 5558 | * <p> Account management can be disabled/enabled by calling |
| 5559 | * {@link #setAccountManagementDisabled}. |
| 5560 | * |
| 5561 | * @return a list of account types for which account management has been disabled. |
| 5562 | * |
| 5563 | * @see #setAccountManagementDisabled |
| 5564 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5565 | public @Nullable String[] getAccountTypesWithManagementDisabled() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5566 | throwIfParentInstance("getAccountTypesWithManagementDisabled"); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 5567 | return getAccountTypesWithManagementDisabledAsUser(myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | /** |
| 5571 | * @see #getAccountTypesWithManagementDisabled() |
| 5572 | * @hide |
| 5573 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5574 | public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5575 | if (mService != null) { |
| 5576 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 5577 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5578 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5579 | throw e.rethrowFromSystemServer(); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | return null; |
| 5584 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5585 | |
| 5586 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5587 | * Sets which packages may enter lock task mode. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5588 | * <p> |
| 5589 | * Any packages that shares uid with an allowed package will also be allowed to activate lock |
| 5590 | * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task |
| 5591 | * package list results in locked tasks belonging to those packages to be finished. This |
| 5592 | * function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5593 | * |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5594 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5595 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5596 | * @throws SecurityException if {@code admin} is not a device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5597 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 5598 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 5599 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 5600 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5601 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5602 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5603 | throws SecurityException { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5604 | throwIfParentInstance("setLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5605 | if (mService != null) { |
| 5606 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5607 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5608 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5609 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5610 | } |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5615 | * 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] | 5616 | * |
| 5617 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5618 | * @hide |
| 5619 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5620 | public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5621 | throwIfParentInstance("getLockTaskPackages"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5622 | if (mService != null) { |
| 5623 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 5624 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5625 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5626 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5627 | } |
| 5628 | } |
| 5629 | return null; |
| 5630 | } |
| 5631 | |
| 5632 | /** |
| 5633 | * This function lets the caller know whether the given component is allowed to start the |
| 5634 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5635 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5636 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5637 | public boolean isLockTaskPermitted(String pkg) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5638 | throwIfParentInstance("isLockTaskPermitted"); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5639 | if (mService != null) { |
| 5640 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 5641 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5642 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5643 | throw e.rethrowFromSystemServer(); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 5644 | } |
| 5645 | } |
| 5646 | return false; |
| 5647 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5648 | |
| 5649 | /** |
| 5650 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 5651 | * 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] | 5652 | * <p> |
| 5653 | * The settings that can be updated with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5654 | * <ul> |
| 5655 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 5656 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 5657 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5658 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5659 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5660 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5661 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from |
| 5662 | * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if |
| 5663 | * {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
| 5664 | * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only |
| 5665 | * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5666 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5667 | * <p> |
| 5668 | * 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] | 5669 | * <ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5670 | * <li>{@link Settings.Global#BLUETOOTH_ON}. Use |
| 5671 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 5672 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5673 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5674 | * <li>{@link Settings.Global#MODE_RINGER}. Use |
| 5675 | * {@link android.media.AudioManager#setRingerMode(int)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5676 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5677 | * <li>{@link Settings.Global#WIFI_ON}. Use |
| 5678 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Esteban Talavera | 656fa7f | 2015-06-29 17:41:39 +0100 | [diff] [blame] | 5679 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5680 | * |
| 5681 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5682 | * @param setting The name of the setting to update. |
| 5683 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5684 | * @throws SecurityException if {@code admin} is not a device owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5685 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5686 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5687 | throwIfParentInstance("setGlobalSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5688 | if (mService != null) { |
| 5689 | try { |
| 5690 | mService.setGlobalSetting(admin, setting, value); |
| 5691 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5692 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5693 | } |
| 5694 | } |
| 5695 | } |
| 5696 | |
| 5697 | /** |
| 5698 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 5699 | * that the value of the setting is in the correct form for the setting type should be performed |
| 5700 | * by the caller. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5701 | * <p> |
| 5702 | * 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] | 5703 | * <ul> |
| 5704 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 5705 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 5706 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 5707 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5708 | * <p> |
| 5709 | * A device owner can additionally update the following settings: |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 5710 | * <ul> |
| 5711 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 5712 | * </ul> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5713 | * |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5714 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5715 | * @param setting The name of the setting to update. |
| 5716 | * @param value The value to update the setting to. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5717 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5718 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5719 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5720 | throwIfParentInstance("setSecureSetting"); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5721 | if (mService != null) { |
| 5722 | try { |
| 5723 | mService.setSecureSetting(admin, setting, value); |
| 5724 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5725 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 5726 | } |
| 5727 | } |
| 5728 | } |
| 5729 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5730 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5731 | * Designates a specific service component as the provider for making permission requests of a |
| 5732 | * local or remote administrator of the user. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5733 | * <p/> |
| 5734 | * Only a profile owner can designate the restrictions provider. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5735 | * |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5736 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5737 | * @param provider The component name of the service that implements |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5738 | * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions |
| 5739 | * provider previously assigned. |
| 5740 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5741 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5742 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 5743 | @Nullable ComponentName provider) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5744 | throwIfParentInstance("setRestrictionsProvider"); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5745 | if (mService != null) { |
| 5746 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 5747 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5748 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5749 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 5750 | } |
| 5751 | } |
| 5752 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5753 | |
| 5754 | /** |
| 5755 | * 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] | 5756 | * This has no effect when set on a managed profile. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5757 | * |
| 5758 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5759 | * @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] | 5760 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5761 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5762 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5763 | throwIfParentInstance("setMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5764 | if (mService != null) { |
| 5765 | try { |
| 5766 | mService.setMasterVolumeMuted(admin, on); |
| 5767 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5768 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5769 | } |
| 5770 | } |
| 5771 | } |
| 5772 | |
| 5773 | /** |
| 5774 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 5775 | * |
| 5776 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5777 | * @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] | 5778 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5779 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5780 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5781 | throwIfParentInstance("isMasterVolumeMuted"); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5782 | if (mService != null) { |
| 5783 | try { |
| 5784 | return mService.isMasterVolumeMuted(admin); |
| 5785 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5786 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 5787 | } |
| 5788 | } |
| 5789 | return false; |
| 5790 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5791 | |
| 5792 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5793 | * Called by profile or device owners to change whether a user can uninstall a package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5794 | * |
| 5795 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5796 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5797 | * @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] | 5798 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5799 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5800 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5801 | boolean uninstallBlocked) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5802 | throwIfParentInstance("setUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5803 | if (mService != null) { |
| 5804 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 5805 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5806 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5807 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5808 | } |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5813 | * 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] | 5814 | * 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] | 5815 | * <p> |
| 5816 | * <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] | 5817 | * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter |
| 5818 | * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null} |
| 5819 | * will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5820 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5821 | * @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] | 5822 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5823 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 5824 | * @return true if uninstallation is blocked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5825 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5826 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5827 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5828 | throwIfParentInstance("isUninstallBlocked"); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5829 | if (mService != null) { |
| 5830 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 5831 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5832 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5833 | throw re.rethrowFromSystemServer(); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 5834 | } |
| 5835 | } |
| 5836 | return false; |
| 5837 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5838 | |
| 5839 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5840 | * Called by the profile owner of a managed profile to enable widget providers from a given |
| 5841 | * package to be available in the parent profile. As a result the user will be able to add |
| 5842 | * widgets from the white-listed package running under the profile to a widget host which runs |
| 5843 | * under the parent profile, for example the home screen. Note that a package may have zero or |
| 5844 | * more provider components, where each component provides a different widget type. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5845 | * <p> |
| 5846 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5847 | * |
| 5848 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5849 | * @param packageName The package from which widget providers are white-listed. |
| 5850 | * @return Whether the package was added. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5851 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5852 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5853 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5854 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5855 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5856 | throwIfParentInstance("addCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5857 | if (mService != null) { |
| 5858 | try { |
| 5859 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 5860 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5861 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5862 | } |
| 5863 | } |
| 5864 | return false; |
| 5865 | } |
| 5866 | |
| 5867 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5868 | * 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] | 5869 | * package to be available in the parent profile. For this method to take effect the package |
| 5870 | * should have been added via |
| 5871 | * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5872 | * <p> |
| 5873 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5874 | * |
| 5875 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5876 | * @param packageName The package from which widget providers are no longer white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5877 | * @return Whether the package was removed. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5878 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5879 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5880 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 5881 | */ |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 5882 | public boolean removeCrossProfileWidgetProvider( |
| 5883 | @NonNull ComponentName admin, String packageName) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5884 | throwIfParentInstance("removeCrossProfileWidgetProvider"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5885 | if (mService != null) { |
| 5886 | try { |
| 5887 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 5888 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5889 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5890 | } |
| 5891 | } |
| 5892 | return false; |
| 5893 | } |
| 5894 | |
| 5895 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 5896 | * 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] | 5897 | * available in the parent profile. |
| 5898 | * |
| 5899 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5900 | * @return The white-listed package list. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5901 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 5902 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5903 | * @throws SecurityException if {@code admin} is not a profile owner. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5904 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5905 | public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5906 | throwIfParentInstance("getCrossProfileWidgetProviders"); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5907 | if (mService != null) { |
| 5908 | try { |
| 5909 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 5910 | if (providers != null) { |
| 5911 | return providers; |
| 5912 | } |
| 5913 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5914 | throw re.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 5915 | } |
| 5916 | } |
| 5917 | return Collections.emptyList(); |
| 5918 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5919 | |
| 5920 | /** |
Makoto Onuki | 32b3057 | 2015-12-11 14:29:51 -0800 | [diff] [blame] | 5921 | * Called by profile or device owners to set the user's photo. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5922 | * |
| 5923 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 5924 | * @param icon the bitmap to set as the photo. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5925 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5926 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5927 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5928 | throwIfParentInstance("setUserIcon"); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5929 | try { |
| 5930 | mService.setUserIcon(admin, icon); |
| 5931 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5932 | throw re.rethrowFromSystemServer(); |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 5933 | } |
| 5934 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 5935 | |
| 5936 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5937 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 5938 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5939 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5940 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5941 | * components in the device owner package can set system update policies and the most |
| 5942 | * recent policy takes effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5943 | * @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] | 5944 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5945 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5946 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5947 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5948 | throwIfParentInstance("setSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5949 | if (mService != null) { |
| 5950 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5951 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5952 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5953 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5954 | } |
| 5955 | } |
| 5956 | } |
| 5957 | |
| 5958 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 5959 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5960 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5961 | * @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] | 5962 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 5963 | public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5964 | throwIfParentInstance("getSystemUpdatePolicy"); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5965 | if (mService != null) { |
| 5966 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 5967 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5968 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5969 | throw re.rethrowFromSystemServer(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 5970 | } |
| 5971 | } |
| 5972 | return null; |
| 5973 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5974 | |
| 5975 | /** |
| 5976 | * Called by a device owner to disable the keyguard altogether. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 5977 | * <p> |
| 5978 | * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock |
| 5979 | * type. However, this call has no effect if a password, pin or pattern is currently set. If a |
| 5980 | * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being |
| 5981 | * disabled. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5982 | * |
| 5983 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5984 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5985 | * @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] | 5986 | * place. {@code true} otherwise. |
| 5987 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5988 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 5989 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 5990 | throwIfParentInstance("setKeyguardDisabled"); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5991 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5992 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5993 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 5994 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 5995 | } |
| 5996 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 5997 | |
| 5998 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 5999 | * 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] | 6000 | * notifications, quick settings and other screen overlays that allow escaping from a single use |
| 6001 | * device. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6002 | * |
| 6003 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6004 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6005 | * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise. |
| 6006 | * @throws SecurityException if {@code admin} is not a device owner. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6007 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6008 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6009 | throwIfParentInstance("setStatusBarDisabled"); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6010 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 6011 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6012 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6013 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 6014 | } |
| 6015 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6016 | |
| 6017 | /** |
| 6018 | * Callable by the system update service to notify device owners about pending updates. |
| 6019 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 6020 | * permission. |
| 6021 | * |
| 6022 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 6023 | * when the current pending update was first available. -1 if no update is available. |
| 6024 | * @hide |
| 6025 | */ |
| 6026 | @SystemApi |
| 6027 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6028 | throwIfParentInstance("notifyPendingSystemUpdate"); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6029 | if (mService != null) { |
| 6030 | try { |
| 6031 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 6032 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6033 | throw re.rethrowFromSystemServer(); |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 6034 | } |
| 6035 | } |
| 6036 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 6037 | |
| 6038 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6039 | * Called by profile or device owners to set the default response for future runtime permission |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6040 | * requests by applications. The policy can allow for normal operation which prompts the user to |
| 6041 | * grant a permission, or can allow automatic granting or denying of runtime permission requests |
| 6042 | * by an application. This also applies to new permissions declared by app updates. When a |
| 6043 | * permission is denied or granted this way, the effect is equivalent to setting the permission |
| 6044 | * grant state via {@link #setPermissionGrantState}. |
| 6045 | * <p/> |
| 6046 | * 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] | 6047 | * 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] | 6048 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6049 | * @param admin Which profile or device owner this request is associated with. |
| 6050 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6051 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 6052 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 45dd666 | 2015-07-08 14:24:14 +0100 | [diff] [blame] | 6053 | * @see #setPermissionGrantState |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6054 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6055 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6056 | throwIfParentInstance("setPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6057 | try { |
| 6058 | mService.setPermissionPolicy(admin, policy); |
| 6059 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6060 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | /** |
| 6065 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 6066 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 6067 | * @param admin Which profile or device owner this request is associated with. |
| 6068 | * @return the current policy for future permission requests. |
| 6069 | */ |
Esteban Talavera | 28b9570 | 2015-06-24 15:23:42 +0100 | [diff] [blame] | 6070 | public int getPermissionPolicy(ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6071 | throwIfParentInstance("getPermissionPolicy"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6072 | try { |
| 6073 | return mService.getPermissionPolicy(admin); |
| 6074 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6075 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6076 | } |
| 6077 | } |
| 6078 | |
| 6079 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6080 | * Sets the grant state of a runtime permission for a specific application. The state can be |
| 6081 | * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI, |
| 6082 | * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user |
| 6083 | * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which |
| 6084 | * the permission is granted and the user cannot manage it through the UI. This might affect all |
| 6085 | * permissions in a group that the runtime permission belongs to. This method can only be called |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6086 | * by a profile or device owner. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6087 | * <p/> |
| 6088 | * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke |
| 6089 | * the permission. It retains the previous grant, if any. |
| 6090 | * <p/> |
| 6091 | * Permissions can be granted or revoked only for applications built with a |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6092 | * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later. |
Amith Yamasani | 0bf8f7c | 2015-06-22 13:00:32 -0700 | [diff] [blame] | 6093 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6094 | * @param admin Which profile or device owner this request is associated with. |
| 6095 | * @param packageName The application to grant or revoke a permission to. |
| 6096 | * @param permission The permission to grant or revoke. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6097 | * @param grantState The permission grant state which is one of |
| 6098 | * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 6099 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6100 | * @return whether the permission was successfully granted or revoked. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6101 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6102 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 6103 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 6104 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6105 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6106 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6107 | String permission, int grantState) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6108 | throwIfParentInstance("setPermissionGrantState"); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6109 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 6110 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6111 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6112 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 6113 | } |
| 6114 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6115 | |
| 6116 | /** |
| 6117 | * Returns the current grant state of a runtime permission for a specific application. |
| 6118 | * |
| 6119 | * @param admin Which profile or device owner this request is associated with. |
| 6120 | * @param packageName The application to check the grant state for. |
| 6121 | * @param permission The permission to check for. |
| 6122 | * @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] | 6123 | * has not set a grant state, the return value is |
| 6124 | * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the |
| 6125 | * permission is currently granted for the package. |
| 6126 | * <p/> |
| 6127 | * If a grant state was set by the profile or device owner, then the return value will |
| 6128 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or |
| 6129 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is |
| 6130 | * currently denied or granted. |
| 6131 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6132 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 6133 | * @see PackageManager#checkPermission(String, String) |
| 6134 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 6135 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6136 | String permission) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6137 | throwIfParentInstance("getPermissionGrantState"); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6138 | try { |
| 6139 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 6140 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6141 | throw re.rethrowFromSystemServer(); |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 6142 | } |
| 6143 | } |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6144 | |
| 6145 | /** |
| 6146 | * Returns if provisioning a managed profile or device is possible or not. |
| 6147 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6148 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6149 | * @return if provisioning a managed profile or device is possible or not. |
| 6150 | * @throws IllegalArgumentException if the supplied action is not valid. |
| 6151 | */ |
| 6152 | public boolean isProvisioningAllowed(String action) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6153 | throwIfParentInstance("isProvisioningAllowed"); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6154 | try { |
| 6155 | return mService.isProvisioningAllowed(action); |
| 6156 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6157 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 07387fe | 2015-10-30 17:53:30 +0000 | [diff] [blame] | 6158 | } |
| 6159 | } |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6160 | |
| 6161 | /** |
Mahaver Chopra | 849fd6f | 2016-11-03 20:28:10 +0000 | [diff] [blame] | 6162 | * Checks if provisioning a managed profile or device is possible and returns one of the |
| 6163 | * {@link ProvisioningPreCondition}. |
| 6164 | * |
| 6165 | * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE}, |
| 6166 | * {@link #ACTION_PROVISION_MANAGED_PROFILE}, |
| 6167 | * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}, |
| 6168 | * {@link #ACTION_PROVISION_MANAGED_USER} |
| 6169 | * @hide |
| 6170 | */ |
| 6171 | public @ProvisioningPreCondition int checkProvisioningPreCondition(String action) { |
| 6172 | try { |
| 6173 | return mService.checkProvisioningPreCondition(action); |
| 6174 | } catch (RemoteException re) { |
| 6175 | throw re.rethrowFromSystemServer(); |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | /** |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6180 | * Return if this user is a managed profile of another user. An admin can become the profile |
| 6181 | * 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] | 6182 | * user with {@link #createAndManageUser} |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6183 | * @param admin Which profile owner this request is associated with. |
| 6184 | * @return if this user is a managed profile of another user. |
| 6185 | */ |
| 6186 | public boolean isManagedProfile(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6187 | throwIfParentInstance("isManagedProfile"); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6188 | try { |
| 6189 | return mService.isManagedProfile(admin); |
| 6190 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6191 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6192 | } |
| 6193 | } |
| 6194 | |
| 6195 | /** |
| 6196 | * @hide |
| 6197 | * Return if this user is a system-only user. An admin can manage a device from a system only |
| 6198 | * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}. |
| 6199 | * @param admin Which device owner this request is associated with. |
| 6200 | * @return if this user is a system-only user. |
| 6201 | */ |
| 6202 | public boolean isSystemOnlyUser(@NonNull ComponentName admin) { |
| 6203 | try { |
| 6204 | return mService.isSystemOnlyUser(admin); |
| 6205 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6206 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 15a46b0 | 2015-11-11 14:54:35 +0000 | [diff] [blame] | 6207 | } |
| 6208 | } |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6209 | |
| 6210 | /** |
| 6211 | * Called by device owner to get the MAC address of the Wi-Fi device. |
| 6212 | * |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6213 | * @param admin Which device owner this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6214 | * @return the MAC address of the Wi-Fi device, or null when the information is not available. |
| 6215 | * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.) |
| 6216 | * <p> |
| 6217 | * The address will be in the {@code XX:XX:XX:XX:XX:XX} format. |
| 6218 | * @throws SecurityException if {@code admin} is not a device owner. |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6219 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6220 | public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6221 | throwIfParentInstance("getWifiMacAddress"); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6222 | try { |
Sudheer Shanka | 3cb4da1 | 2016-03-07 18:51:49 -0800 | [diff] [blame] | 6223 | return mService.getWifiMacAddress(admin); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6224 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6225 | throw re.rethrowFromSystemServer(); |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 6226 | } |
| 6227 | } |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6228 | |
| 6229 | /** |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6230 | * Called by device owner to reboot the device. If there is an ongoing call on the device, |
| 6231 | * throws an {@link IllegalStateException}. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6232 | * @param admin Which device owner the request is associated with. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6233 | * @throws IllegalStateException if device has an ongoing call. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6234 | * @throws SecurityException if {@code admin} is not a device owner. |
Mahaver Chopra | 1216ae5 | 2016-03-11 15:39:48 +0000 | [diff] [blame] | 6235 | * @see TelephonyManager#CALL_STATE_IDLE |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6236 | */ |
| 6237 | public void reboot(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6238 | throwIfParentInstance("reboot"); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6239 | try { |
| 6240 | mService.reboot(admin); |
| 6241 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6242 | throw re.rethrowFromSystemServer(); |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 6243 | } |
| 6244 | } |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6245 | |
| 6246 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6247 | * Called by a device admin to set the short support message. This will be displayed to the user |
| 6248 | * in settings screens where funtionality has been disabled by the admin. The message should be |
| 6249 | * limited to a short statement such as "This setting is disabled by your administrator. Contact |
| 6250 | * someone@example.com for support." If the message is longer than 200 characters it may be |
| 6251 | * truncated. |
| 6252 | * <p> |
| 6253 | * 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] | 6254 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6255 | * and set a new version of this string accordingly. |
| 6256 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6257 | * @see #setLongSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6258 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6259 | * @param message Short message to be displayed to the user in settings or null to clear the |
| 6260 | * existing message. |
| 6261 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6262 | */ |
| 6263 | public void setShortSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6264 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6265 | throwIfParentInstance("setShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6266 | if (mService != null) { |
| 6267 | try { |
| 6268 | mService.setShortSupportMessage(admin, message); |
| 6269 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6270 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6271 | } |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | /** |
| 6276 | * Called by a device admin to get the short support message. |
| 6277 | * |
| 6278 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6279 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or |
| 6280 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6281 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6282 | */ |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6283 | public CharSequence getShortSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6284 | throwIfParentInstance("getShortSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6285 | if (mService != null) { |
| 6286 | try { |
| 6287 | return mService.getShortSupportMessage(admin); |
| 6288 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6289 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6290 | } |
| 6291 | } |
| 6292 | return null; |
| 6293 | } |
| 6294 | |
| 6295 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6296 | * Called by a device admin to set the long support message. This will be displayed to the user |
| 6297 | * in the device administators settings screen. |
| 6298 | * <p> |
| 6299 | * 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] | 6300 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6301 | * and set a new version of this string accordingly. |
| 6302 | * |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6303 | * @see #setShortSupportMessage |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6304 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6305 | * @param message Long message to be displayed to the user in settings or null to clear the |
| 6306 | * existing message. |
| 6307 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6308 | */ |
| 6309 | public void setLongSupportMessage(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6310 | @Nullable CharSequence message) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6311 | throwIfParentInstance("setLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6312 | if (mService != null) { |
| 6313 | try { |
| 6314 | mService.setLongSupportMessage(admin, message); |
| 6315 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6316 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6317 | } |
| 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | /** |
| 6322 | * Called by a device admin to get the long support message. |
| 6323 | * |
| 6324 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6325 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or |
| 6326 | * null if no message has been set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6327 | * @throws SecurityException if {@code admin} is not an active administrator. |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6328 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6329 | public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6330 | throwIfParentInstance("getLongSupportMessage"); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6331 | if (mService != null) { |
| 6332 | try { |
| 6333 | return mService.getLongSupportMessage(admin); |
| 6334 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6335 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6336 | } |
| 6337 | } |
| 6338 | return null; |
| 6339 | } |
| 6340 | |
| 6341 | /** |
| 6342 | * Called by the system to get the short support message. |
| 6343 | * |
| 6344 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6345 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6346 | * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6347 | * |
| 6348 | * @hide |
| 6349 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6350 | public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin, |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6351 | int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6352 | if (mService != null) { |
| 6353 | try { |
| 6354 | return mService.getShortSupportMessageForUser(admin, userHandle); |
| 6355 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6356 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6357 | } |
| 6358 | } |
| 6359 | return null; |
| 6360 | } |
| 6361 | |
| 6362 | |
| 6363 | /** |
| 6364 | * Called by the system to get the long support message. |
| 6365 | * |
| 6366 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6367 | * @param userHandle user id the admin is running as. |
Sudheer Shanka | 3ccca91e | 2016-04-11 21:36:17 -0700 | [diff] [blame] | 6368 | * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6369 | * |
| 6370 | * @hide |
| 6371 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6372 | public @Nullable CharSequence getLongSupportMessageForUser( |
| 6373 | @NonNull ComponentName admin, int userHandle) { |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6374 | if (mService != null) { |
| 6375 | try { |
| 6376 | return mService.getLongSupportMessageForUser(admin, userHandle); |
| 6377 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6378 | throw e.rethrowFromSystemServer(); |
Kenny Guy | 06de4e7 | 2015-12-22 12:07:39 +0000 | [diff] [blame] | 6379 | } |
| 6380 | } |
| 6381 | return null; |
| 6382 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6383 | |
| 6384 | /** |
Esteban Talavera | 6239991 | 2016-01-11 15:37:55 +0000 | [diff] [blame] | 6385 | * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager} |
| 6386 | * whose calls act on the parent profile. |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6387 | * |
| 6388 | * <p>The following methods are supported for the parent instance, all other methods will |
| 6389 | * throw a SecurityException when called on the parent instance: |
| 6390 | * <ul> |
| 6391 | * <li>{@link #getPasswordQuality}</li> |
| 6392 | * <li>{@link #setPasswordQuality}</li> |
| 6393 | * <li>{@link #getPasswordMinimumLength}</li> |
| 6394 | * <li>{@link #setPasswordMinimumLength}</li> |
| 6395 | * <li>{@link #getPasswordMinimumUpperCase}</li> |
| 6396 | * <li>{@link #setPasswordMinimumUpperCase}</li> |
| 6397 | * <li>{@link #getPasswordMinimumLowerCase}</li> |
| 6398 | * <li>{@link #setPasswordMinimumLowerCase}</li> |
| 6399 | * <li>{@link #getPasswordMinimumLetters}</li> |
| 6400 | * <li>{@link #setPasswordMinimumLetters}</li> |
| 6401 | * <li>{@link #getPasswordMinimumNumeric}</li> |
| 6402 | * <li>{@link #setPasswordMinimumNumeric}</li> |
| 6403 | * <li>{@link #getPasswordMinimumSymbols}</li> |
| 6404 | * <li>{@link #setPasswordMinimumSymbols}</li> |
| 6405 | * <li>{@link #getPasswordMinimumNonLetter}</li> |
| 6406 | * <li>{@link #setPasswordMinimumNonLetter}</li> |
| 6407 | * <li>{@link #getPasswordHistoryLength}</li> |
| 6408 | * <li>{@link #setPasswordHistoryLength}</li> |
| 6409 | * <li>{@link #getPasswordExpirationTimeout}</li> |
| 6410 | * <li>{@link #setPasswordExpirationTimeout}</li> |
| 6411 | * <li>{@link #getPasswordExpiration}</li> |
Charles He | 8c76056 | 2016-10-25 16:36:53 +0100 | [diff] [blame] | 6412 | * <li>{@link #getPasswordMaximumLength}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6413 | * <li>{@link #isActivePasswordSufficient}</li> |
| 6414 | * <li>{@link #getCurrentFailedPasswordAttempts}</li> |
| 6415 | * <li>{@link #getMaximumFailedPasswordsForWipe}</li> |
| 6416 | * <li>{@link #setMaximumFailedPasswordsForWipe}</li> |
| 6417 | * <li>{@link #getMaximumTimeToLock}</li> |
| 6418 | * <li>{@link #setMaximumTimeToLock}</li> |
| 6419 | * <li>{@link #lockNow}</li> |
| 6420 | * <li>{@link #getKeyguardDisabledFeatures}</li> |
| 6421 | * <li>{@link #setKeyguardDisabledFeatures}</li> |
| 6422 | * <li>{@link #getTrustAgentConfiguration}</li> |
| 6423 | * <li>{@link #setTrustAgentConfiguration}</li> |
Michal Karpinski | a20d8bb | 2016-11-23 12:09:08 +0000 | [diff] [blame] | 6424 | * <li>{@link #getRequiredStrongAuthTimeout}</li> |
| 6425 | * <li>{@link #setRequiredStrongAuthTimeout}</li> |
Benjamin Franz | 66b45f0 | 2016-04-05 19:12:39 +0100 | [diff] [blame] | 6426 | * </ul> |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6427 | * |
| 6428 | * @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] | 6429 | * @throws SecurityException if {@code admin} is not a profile owner. |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6430 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6431 | public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6432 | throwIfParentInstance("getParentProfileInstance"); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6433 | try { |
| 6434 | if (!mService.isManagedProfile(admin)) { |
| 6435 | throw new SecurityException("The current user does not have a parent profile."); |
| 6436 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6437 | return new DevicePolicyManager(mContext, mService, true); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6438 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6439 | throw e.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6440 | } |
| 6441 | } |
| 6442 | |
| 6443 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6444 | * Called by device owner to control the security logging feature. Logging can only be |
| 6445 | * enabled on single user devices where the sole user is managed by the device owner. |
| 6446 | * |
| 6447 | * <p> Security logs contain various information intended for security auditing purposes. |
| 6448 | * See {@link SecurityEvent} for details. |
| 6449 | * |
| 6450 | * <p>There must be only one user on the device, managed by the device owner. |
| 6451 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6452 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6453 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6454 | * @param enabled whether security logging should be enabled or not. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6455 | * @throws SecurityException if {@code admin} is not a device owner. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6456 | * @see #retrieveSecurityLogs |
| 6457 | */ |
| 6458 | public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6459 | throwIfParentInstance("setSecurityLoggingEnabled"); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6460 | try { |
| 6461 | mService.setSecurityLoggingEnabled(admin, enabled); |
| 6462 | } catch (RemoteException re) { |
| 6463 | throw re.rethrowFromSystemServer(); |
| 6464 | } |
| 6465 | } |
| 6466 | |
| 6467 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6468 | * Return whether security logging is enabled or not by the device owner. |
| 6469 | * |
| 6470 | * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be |
| 6471 | * thrown. |
| 6472 | * |
| 6473 | * @param admin Which device owner this request is associated with. |
| 6474 | * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise. |
| 6475 | * @throws SecurityException if {@code admin} is not a device owner. |
| 6476 | */ |
| 6477 | public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6478 | throwIfParentInstance("isSecurityLoggingEnabled"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6479 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6480 | return mService.isSecurityLoggingEnabled(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6481 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6482 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | /** |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6487 | * Called by device owner to retrieve all new security logging entries since the last call to |
| 6488 | * this API after device boots. |
| 6489 | * |
| 6490 | * <p> Access to the logs is rate limited and it will only return new logs after the device |
| 6491 | * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}. |
| 6492 | * |
| 6493 | * <p>There must be only one user on the device, managed by the device owner. |
| 6494 | * Otherwise a {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6495 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6496 | * @param admin Which device owner this request is associated with. |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6497 | * @return the new batch of security logs which is a list of {@link SecurityEvent}, |
| 6498 | * or {@code null} if rate limitation is exceeded or if logging is currently disabled. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6499 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6500 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6501 | public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6502 | throwIfParentInstance("retrieveSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6503 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6504 | ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6505 | if (list != null) { |
| 6506 | return list.getList(); |
| 6507 | } else { |
| 6508 | // Rate limit exceeded. |
| 6509 | return null; |
| 6510 | } |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6511 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6512 | throw re.rethrowFromSystemServer(); |
Clara Bayarri | 3e826ef | 2015-12-14 17:51:22 +0000 | [diff] [blame] | 6513 | } |
| 6514 | } |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6515 | |
| 6516 | /** |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6517 | * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent |
| 6518 | * profile. |
| 6519 | * |
| 6520 | * @hide |
| 6521 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6522 | public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) { |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6523 | mContext.checkSelfPermission( |
| 6524 | android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); |
| 6525 | if (!uInfo.isManagedProfile()) { |
| 6526 | throw new SecurityException("The user " + uInfo.id |
| 6527 | + " does not have a parent profile."); |
| 6528 | } |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 6529 | return new DevicePolicyManager(mContext, mService, true); |
Sudheer Shanka | 978fc0d | 2016-01-28 13:51:10 +0000 | [diff] [blame] | 6530 | } |
| 6531 | |
| 6532 | /** |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6533 | * 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] | 6534 | * <p> |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6535 | * <strong> This API is not supported on all devices. Calling this API on unsupported devices |
| 6536 | * will result in {@code null} being returned. The device logs are retrieved from a RAM region |
| 6537 | * which is not guaranteed to be corruption-free during power cycles, as a result be cautious |
| 6538 | * about data corruption when parsing. </strong> |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6539 | * <p> |
| 6540 | * There must be only one user on the device, managed by the device owner. Otherwise a |
| 6541 | * {@link SecurityException} will be thrown. |
Michal Karpinski | b58e496 | 2016-03-01 14:55:10 +0000 | [diff] [blame] | 6542 | * |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6543 | * @param admin Which device owner this request is associated with. |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6544 | * @return Device logs from before the latest reboot of the system, or {@code null} if this API |
| 6545 | * is not supported on the device. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6546 | * @throws SecurityException if {@code admin} is not a device owner. |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6547 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6548 | public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs( |
| 6549 | @NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6550 | throwIfParentInstance("retrievePreRebootSecurityLogs"); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6551 | try { |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 6552 | ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin); |
Rubin Xu | 0fb6b9e | 2016-05-04 19:01:07 +0100 | [diff] [blame] | 6553 | if (list != null) { |
| 6554 | return list.getList(); |
| 6555 | } else { |
| 6556 | return null; |
| 6557 | } |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6558 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6559 | throw re.rethrowFromSystemServer(); |
Rubin Xu | c3cd05f | 2016-01-11 12:11:35 +0000 | [diff] [blame] | 6560 | } |
| 6561 | } |
| 6562 | |
| 6563 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6564 | * Called by a profile owner of a managed profile to set the color used for customization. This |
| 6565 | * 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] | 6566 | * default color is teal (#00796B). |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6567 | * <p> |
| 6568 | * The confirm credentials screen can be created using |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6569 | * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}. |
| 6570 | * |
| 6571 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6572 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6573 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6574 | */ |
| 6575 | public void setOrganizationColor(@NonNull ComponentName admin, int color) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6576 | throwIfParentInstance("setOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6577 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6578 | // always enforce alpha channel to have 100% opacity |
| 6579 | color |= 0xFF000000; |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6580 | mService.setOrganizationColor(admin, color); |
| 6581 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6582 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6583 | } |
| 6584 | } |
| 6585 | |
| 6586 | /** |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6587 | * @hide |
| 6588 | * |
| 6589 | * Sets the color used for customization. |
| 6590 | * |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6591 | * @param color The 24bit (0xRRGGBB) representation of the color to be used. |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6592 | * @param userId which user to set the color to. |
| 6593 | * @RequiresPermission(allOf = { |
| 6594 | * Manifest.permission.MANAGE_USERS, |
| 6595 | * Manifest.permission.INTERACT_ACROSS_USERS_FULL}) |
| 6596 | */ |
| 6597 | public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) { |
| 6598 | try { |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6599 | // always enforce alpha channel to have 100% opacity |
| 6600 | color |= 0xFF000000; |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6601 | mService.setOrganizationColorForUser(color, userId); |
| 6602 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6603 | throw re.rethrowFromSystemServer(); |
Nicolas Prevot | 8f7698a | 2016-02-11 16:05:33 +0000 | [diff] [blame] | 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | /** |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6608 | * Called by a profile owner of a managed profile to retrieve the color used for customization. |
| 6609 | * This color is used as background color of the confirm credentials screen for that user. |
| 6610 | * |
| 6611 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6612 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6613 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6614 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6615 | public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6616 | throwIfParentInstance("getOrganizationColor"); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6617 | try { |
| 6618 | return mService.getOrganizationColor(admin); |
| 6619 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6620 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6621 | } |
| 6622 | } |
| 6623 | |
| 6624 | /** |
| 6625 | * @hide |
| 6626 | * Retrieve the customization color for a given user. |
| 6627 | * |
| 6628 | * @param userHandle The user id of the user we're interested in. |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6629 | * @return The 24bit (0xRRGGBB) representation of the color to be used. |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6630 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6631 | public @ColorInt int getOrganizationColorForUser(int userHandle) { |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6632 | try { |
| 6633 | return mService.getOrganizationColorForUser(userHandle); |
| 6634 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6635 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 59720bb | 2016-01-18 15:26:11 +0000 | [diff] [blame] | 6636 | } |
| 6637 | } |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6638 | |
| 6639 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 6640 | * 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] | 6641 | * management. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6642 | * <p> |
| 6643 | * 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] | 6644 | * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast |
| 6645 | * and set a new version of this string accordingly. |
| 6646 | * |
| 6647 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6648 | * @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] | 6649 | * @throws SecurityException if {@code admin} is not a device or profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6650 | */ |
Michal Karpinski | 74cd730 | 2016-04-12 15:17:36 +0100 | [diff] [blame] | 6651 | public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6652 | throwIfParentInstance("setOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6653 | try { |
| 6654 | mService.setOrganizationName(admin, title); |
| 6655 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6656 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | /** |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6661 | * Called by a profile owner of a managed profile to retrieve the name of the organization under |
| 6662 | * management. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6663 | * |
| 6664 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6665 | * @return The organization name or {@code null} if none is set. |
Suprabh Shukla | 34d92ef | 2016-03-14 13:49:37 -0700 | [diff] [blame] | 6666 | * @throws SecurityException if {@code admin} is not a profile owner. |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6667 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6668 | public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6669 | throwIfParentInstance("getOrganizationName"); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6670 | try { |
| 6671 | return mService.getOrganizationName(admin); |
| 6672 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6673 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | /** |
Bartosz Fabianowski | 365a3db | 2016-11-30 18:28:10 +0100 | [diff] [blame] | 6678 | * Called by the system to retrieve the name of the organization managing the device. |
| 6679 | * |
| 6680 | * @return The organization name or {@code null} if none is set. |
| 6681 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 6682 | * MANAGE_USERS permission and is not the system. |
| 6683 | * |
| 6684 | * @hide |
| 6685 | */ |
| 6686 | @SystemApi |
| 6687 | @TestApi |
| 6688 | public @Nullable CharSequence getDeviceOwnerOrganizationName() { |
| 6689 | try { |
| 6690 | return mService.getDeviceOwnerOrganizationName(); |
| 6691 | } catch (RemoteException re) { |
| 6692 | throw re.rethrowFromSystemServer(); |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | /** |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6697 | * Retrieve the default title message used in the confirm credentials screen for a given user. |
| 6698 | * |
| 6699 | * @param userHandle The user id of the user we're interested in. |
| 6700 | * @return The organization name or {@code null} if none is set. |
| 6701 | * |
| 6702 | * @hide |
| 6703 | */ |
Makoto Onuki | 408e8e4 | 2016-10-25 12:10:27 -0700 | [diff] [blame] | 6704 | public @Nullable CharSequence getOrganizationNameForUser(int userHandle) { |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6705 | try { |
| 6706 | return mService.getOrganizationNameForUser(userHandle); |
| 6707 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6708 | throw re.rethrowFromSystemServer(); |
Benjamin Franz | 3e8a709 | 2016-01-25 16:19:08 +0000 | [diff] [blame] | 6709 | } |
| 6710 | } |
| 6711 | |
| 6712 | /** |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6713 | * @return the {@link UserProvisioningState} for the current user - for unmanaged users will |
| 6714 | * return {@link #STATE_USER_UNMANAGED} |
| 6715 | * @hide |
| 6716 | */ |
Benjamin Franz | eed2a8e | 2016-02-19 14:19:05 +0000 | [diff] [blame] | 6717 | @SystemApi |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6718 | @UserProvisioningState |
| 6719 | public int getUserProvisioningState() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6720 | throwIfParentInstance("getUserProvisioningState"); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6721 | if (mService != null) { |
| 6722 | try { |
| 6723 | return mService.getUserProvisioningState(); |
| 6724 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6725 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6726 | } |
| 6727 | } |
| 6728 | return STATE_USER_UNMANAGED; |
| 6729 | } |
| 6730 | |
| 6731 | /** |
| 6732 | * Set the {@link UserProvisioningState} for the supplied user, if they are managed. |
| 6733 | * |
| 6734 | * @param state to store |
| 6735 | * @param userHandle for user |
| 6736 | * @hide |
| 6737 | */ |
| 6738 | public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) { |
| 6739 | if (mService != null) { |
| 6740 | try { |
| 6741 | mService.setUserProvisioningState(state, userHandle); |
| 6742 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6743 | throw e.rethrowFromSystemServer(); |
Alan Treadway | afad878 | 2016-01-19 15:15:08 +0000 | [diff] [blame] | 6744 | } |
| 6745 | } |
| 6746 | } |
| 6747 | |
| 6748 | /** |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6749 | * Indicates the entity that controls the device or profile owner. Two users/profiles are |
| 6750 | * 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] | 6751 | * |
| 6752 | * @param admin Which profile or device owner this request is associated with. |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6753 | * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored. |
| 6754 | * |
| 6755 | * @throws NullPointerException if {@code ids} is null or contains null elements. |
| 6756 | * @throws IllegalArgumentException if {@code ids} contains an empty string. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6757 | */ |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6758 | public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6759 | throwIfParentInstance("setAffiliationIds"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6760 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6761 | mService.setAffiliationIds(admin, ids); |
| 6762 | } catch (RemoteException e) { |
| 6763 | throw e.rethrowFromSystemServer(); |
| 6764 | } |
| 6765 | } |
| 6766 | |
| 6767 | /** |
| 6768 | * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an |
| 6769 | * empty list if none have been set. |
| 6770 | */ |
| 6771 | public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) { |
| 6772 | throwIfParentInstance("getAffiliationIds"); |
| 6773 | try { |
| 6774 | return mService.getAffiliationIds(admin); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6775 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6776 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | /** |
| 6781 | * @hide |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6782 | * Returns whether this user/profile is affiliated with the device. |
| 6783 | * <p> |
| 6784 | * By definition, the user that the device owner runs on is always affiliated with the device. |
| 6785 | * Any other user/profile is considered affiliated with the device if the set specified by its |
| 6786 | * profile owner via {@link #setAffiliationIds} intersects with the device owner's. |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6787 | * |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6788 | */ |
| 6789 | public boolean isAffiliatedUser() { |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6790 | throwIfParentInstance("isAffiliatedUser"); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6791 | try { |
Esteban Talavera | c9bb378 | 2016-11-11 15:41:14 +0000 | [diff] [blame] | 6792 | return mService.isAffiliatedUser(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6793 | } catch (RemoteException e) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6794 | throw e.rethrowFromSystemServer(); |
Bartosz Fabianowski | 4c052f2 | 2016-01-25 14:18:43 +0100 | [diff] [blame] | 6795 | } |
| 6796 | } |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6797 | |
| 6798 | /** |
| 6799 | * @hide |
| 6800 | * Returns whether the uninstall for {@code packageName} for the current user is in queue |
| 6801 | * to be started |
| 6802 | * @param packageName the package to check for |
| 6803 | * @return whether the uninstall intent for {@code packageName} is pending |
| 6804 | */ |
| 6805 | public boolean isUninstallInQueue(String packageName) { |
| 6806 | try { |
| 6807 | return mService.isUninstallInQueue(packageName); |
| 6808 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6809 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6810 | } |
| 6811 | } |
| 6812 | |
| 6813 | /** |
| 6814 | * @hide |
| 6815 | * @param packageName the package containing active DAs to be uninstalled |
| 6816 | */ |
| 6817 | public void uninstallPackageWithActiveAdmins(String packageName) { |
| 6818 | try { |
| 6819 | mService.uninstallPackageWithActiveAdmins(packageName); |
| 6820 | } catch (RemoteException re) { |
Jeff Sharkey | dbff9ca | 2016-03-01 19:46:25 -0700 | [diff] [blame] | 6821 | throw re.rethrowFromSystemServer(); |
Suprabh Shukla | a2ae223 | 2016-01-28 18:05:14 -0800 | [diff] [blame] | 6822 | } |
| 6823 | } |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6824 | |
Kenny Guy | 38dcca5 | 2016-04-19 13:09:18 +0100 | [diff] [blame] | 6825 | /** |
| 6826 | * @hide |
| 6827 | * Remove a test admin synchronously without sending it a broadcast about being removed. |
| 6828 | * If the admin is a profile owner or device owner it will still be removed. |
| 6829 | * |
| 6830 | * @param userHandle user id to remove the admin for. |
| 6831 | * @param admin The administration compononent to remove. |
| 6832 | * @throws SecurityException if the caller is not shell / root or the admin package |
| 6833 | * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}. |
| 6834 | */ |
| 6835 | public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 6836 | try { |
| 6837 | mService.forceRemoveActiveAdmin(adminReceiver, userHandle); |
| 6838 | } catch (RemoteException re) { |
| 6839 | throw re.rethrowFromSystemServer(); |
| 6840 | } |
| 6841 | } |
| 6842 | |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 6843 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 6844 | * Returns whether the device has been provisioned. |
| 6845 | * |
| 6846 | * <p>Not for use by third-party applications. |
| 6847 | * |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 6848 | * @hide |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 6849 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 6850 | @SystemApi |
Mahaver Chopra | 790d198 | 2016-07-07 16:06:49 +0100 | [diff] [blame] | 6851 | public boolean isDeviceProvisioned() { |
| 6852 | try { |
| 6853 | return mService.isDeviceProvisioned(); |
| 6854 | } catch (RemoteException re) { |
| 6855 | throw re.rethrowFromSystemServer(); |
| 6856 | } |
| 6857 | } |
| 6858 | |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 6859 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 6860 | * Writes that the provisioning configuration has been applied. |
| 6861 | * |
| 6862 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} |
| 6863 | * permission. |
| 6864 | * |
| 6865 | * <p>Not for use by third-party applications. |
| 6866 | * |
| 6867 | * @hide |
| 6868 | */ |
| 6869 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 6870 | public void setDeviceProvisioningConfigApplied() { |
| 6871 | try { |
| 6872 | mService.setDeviceProvisioningConfigApplied(); |
| 6873 | } catch (RemoteException re) { |
| 6874 | throw re.rethrowFromSystemServer(); |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | /** |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 6879 | * Returns whether the provisioning configuration has been applied. |
| 6880 | * |
| 6881 | * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 6882 | * |
| 6883 | * <p>Not for use by third-party applications. |
| 6884 | * |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 6885 | * @return whether the provisioning configuration has been applied. |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 6886 | * |
| 6887 | * @hide |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 6888 | */ |
Lenka Trochtova | 5291ee7 | 2016-11-28 16:38:23 +0100 | [diff] [blame] | 6889 | @SystemApi |
Benjamin Franz | 2aa9bab | 2016-07-11 19:10:36 +0100 | [diff] [blame] | 6890 | public boolean isDeviceProvisioningConfigApplied() { |
| 6891 | try { |
| 6892 | return mService.isDeviceProvisioningConfigApplied(); |
| 6893 | } catch (RemoteException re) { |
| 6894 | throw re.rethrowFromSystemServer(); |
| 6895 | } |
| 6896 | } |
| 6897 | |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 6898 | /** |
| 6899 | * @hide |
Victor Chang | 3577ed2 | 2016-08-25 18:49:26 +0100 | [diff] [blame] | 6900 | * Force update user setup completed status. This API has no effect on user build. |
| 6901 | * @throws {@link SecurityException} if the caller has no |
| 6902 | * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is |
| 6903 | * not {@link UserHandle.SYSTEM_USER} |
Victor Chang | 9bfc65f | 2016-08-15 12:27:09 +0100 | [diff] [blame] | 6904 | */ |
| 6905 | public void forceUpdateUserSetupComplete() { |
| 6906 | try { |
| 6907 | mService.forceUpdateUserSetupComplete(); |
| 6908 | } catch (RemoteException re) { |
| 6909 | throw re.rethrowFromSystemServer(); |
| 6910 | } |
| 6911 | } |
| 6912 | |
Benjamin Franz | bc33c82 | 2016-04-15 08:57:52 +0100 | [diff] [blame] | 6913 | private void throwIfParentInstance(String functionName) { |
| 6914 | if (mParentInstance) { |
| 6915 | throw new SecurityException(functionName + " cannot be called on the parent instance"); |
| 6916 | } |
| 6917 | } |
Vladislav Kuzkokov | a820252 | 2016-08-18 19:01:27 +0200 | [diff] [blame] | 6918 | |
| 6919 | /** |
| 6920 | * @hide |
| 6921 | * Enable backup service. |
| 6922 | * <p>This includes all backup and restore mechanisms. |
| 6923 | * Setting this to {@code false} will make backup service no-op or return empty results. |
| 6924 | * |
| 6925 | * <p>There must be only one user on the device, managed by the device owner. |
| 6926 | * Otherwise a {@link SecurityException} will be thrown. |
| 6927 | * |
| 6928 | * <p>Backup service is off by default when device owner is present. |
| 6929 | */ |
| 6930 | public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 6931 | try { |
| 6932 | mService.setBackupServiceEnabled(admin, enabled); |
| 6933 | } catch (RemoteException re) { |
| 6934 | throw re.rethrowFromSystemServer(); |
| 6935 | } |
| 6936 | } |
| 6937 | |
| 6938 | /** |
| 6939 | * @hide |
| 6940 | * @return {@code true} if backup service is enabled, {@code false} otherwise. |
| 6941 | */ |
| 6942 | public boolean isBackupServiceEnabled(@NonNull ComponentName admin) { |
| 6943 | try { |
| 6944 | return mService.isBackupServiceEnabled(admin); |
| 6945 | } catch (RemoteException re) { |
| 6946 | throw re.rethrowFromSystemServer(); |
| 6947 | } |
| 6948 | } |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 6949 | |
| 6950 | /** |
| 6951 | * Called by a device owner to control the network logging feature. Logging can only be |
| 6952 | * enabled on single user devices where the sole user is managed by the device owner. If a new |
| 6953 | * user is added on the device, logging is disabled. |
| 6954 | * |
| 6955 | * <p> Network logs contain DNS lookup and connect() library call events. |
| 6956 | * |
| 6957 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 6958 | * @param enabled whether network logging should be enabled or not. |
| 6959 | * @throws {@link SecurityException} if {@code admin} is not a device owner. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6960 | * @see #retrieveNetworkLogs |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 6961 | */ |
| 6962 | public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) { |
| 6963 | throwIfParentInstance("setNetworkLoggingEnabled"); |
| 6964 | try { |
| 6965 | mService.setNetworkLoggingEnabled(admin, enabled); |
| 6966 | } catch (RemoteException re) { |
| 6967 | throw re.rethrowFromSystemServer(); |
| 6968 | } |
| 6969 | } |
| 6970 | |
| 6971 | /** |
| 6972 | * Return whether network logging is enabled by a device owner. |
| 6973 | * |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 6974 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only |
| 6975 | * be {@code null} if the caller has MANAGE_USERS permission. |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 6976 | * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise. |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 6977 | * @throws {@link SecurityException} if {@code admin} is not a device owner and caller has |
| 6978 | * no MANAGE_USERS permission |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 6979 | */ |
phweiss | a4e169e | 2016-11-24 16:20:57 +0100 | [diff] [blame] | 6980 | public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) { |
Michal Karpinski | dd9bb4f | 2016-10-12 14:59:26 +0100 | [diff] [blame] | 6981 | throwIfParentInstance("isNetworkLoggingEnabled"); |
| 6982 | try { |
| 6983 | return mService.isNetworkLoggingEnabled(admin); |
| 6984 | } catch (RemoteException re) { |
| 6985 | throw re.rethrowFromSystemServer(); |
| 6986 | } |
| 6987 | } |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6988 | |
| 6989 | /** |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 6990 | * Called by device owner to retrieve the most recent batch of network logging events. |
| 6991 | * A device owner has to provide a batchToken provided as part of |
| 6992 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the |
| 6993 | * token of the most recent available batch of logs, {@code null} will be returned. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 6994 | * |
| 6995 | * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}. |
| 6996 | * |
| 6997 | * <p> The list of network events is sorted chronologically, and contains at most 1200 events. |
| 6998 | * |
| 6999 | * <p> Access to the logs is rate limited and this method will only return a new batch of logs |
| 7000 | * after the device device owner has been notified via |
| 7001 | * {@link DeviceAdminReceiver#onNetworkLogsAvailable}. |
| 7002 | * |
| 7003 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7004 | * @param batchToken A token of the batch to retrieve |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7005 | * @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] | 7006 | * {@code null} if the batch represented by batchToken is no longer available or if |
| 7007 | * logging is disabled. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7008 | * @throws {@link SecurityException} if {@code admin} is not a device owner. |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7009 | * @see DeviceAdminReceiver#onNetworkLogsAvailable |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7010 | */ |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7011 | public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin, |
| 7012 | long batchToken) { |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7013 | throwIfParentInstance("retrieveNetworkLogs"); |
| 7014 | try { |
Michal Karpinski | a9ff206 | 2016-11-03 15:46:17 +0000 | [diff] [blame] | 7015 | return mService.retrieveNetworkLogs(admin, batchToken); |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 7016 | } catch (RemoteException re) { |
| 7017 | throw re.rethrowFromSystemServer(); |
| 7018 | } |
| 7019 | } |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7020 | |
| 7021 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7022 | * Called by a device owner to bind to a service from a profile owner of a managed profile or |
| 7023 | * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which |
| 7024 | * device/profile owners are allowed to bind to services of another profile/device owner. |
| 7025 | * <p> |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7026 | * The service must be unexported. Note that the {@link Context} used to obtain this |
| 7027 | * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used |
| 7028 | * to bind to the {@link android.app.Service}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7029 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7030 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 7031 | * @param serviceIntent Identifies the service to connect to. The Intent must specify either an |
| 7032 | * explicit component name or a package name to match an |
| 7033 | * {@link IntentFilter} published by a service. |
| 7034 | * @param conn Receives information as the service is started and stopped. This must be a |
| 7035 | * valid {@link ServiceConnection} object; it must not be {@code null}. |
| 7036 | * @param flags Operation options for the binding operation. See |
| 7037 | * {@link Context#bindService(Intent, ServiceConnection, int)}. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7038 | * @param targetUser Which user to bind to. Must be one of the users returned by |
| 7039 | * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will |
| 7040 | * be thrown. |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7041 | * @return If you have successfully bound to the service, {@code true} is returned; |
| 7042 | * {@code false} is returned if the connection is not made and you will not |
| 7043 | * receive the service object. |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7044 | * |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7045 | * @see Context#bindService(Intent, ServiceConnection, int) |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7046 | * @see #getBindDeviceAdminTargetUsers(ComponentName) |
Tony Mak | 46aabe5 | 2016-11-14 12:53:06 +0000 | [diff] [blame] | 7047 | */ |
| 7048 | public boolean bindDeviceAdminServiceAsUser( |
| 7049 | @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn, |
| 7050 | @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) { |
| 7051 | throwIfParentInstance("bindDeviceAdminServiceAsUser"); |
| 7052 | // Keep this in sync with ContextImpl.bindServiceCommon. |
| 7053 | try { |
| 7054 | final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags); |
| 7055 | serviceIntent.prepareToLeaveProcess(mContext); |
| 7056 | return mService.bindDeviceAdminServiceAsUser(admin, |
| 7057 | mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent, |
| 7058 | sd, flags, targetUser.getIdentifier()); |
| 7059 | } catch (RemoteException re) { |
| 7060 | throw re.rethrowFromSystemServer(); |
| 7061 | } |
| 7062 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7063 | |
| 7064 | /** |
Esteban Talavera | fc291bc | 2016-11-21 13:52:03 +0000 | [diff] [blame] | 7065 | * Returns the list of target users that the calling device or profile owner can use when |
| 7066 | * calling {@link #bindDeviceAdminServiceAsUser}. |
| 7067 | * <p> |
| 7068 | * A device owner can bind to a service from a profile owner of a managed profile and |
| 7069 | * vice versa, provided that: |
| 7070 | * <ul> |
| 7071 | * <li>Both belong to the same package name. |
| 7072 | * <li>The managed profile is a profile of the user where the device owner is set. |
| 7073 | * See {@link UserManager#getUserProfiles()} |
| 7074 | * <li>Both users are affiliated. |
| 7075 | * STOPSHIP(b/32326223) Add reference to setAffiliationIds here once public. |
| 7076 | * </ul> |
| 7077 | */ |
| 7078 | public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) { |
| 7079 | throwIfParentInstance("getBindDeviceAdminTargetUsers"); |
| 7080 | try { |
| 7081 | return mService.getBindDeviceAdminTargetUsers(admin); |
| 7082 | } catch (RemoteException re) { |
| 7083 | throw re.rethrowFromSystemServer(); |
| 7084 | } |
| 7085 | } |
| 7086 | |
| 7087 | /** |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7088 | * Called by the system to get the time at which the device owner last retrieved security |
| 7089 | * logging entries. |
| 7090 | * |
| 7091 | * @return the time at which the device owner most recently retrieved security logging entries, |
| 7092 | * in milliseconds since epoch; -1 if security logging entries were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7093 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7094 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7095 | * |
| 7096 | * @hide |
| 7097 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7098 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7099 | public long getLastSecurityLogRetrievalTime() { |
| 7100 | try { |
| 7101 | return mService.getLastSecurityLogRetrievalTime(); |
| 7102 | } catch (RemoteException re) { |
| 7103 | throw re.rethrowFromSystemServer(); |
| 7104 | } |
| 7105 | } |
| 7106 | |
| 7107 | /** |
| 7108 | * Called by the system to get the time at which the device owner last requested a bug report. |
| 7109 | * |
| 7110 | * @return the time at which the device owner most recently requested a bug report, in |
| 7111 | * milliseconds since epoch; -1 if a bug report was never requested. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7112 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7113 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7114 | * |
| 7115 | * @hide |
| 7116 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7117 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7118 | public long getLastBugReportRequestTime() { |
| 7119 | try { |
| 7120 | return mService.getLastBugReportRequestTime(); |
| 7121 | } catch (RemoteException re) { |
| 7122 | throw re.rethrowFromSystemServer(); |
| 7123 | } |
| 7124 | } |
| 7125 | |
| 7126 | /** |
| 7127 | * Called by the system to get the time at which the device owner last retrieved network logging |
| 7128 | * events. |
| 7129 | * |
| 7130 | * @return the time at which the device owner most recently retrieved network logging events, in |
| 7131 | * milliseconds since epoch; -1 if network logging events were never retrieved. |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7132 | * @throws SecurityException if the caller is not the device owner, does not hold the |
| 7133 | * MANAGE_USERS permission and is not the system. |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7134 | * |
| 7135 | * @hide |
| 7136 | */ |
Bartosz Fabianowski | 8d76e72 | 2016-11-25 12:36:20 +0100 | [diff] [blame] | 7137 | @TestApi |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 7138 | public long getLastNetworkLogRetrievalTime() { |
| 7139 | try { |
| 7140 | return mService.getLastNetworkLogRetrievalTime(); |
| 7141 | } catch (RemoteException re) { |
| 7142 | throw re.rethrowFromSystemServer(); |
| 7143 | } |
| 7144 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 7145 | } |